From: Mike Rapoport <rppt@linux.vnet.ibm.com>
To: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>,
Pavel Emelyanov <xemul@virtuozzo.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Mike Rapoport <rppt@linux.vnet.ibm.com>
Subject: [PATCH 6/7] userfaultfd: shmem: allow registration of shared memory ranges
Date: Thu, 4 Aug 2016 11:14:17 +0300 [thread overview]
Message-ID: <1470298458-9925-7-git-send-email-rppt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1470298458-9925-1-git-send-email-rppt@linux.vnet.ibm.com>
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 <rppt@linux.vnet.ibm.com>
---
fs/userfaultfd.c | 21 +++++++--------------
include/uapi/linux/userfaultfd.h | 2 +-
tools/testing/selftests/vm/userfaultfd.c | 2 +-
3 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 2aab2e1..2f9c87e 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1068,7 +1068,8 @@ static __always_inline int validate_range(struct mm_struct *mm,
static 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,
@@ -1081,7 +1082,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
struct 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;
@@ -1138,13 +1139,9 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
/*
* 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();
@@ -1188,8 +1185,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
/*
* 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;
}
@@ -1260,7 +1257,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;
@@ -1320,10 +1317,6 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
/*
* 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;
diff --git a/include/uapi/linux/userfaultfd.h b/include/uapi/linux/userfaultfd.h
index 7a386c5..a9c3389 100644
--- a/include/uapi/linux/userfaultfd.h
+++ b/include/uapi/linux/userfaultfd.h
@@ -31,7 +31,7 @@
(__u64)1 << _UFFDIO_COPY | \
(__u64)1 << _UFFDIO_ZEROPAGE | \
(__u64)1 << _UFFDIO_WRITEPROTECT)
-#define UFFD_API_RANGE_IOCTLS_HPAGE \
+#define UFFD_API_RANGE_IOCTLS_BASIC \
((__u64)1 << _UFFDIO_WAKE | \
(__u64)1 << _UFFDIO_COPY)
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index 3011711..d753a91 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -129,7 +129,7 @@ static void allocate_area(void **alloc_area)
#else /* HUGETLB_TEST */
-#define EXPECTED_IOCTLS UFFD_API_RANGE_IOCTLS_HPAGE
+#define EXPECTED_IOCTLS UFFD_API_RANGE_IOCTLS_BASIC
static int release_pages(char *rel_area)
{
--
1.9.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-08-04 8:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-04 8:14 [PATCH 0/7] userfaultfd: add support for shared memory Mike Rapoport
2016-08-04 8:14 ` [PATCH 1/7] userfaultfd: introduce vma_can_userfault Mike Rapoport
2016-08-04 8:14 ` [PATCH 2/7] userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support Mike Rapoport
2016-08-04 8:14 ` [PATCH 3/7] userfaultfd: shmem: introduce vma_is_shmem Mike Rapoport
2016-08-04 8:14 ` [PATCH 4/7] userfaultfd: shmem: use shmem_mcopy_atomic_pte for shared memory Mike Rapoport
2016-08-04 8:14 ` [PATCH 5/7] userfaultfd: shmem: add userfaultfd hook for shared memory faults Mike Rapoport
2016-08-04 8:14 ` Mike Rapoport [this message]
2016-08-04 8:14 ` [PATCH 7/7] userfaultfd: shmem: add userfaultfd_shmem test Mike Rapoport
2016-08-04 18:54 ` [PATCH 0/7] userfaultfd: add support for shared memory Andrea Arcangeli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470298458-9925-7-git-send-email-rppt@linux.vnet.ibm.com \
--to=rppt@linux.vnet.ibm.com \
--cc=aarcange@redhat.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=xemul@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox