Skip to content

mm, kvm: add guest_memfd support for uffd minor faults

Mike Rapoport kvm linux-kselftest linux-mm lkml 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest5 patches 14 repliesIn review
  2. v25 patches 21 repliesSuperseded
  3. v15 patches 5 repliesSuperseded

Changes in v3 from the cover letter

* rename ->get_folio() to ->get_folio_noalloc()
* fix build errors reported by kbuild
* pull handling of UFFD_MINOR out of hotpath in __do_fault()
* update guest_memfs changes so its ->fault() and ->get_folio_noalloc() follow the same semantics as shmem and hugetlb.
* s/MISSING/MINOR/g in changelogs
* added review tags

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5userfaultfd: move vma_can_userfault out of lineinclude/linux/userfaultfd_k.h mm/userfaultfd.c+36 -340 replies
2/5userfaultfd, shmem: use a VMA callback to handle UFFDIO_CONTINUEinclude/linux/mm.h mm/shmem.c mm/userfaultfd.c+60 -190 replies
3/5mm: introduce VM_FAULT_UFFD_MINOR fault reasoninclude/linux/mm_types.h mm/memory.c mm/shmem.c+14 -31 reply
4/5guest_memfd: add support for userfaultfd minor modevirt/kvm/guest_memfd.c+32 -113 replies
5/5KVM: selftests: test userfaultfd minor for guest_memfdtools/testing/selftests/kvm/guest_memfd_test.c+97 -00 replies

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchDavid Hildenbrand (Red Hat)Liam R. Howlett
1/5R-b R-b
2/5A-b R-b
3/5A-b
4/5R-b
5/5A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/5] mm, kvm: add guest_memfd support for uffd minor faults

From: "Mike Rapoport (Microsoft)" <[email protected]>

Hi,

These patches allow guest_memfd to notify userspace about minor page faults using userfaultfd and let userspace to resolve these page faults using UFFDIO_CONTINUE.

To allow UFFDIO_CONTINUE outside of the core mm I added a get_folio_noalloc() callback to vm_ops that allows an address space backing a VMA to return a folio that exists in it's page cache (patch 2)

In order for guest_memfd to notify userspace about page faults, there is a new VM_FAULT_UFFD_MINOR that a ->fault() handler can return to inform the page fault handler that it needs to call handle_userfault() to complete the fault (patch 3).

Patch 4 plumbs these new goodies into guest_memfd.

This series is the minimal change I've been able to come up with to allow integration of guest_memfd with uffd and while refactoring uffd and making mfill_atomic() flow more linear would have been a nice improvement, it's way out of the scope of enabling uffd with guest_memfd.

v3 changes:
* rename ->get_folio() to ->get_folio_noalloc()
* fix build errors reported by kbuild
* pull handling of UFFD_MINOR out of hotpath in __do_fault()
* update guest_memfs changes so its ->fault() and ->get_folio_noalloc() follow the same semantics as shmem and hugetlb.
* s/MISSING/MINOR/g in changelogs
* added review tags

v2: https://lore.kernel.org/all/[email protected]
* rename ->get_shared_folio() to ->get_folio()
* hardwire VM_FAULF_UFFD_MINOR to 0 when CONFIG_USERFAULTFD=n

v1: https://patch.msgid.link/[email protected]
* Introduce VM_FAULF_UFFD_MINOR to avoid exporting handle_userfault()
* Simplify vma_can_mfill_atomic()
* Rename get_pagecache_folio() to get_shared_folio() and use inode instead of vma as its argument

rfc: https://patch.msgid.link/[email protected]

Mike Rapoport (Microsoft) (4):
userfaultfd: move vma_can_userfault out of line userfaultfd, shmem: use a VMA callback to handle UFFDIO_CONTINUE
mm: introduce VM_FAULT_UFFD_MINOR fault reason
guest_memfd: add support for userfaultfd minor mode

Nikita Kalyazin (1):
KVM: selftests: test userfaultfd minor for guest_memfd

 include/linux/mm.h                            |  9 ++
 include/linux/mm_types.h                      | 10 +-
 include/linux/userfaultfd_k.h                 | 36 +------
 mm/memory.c                                   |  5 +-
 mm/shmem.c                                    | 20 +++-
 mm/userfaultfd.c                              | 80 ++++++++++++---
 .../testing/selftests/kvm/guest_memfd_test.c  | 97 +++++++++++++++++++
 virt/kvm/guest_memfd.c                        | 33 ++++++-
 8 files changed, 236 insertions(+), 54 deletions(-)

base-commit: ac3fd01e4c1efce8f2c054cdeb2ddd2fc0fb150d

Signature · 1 line
2.51.0