mirror of
https://github.com/brain-hackers/linux-brain.git
synced 2024-06-09 23:36:23 +09:00
mm: replace get_user_pages_unlocked() write/force parameters with gup_flags
commit c164154f66
upstream.
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: Lorenzo Stoakes <lstoakes@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[bwh: Backported to 4.4:
- Also update calls from process_vm_rw_single_vec() and async_pf_execute()
- Adjust context]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ff099ed774
commit
2b29980eb7
|
@ -303,7 +303,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
|
||||||
|
|
||||||
ret = get_user_pages_unlocked(current, mm, start,
|
ret = get_user_pages_unlocked(current, mm, 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) {
|
||||||
|
|
|
@ -242,7 +242,7 @@ 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(current, mm, start,
|
ret = get_user_pages_unlocked(current, mm, start,
|
||||||
nr_pages - nr, write, 0, pages);
|
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,
|
||||||
pages += nr;
|
pages += nr;
|
||||||
|
|
||||||
ret = get_user_pages_unlocked(current, mm, start,
|
ret = get_user_pages_unlocked(current, mm, 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) {
|
||||||
|
|
|
@ -250,7 +250,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
|
||||||
pages += nr;
|
pages += nr;
|
||||||
|
|
||||||
ret = get_user_pages_unlocked(current, mm, start,
|
ret = get_user_pages_unlocked(current, mm, 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) {
|
||||||
|
|
|
@ -388,7 +388,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
|
||||||
|
|
||||||
ret = get_user_pages_unlocked(current, mm, start,
|
ret = get_user_pages_unlocked(current, mm, 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) {
|
||||||
|
|
|
@ -125,7 +125,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(current, current->mm,
|
err = get_user_pages_unlocked(current, current->mm,
|
||||||
user_dma.uaddr, user_dma.page_count, 0, 1, dma->map);
|
user_dma.uaddr, user_dma.page_count, 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,13 +76,13 @@ 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(current, current->mm,
|
y_pages = get_user_pages_unlocked(current, current->mm,
|
||||||
y_dma.uaddr, y_dma.page_count, 0, 1,
|
y_dma.uaddr, y_dma.page_count,
|
||||||
&dma->map[0]);
|
&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(current, current->mm,
|
uv_pages = get_user_pages_unlocked(current, current->mm,
|
||||||
uv_dma.uaddr, uv_dma.page_count, 0, 1,
|
uv_dma.uaddr, uv_dma.page_count,
|
||||||
&dma->map[y_pages]);
|
&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) {
|
||||||
|
|
|
@ -4821,9 +4821,8 @@ static int sgl_map_user_pages(struct st_buffer *STbp,
|
||||||
current->mm,
|
current->mm,
|
||||||
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)
|
||||||
|
|
|
@ -687,7 +687,7 @@ static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = get_user_pages_unlocked(current, current->mm, (unsigned long)buf,
|
ret = get_user_pages_unlocked(current, current->mm, (unsigned long)buf,
|
||||||
nr_pages, WRITE, 0, pages);
|
nr_pages, pages, FOLL_WRITE);
|
||||||
|
|
||||||
if (ret < nr_pages) {
|
if (ret < nr_pages) {
|
||||||
nr_pages = ret;
|
nr_pages = ret;
|
||||||
|
|
|
@ -1210,7 +1210,7 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
|
||||||
struct page **pages, unsigned int gup_flags);
|
struct page **pages, unsigned int gup_flags);
|
||||||
long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
|
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,
|
||||||
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);
|
||||||
|
|
||||||
|
|
14
mm/gup.c
14
mm/gup.c
|
@ -797,17 +797,10 @@ EXPORT_SYMBOL(__get_user_pages_unlocked);
|
||||||
*/
|
*/
|
||||||
long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
|
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,
|
||||||
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(tsk, mm, start, nr_pages,
|
return __get_user_pages_unlocked(tsk, mm, start, nr_pages,
|
||||||
pages, flags);
|
pages, gup_flags | FOLL_TOUCH);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(get_user_pages_unlocked);
|
EXPORT_SYMBOL(get_user_pages_unlocked);
|
||||||
|
|
||||||
|
@ -1427,7 +1420,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
|
||||||
pages += nr;
|
pages += nr;
|
||||||
|
|
||||||
ret = get_user_pages_unlocked(current, mm, start,
|
ret = get_user_pages_unlocked(current, mm, start,
|
||||||
nr_pages - nr, write, 0, pages);
|
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) {
|
||||||
|
|
11
mm/nommu.c
11
mm/nommu.c
|
@ -224,17 +224,10 @@ EXPORT_SYMBOL(__get_user_pages_unlocked);
|
||||||
|
|
||||||
long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
|
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,
|
||||||
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(tsk, mm, start, nr_pages,
|
return __get_user_pages_unlocked(tsk, mm, start, nr_pages,
|
||||||
pages, flags);
|
pages, gup_flags);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(get_user_pages_unlocked);
|
EXPORT_SYMBOL(get_user_pages_unlocked);
|
||||||
|
|
||||||
|
|
|
@ -88,19 +88,23 @@ static int process_vm_rw_single_vec(unsigned long addr,
|
||||||
ssize_t rc = 0;
|
ssize_t rc = 0;
|
||||||
unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES
|
unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES
|
||||||
/ sizeof(struct pages *);
|
/ sizeof(struct pages *);
|
||||||
|
unsigned int flags = 0;
|
||||||
|
|
||||||
/* Work out address and page range required */
|
/* Work out address and page range required */
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1;
|
nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1;
|
||||||
|
|
||||||
|
if (vm_write)
|
||||||
|
flags |= FOLL_WRITE;
|
||||||
|
|
||||||
while (!rc && nr_pages && iov_iter_count(iter)) {
|
while (!rc && nr_pages && iov_iter_count(iter)) {
|
||||||
int pages = min(nr_pages, max_pages_per_loop);
|
int pages = min(nr_pages, max_pages_per_loop);
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
|
|
||||||
/* Get the pages we're interested in */
|
/* Get the pages we're interested in */
|
||||||
pages = get_user_pages_unlocked(task, mm, pa, pages,
|
pages = get_user_pages_unlocked(task, mm, pa, pages,
|
||||||
vm_write, 0, process_pages);
|
process_pages, flags);
|
||||||
if (pages <= 0)
|
if (pages <= 0)
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
|
|
|
@ -278,7 +278,7 @@ int __weak get_user_pages_fast(unsigned long start,
|
||||||
{
|
{
|
||||||
struct mm_struct *mm = current->mm;
|
struct mm_struct *mm = current->mm;
|
||||||
return get_user_pages_unlocked(current, mm, start, nr_pages,
|
return get_user_pages_unlocked(current, mm, start, nr_pages,
|
||||||
write, 0, 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,
|
||||||
while (got < num_pages) {
|
while (got < num_pages) {
|
||||||
rc = get_user_pages_unlocked(current, current->mm,
|
rc = get_user_pages_unlocked(current, current->mm,
|
||||||
(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);
|
||||||
|
|
|
@ -80,7 +80,7 @@ static void async_pf_execute(struct work_struct *work)
|
||||||
|
|
||||||
might_sleep();
|
might_sleep();
|
||||||
|
|
||||||
get_user_pages_unlocked(NULL, mm, addr, 1, 1, 0, NULL);
|
get_user_pages_unlocked(NULL, mm, addr, 1, NULL, FOLL_WRITE);
|
||||||
kvm_async_page_present_sync(vcpu, apf);
|
kvm_async_page_present_sync(vcpu, apf);
|
||||||
|
|
||||||
spin_lock(&vcpu->async_pf.lock);
|
spin_lock(&vcpu->async_pf.lock);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user