Commit 859110d7 authored by Lorenzo Stoakes's avatar Lorenzo Stoakes Committed by Linus Torvalds

mm: remove write/force parameters from __get_user_pages_locked()

This removes the redundant 'write' and 'force' parameters from
__get_user_pages_locked() to make the use of FOLL_FORCE explicit in
callers as use of this flag can result in surprising behaviour (and
hence bugs) within the mm subsystem.
Signed-off-by: default avatarLorenzo Stoakes <lstoakes@gmail.com>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 19be0eaf
...@@ -739,7 +739,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, ...@@ -739,7 +739,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
struct mm_struct *mm, struct mm_struct *mm,
unsigned long start, unsigned long start,
unsigned long nr_pages, unsigned long nr_pages,
int write, int force,
struct page **pages, struct page **pages,
struct vm_area_struct **vmas, struct vm_area_struct **vmas,
int *locked, bool notify_drop, int *locked, bool notify_drop,
...@@ -757,10 +756,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, ...@@ -757,10 +756,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
if (pages) if (pages)
flags |= FOLL_GET; flags |= FOLL_GET;
if (write)
flags |= FOLL_WRITE;
if (force)
flags |= FOLL_FORCE;
pages_done = 0; pages_done = 0;
lock_dropped = false; lock_dropped = false;
...@@ -856,9 +851,15 @@ long get_user_pages_locked(unsigned long start, unsigned long nr_pages, ...@@ -856,9 +851,15 @@ long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
int write, int force, struct page **pages, int write, int force, struct page **pages,
int *locked) int *locked)
{ {
unsigned int flags = FOLL_TOUCH;
if (write)
flags |= FOLL_WRITE;
if (force)
flags |= FOLL_FORCE;
return __get_user_pages_locked(current, current->mm, start, nr_pages, return __get_user_pages_locked(current, current->mm, start, nr_pages,
write, force, pages, NULL, locked, true, pages, NULL, locked, true, flags);
FOLL_TOUCH);
} }
EXPORT_SYMBOL(get_user_pages_locked); EXPORT_SYMBOL(get_user_pages_locked);
...@@ -879,9 +880,15 @@ __always_inline long __get_user_pages_unlocked(struct task_struct *tsk, struct m ...@@ -879,9 +880,15 @@ __always_inline long __get_user_pages_unlocked(struct task_struct *tsk, struct m
{ {
long ret; long ret;
int locked = 1; int locked = 1;
if (write)
gup_flags |= FOLL_WRITE;
if (force)
gup_flags |= FOLL_FORCE;
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
ret = __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, ret = __get_user_pages_locked(tsk, mm, start, nr_pages, pages, NULL,
pages, NULL, &locked, false, gup_flags); &locked, false, gup_flags);
if (locked) if (locked)
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return ret; return ret;
...@@ -973,9 +980,15 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm, ...@@ -973,9 +980,15 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
int write, int force, struct page **pages, int write, int force, struct page **pages,
struct vm_area_struct **vmas) struct vm_area_struct **vmas)
{ {
return __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, unsigned int flags = FOLL_TOUCH | FOLL_REMOTE;
pages, vmas, NULL, false,
FOLL_TOUCH | FOLL_REMOTE); if (write)
flags |= FOLL_WRITE;
if (force)
flags |= FOLL_FORCE;
return __get_user_pages_locked(tsk, mm, start, nr_pages, pages, vmas,
NULL, false, flags);
} }
EXPORT_SYMBOL(get_user_pages_remote); EXPORT_SYMBOL(get_user_pages_remote);
...@@ -989,9 +1002,15 @@ long get_user_pages(unsigned long start, unsigned long nr_pages, ...@@ -989,9 +1002,15 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,
int write, int force, struct page **pages, int write, int force, struct page **pages,
struct vm_area_struct **vmas) struct vm_area_struct **vmas)
{ {
unsigned int flags = FOLL_TOUCH;
if (write)
flags |= FOLL_WRITE;
if (force)
flags |= FOLL_FORCE;
return __get_user_pages_locked(current, current->mm, start, nr_pages, return __get_user_pages_locked(current, current->mm, start, nr_pages,
write, force, pages, vmas, NULL, false, pages, vmas, NULL, false, flags);
FOLL_TOUCH);
} }
EXPORT_SYMBOL(get_user_pages); EXPORT_SYMBOL(get_user_pages);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment