[PATCH 1/1] userfaultfd: allow registration of WP_ASYNC for any VMA
From: Mike Rapoport (Microsoft)
Date: Wed Mar 11 2026 - 14:21:38 EST
Registration of a VMA with WP_ASYNC userfaulfd context in write-protect
mode does not require any VMA-specific resolution of user faults and
these faults are completely handled by the generic page fault handler.
This functionality existed since the introduction of WP_ASYNC mode and
it allows tracking writes to SysV shared memory mappings (shmget(2) and
shmat(2)).
Move the check for WP mode before checking for presence of ->uffd_ops in a
VMA to restore the original behaviour.
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
mm/userfaultfd.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index b55d4a8d88cc..436795bf218e 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -2044,22 +2044,22 @@ bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
{
const struct vm_uffd_ops *ops = vma_uffd_ops(vma);
- /* only VMAs that implement vm_uffd_ops are supported */
- if (!ops)
- return false;
-
vm_flags &= __VM_UFFD_FLAGS;
- if (vma->vm_flags & VM_DROPPABLE)
- return false;
-
/*
- * If wp async enabled, and WP is the only mode enabled, allow any
+ * If WP is the only mode enabled and context is wp async, allow any
* memory type.
*/
if (wp_async && (vm_flags == VM_UFFD_WP))
return true;
+ /* For any other mode reject VMAs that don't implement vm_uffd_ops */
+ if (!ops)
+ return false;
+
+ if (vma->vm_flags & VM_DROPPABLE)
+ return false;
+
/*
* If user requested uffd-wp but not enabled pte markers for
* uffd-wp, then only anonymous memory is supported
--
2.51.0