Re: [PATCH v2 1/4] mm: Introduce vm_uffd_ops API

Peter Xu
2025-09-22T16:38:18Z

On Fri, Sep 19, 2025 at 01:22:01PM -0400, Liam R. Howlett wrote:
> > > The shmem call already depends on the vma flags.. which it still does in
> > > your patch 4 here. So you've replaced this:
> > >
> > > if (!(dst_vma->vm_flags & VM_SHARED)) {
> > > ...
> > > } else {
> > > shmem_mfill_atomic_pte()
> > > }
> > >
> > > With...
> > >
> > > if (!(dst_vma->vm_flags & VM_SHARED)) {
> > > ...
> > > } else {
> > > ...
> > > uffd_ops->uffd_copy()
> > > }
> >
> > I'm not 100% sure I get this comment. It's intentional to depend on vma
> > flags here for shmem. See Andrea's commit:
> >
> > commit 5b51072e97d587186c2f5390c8c9c1fb7e179505
> > Author: Andrea Arcangeli <aarcange@redhat.com>
> > Date: Fri Nov 30 14:09:28 2018 -0800
> >
> > userfaultfd: shmem: allocate anonymous memory for MAP_PRIVATE shmem
> >
> > Are you suggesting we should merge it somehow? I'd appreciate some
> > concrete example here if so.
>
> What I am saying is that the containing function, mfill_atomic_pte(),
> should be absorbed into each memory type's ->uffd_copy(), at least
> partially.
>
> Shouldn't each memory type do all the necessary checks in ->uffd_copy()?
>
> To put it another way, no shared memory vma will enter the if()
> statement, so why are we checking if they need to?
>
> So if the default uffd_copy() does the if (!shared) stuff, you can just
> call uffd_ops->uffd_copy() with out any check there, right?

IIUC this is the only piece of technical side of discussion that was not
addressed, so I'm replying explicitly to this one. Please let me know if I
missed something else.

Here we need to keep MAP_PRIVATE separate and as a common code to
UFFDIO_COPY / ZEROCOPY. It not only applies to shmem even if it was about
shmem only at that time when Andrea fixed this case, it was simply because
hugetlbfs was working fine via its separate path.

In general, shmem is the file system, and when it's mapped MAP_PRIVATE (and
even if it's called shmem) we should bypass page cache, hence uffd_copy()
shouldn't be used. It should apply to other file systems too when
UFFDIO_COPY/ZEROCOPY will be implemented via ->uffd_copy().

However since we're not going to export ->uffd_copy() in the new version,
it's also out of the picture.

Thanks,

--
Peter Xu