From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 0208B6B02B9 for ; Wed, 2 Nov 2016 15:34:12 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id w39so10770661qtw.0 for ; Wed, 02 Nov 2016 12:34:12 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id a8si1908483qte.122.2016.11.02.12.34.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Nov 2016 12:34:12 -0700 (PDT) From: Andrea Arcangeli Subject: [PATCH 20/33] userfaultfd: introduce vma_can_userfault Date: Wed, 2 Nov 2016 20:33:52 +0100 Message-Id: <1478115245-32090-21-git-send-email-aarcange@redhat.com> In-Reply-To: <1478115245-32090-1-git-send-email-aarcange@redhat.com> References: <1478115245-32090-1-git-send-email-aarcange@redhat.com> Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton Cc: linux-mm@kvack.org, Michael Rapoport , "Dr. David Alan Gilbert"@v2.random, " , Mike Kravetz , Shaohua Li , Pavel Emelyanov "@v2.random From: Mike Rapoport Check whether a VMA can be used with userfault in more compact way Signed-off-by: Mike Rapoport Signed-off-by: Andrea Arcangeli --- fs/userfaultfd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 9552734..387fe77 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1060,6 +1060,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) { @@ -1149,7 +1154,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 @@ -1193,7 +1198,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); @@ -1331,7 +1336,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; @@ -1345,7 +1350,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 -- 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: email@kvack.org