summaryrefslogtreecommitdiffstats
path: root/fs/userfaultfd.c
diff options
context:
space:
mode:
authorMike Rapoport <rppt@linux.vnet.ibm.com>2017-02-22 15:43:22 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2017-02-22 16:41:28 -0800
commitba6907db6de17cf90c4fc67f3eb1d1d37dd0b7ac (patch)
tree3276c0440ef2e4ba611fc5b235d0567a3b0e1fb4 /fs/userfaultfd.c
parent163e11bc4f6ebbfcfdf751c108bd212a26e492ee (diff)
downloadop-kernel-dev-ba6907db6de17cf90c4fc67f3eb1d1d37dd0b7ac.zip
op-kernel-dev-ba6907db6de17cf90c4fc67f3eb1d1d37dd0b7ac.tar.gz
userfaultfd: introduce vma_can_userfault
Check whether a VMA can be used with userfault in more compact way Link: http://lkml.kernel.org/r/20161216144821.5183-28-aarcange@redhat.com Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Acked-by: Hillf Danton <hillf.zj@alibaba-inc.com> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com> Cc: Michael Rapoport <RAPOPORT@il.ibm.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/userfaultfd.c')
-rw-r--r--fs/userfaultfd.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 11b5e65..593135c 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1096,6 +1096,11 @@ static __always_inline int validate_range(struct mm_struct *mm,
return 0;
}
+static inline bool vma_can_userfault(struct vm_area_struct *vma)
+{
+ return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma);
+}
+
static int userfaultfd_register(struct userfaultfd_ctx *ctx,
unsigned long arg)
{
@@ -1185,7 +1190,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
/* check not compatible vmas */
ret = -EINVAL;
- if (!vma_is_anonymous(cur) && !is_vm_hugetlb_page(cur))
+ if (!vma_can_userfault(cur))
goto out_unlock;
/*
* If this vma contains ending address, and huge pages
@@ -1229,7 +1234,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
do {
cond_resched();
- BUG_ON(!vma_is_anonymous(vma) && !is_vm_hugetlb_page(vma));
+ BUG_ON(!vma_can_userfault(vma));
BUG_ON(vma->vm_userfaultfd_ctx.ctx &&
vma->vm_userfaultfd_ctx.ctx != ctx);
@@ -1367,7 +1372,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
* provides for more strict behavior to notice
* unregistration errors.
*/
- if (!vma_is_anonymous(cur) && !is_vm_hugetlb_page(cur))
+ if (!vma_can_userfault(cur))
goto out_unlock;
found = true;
@@ -1381,7 +1386,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
do {
cond_resched();
- BUG_ON(!vma_is_anonymous(vma) && !is_vm_hugetlb_page(vma));
+ BUG_ON(!vma_can_userfault(vma));
/*
* Nothing to do: this vma is already registered into this
OpenPOWER on IntegriCloud