Re: [PATCH RESEND] userfaultfd: snapshot VMA state across UFFDIO_COPY retry

From: Mike Rapoport

Date: Wed May 20 2026 - 08:45:10 EST


Hi David,

On Tue, May 19, 2026 at 06:36:23AM +0100, David CARLIER wrote:
> On Tue, 19 May 2026 at 06:25, Mike Rapoport <rppt@xxxxxxxxxx> wrote:
>
> > @@ -69,6 +71,24 @@ static const struct vm_uffd_ops *vma_uffd_ops(struct vm_area_struct *vma)
> > return vma->vm_ops ? vma->vm_ops->uffd_ops : NULL;
> > }
> >
> > +static const struct vm_uffd_ops *vma_uffd_copy_ops(struct vm_area_struct *vma)
>
>
> My only 2 cent, I would name it vma_uffd_effective_copy_ops() instead or
> a comment to highlight it is about "UFFDIO_COPY into a MAP_PRIVATE file-backed"

Too long for my taste :)
And comment is useful anyway as it explains why we override the ops at all.

> > +{
> > + const struct vm_uffd_ops *ops = vma_uffd_ops(vma);
> > +
> > + if (!ops)
> > + return NULL;
> > +
> > + /*
> > + * UFFDIO_COPY fills MAP_PRIVATE file-backed mappings as anonymous
> > + * memory. This is an effective ops override, so retry validation must
> > + * compare the override result, not just vma->vm_ops->uffd_ops.
> > + */
> > + if (!(vma->vm_flags & VM_SHARED))
> > + return &anon_uffd_ops;
> > +
> > + return ops;
> > +}

--
Sincerely yours,
Mike.