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

From: Tal Zussman

Date: Thu Apr 02 2026 - 15:33:16 EST


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...

[1] https://lore.kernel.org/linux-mm/5a875a3a-2243-4eab-856f-bc53ccfec3ea@xxxxxxxxxx/

Thanks,
Tal