Skip to content

Commit ba6907d

Browse files
rppttorvalds
authored andcommitted
userfaultfd: introduce vma_can_userfault
Check whether a VMA can be used with userfault in more compact way Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport <[email protected]> Signed-off-by: Andrea Arcangeli <[email protected]> Acked-by: Hillf Danton <[email protected]> Cc: "Dr. David Alan Gilbert" <[email protected]> Cc: Michael Rapoport <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Pavel Emelyanov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 163e11b commit ba6907d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

fs/userfaultfd.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,11 @@ static __always_inline int validate_range(struct mm_struct *mm,
10961096
return 0;
10971097
}
10981098

1099+
static inline bool vma_can_userfault(struct vm_area_struct *vma)
1100+
{
1101+
return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma);
1102+
}
1103+
10991104
static int userfaultfd_register(struct userfaultfd_ctx *ctx,
11001105
unsigned long arg)
11011106
{
@@ -1185,7 +1190,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
11851190

11861191
/* check not compatible vmas */
11871192
ret = -EINVAL;
1188-
if (!vma_is_anonymous(cur) && !is_vm_hugetlb_page(cur))
1193+
if (!vma_can_userfault(cur))
11891194
goto out_unlock;
11901195
/*
11911196
* If this vma contains ending address, and huge pages
@@ -1229,7 +1234,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
12291234
do {
12301235
cond_resched();
12311236

1232-
BUG_ON(!vma_is_anonymous(vma) && !is_vm_hugetlb_page(vma));
1237+
BUG_ON(!vma_can_userfault(vma));
12331238
BUG_ON(vma->vm_userfaultfd_ctx.ctx &&
12341239
vma->vm_userfaultfd_ctx.ctx != ctx);
12351240

@@ -1367,7 +1372,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
13671372
* provides for more strict behavior to notice
13681373
* unregistration errors.
13691374
*/
1370-
if (!vma_is_anonymous(cur) && !is_vm_hugetlb_page(cur))
1375+
if (!vma_can_userfault(cur))
13711376
goto out_unlock;
13721377

13731378
found = true;
@@ -1381,7 +1386,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
13811386
do {
13821387
cond_resched();
13831388

1384-
BUG_ON(!vma_is_anonymous(vma) && !is_vm_hugetlb_page(vma));
1389+
BUG_ON(!vma_can_userfault(vma));
13851390

13861391
/*
13871392
* Nothing to do: this vma is already registered into this

0 commit comments

Comments
 (0)