mm: unexport __get_user_pages_unlocked()
Subsystems (16)
cover mm: unexport __get_user_pages_unlocked()
This patch series continues the cleanup of get_user_pages*() functions taking advantage of the fact we can now pass gup_flags as we please.
It firstly adds an additional 'locked' parameter to get_user_pages_remote() to allow for its callers to utilise VM_FAULT_RETRY functionality. This is necessary as the invocation of __get_user_pages_unlocked() in process_vm_rw_single_vec() makes use of this and no other existing higher level function would allow it to do so.
Secondly existing callers of __get_user_pages_unlocked() are replaced with the appropriate higher-level replacement - get_user_pages_unlocked() if the current task and memory descriptor are referenced, or get_user_pages_remote() if other task/memory descriptors are referenced (having acquiring mmap_sem.)
Lorenzo Stoakes (2):
mm: add locked parameter to get_user_pages_remote()
mm: unexport __get_user_pages_unlocked()
drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/i915_gem_userptr.c | 2 +- drivers/infiniband/core/umem_odp.c | 2 +- fs/exec.c | 2 +- include/linux/mm.h | 5 +---- kernel/events/uprobes.c | 4 ++-- mm/gup.c | 20 ++++++++++++-------- mm/memory.c | 2 +- mm/nommu.c | 7 +++---- mm/process_vm_access.c | 12 ++++++++---- security/tomoyo/domain.c | 2 +- virt/kvm/async_pf.c | 10 +++++++--- virt/kvm/kvm_main.c | 5 ++--- 13 files changed, 41 insertions(+), 34 deletions(-)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/2 mm: add locked parameter to get_user_pages_remote()
This patch adds a int *locked parameter to get_user_pages_remote() to allow VM_FAULT_RETRY faulting behaviour similar to get_user_pages_[un]locked().
Taking into account the previous adjustments to get_user_pages*() functions allowing for the passing of gup_flags, we are now in a position where __get_user_pages_unlocked() need only be exported for his ability to allow VM_FAULT_RETRY behaviour, this adjustment allows us to subsequently unexport __get_user_pages_unlocked() as well as allowing for future flexibility in the use of get_user_pages_remote().
--- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/i915_gem_userptr.c | 2 +- drivers/infiniband/core/umem_odp.c | 2 +- fs/exec.c | 2 +- include/linux/mm.h | 2 +- kernel/events/uprobes.c | 4 ++-- mm/gup.c | 12 ++++++++---- mm/memory.c | 2 +- security/tomoyo/domain.c | 2 +- 9 files changed, 17 insertions(+), 13 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gem.c +1 -1
@@ -763,7 +763,7 @@ static struct page **etnaviv_gem_userptr_do_get_pages(down_read (&mm->mmap_sem);while (pinned < npages) { ret =get_user_pages_remote (task, mm, ptr, npages - pinned, - flags, pvec + pinned,NULL ); + flags, pvec + pinned,NULL ,NULL );if (ret <0 )break ;
drivers/gpu/drm/i915/i915_gem_userptr.c +1 -1
@@ -522,7 +522,7 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work) obj->userptr.ptr + pinned *PAGE_SIZE , npages - pinned, flags, - pvec + pinned, NULL); + pvec + pinned, NULL, NULL);if (ret <0 )break ;
drivers/infiniband/core/umem_odp.c +1 -1
@@ -578,7 +578,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,*/ npages =get_user_pages_remote (owning_process, owning_mm, user_virt, gup_num_pages, - flags, local_page_list,NULL ); + flags, local_page_list,NULL ,NULL );up_read (&owning_mm->mmap_sem);if (npages <0 )
fs/exec.c +1 -1
@@ -209,7 +209,7 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,* doing the exec and bprm->mm is the new process's mm. */ ret =get_user_pages_remote (current, bprm->mm, pos,1 , gup_flags, - &page,NULL ); + &page,NULL ,NULL );if (ret <=0 )return NULL ;
include/linux/mm.h +1 -1
@@ -1274,7 +1274,7 @@ extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,long get_user_pages_remote (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages, -struct vm_area_struct **vmas); +struct vm_area_struct **vmas,int *locked);long get_user_pages (unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages,struct vm_area_struct **vmas);
kernel/events/uprobes.c +2 -2
@@ -301,7 +301,7 @@ int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, retry:/* Read the page with vaddr into memory */ ret =get_user_pages_remote (NULL , mm, vaddr,1 ,FOLL_FORCE , &old_page, - &vma); + &vma,NULL );if (ret <=0 )return ret;
@@ -1712,7 +1712,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)* essentially a kernel access to the memory. */ result =get_user_pages_remote (NULL , mm, vaddr,1 ,FOLL_FORCE , &page, -NULL ); +NULL ,NULL );if (result <0 )return result;
mm/gup.c +8 -4
@@ -920,6 +920,9 @@ EXPORT_SYMBOL(get_user_pages_unlocked);* only intends to ensure the pages are faulted in. * @vmas: array of pointers to vmas corresponding to each page. * Or NULL if the caller does not require them. +* @locked: pointer to lock flag indicating whether lock is held and +* subsequently whether VM_FAULT_RETRY functionality can be +* utilised. Lock must initially be held. * * Returns number of pages pinned. This may be fewer than the number * requested. If nr_pages is 0 or negative, returns 0. If no pages
@@ -963,10 +966,10 @@ EXPORT_SYMBOL(get_user_pages_unlocked);long get_user_pages_remote (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages, -struct vm_area_struct **vmas) +struct vm_area_struct **vmas,int *locked) {return __get_user_pages_locked (tsk, mm, start, nr_pages, pages, vmas, -NULL , false, + locked, true, gup_flags |FOLL_TOUCH |FOLL_REMOTE ); }EXPORT_SYMBOL (get_user_pages_remote);
@@ -974,8 +977,9 @@ EXPORT_SYMBOL(get_user_pages_remote);/* * This is the same as get_user_pages_remote(), just with a * less-flexible calling convention where we assume that the task -* and mm being operated on are the current task's. We also -* obviously don't pass FOLL_REMOTE in here. +* and mm being operated on are the current task's and don't allow +* passing of a locked parameter. We also obviously don't pass +* FOLL_REMOTE in here. */ long get_user_pages(unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages,
mm/memory.c +1 -1
@@ -3883,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,struct page *page =NULL ; ret =get_user_pages_remote (tsk, mm, addr,1 , - gup_flags, &page, &vma); + gup_flags, &page, &vma,NULL );if (ret <=0 ) {#ifndef CONFIG_HAVE_IOREMAP_PROT break ;
security/tomoyo/domain.c +1 -1
@@ -881,7 +881,7 @@ bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos,* the execve(). */ if (get_user_pages_remote (current, bprm->mm, pos,1 , -FOLL_FORCE , &page,NULL ) <=0 ) +FOLL_FORCE , &page,NULL ,NULL ) <=0 )return false;#else page = bprm->page[pos /PAGE_SIZE ];
--
2.10.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/2 mm: unexport __get_user_pages_unlocked()
In reply to Lorenzo StoakesThis patch unexports the low-level __get_user_pages_unlocked() function and replaces invocations with calls to more appropriate higher-level functions.
In hva_to_pfn_slow() we are able to replace __get_user_pages_unlocked() with get_user_pages_unlocked() since we can now pass gup_flags.
In async_pf_execute() and process_vm_rw_single_vec() we need to pass different tsk, mm arguments so get_user_pages_remote() is the sane replacement in these cases (having added manual acquisition and release of mmap_sem.)
Additionally get_user_pages_remote() reintroduces use of the FOLL_TOUCH flag. However, this flag was originally silently dropped by 1e9877902dc7e ("mm/gup: Introduce get_user_pages_remote()"), so this appears to have been unintentional and reintroducing it is therefore not an issue.
--- include/linux/mm.h | 3 --- mm/gup.c | 8 ++++---- mm/nommu.c | 7 +++---- mm/process_vm_access.c | 12 ++++++++---- virt/kvm/async_pf.c | 10 +++++++--- virt/kvm/kvm_main.c | 5 ++--- 6 files changed, 24 insertions(+), 21 deletions(-)
include/linux/mm.h +0 -3
@@ -1280,9 +1280,6 @@ long get_user_pages(unsigned long start, unsigned long nr_pages, struct vm_area_struct **vmas);long get_user_pages_locked (unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages,int *locked); -long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, -struct page **pages,unsigned int gup_flags);long get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,struct page **pages,unsigned int gup_flags); int get_user_pages_fast(unsigned long start, int nr_pages, int write,
mm/gup.c +4 -4
@@ -866,9 +866,10 @@ EXPORT_SYMBOL(get_user_pages_locked);* caller if required (just like with __get_user_pages). "FOLL_GET" * is set implicitly if "pages" is non-NULL. */ -__always_inline long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, -struct page **pages,unsigned int gup_flags) +static __always_inline long __get_user_pages_unlocked (struct task_struct *tsk, +struct mm_struct *mm,unsigned long start, +unsigned long nr_pages,struct page **pages, +unsigned int gup_flags) {long ret;int locked =1 ;
@@ -880,7 +881,6 @@ __always_inline long __get_user_pages_unlocked(struct task_struct *tsk, struct mup_read (&mm->mmap_sem);return ret; } -EXPORT_SYMBOL (__get_user_pages_unlocked);/* * get_user_pages_unlocked() is suitable to replace the form:
mm/nommu.c +3 -4
@@ -176,9 +176,9 @@ long get_user_pages_locked(unsigned long start, unsigned long nr_pages, }EXPORT_SYMBOL (get_user_pages_locked); -long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, -struct page **pages,unsigned int gup_flags) +static long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, +unsigned long start,unsigned long nr_pages, +struct page **pages,unsigned int gup_flags) {long ret;down_read (&mm->mmap_sem);
@@ -187,7 +187,6 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,up_read (&mm->mmap_sem);return ret; } -EXPORT_SYMBOL (__get_user_pages_unlocked);long get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,struct page **pages,unsigned int gup_flags)
mm/process_vm_access.c +8 -4
@@ -88,7 +88,7 @@ static int process_vm_rw_single_vec(unsigned long addr,ssize_t rc =0 ;unsigned long max_pages_per_loop =PVM_MAX_KMALLOC_PAGES /sizeof (struct pages *); -unsigned int flags =FOLL_REMOTE ; +unsigned int flags =0 ;/* Work out address and page range required */ if (len ==0 )
@@ -100,15 +100,19 @@ static int process_vm_rw_single_vec(unsigned long addr,while (!rc && nr_pages &&iov_iter_count (iter)) {int pages =min (nr_pages, max_pages_per_loop); +int locked =1 ;size_t bytes;/* * Get the pages we're interested in. We must -* add FOLL_REMOTE because task/mm might not +* access remotely because task/mm might not * current/current->mm */ - pages =__get_user_pages_unlocked (task, mm, pa, pages, - process_pages, flags); +down_read (&mm->mmap_sem); + pages =get_user_pages_remote (task, mm, pa, pages, flags, + process_pages,NULL , &locked); +if (locked) +up_read (&mm->mmap_sem);if (pages <=0 )return -EFAULT ;
virt/kvm/async_pf.c +7 -3
@@ -76,16 +76,20 @@ static void async_pf_execute(struct work_struct *work)struct kvm_vcpu *vcpu = apf->vcpu;unsigned long addr = apf->addr;gva_t gva = apf->gva; +int locked =1 ;might_sleep ();/* * This work is run asynchromously to the task which owns * mm and might be done in another context, so we must -* use FOLL_REMOTE. +* access remotely. */ -__get_user_pages_unlocked (NULL , mm, addr,1 ,NULL , -FOLL_WRITE |FOLL_REMOTE ); +down_read (&mm->mmap_sem); +get_user_pages_remote (NULL , mm, addr,1 ,FOLL_WRITE ,NULL ,NULL , + &locked); +if (locked) +up_read (&mm->mmap_sem);kvm_async_page_present_sync (vcpu, apf);
virt/kvm/kvm_main.c +2 -3
@@ -1415,13 +1415,12 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault, npages =get_user_page_nowait (addr, write_fault, page);up_read (¤t->mm->mmap_sem); }else { -unsigned int flags =FOLL_TOUCH |FOLL_HWPOISON ; +unsigned int flags =FOLL_HWPOISON ;if (write_fault) flags |=FOLL_WRITE ; - npages =__get_user_pages_unlocked (current, current->mm, addr,1 , - page, flags); + npages =get_user_pages_unlocked (addr,1 , page, flags); }if (npages !=1 )return npages;
--
2.10.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · Lorenzo Stoakes
This patch series continues the cleanup of get_user_pages*() functions taking advantage of the fact we can now pass
gup_flagsas we please.
Note that this patch series has an unfortunate trivial dependency on my recent 'fix up get_user_pages* comments' patch which means this series applies against -mmots but not mainline at this point in time.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 1/2] mm: add locked parameter to get_user_pages_remote()
In reply to Lorenzo StoakesQuoted 9 lines · Lorenzo Stoakes
This patch adds a int *locked parameter to
get_user_pages_remote()to allowVM_FAULT_RETRYfaulting behaviour similar to get_user_pages_[un]locked().Taking into account the previous adjustments to get_user_pages*() functions allowing for the passing of
gup_flags, we are now in a position where__get_user_pages_unlocked()need only be exported for his ability to allowVM_FAULT_RETRYbehaviour, this adjustment allows us to subsequently unexport__get_user_pages_unlocked()as well as allowing for future flexibility in the use ofget_user_pages_remote().
I would also add that this shouldn't introduce any functional change.
Quoted 1 line
Signed-off-by Lorenzo Stoakes <[email protected]>
Quoted 166 lines
--- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/i915_gem_userptr.c | 2 +- drivers/infiniband/core/umem_odp.c | 2 +- fs/exec.c | 2 +- include/linux/mm.h | 2 +- kernel/events/uprobes.c | 4 ++-- mm/gup.c | 12 ++++++++---- mm/memory.c | 2 +- security/tomoyo/domain.c | 2 +- 9 files changed, 17 insertions(+), 13 deletions(-)drivers/gpu/drm/etnaviv/etnaviv_gem.c +1
-1@@ -763,7 +763,7 @@ static struct page **etnaviv_gem_userptr_do_get_pages(down_read (&mm->mmap_sem);while (pinned < npages) { ret =get_user_pages_remote (task, mm, ptr, npages - pinned, - flags, pvec + pinned,NULL ); + flags, pvec + pinned,NULL ,NULL );if (ret <0 )break ;drivers/gpu/drm/i915/i915_gem_userptr.c +1
-1@@ -522,7 +522,7 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work) obj->userptr.ptr + pinned *PAGE_SIZE , npages - pinned, flags, - pvec + pinned, NULL); + pvec + pinned, NULL, NULL);if (ret <0 )break ;drivers/infiniband/core/umem_odp.c +1
-1@@ -578,7 +578,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,*/ npages =get_user_pages_remote (owning_process, owning_mm, user_virt, gup_num_pages, - flags, local_page_list,NULL ); + flags, local_page_list,NULL ,NULL );up_read (&owning_mm->mmap_sem);if (npages <0 )fs/exec.c +1
-1@@ -209,7 +209,7 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,* doing the exec and bprm->mm is the new process's mm. */ ret =get_user_pages_remote (current, bprm->mm, pos,1 , gup_flags, - &page,NULL ); + &page,NULL ,NULL );if (ret <=0 )return NULL ;include/linux/mm.h +1
-1@@ -1274,7 +1274,7 @@ extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,long get_user_pages_remote (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages, -struct vm_area_struct **vmas); +struct vm_area_struct **vmas,int *locked);long get_user_pages (unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages,struct vm_area_struct **vmas);kernel/events/uprobes.c +2
-2@@ -301,7 +301,7 @@ int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, retry:/* Read the page with vaddr into memory */ ret =get_user_pages_remote (NULL , mm, vaddr,1 ,FOLL_FORCE , &old_page, - &vma); + &vma,NULL );if (ret <=0 )return ret;@@ -1712,7 +1712,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)* essentially a kernel access to the memory. */ result =get_user_pages_remote (NULL , mm, vaddr,1 ,FOLL_FORCE , &page, -NULL ); +NULL ,NULL );if (result <0 )return result;mm/gup.c +8
-4@@ -920,6 +920,9 @@ EXPORT_SYMBOL(get_user_pages_unlocked);* only intends to ensure the pages are faulted in. * @vmas: array of pointers to vmas corresponding to each page. * Or NULL if the caller does not require them. +* @locked: pointer to lock flag indicating whether lock is held and +* subsequently whether VM_FAULT_RETRY functionality can be +* utilised. Lock must initially be held. * * Returns number of pages pinned. This may be fewer than the number * requested. If nr_pages is 0 or negative, returns 0. If no pages @@ -963,10 +966,10 @@ EXPORT_SYMBOL(get_user_pages_unlocked);long get_user_pages_remote (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages, -struct vm_area_struct **vmas) +struct vm_area_struct **vmas,int *locked) {return __get_user_pages_locked (tsk, mm, start, nr_pages, pages, vmas, -NULL , false, + locked, true, gup_flags |FOLL_TOUCH |FOLL_REMOTE ); }EXPORT_SYMBOL (get_user_pages_remote);@@ -974,8 +977,9 @@ EXPORT_SYMBOL(get_user_pages_remote);/* * This is the same as get_user_pages_remote(), just with a * less-flexible calling convention where we assume that the task -* and mm being operated on are the current task's. We also -* obviously don't pass FOLL_REMOTE in here. +* and mm being operated on are the current task's and don't allow +* passing of a locked parameter. We also obviously don't pass +* FOLL_REMOTE in here. */ long get_user_pages(unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages,mm/memory.c +1
-1@@ -3883,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,struct page *page =NULL ; ret =get_user_pages_remote (tsk, mm, addr,1 , - gup_flags, &page, &vma); + gup_flags, &page, &vma,NULL );if (ret <=0 ) {#ifndef CONFIG_HAVE_IOREMAP_PROT break ;security/tomoyo/domain.c +1
-2@@ -881,7 +881,7 @@ bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos,* the execve(). */ if (get_user_pages_remote (current, bprm->mm, pos,1 , -FOLL_FORCE , &page,NULL ) <=0 ) +FOLL_FORCE , &page,NULL ,NULL ) <=0 )return false;#else page = bprm->page[pos /PAGE_SIZE ]; --2.10.1
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Lorenzo Stoakes
This patch unexports the low-level
__get_user_pages_unlocked()function and replaces invocations with calls to more appropriate higher-level functions.In
hva_to_pfn_slow()we are able to replace__get_user_pages_unlocked()withget_user_pages_unlocked()since we can now passgup_flags.
Quoted 8 lines
In
async_pf_execute()andprocess_vm_rw_single_vec()we need to pass different tsk, mm arguments soget_user_pages_remote()is the sane replacement in these cases (having added manual acquisition and release ofmmap_sem.)Additionally
get_user_pages_remote()reintroduces use of theFOLL_TOUCHflag. However, this flag was originally silently dropped by1e9877902dc7e("mm/gup: Introduceget_user_pages_remote()"), so this appears to have been unintentional and reintroducing it is therefore not an issue.
Looks good to me.
Quoted 1 line
Signed-off-by Lorenzo Stoakes <[email protected]>
Quoted 160 lines
--- include/linux/mm.h | 3 --- mm/gup.c | 8 ++++---- mm/nommu.c | 7 +++---- mm/process_vm_access.c | 12 ++++++++---- virt/kvm/async_pf.c | 10 +++++++--- virt/kvm/kvm_main.c | 5 ++--- 6 files changed, 24 insertions(+), 21 deletions(-)include/linux/mm.h +0
-3@@ -1280,9 +1280,6 @@ long get_user_pages(unsigned long start, unsigned long nr_pages, struct vm_area_struct **vmas);long get_user_pages_locked (unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages,int *locked); -long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, -struct page **pages,unsigned int gup_flags);long get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,struct page **pages,unsigned int gup_flags); int get_user_pages_fast(unsigned long start, int nr_pages, int write,mm/gup.c +4
-4@@ -866,9 +866,10 @@ EXPORT_SYMBOL(get_user_pages_locked);* caller if required (just like with __get_user_pages). "FOLL_GET" * is set implicitly if "pages" is non-NULL. */ -__always_inline long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, -struct page **pages,unsigned int gup_flags) +static __always_inline long __get_user_pages_unlocked (struct task_struct *tsk, +struct mm_struct *mm,unsigned long start, +unsigned long nr_pages,struct page **pages, +unsigned int gup_flags) {long ret;int locked =1 ;@@ -880,7 +881,6 @@ __always_inline long __get_user_pages_unlocked(struct task_struct *tsk, struct mup_read (&mm->mmap_sem);return ret; } -EXPORT_SYMBOL (__get_user_pages_unlocked);/* * get_user_pages_unlocked() is suitable to replace the form: mm/nommu.c +3
-4@@ -176,9 +176,9 @@ long get_user_pages_locked(unsigned long start, unsigned long nr_pages, }EXPORT_SYMBOL (get_user_pages_locked); -long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, -struct page **pages,unsigned int gup_flags) +static long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, +unsigned long start,unsigned long nr_pages, +struct page **pages,unsigned int gup_flags) {long ret;down_read (&mm->mmap_sem);@@ -187,7 +187,6 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,up_read (&mm->mmap_sem);return ret; } -EXPORT_SYMBOL (__get_user_pages_unlocked);long get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,struct page **pages,unsigned int gup_flags)mm/process_vm_access.c +8
-4@@ -88,7 +88,7 @@ static int process_vm_rw_single_vec(unsigned long addr,ssize_t rc =0 ;unsigned long max_pages_per_loop =PVM_MAX_KMALLOC_PAGES /sizeof (struct pages *); -unsigned int flags =FOLL_REMOTE ; +unsigned int flags =0 ;/* Work out address and page range required */ if (len ==0 )@@ -100,15 +100,19 @@ static int process_vm_rw_single_vec(unsigned long addr,while (!rc && nr_pages &&iov_iter_count (iter)) {int pages =min (nr_pages, max_pages_per_loop); +int locked =1 ;size_t bytes;/* * Get the pages we're interested in. We must -* add FOLL_REMOTE because task/mm might not +* access remotely because task/mm might not * current/current->mm */ - pages =__get_user_pages_unlocked (task, mm, pa, pages, - process_pages, flags); +down_read (&mm->mmap_sem); + pages =get_user_pages_remote (task, mm, pa, pages, flags, + process_pages,NULL , &locked); +if (locked) +up_read (&mm->mmap_sem);if (pages <=0 )return -EFAULT ;virt/kvm/async_pf.c +7
-3@@ -76,16 +76,20 @@ static void async_pf_execute(struct work_struct *work)struct kvm_vcpu *vcpu = apf->vcpu;unsigned long addr = apf->addr;gva_t gva = apf->gva; +int locked =1 ;might_sleep ();/* * This work is run asynchromously to the task which owns * mm and might be done in another context, so we must -* use FOLL_REMOTE. +* access remotely. */ -__get_user_pages_unlocked (NULL , mm, addr,1 ,NULL , -FOLL_WRITE |FOLL_REMOTE ); +down_read (&mm->mmap_sem); +get_user_pages_remote (NULL , mm, addr,1 ,FOLL_WRITE ,NULL ,NULL , + &locked); +if (locked) +up_read (&mm->mmap_sem);kvm_async_page_present_sync (vcpu, apf);virt/kvm/kvm_main.c +2
-4@@ -1415,13 +1415,12 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault, npages =get_user_page_nowait (addr, write_fault, page);up_read (¤t->mm->mmap_sem); }else { -unsigned int flags =FOLL_TOUCH |FOLL_HWPOISON ; +unsigned int flags =FOLL_HWPOISON ;if (write_fault) flags |=FOLL_WRITE ; - npages =__get_user_pages_unlocked (current, current->mm, addr,1 , - page, flags); + npages =get_user_pages_unlocked (addr,1 , page, flags); }if (npages !=1 )return npages; --2.10.1
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 1/2] mm: add locked parameter to get_user_pages_remote()
In reply to Michal HockoQuoted 4 lines · Michal Hocko
Quoted 3 lines · Lorenzo Stoakes
This patch adds a int *locked parameter to
get_user_pages_remote()to allowVM_FAULT_RETRYfaulting behaviour similar to get_user_pages_[un]locked().
Quoted 8 lines
Quoted 6 lines
Taking into account the previous adjustments to get_user_pages*() functions allowing for the passing of
gup_flags, we are now in a position where__get_user_pages_unlocked()need only be exported for his ability to allowVM_FAULT_RETRYbehaviour, this adjustment allows us to subsequently unexport__get_user_pages_unlocked()as well as allowing for future flexibility in the use ofget_user_pages_remote().I would also add that this shouldn't introduce any functional change.
Forgot to mention that this also opens doors to change other g_u_p_r callers to allow FAULT_RETRY logic.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>