Re: [PATCH v4 07/15] userfaultfd: introduce vm_uffd_ops

Mike Rapoport
2026-04-09T17:19:14Z

On Thu, Apr 02, 2026 at 03:32:58PM -0400, Tal Zussman wrote:
> Hi Mike,
>
> On 4/2/26 12:11 AM, Mike Rapoport wrote:
> > @@ -2021,34 +2040,33 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
> > bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
> > bool wp_async)
> > {
> > - vm_flags &= __VM_UFFD_FLAGS;
> > + const struct vm_uffd_ops *ops = vma_uffd_ops(vma);
> >
> > - if (vma->vm_flags & VM_DROPPABLE)
> > - return false;
> > -
> > - if ((vm_flags & VM_UFFD_MINOR) &&
> > - (!is_vm_hugetlb_page(vma) && !vma_is_shmem(vma)))
> > - return false;
> > + vm_flags &= __VM_UFFD_FLAGS;
> >
> > /*
> > - * 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;
> > +
>
> Doesn't moving the VM_DROPPABLE check after the wp_async early return make
> the issue David raised in [1] possible again (i.e. moving swapbacked pages
> into a droppable region using UFFDIO_MOVE)? With this change, VM_DROPPABLE
> pages can now be registered with uffd under wp_async, which allows
> UFFDIO_MOVE.
>
> I think the VM_DROPPABLE check should go right before the wp_async check.
> And it would probably benefit from a comment...

You are right.

Andrew, if it's not too late can you please add this fixup:

diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index f1828106484b..75290483ffc7 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -2019,6 +2019,9 @@ bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
{
const struct vm_uffd_ops *ops = vma_uffd_ops(vma);

+ if (vma->vm_flags & VM_DROPPABLE)
+ return false;
+
vm_flags &= __VM_UFFD_FLAGS;

/*
@@ -2032,9 +2035,6 @@ bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
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

> Thanks,
> Tal

--
Sincerely yours,
Mike.