Commit c164154f authored by Lorenzo Stoakes's avatar Lorenzo Stoakes Committed by Linus Torvalds

mm: replace get_user_pages_unlocked() write/force parameters with gup_flags

This removes the 'write' and 'force' use from get_user_pages_unlocked()
and replaces them with 'gup_flags' 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 d4944b0e
...@@ -287,7 +287,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, ...@@ -287,7 +287,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
pages += nr; pages += nr;
ret = get_user_pages_unlocked(start, (end - start) >> PAGE_SHIFT, ret = get_user_pages_unlocked(start, (end - start) >> PAGE_SHIFT,
write, 0, pages); pages, write ? FOLL_WRITE : 0);
/* Have to be a bit careful with return values */ /* Have to be a bit careful with return values */
if (nr > 0) { if (nr > 0) {
......
...@@ -266,7 +266,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, ...@@ -266,7 +266,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
/* Try to get the remaining pages with get_user_pages */ /* Try to get the remaining pages with get_user_pages */
start += nr << PAGE_SHIFT; start += nr << PAGE_SHIFT;
pages += nr; pages += nr;
ret = get_user_pages_unlocked(start, nr_pages - nr, write, 0, pages); ret = get_user_pages_unlocked(start, nr_pages - nr, pages,
write ? FOLL_WRITE : 0);
/* Have to be a bit careful with return values */ /* Have to be a bit careful with return values */
if (nr > 0) if (nr > 0)
ret = (ret < 0) ? nr : ret + nr; ret = (ret < 0) ? nr : ret + nr;
......
...@@ -258,7 +258,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, ...@@ -258,7 +258,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
pages += nr; pages += nr;
ret = get_user_pages_unlocked(start, ret = get_user_pages_unlocked(start,
(end - start) >> PAGE_SHIFT, write, 0, pages); (end - start) >> PAGE_SHIFT, pages,
write ? FOLL_WRITE : 0);
/* Have to be a bit careful with return values */ /* Have to be a bit careful with return values */
if (nr > 0) { if (nr > 0) {
......
...@@ -238,7 +238,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, ...@@ -238,7 +238,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
pages += nr; pages += nr;
ret = get_user_pages_unlocked(start, ret = get_user_pages_unlocked(start,
(end - start) >> PAGE_SHIFT, write, 0, pages); (end - start) >> PAGE_SHIFT, pages,
write ? FOLL_WRITE : 0);
/* Have to be a bit careful with return values */ /* Have to be a bit careful with return values */
if (nr > 0) { if (nr > 0) {
......
...@@ -435,7 +435,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, ...@@ -435,7 +435,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
ret = get_user_pages_unlocked(start, ret = get_user_pages_unlocked(start,
(end - start) >> PAGE_SHIFT, (end - start) >> PAGE_SHIFT,
write, 0, pages); pages, write ? FOLL_WRITE : 0);
/* Have to be a bit careful with return values */ /* Have to be a bit careful with return values */
if (nr > 0) { if (nr > 0) {
......
...@@ -124,8 +124,8 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr, ...@@ -124,8 +124,8 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr,
} }
/* Get user pages for DMA Xfer */ /* Get user pages for DMA Xfer */
err = get_user_pages_unlocked(user_dma.uaddr, user_dma.page_count, 0, err = get_user_pages_unlocked(user_dma.uaddr, user_dma.page_count,
1, dma->map); dma->map, FOLL_FORCE);
if (user_dma.page_count != err) { if (user_dma.page_count != err) {
IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n", IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n",
......
...@@ -76,11 +76,12 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma, ...@@ -76,11 +76,12 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
/* Get user pages for DMA Xfer */ /* Get user pages for DMA Xfer */
y_pages = get_user_pages_unlocked(y_dma.uaddr, y_pages = get_user_pages_unlocked(y_dma.uaddr,
y_dma.page_count, 0, 1, &dma->map[0]); y_dma.page_count, &dma->map[0], FOLL_FORCE);
uv_pages = 0; /* silence gcc. value is set and consumed only if: */ uv_pages = 0; /* silence gcc. value is set and consumed only if: */
if (y_pages == y_dma.page_count) { if (y_pages == y_dma.page_count) {
uv_pages = get_user_pages_unlocked(uv_dma.uaddr, uv_pages = get_user_pages_unlocked(uv_dma.uaddr,
uv_dma.page_count, 0, 1, &dma->map[y_pages]); uv_dma.page_count, &dma->map[y_pages],
FOLL_FORCE);
} }
if (y_pages != y_dma.page_count || uv_pages != uv_dma.page_count) { if (y_pages != y_dma.page_count || uv_pages != uv_dma.page_count) {
......
...@@ -4922,9 +4922,8 @@ static int sgl_map_user_pages(struct st_buffer *STbp, ...@@ -4922,9 +4922,8 @@ static int sgl_map_user_pages(struct st_buffer *STbp,
res = get_user_pages_unlocked( res = get_user_pages_unlocked(
uaddr, uaddr,
nr_pages, nr_pages,
rw == READ, pages,
0, /* don't force */ rw == READ ? FOLL_WRITE : 0); /* don't force */
pages);
/* Errors and no page mapped should return here */ /* Errors and no page mapped should return here */
if (res < nr_pages) if (res < nr_pages)
......
...@@ -686,8 +686,8 @@ static ssize_t pvr2fb_write(struct fb_info *info, const char *buf, ...@@ -686,8 +686,8 @@ static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
if (!pages) if (!pages)
return -ENOMEM; return -ENOMEM;
ret = get_user_pages_unlocked((unsigned long)buf, nr_pages, WRITE, ret = get_user_pages_unlocked((unsigned long)buf, nr_pages, pages,
0, pages); FOLL_WRITE);
if (ret < nr_pages) { if (ret < nr_pages) {
nr_pages = ret; nr_pages = ret;
......
...@@ -1287,7 +1287,7 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, ...@@ -1287,7 +1287,7 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
unsigned long start, unsigned long nr_pages, unsigned long start, unsigned long nr_pages,
struct page **pages, unsigned int gup_flags); struct page **pages, unsigned int gup_flags);
long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
int write, int force, struct page **pages); struct page **pages, unsigned int gup_flags);
int get_user_pages_fast(unsigned long start, int nr_pages, int write, int get_user_pages_fast(unsigned long start, int nr_pages, int write,
struct page **pages); struct page **pages);
......
...@@ -907,17 +907,10 @@ EXPORT_SYMBOL(__get_user_pages_unlocked); ...@@ -907,17 +907,10 @@ EXPORT_SYMBOL(__get_user_pages_unlocked);
* "force" parameter). * "force" parameter).
*/ */
long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
int write, int force, struct page **pages) struct page **pages, unsigned int gup_flags)
{ {
unsigned int flags = FOLL_TOUCH;
if (write)
flags |= FOLL_WRITE;
if (force)
flags |= FOLL_FORCE;
return __get_user_pages_unlocked(current, current->mm, start, nr_pages, return __get_user_pages_unlocked(current, current->mm, start, nr_pages,
pages, flags); pages, gup_flags | FOLL_TOUCH);
} }
EXPORT_SYMBOL(get_user_pages_unlocked); EXPORT_SYMBOL(get_user_pages_unlocked);
...@@ -1535,7 +1528,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, ...@@ -1535,7 +1528,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
start += nr << PAGE_SHIFT; start += nr << PAGE_SHIFT;
pages += nr; pages += nr;
ret = get_user_pages_unlocked(start, nr_pages - nr, write, 0, pages); ret = get_user_pages_unlocked(start, nr_pages - nr, pages,
write ? FOLL_WRITE : 0);
/* Have to be a bit careful with return values */ /* Have to be a bit careful with return values */
if (nr > 0) { if (nr > 0) {
......
...@@ -197,17 +197,10 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, ...@@ -197,17 +197,10 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
EXPORT_SYMBOL(__get_user_pages_unlocked); EXPORT_SYMBOL(__get_user_pages_unlocked);
long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
int write, int force, struct page **pages) struct page **pages, unsigned int gup_flags)
{ {
unsigned int flags = 0;
if (write)
flags |= FOLL_WRITE;
if (force)
flags |= FOLL_FORCE;
return __get_user_pages_unlocked(current, current->mm, start, nr_pages, return __get_user_pages_unlocked(current, current->mm, start, nr_pages,
pages, flags); pages, gup_flags);
} }
EXPORT_SYMBOL(get_user_pages_unlocked); EXPORT_SYMBOL(get_user_pages_unlocked);
......
...@@ -283,7 +283,8 @@ EXPORT_SYMBOL_GPL(__get_user_pages_fast); ...@@ -283,7 +283,8 @@ EXPORT_SYMBOL_GPL(__get_user_pages_fast);
int __weak get_user_pages_fast(unsigned long start, int __weak get_user_pages_fast(unsigned long start,
int nr_pages, int write, struct page **pages) int nr_pages, int write, struct page **pages)
{ {
return get_user_pages_unlocked(start, nr_pages, write, 0, pages); return get_user_pages_unlocked(start, nr_pages, pages,
write ? FOLL_WRITE : 0);
} }
EXPORT_SYMBOL_GPL(get_user_pages_fast); EXPORT_SYMBOL_GPL(get_user_pages_fast);
......
...@@ -26,7 +26,7 @@ struct page **ceph_get_direct_page_vector(const void __user *data, ...@@ -26,7 +26,7 @@ struct page **ceph_get_direct_page_vector(const void __user *data,
while (got < num_pages) { while (got < num_pages) {
rc = get_user_pages_unlocked( rc = get_user_pages_unlocked(
(unsigned long)data + ((unsigned long)got * PAGE_SIZE), (unsigned long)data + ((unsigned long)got * PAGE_SIZE),
num_pages - got, write_page, 0, pages + got); num_pages - got, pages + got, write_page ? FOLL_WRITE : 0);
if (rc < 0) if (rc < 0)
break; break;
BUG_ON(rc == 0); BUG_ON(rc == 0);
......
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