All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: James Houghton <jthoughton@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	David Hildenbrand <david@kernel.org>,
	Hugh Dickins <hughd@google.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Michal Hocko <mhocko@suse.com>,
	Muchun Song <muchun.song@linux.dev>,
	Nikita Kalyazin <kalyazin@amazon.com>,
	Oscar Salvador <osalvador@suse.de>,
	Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Shuah Khan <shuah@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v2 10/15] shmem, userfaultfd: implement shmem uffd operations using vm_uffd_ops
Date: Fri, 27 Mar 2026 10:46:15 +0300	[thread overview]
Message-ID: <acY1x8M3y7xWLwBa@kernel.org> (raw)
In-Reply-To: <CADrL8HXajnfE=WusxL=DeF7VcvrsX9z5XDC4mPt1JfMOd7J5DA@mail.gmail.com>

On Thu, Mar 26, 2026 at 06:13:37PM -0700, James Houghton wrote:
> On Fri, Mar 6, 2026 at 9:19 AM Mike Rapoport <rppt@kernel.org> wrote:
> >
> > From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> >
> > Add filemap_add() and filemap_remove() methods to vm_uffd_ops and use
> > them in __mfill_atomic_pte() to add shmem folios to page cache and
> > remove them in case of error.
> >
> > Implement these methods in shmem along with vm_uffd_ops->alloc_folio()
> > and drop shmem_mfill_atomic_pte().
> >
> > Since userfaultfd now does not reference any functions from shmem, drop
> > include if linux/shmem_fs.h from mm/userfaultfd.c
> >
> > mfill_atomic_install_pte() is not used anywhere outside of
> > mm/userfaultfd, make it static.
> >
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > ---
> >  include/linux/shmem_fs.h      |  14 ----
> >  include/linux/userfaultfd_k.h |  21 +++--
> >  mm/shmem.c                    | 148 ++++++++++++----------------------
> >  mm/userfaultfd.c              |  79 +++++++++---------
> >  4 files changed, 106 insertions(+), 156 deletions(-)
> >
> > diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
> > index a8273b32e041..1a345142af7d 100644
> > --- a/include/linux/shmem_fs.h
> > +++ b/include/linux/shmem_fs.h
> > @@ -221,20 +221,6 @@ static inline pgoff_t shmem_fallocend(struct inode *inode, pgoff_t eof)
> >
> >  extern bool shmem_charge(struct inode *inode, long pages);
> >
> > -#ifdef CONFIG_USERFAULTFD
> > -#ifdef CONFIG_SHMEM
> > -extern int shmem_mfill_atomic_pte(pmd_t *dst_pmd,
> > -                                 struct vm_area_struct *dst_vma,
> > -                                 unsigned long dst_addr,
> > -                                 unsigned long src_addr,
> > -                                 uffd_flags_t flags,
> > -                                 struct folio **foliop);
> > -#else /* !CONFIG_SHMEM */
> > -#define shmem_mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, \
> > -                              src_addr, flags, foliop) ({ BUG(); 0; })
> > -#endif /* CONFIG_SHMEM */
> > -#endif /* CONFIG_USERFAULTFD */
> > -
> >  /*
> >   * Used space is stored as unsigned 64-bit value in bytes but
> >   * quota core supports only signed 64-bit values so use that
> > diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
> > index 4d8b879eed91..bf4e595ac914 100644
> > --- a/include/linux/userfaultfd_k.h
> > +++ b/include/linux/userfaultfd_k.h
> > @@ -93,10 +93,24 @@ struct vm_uffd_ops {
> >         struct folio *(*get_folio_noalloc)(struct inode *inode, pgoff_t pgoff);
> >         /*
> >          * Called during resolution of UFFDIO_COPY request.
> > -        * Should return allocate a and return folio or NULL if allocation fails.
> > +        * Should allocate and return a folio or NULL if allocation
> > +        * fails.
> >          */
> >         struct folio *(*alloc_folio)(struct vm_area_struct *vma,
> >                                      unsigned long addr);
> > +       /*
> > +        * Called during resolution of UFFDIO_COPY request.
> > +        * Should lock the folio and add it to VMA's page cache.
> 
> I don't think "should lock the folio" is accurate. That sounds like
> "it will call folio_lock()" but it actually calls
> __folio_set_locked(). Maybe this is better:
> 
> "Should only be called with a folio returned by alloc_folio() above.
> The folio will set to locked."

Yeah, sounds good.
 
> > +        * Returns 0 on success, error code on failure.
> > +        */
> > +       int (*filemap_add)(struct folio *folio, struct vm_area_struct *vma,
> > +                        unsigned long addr);

> > @@ -404,6 +400,9 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd,
> >
> >         set_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte);
> >
> > +       if (page_in_cache)
> > +               folio_unlock(folio);
> 
> I don't really like doing the folio_unlock() *here*, I think it's
> clearer if the callers (mfill_atomic_pte_continue() and
> __mfill_atomic_pte()) unlocked the folio themselves. But that's just
> my opinion.

We already have page_in_cache here, so I'd prefer to keep a single
folio_unlock() rather than add additional if (page_in_cache) in
__mfill_atomic_pte().
 
