BACKPORT: FROMGIT: userfaultfd/shmem: support minor fault registration for shmem
This patch allows shmem-backed VMAs to be registered for minor faults. Minor faults are appropriately relayed to userspace in the fault path, for VMAs with the relevant flag. This commit doesn't hook up the UFFDIO_CONTINUE ioctl for shmem-backed minor faults, though, so userspace doesn't yet have a way to resolve such faults. Because of this, we also don't yet advertise this as a supported feature. That will be done in a separate commit when the feature is fully implemented. Link: https://lkml.kernel.org/r/20210503180737.2487560-4-axelrasmussen@google.com Signed-off-by: Axel Rasmussen <axelrasmussen@google.com> Acked-by: Peter Xu <peterx@redhat.com> Acked-by: Hugh Dickins <hughd@google.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Brian Geffon <bgeffon@google.com> Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Joe Perches <joe@perches.com> Cc: Kirill A. Shutemov <kirill@shutemov.name> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: Mina Almasry <almasrymina@google.com> Cc: Oliver Upton <oupton@google.com> Cc: Shaohua Li <shli@fb.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Wang Qing <wangqing@vivo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> (cherry picked from commit 5e5c844fd6d406a47c921c54b99f023ee6e3da8b https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm) Link: https://lore.kernel.org/patchwork/patch/1420970/ Conflicts: mm/shmem.c (Manual rebase) Signed-off-by: Lokesh Gidra <lokeshgidra@google.com> Bug: 187930641 Change-Id: Ib8e3fe202feab7404742814f4250a0981065368c
This commit is contained in:

committed by
Suren Baghdasaryan

parent
5f6dc07839
commit
0c959cd889
@@ -1273,8 +1273,7 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma,
|
||||
}
|
||||
|
||||
if (vm_flags & VM_UFFD_MINOR) {
|
||||
/* FIXME: Add minor fault interception for shmem. */
|
||||
if (!is_vm_hugetlb_page(vma))
|
||||
if (!(is_vm_hugetlb_page(vma) || vma_is_shmem(vma)))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -4244,9 +4244,11 @@ static vm_fault_t do_read_fault(struct vm_fault *vmf)
|
||||
* something).
|
||||
*/
|
||||
if (vma->vm_ops->map_pages && fault_around_bytes >> PAGE_SHIFT > 1) {
|
||||
ret = do_fault_around(vmf);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (likely(!userfaultfd_minor(vmf->vma))) {
|
||||
ret = do_fault_around(vmf);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret = __do_fault(vmf);
|
||||
|
12
mm/shmem.c
12
mm/shmem.c
@@ -1787,7 +1787,7 @@ unlock:
|
||||
* vm. If we swap it in we mark it dirty since we also free the swap
|
||||
* entry since a page cannot live in both the swap and page cache.
|
||||
*
|
||||
* vmf and fault_type are only supplied by shmem_fault:
|
||||
* vma, vmf, and fault_type are only supplied by shmem_fault:
|
||||
* otherwise they are NULL.
|
||||
*/
|
||||
static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
|
||||
@@ -1820,6 +1820,16 @@ repeat:
|
||||
charge_mm = vma ? vma->vm_mm : current->mm;
|
||||
|
||||
page = find_lock_entry(mapping, index);
|
||||
|
||||
if (page && vma && userfaultfd_minor(vma)) {
|
||||
if (!xa_is_value(page)) {
|
||||
unlock_page(page);
|
||||
put_page(page);
|
||||
}
|
||||
*fault_type = handle_userfault(vmf, VM_UFFD_MINOR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (xa_is_value(page)) {
|
||||
error = shmem_swapin_page(inode, index, &page,
|
||||
sgp, gfp, vma, fault_type);
|
||||
|
Reference in New Issue
Block a user