The userfaultfd handling in do_wp_page() is very special comparing to
the rest of the function because it only postpones the real handling
of the page fault to the userspace program.  Isolate the handling part
of do_wp_page() into a new function called do_wp_page_cont() so that
we can use it somewhere else when resolving the userfault page fault.

Signed-off-by: Peter Xu <pet...@redhat.com>
---
 include/linux/mm.h | 2 ++
 mm/memory.c        | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index a5ac81188523..a2911de04cdd 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -445,6 +445,8 @@ struct vm_fault {
                                         */
 };
 
+vm_fault_t do_wp_page_cont(struct vm_fault *vmf);
+
 /* page entry size for vm->huge_fault() */
 enum page_entry_size {
        PE_SIZE_PTE = 0,
diff --git a/mm/memory.c b/mm/memory.c
index 64bd8075f054..ab98a1eb4702 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2497,6 +2497,14 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
                return handle_userfault(vmf, VM_UFFD_WP);
        }
 
+       return do_wp_page_cont(vmf);
+}
+
+vm_fault_t do_wp_page_cont(struct vm_fault *vmf)
+       __releases(vmf->ptl)
+{
+       struct vm_area_struct *vma = vmf->vma;
+
        vmf->page = vm_normal_page(vma, vmf->address, vmf->orig_pte);
        if (!vmf->page) {
                /*
-- 
2.17.1

Reply via email to