leverage FAULT_FOLL_ALLOW_RETRY in get_user_pages try#2
Subsystems (19)
PATCH 4/5 mm: gup: use get_user_pages_unlocked
In reply to Andrea ArcangeliThis allows those get_user_pages calls to pass FAULT_FLAG_ALLOW_RETRY to the page fault in order to release the mmap_sem during the I/O.
--- drivers/media/pci/ivtv/ivtv-udma.c | 6 ++---- drivers/scsi/st.c | 7 ++----- drivers/video/fbdev/pvr2fb.c | 6 ++---- mm/process_vm_access.c | 7 ++----- net/ceph/pagevec.c | 6 ++---- 5 files changed, 10 insertions(+), 22 deletions(-)
drivers/media/pci/ivtv/ivtv-udma.c +2 -4
@@ -124,10 +124,8 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr, }/* Get user pages for DMA Xfer */ -down_read (¤t->mm->mmap_sem); - err =get_user_pages (current, current->mm, - user_dma.uaddr, user_dma.page_count,0 ,1 , dma->map,NULL ); -up_read (¤t->mm->mmap_sem); + err =get_user_pages_unlocked (current, current->mm, + user_dma.uaddr, user_dma.page_count,0 ,1 , dma->map);if (user_dma.page_count != err) { IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n",
drivers/scsi/st.c +2 -5
@@ -4551,18 +4551,15 @@ static int sgl_map_user_pages(struct st_buffer *STbp,return -ENOMEM ;/* Try to fault in all of the necessary pages */ -down_read (¤t->mm->mmap_sem);/* rw==READ means read from drive, write into memory area */ - res =get_user_pages ( + res =get_user_pages_unlocked ( current, current->mm, uaddr, nr_pages, rw ==READ ,0 ,/* don't force */ - pages, -NULL ); -up_read (¤t->mm->mmap_sem); + pages);/* Errors and no page mapped should return here */ if (res < nr_pages)
drivers/video/fbdev/pvr2fb.c +2 -4
@@ -686,10 +686,8 @@ static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,if (!pages)return -ENOMEM ; -down_read (¤t->mm->mmap_sem); - ret =get_user_pages (current, current->mm, (unsigned long )buf, - nr_pages,WRITE ,0 , pages,NULL ); -up_read (¤t->mm->mmap_sem); + ret =get_user_pages_unlocked (current, current->mm, (unsigned long )buf, + nr_pages,WRITE ,0 , pages);if (ret < nr_pages) { nr_pages = ret;
mm/process_vm_access.c +2 -5
@@ -99,11 +99,8 @@ static int process_vm_rw_single_vec(unsigned long addr,size_t bytes;/* Get the pages we're interested in */ -down_read (&mm->mmap_sem); - pages =get_user_pages (task, mm, pa, pages, - vm_write,0 , process_pages,NULL ); -up_read (&mm->mmap_sem); - + pages =get_user_pages_unlocked (task, mm, pa, pages, + vm_write,0 , process_pages);if (pages <=0 )return -EFAULT ;
net/ceph/pagevec.c +2 -4
@@ -23,17 +23,15 @@ struct page **ceph_get_direct_page_vector(const void __user *data,if (!pages)return ERR_PTR (-ENOMEM ); -down_read (¤t->mm->mmap_sem);while (got < num_pages) { - rc =get_user_pages (current, current->mm, + rc =get_user_pages_unlocked (current, current->mm, (unsigned long )data + ((unsigned long )got *PAGE_SIZE ), - num_pages - got, write_page,0 , pages + got,NULL ); + num_pages - got, write_page,0 , pages + got);if (rc <0 )break ;BUG_ON (rc ==0 ); got += rc; } -up_read (¤t->mm->mmap_sem);if (rc <0 ) goto fail;return pages;
--
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 5/5 mm: gup: kvm use get_user_pages_unlocked
In reply to Andrea ArcangeliUse the more generic get_user_pages_unlocked which has the additional benefit of passing FAULT_FLAG_ALLOW_RETRY at the very first page fault (which allows the first page fault in an unmapped area to be always able to block indefinitely by being allowed to release the mmap_sem).
--- include/linux/kvm_host.h | 11 ----------- virt/kvm/async_pf.c | 2 +- virt/kvm/kvm_main.c | 50 ++++-------------------------------------------- 3 files changed, 5 insertions(+), 58 deletions(-)
include/linux/kvm_host.h +0 -11
@@ -200,17 +200,6 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva,int kvm_async_pf_wakeup_all (struct kvm_vcpu *vcpu);#endif -/* -* Carry out a gup that requires IO. Allow the mm to relinquish the mmap -* semaphore if the filemap/swap has to wait on a page lock. pagep == NULL -* controls whether we retry the gup one more time to completion in that case. -* Typically this is called after a FAULT_FLAG_RETRY_NOWAIT in the main tdp -* handler. -*/ -int kvm_get_user_page_io (struct task_struct *tsk,struct mm_struct *mm, -unsigned long addr,bool write_fault, -struct page **pagep); -enum {OUTSIDE_GUEST_MODE ,IN_GUEST_MODE ,
virt/kvm/async_pf.c +1 -1
@@ -80,7 +80,7 @@ static void async_pf_execute(struct work_struct *work)might_sleep (); -kvm_get_user_page_io (NULL , mm, addr,1 ,NULL ); +get_user_pages_unlocked (NULL , mm, addr,1 ,1 ,0 ,NULL );kvm_async_page_present_sync (vcpu, apf);spin_lock (&vcpu->async_pf.lock);
virt/kvm/kvm_main.c +4 -46
62 lines not on this page · raw message
--
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 3/5 mm: gup: use get_user_pages_unlocked within get_user_pages_fast
In reply to Andrea ArcangeliThis allows the get_user_pages_fast slow path to release the mmap_sem before blocking.
--- arch/mips/mm/gup.c | 8 +++----- arch/s390/mm/gup.c | 6 ++---- arch/sh/mm/gup.c | 6 ++---- arch/sparc/mm/gup.c | 6 ++---- arch/x86/mm/gup.c | 7 +++---- mm/gup.c | 6 ++---- mm/util.c | 10 ++-------- 7 files changed, 16 insertions(+), 33 deletions(-)
arch/mips/mm/gup.c +3 -5
@@ -301,11 +301,9 @@ slow_irqon: start += nr <<PAGE_SHIFT ; pages += nr; -down_read (&mm->mmap_sem); - ret =get_user_pages (current, mm, start, - (end - start) >>PAGE_SHIFT , - write,0 , pages,NULL ); -up_read (&mm->mmap_sem); + ret =get_user_pages_unlocked (current, mm, start, + (end - start) >>PAGE_SHIFT , + write,0 , pages);/* Have to be a bit careful with return values */ if (nr >0 ) {
arch/s390/mm/gup.c +2 -4
@@ -235,10 +235,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,/* Try to get the remaining pages with get_user_pages */ start += nr <<PAGE_SHIFT ; pages += nr; -down_read (&mm->mmap_sem); - ret =get_user_pages (current, mm, start, - nr_pages - nr, write,0 , pages,NULL ); -up_read (&mm->mmap_sem); + ret =get_user_pages_unlocked (current, mm, start, + nr_pages - nr, write,0 , pages);/* Have to be a bit careful with return values */ if (nr >0 ) ret = (ret <0 ) ? nr : ret + nr;
arch/sh/mm/gup.c +2 -4
@@ -257,10 +257,8 @@ slow_irqon: start += nr <<PAGE_SHIFT ; pages += nr; -down_read (&mm->mmap_sem); - ret =get_user_pages (current, mm, start, - (end - start) >>PAGE_SHIFT , write,0 , pages,NULL ); -up_read (&mm->mmap_sem); + ret =get_user_pages_unlocked (current, mm, start, + (end - start) >>PAGE_SHIFT , write,0 , pages);/* Have to be a bit careful with return values */ if (nr >0 ) {
arch/sparc/mm/gup.c +2 -4
@@ -249,10 +249,8 @@ slow: start += nr <<PAGE_SHIFT ; pages += nr; -down_read (&mm->mmap_sem); - ret =get_user_pages (current, mm, start, - (end - start) >>PAGE_SHIFT , write,0 , pages,NULL ); -up_read (&mm->mmap_sem); + ret =get_user_pages_unlocked (current, mm, start, + (end - start) >>PAGE_SHIFT , write,0 , pages);/* Have to be a bit careful with return values */ if (nr >0 ) {
arch/x86/mm/gup.c +3 -4
@@ -388,10 +388,9 @@ slow_irqon: start += nr <<PAGE_SHIFT ; pages += nr; -down_read (&mm->mmap_sem); - ret =get_user_pages (current, mm, start, - (end - start) >>PAGE_SHIFT , write,0 , pages,NULL ); -up_read (&mm->mmap_sem); + ret =get_user_pages_unlocked (current, mm, start, + (end - start) >>PAGE_SHIFT , + write,0 , pages);/* Have to be a bit careful with return values */ if (nr >0 ) {
mm/gup.c +2 -4
@@ -1252,10 +1252,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, start += nr <<PAGE_SHIFT ; pages += nr; -down_read (&mm->mmap_sem); - ret =get_user_pages (current, mm, start, - nr_pages - nr, write,0 , pages,NULL ); -up_read (&mm->mmap_sem); + ret =get_user_pages_unlocked (current, mm, start, + nr_pages - nr, write,0 , pages);/* Have to be a bit careful with return values */ if (nr >0 ) {
mm/util.c +2 -8
@@ -240,14 +240,8 @@ int __weak get_user_pages_fast(unsigned long start, int nr_pages, int write, struct page **pages) { struct mm_struct *mm = current->mm; -int ret; - -down_read (&mm->mmap_sem); - ret =get_user_pages (current, mm, start, nr_pages, - write,0 , pages,NULL ); -up_read (&mm->mmap_sem); - -return ret; +return get_user_pages_unlocked (current, mm, start, nr_pages, + write,0 , pages); }EXPORT_SYMBOL_GPL (get_user_pages_fast);
--
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/5 mm: gup: add get_user_pages_locked and get_user_pages_unlocked
In reply to Andrea ArcangeliWe can leverage the VM_FAULT_RETRY functionality in the page fault paths better by using either get_user_pages_locked or get_user_pages_unlocked.
The former allow conversion of get_user_pages invocations that will have to pass a "&locked" parameter to know if the mmap_sem was dropped during the call. Example from:
down_read(&mm->mmap_sem);
do_something()
get_user_pages(tsk, mm, ..., pages, NULL);
up_read(&mm->mmap_sem);to:
int locked = 1;
down_read(&mm->mmap_sem);
do_something()
get_user_pages_locked(tsk, mm, ..., pages, &locked);
if (locked)
up_read(&mm->mmap_sem);The latter is suitable only as a drop in replacement of the form:
down_read(&mm->mmap_sem);
get_user_pages(tsk, mm, ..., pages, NULL);
up_read(&mm->mmap_sem);into:
get_user_pages_unlocked(tsk, mm, ..., pages);
Where tsk, mm, the intermediate "..." paramters and "pages" can be any value as before. Just the last parameter of get_user_pages (vmas) must be NULL for get_user_pages_locked|unlocked to be usable (the latter original form wouldn't have been safe anyway if vmas wasn't null, for the former we just make it explicit by dropping the parameter).
If vmas is not NULL these two methods cannot be used.
--- include/linux/mm.h | 7 +++ mm/gup.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++---- mm/nommu.c | 23 +++++++ 3 files changed, 196 insertions(+), 11 deletions(-)
include/linux/mm.h +7 -0
@@ -1234,6 +1234,13 @@ long get_user_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, unsigned long nr_pages, int write, int force, struct page **pages, struct vm_area_struct **vmas); +long get_user_pages_locked (struct task_struct *tsk,struct mm_struct *mm, +unsigned long start,unsigned long nr_pages, +int write,int force,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, +int write,int force,struct page **pages);int get_user_pages_fast (unsigned long start,int nr_pages,int write,struct page **pages);struct kvec ;
mm/gup.c +166 -11
194 lines not on this page · raw message
mm/nommu.c +23 -0
@@ -213,6 +213,29 @@ long get_user_pages(struct task_struct *tsk, struct mm_struct *mm, }EXPORT_SYMBOL (get_user_pages); +long get_user_pages_locked (struct task_struct *tsk,struct mm_struct *mm, +unsigned long start,unsigned long nr_pages, +int write,int force,struct page **pages, +int *locked) +{ +return get_user_pages (tsk, mm, start, nr_pages, write, force, + pages,NULL ); +} +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, +int write,int force,struct page **pages) +{ +long ret; +down_read (&mm->mmap_sem); + ret =get_user_pages (tsk, mm, start, nr_pages, write, force, + pages,NULL ); +up_read (&mm->mmap_sem); +return ret; +} +EXPORT_SYMBOL (get_user_pages_unlocked); +/** * follow_pfn - look up PFN at a user virtual address * @vma: memory mapping
--
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/5 mm: gup: add __get_user_pages_unlocked to customize gup_flags
In reply to Andrea ArcangeliSome caller (like KVM) may want to set the gup_flags like FOLL_HWPOSION to get a proper -EHWPOSION retval instead of -EFAULT to take a more appropriate action if get_user_pages runs into a memory failure.
--- include/linux/mm.h | 4 ++++ mm/gup.c | 44 ++++++++++++++++++++++++++++++++------------ mm/nommu.c | 16 +++++++++++++--- 3 files changed, 49 insertions(+), 15 deletions(-)
include/linux/mm.h +4 -0
@@ -1238,6 +1238,10 @@ long get_user_pages_locked(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, unsigned long nr_pages, int write, int force, 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, +int write,int force,struct page **pages, +unsigned int gup_flags);long get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,unsigned long nr_pages,int write,int force,struct page **pages);
mm/gup.c +32 -12
73 lines not on this page · raw message
mm/nommu.c +13 -3
@@ -223,9 +223,10 @@ long get_user_pages_locked(struct task_struct *tsk, struct mm_struct *mm, }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, -int write,int force,struct page **pages) +long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, +unsigned long start,unsigned long nr_pages, +int write,int force,struct page **pages, +unsigned int gup_flags) {long ret;down_read (&mm->mmap_sem);
@@ -234,6 +235,15 @@ 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 (struct task_struct *tsk,struct mm_struct *mm, +unsigned long start,unsigned long nr_pages, +int write,int force,struct page **pages) +{ +return __get_user_pages_unlocked (tsk, mm, start, nr_pages, write, + force, pages,0 ); +}EXPORT_SYMBOL (get_user_pages_unlocked);/**
--
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>
cover leverage FAULT_FOLL_ALLOW_RETRY in get_user_pages try#2
Last submit didn't go into -mm/3.19-rc, no prob but here I retry (possibly too early for 3.20-rc but I don't expect breakages in this area post -rc4) after a rebase on upstream.
FAULT_FOLL_ALLOW_RETRY allows the page fault to drop the mmap_sem for reading to reduce the mmap_sem contention (for writing), like while waiting for I/O completion. The problem is that right now practically no get_user_pages call uses FAULT_FOLL_ALLOW_RETRY, so we're not leveraging that nifty feature.
Andres fixed it for the KVM page fault. However get_user_pages_fast remains uncovered, and 99% of other get_user_pages aren't using it either (the only exception being FOLL_NOWAIT in KVM which is really nonblocking and in fact it doesn't even release the mmap_sem).
So this patchsets extends the optimization Andres did in the KVM page fault to the whole kernel. It makes most important places (including gup_fast) to use FAULT_FOLL_ALLOW_RETRY to reduce the mmap_sem hold times during I/O.
The only few places that remains uncovered are drivers like v4l and other exceptions that tends to work on their own memory and they're not working on random user memory (for example like O_DIRECT that uses gup_fast and is fully covered by this patch).
A follow up patch should probably also add a printk_once warning to get_user_pages that should go obsolete and be phased out eventually. The "vmas" parameter of get_user_pages makes it fundamentally incompatible with FAULT_FOLL_ALLOW_RETRY (vmas array becomes meaningless the moment the mmap_sem is released).
While this is just an optimization, this becomes an absolute requirement for the userfaultfd feature
http://lwn.net/Articles/615086/ .
The userfaultfd allows to block the page fault, and in order to do so I need to drop the mmap_sem first. So this patch also ensures that all memory where userfaultfd could be registered by KVM, the very first fault (no matter if it is a regular page fault, or a get_user_pages) always has FAULT_FOLL_ALLOW_RETRY set. Then the userfaultfd blocks and it is waken only when the pagetable is already mapped. The second fault attempt after the wakeup doesn't need FAULT_FOLL_ALLOW_RETRY, so it's ok to retry without it.
Thanks,
Andrea
Andrea Arcangeli (5):
mm: gup: add get_user_pages_locked and get_user_pages_unlocked
mm: gup: add __get_user_pages_unlocked to customize gup_flags
mm: gup: use get_user_pages_unlocked within get_user_pages_fast
mm: gup: use get_user_pages_unlocked
mm: gup: kvm use get_user_pages_unlocked
arch/mips/mm/gup.c | 8 +- arch/s390/mm/gup.c | 6 +- arch/sh/mm/gup.c | 6 +- arch/sparc/mm/gup.c | 6 +- arch/x86/mm/gup.c | 7 +- drivers/media/pci/ivtv/ivtv-udma.c | 6 +- drivers/scsi/st.c | 7 +- drivers/video/fbdev/pvr2fb.c | 6 +- include/linux/kvm_host.h | 11 -- include/linux/mm.h | 11 ++ mm/gup.c | 203 ++++++++++++++++++++++++++++++++++--- mm/nommu.c | 33 ++++++ mm/process_vm_access.c | 7 +- mm/util.c | 10 +- net/ceph/pagevec.c | 6 +- virt/kvm/async_pf.c | 2 +- virt/kvm/kvm_main.c | 50 +-------- 17 files changed, 261 insertions(+), 124 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>
Re: [PATCH 5/5] mm: gup: kvm use get_user_pages_unlocked
In reply to Andrea ArcangeliQuoted 6 lines · Andrea Arcangeli
Use the more generic
get_user_pages_unlockedwhich has the additional benefit of passingFAULT_FLAG_ALLOW_RETRYat the very first page fault (which allows the first page fault in an unmapped area to be always able to block indefinitely by being allowed to release themmap_sem).Signed-off-by Andrea Arcangeli <[email protected]>
Thanks for the cleanup.
Quoted 109 lines
--- include/linux/kvm_host.h | 11 ----------- virt/kvm/async_pf.c | 2 +- virt/kvm/kvm_main.c | 50 ++++-------------------------------------------- 3 files changed, 5 insertions(+), 58 deletions(-)include/linux/kvm_host.h +0
-11@@ -200,17 +200,6 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva,int kvm_async_pf_wakeup_all (struct kvm_vcpu *vcpu);#endif -/* -* Carry out a gup that requires IO. Allow the mm to relinquish the mmap -* semaphore if the filemap/swap has to wait on a page lock. pagep == NULL -* controls whether we retry the gup one more time to completion in that case. -* Typically this is called after a FAULT_FLAG_RETRY_NOWAIT in the main tdp -* handler. -*/ -int kvm_get_user_page_io (struct task_struct *tsk,struct mm_struct *mm, -unsigned long addr,bool write_fault, -struct page **pagep); -enum {OUTSIDE_GUEST_MODE ,IN_GUEST_MODE ,virt/kvm/async_pf.c +1
-1@@ -80,7 +80,7 @@ static void async_pf_execute(struct work_struct *work)might_sleep (); -kvm_get_user_page_io (NULL , mm, addr,1 ,NULL ); +get_user_pages_unlocked (NULL , mm, addr,1 ,1 ,0 ,NULL );kvm_async_page_present_sync (vcpu, apf);spin_lock (&vcpu->async_pf.lock);virt/kvm/kvm_main.c +4
-46@@ -1128,43 +1128,6 @@ static int get_user_page_nowait(struct task_struct *tsk, struct mm_struct *mm,return __get_user_pages (tsk, mm, start,1 , flags, page,NULL ,NULL ); } -int kvm_get_user_page_io (struct task_struct *tsk,struct mm_struct *mm, -unsigned long addr,bool write_fault, -struct page **pagep) -{ -int npages; -int locked =1 ; -int flags =FOLL_TOUCH |FOLL_HWPOISON | - (pagep ?FOLL_GET :0 ) | - (write_fault ?FOLL_WRITE :0 ); - -/* -* If retrying the fault, we get here *not* having allowed the filemap -* to wait on the page lock. We should now allow waiting on the IO with -* the mmap semaphore released. -*/ -down_read (&mm->mmap_sem); - npages =__get_user_pages (tsk, mm, addr,1 , flags, pagep,NULL , - &locked); -if (!locked) { -VM_BUG_ON (npages); - -if (!pagep) -return 0 ; - -/* -* The previous call has now waited on the IO. Now we can -* retry and complete. Pass TRIED to ensure we do not re -* schedule async IO (see e.g. filemap_fault). -*/ -down_read (&mm->mmap_sem); - npages =__get_user_pages (tsk, mm, addr,1 , flags |FOLL_TRIED , - pagep,NULL ,NULL ); - } -up_read (&mm->mmap_sem); -return npages; -} -static inline int check_user_page_hwpoison (unsigned long addr) {int rc, flags =FOLL_TOUCH |FOLL_HWPOISON |FOLL_WRITE ;@@ -1227,15 +1190,10 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault, npages =get_user_page_nowait (current, current->mm, addr, write_fault, page);up_read (¤t->mm->mmap_sem); - }else { -/* -* By now we have tried gup_fast, and possibly async_pf, and we -* are certainly not atomic. Time to retry the gup, allowing -* mmap semaphore to be relinquished in the case of IO. -*/ - npages =kvm_get_user_page_io (current, current->mm, addr, - write_fault, page); - } + }else + npages =__get_user_pages_unlocked (current, current->mm, addr,1 , + write_fault,0 , page, +FOLL_TOUCH |FOLL_HWPOISON );if (npages !=1 )return npages;
Signature · 7 lines
Andres Lagar-Cavilla | Google Kernel Team | [email protected] -- 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 3 lines · Andrea Arcangeli
Last submit didn't go into -mm/3.19-rc, no prob but here I retry (possibly too early for 3.20-rc but I don't expect breakages in this area post -rc4) after a rebase on upstream.
The series looks good to me, I didn't spot any material changes from last time.
I would fold patches 3 & 4 together: it's the same idea behind both, just different parts of the tree.
You could argue also for folding 1 &2 together, the "damage" is done in 1, 2 as a standalone results in an (IMHO) unnecessarily large diff.
Thanks,
Andres
------ 8< snipping the rest ---------------
--
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/5] mm: gup: add get_user_pages_locked and get_user_pages_unlocked
In reply to Andrea ArcangeliQuoted 38 lines · Andrea Arcangeli
We can leverage the
VM_FAULT_RETRYfunctionality in the page fault paths better by using eitherget_user_pages_lockedorget_user_pages_unlocked.The former allow conversion of
get_user_pagesinvocations that will have to pass a "&locked" parameter to know if themmap_semwas dropped during the call. Example from:down_read(&mm->mmap_sem); do_something() get_user_pages(tsk, mm, ..., pages, NULL); up_read(&mm->mmap_sem);to:
int locked = 1; down_read(&mm->mmap_sem); do_something() get_user_pages_locked(tsk, mm, ..., pages, &locked); if (locked) up_read(&mm->mmap_sem);The latter is suitable only as a drop in replacement of the form:
down_read(&mm->mmap_sem); get_user_pages(tsk, mm, ..., pages, NULL); up_read(&mm->mmap_sem);into:
get_user_pages_unlocked(tsk, mm, ..., pages);Where tsk, mm, the intermediate "..." paramters and "pages" can be any value as before. Just the last parameter of
get_user_pages(vmas) must be NULL for get_user_pages_locked|unlocked to be usable (the latter original form wouldn't have been safe anyway if vmas wasn't null, for the former we just make it explicit by dropping the parameter).
Quoted 5 lines
If vmas is not NULL these two methods cannot be used.
Signed-off-by Andrea Arcangeli <[email protected]>Reviewed-by Andres Lagar-Cavilla <[email protected]>Reviewed-by Peter Feiner <[email protected]>
Signature · 7 lines
Kirill A. Shutemov -- 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 2/5] mm: gup: add __get_user_pages_unlocked to customize gup_flags
In reply to Andrea ArcangeliQuoted 6 lines · Andrea Arcangeli
Some caller (like KVM) may want to set the
gup_flagslikeFOLL_HWPOSIONto get a proper-EHWPOSIONretval instead of-EFAULTto take a more appropriate action ifget_user_pagesruns into a memory failure.Signed-off-by Andrea Arcangeli <[email protected]>
Signature · 7 lines
Kirill A. Shutemov -- 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 3/5] mm: gup: use get_user_pages_unlocked within get_user_pages_fast
In reply to Andrea ArcangeliQuoted 4 lines · Andrea Arcangeli
This allows the
get_user_pages_fastslow path to release themmap_sembefore blocking.Signed-off-by Andrea Arcangeli <[email protected]>
Signature · 7 lines
Kirill A. Shutemov -- 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 4/5] mm: gup: use get_user_pages_unlocked
In reply to Andrea ArcangeliQuoted 4 lines · Andrea Arcangeli
This allows those
get_user_pagescalls to passFAULT_FLAG_ALLOW_RETRYto the page fault in order to release themmap_semduring the I/O.Signed-off-by Andrea Arcangeli <[email protected]>
Signature · 7 lines
Kirill A. Shutemov -- 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 5/5] mm: gup: kvm use get_user_pages_unlocked
In reply to Andrea ArcangeliQuoted 6 lines · Andrea Arcangeli
Use the more generic
get_user_pages_unlockedwhich has the additional benefit of passingFAULT_FLAG_ALLOW_RETRYat the very first page fault (which allows the first page fault in an unmapped area to be always able to block indefinitely by being allowed to release themmap_sem).Signed-off-by Andrea Arcangeli <[email protected]>
Signature · 7 lines
Kirill A. Shutemov -- 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>