> > +
> >         /* No need to invalidate - it was non-present before */
> >         update_mmu_cache(dst_vma, dst_addr, dst_pte);
> >         ret = 0;
> > @@ -836,41 +856,18 @@ extern ssize_t mfill_atomic_hugetlb(struct userfaultfd_ctx *ctx,
> >
> >  static __always_inline ssize_t mfill_atomic_pte(struct mfill_state *state)
> >  {
> > -       struct vm_area_struct *dst_vma = state->vma;
> > -       unsigned long src_addr = state->src_addr;
> > -       unsigned long dst_addr = state->dst_addr;
> > -       struct folio **foliop = &state->folio;
> >         uffd_flags_t flags = state->flags;
> > -       pmd_t *dst_pmd = state->pmd;
> > -       ssize_t err;
> >
> >         if (uffd_flags_mode_is(flags, MFILL_ATOMIC_CONTINUE))
> >                 return mfill_atomic_pte_continue(state);
> >         if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON))
> >                 return mfill_atomic_pte_poison(state);
> > +       if (uffd_flags_mode_is(flags, MFILL_ATOMIC_COPY))
> > +               return mfill_atomic_pte_copy(state);
> > +       if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE))
> > +               return mfill_atomic_pte_zeropage(state);
> 
> Thanks for this cleanup. :)
> 
> >
> > -       /*
> > -        * The normal page fault path for a shmem will invoke the
> > -        * fault, fill the hole in the file and COW it right away. The
> > -        * result generates plain anonymous memory. So when we are
> > -        * asked to fill an hole in a MAP_PRIVATE shmem mapping, we'll
> > -        * generate anonymous memory directly without actually filling
> > -        * the hole. For the MAP_PRIVATE case the robustness check
> > -        * only happens in the pagetable (to verify it's still none)
> > -        * and not in the radix tree.
> > -        */
> > -       if (!(dst_vma->vm_flags & VM_SHARED)) {
> > -               if (uffd_flags_mode_is(flags, MFILL_ATOMIC_COPY))
> > -                       err = mfill_atomic_pte_copy(state);
> > -               else
> > -                       err = mfill_atomic_pte_zeropage(state);
> > -       } else {
> > -               err = shmem_mfill_atomic_pte(dst_pmd, dst_vma,
> > -                                            dst_addr, src_addr,
> > -                                            flags, foliop);
> > -       }
> > -
> > -       return err;
> > +       return -EOPNOTSUPP;
> 
> WARN_ONCE() here I think.

I'll add VM_WARN_ONCE() here.

> Feel free to add:
> 
> Reviewed-by: James Houghton <jthoughton@google.com>

Thanks!

-- 
Sincerely yours,
Mike.

  reply	other threads:[~2026-03-27  7:46 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-06 17:18 [PATCH v2 00/15] mm, kvm: allow uffd support in guest_memfd Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 01/15] userfaultfd: introduce mfill_copy_folio_locked() helper Mike Rapoport
2026-03-20 11:58   ` David Hildenbrand (Arm)
2026-03-06 17:18 ` [PATCH v2 02/15] userfaultfd: introduce struct mfill_state Mike Rapoport
2026-03-20 12:43   ` David Hildenbrand (Arm)
2026-03-22 10:03     ` Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 03/15] userfaultfd: introduce mfill_get_pmd() helper Mike Rapoport
2026-03-20 12:55   ` David Hildenbrand (Arm)
2026-03-22 10:22     ` Mike Rapoport
2026-03-30 15:21       ` David Hildenbrand (Arm)
2026-03-06 17:18 ` [PATCH v2 04/15] userfaultfd: introduce mfill_get_vma() and mfill_put_vma() Mike Rapoport
     [not found]   ` <abe1FHyYinvfLYnw@hyeyoo>
2026-03-16  7:48     ` [PATCH v2 4/15] " Harry Yoo
2026-03-16  8:05       ` Deepanshu Kartikey
2026-03-16  8:36         ` Harry Yoo
2026-03-16  8:52           ` Deepanshu Kartikey
2026-03-06 17:18 ` [PATCH v2 05/15] userfaultfd: retry copying with locks dropped in mfill_atomic_pte_copy() Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 06/15] userfaultfd: move vma_can_userfault out of line Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 07/15] userfaultfd: introduce vm_uffd_ops Mike Rapoport
2026-03-11 18:49   ` Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 08/15] shmem, userfaultfd: use a VMA callback to handle UFFDIO_CONTINUE Mike Rapoport
2026-03-26 23:43   ` James Houghton
2026-03-27  0:26     ` Andrew Morton
2026-03-27  7:12     ` Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 09/15] userfaultfd: introduce vm_uffd_ops->alloc_folio() Mike Rapoport
2026-03-27  0:07   ` James Houghton
2026-03-27  7:17     ` Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 10/15] shmem, userfaultfd: implement shmem uffd operations using vm_uffd_ops Mike Rapoport
2026-03-27  1:13   ` James Houghton
2026-03-27  7:46     ` Mike Rapoport [this message]
2026-03-06 17:18 ` [PATCH v2 11/15] userfaultfd: mfill_atomic(): remove retry logic Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 12/15] mm: generalize handling of userfaults in __do_fault() Mike Rapoport
2026-03-27  1:55   ` James Houghton
2026-03-27 11:31     ` Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 13/15] KVM: guest_memfd: implement userfaultfd operations Mike Rapoport
2026-03-27  2:33   ` James Houghton
2026-03-27 11:47     ` Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 14/15] KVM: selftests: test userfaultfd minor for guest_memfd Mike Rapoport
2026-03-06 17:18 ` [PATCH v2 15/15] KVM: selftests: test userfaultfd missing " Mike Rapoport
2026-03-06 22:21 ` [PATCH v2 00/15] mm, kvm: allow uffd support in guest_memfd Andrew Morton
2026-03-26 23:23 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=acY1x8M3y7xWLwBa@kernel.org \
    --to=rppt@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=hughd@google.com \
    --cc=jthoughton@google.com \
    --cc=kalyazin@amazon.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.