userfaultfd: shmem: allow registration of shared memory ranges
Subsystems (3)
[email protected]
maintainerPATCH 78/142 userfaultfd: shmem: allow registration of shared memory ranges
From: Mike Rapoport <[email protected]>
Subject: userfaultfd: shmem: allow registration of shared memory ranges
Expand the userfaultfd_register/unregister routines to allow shared memory VMAs. Currently, there is no UFFDIO_ZEROPAGE and write-protection support for shared memory VMAs, which is reflected in ioctl methods supported by uffdio_register.
Signed-off-by Mike Rapoport <[email protected]>
Signed-off-by Andrea Arcangeli <[email protected]>
Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Michael Rapoport <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
fs/userfaultfd.c | 21 +++++++-------------- include/uapi/linux/userfaultfd.h | 2 +- tools/testing/selftests/vm/userfaultfd.c | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-)
fs/userfaultfd.c renamed from fs/userfaultfd.c~userfaultfd-shmem-allow-registration-of-shared-memory-ranges +7 -14
@@ -1098,7 +1098,8 @@ static __always_inline int validate_rangstatic inline bool vma_can_userfault (struct vm_area_struct *vma) { -return vma_is_anonymous (vma) ||is_vm_hugetlb_page (vma); +return vma_is_anonymous (vma) ||is_vm_hugetlb_page (vma) || +vma_is_shmem (vma); } static int userfaultfd_register(struct userfaultfd_ctx *ctx,
@@ -1111,7 +1112,7 @@ static int userfaultfd_register(struct ustruct uffdio_register __user *user_uffdio_register;unsigned long vm_flags, new_flags;bool found; -bool huge_pages; +bool non_anon_pages;unsigned long start, end, vma_end; user_uffdio_register = (struct uffdio_register __user *) arg;
@@ -1175,13 +1176,9 @@ static int userfaultfd_register(struct u/* * Search for not compatible vmas. -* -* FIXME: this shall be relaxed later so that it doesn't fail -* on tmpfs backed vmas (in addition to the current allowance -* on anonymous vmas). */ found = false; - huge_pages = false; + non_anon_pages = false;for (cur = vma; cur && cur->vm_start < end; cur = cur->vm_next) {cond_resched ();
@@ -1220,8 +1217,8 @@ static int userfaultfd_register(struct u/* * Note vmas containing huge pages */ -if (is_vm_hugetlb_page (cur)) - huge_pages = true; +if (is_vm_hugetlb_page (cur) ||vma_is_shmem (cur)) + non_anon_pages = true; found = true; }
@@ -1292,7 +1289,7 @@ out_unlock:* userland which ioctls methods are guaranteed to * succeed on this range. */ -if (put_user (huge_pages ?UFFD_API_RANGE_IOCTLS_HPAGE : +if (put_user (non_anon_pages ?UFFD_API_RANGE_IOCTLS_BASIC :UFFD_API_RANGE_IOCTLS , &user_uffdio_register->ioctls)) ret = -EFAULT ;
@@ -1352,10 +1349,6 @@ static int userfaultfd_unregister(struct/* * Search for not compatible vmas. -* -* FIXME: this shall be relaxed later so that it doesn't fail -* on tmpfs backed vmas (in addition to the current allowance -* on anonymous vmas). */ found = false; ret = -EINVAL ;
include/uapi/linux/userfaultfd.h renamed from include/uapi/linux/userfaultfd.h~userfaultfd-shmem-allow-registration-of-shared-memory-ranges +1 -1
@@ -30,7 +30,7 @@ ((__u64 )1 << _UFFDIO_WAKE | \ (__u64 )1 << _UFFDIO_COPY | \ (__u64)1 << _UFFDIO_ZEROPAGE) -#define UFFD_API_RANGE_IOCTLS_HPAGE \ +#define UFFD_API_RANGE_IOCTLS_BASIC \ ((__u64)1 << _UFFDIO_WAKE | \ (__u64)1 << _UFFDIO_COPY)
tools/testing/selftests/vm/userfaultfd.c renamed from tools/testing/selftests/vm/userfaultfd.c~userfaultfd-shmem-allow-registration-of-shared-memory-ranges +1 -1
@@ -129,7 +129,7 @@ static void allocate_area(void **alloc_a#else /* HUGETLB_TEST */ -#define EXPECTED_IOCTLS UFFD_API_RANGE_IOCTLS_HPAGE +#define EXPECTED_IOCTLS UFFD_API_RANGE_IOCTLS_BASICstatic int release_pages (char *rel_area) {
_