From: Mike Rapoport <rppt@kernel.org>
To: David CARLIER <devnexen@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Peter Xu <peterx@redhat.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@kernel.org>
Subject: Re: [PATCH v4] mm/userfaultfd: detect VMA replacement after copy retry in mfill_copy_folio_retry()
Date: Thu, 2 Apr 2026 06:58:33 +0300 [thread overview]
Message-ID: <ac3paYh6sPHr3EJd@kernel.org> (raw)
In-Reply-To: <CA+XhMqzdQLZD4YWzyZfTwd_+sDnLqj24APqBRgum97_=8EcM2Q@mail.gmail.com>
Hi David,
It feels that you use an LLM for correspondence. Please tune it down to
produce more laconic and to the point responses.
On Wed, Apr 01, 2026 at 09:06:36AM +0100, David CARLIER wrote:
> On Tue, Apr 01, 2026 at 08:49:00AM +0300, Mike Rapoport wrote:
> > What does "folio allocated from the original VMA's backing store" exactly
> > mean? Why is this a problem?
>
> Fair point, the commit message was vague here. What I meant is:
>
> mfill_atomic_pte_copy() captures ops = vma_uffd_ops(state->vma) and
> passes it to __mfill_atomic_pte(). There, ops->alloc_folio() allocates
> a folio for the original VMA's inode (e.g. a shmem folio for that
> specific shmem inode).
I wouldn't say ->alloc_folio() allocates a folio _for_ the inode, it
allocates it with inode's memory policy. Worst can happen without any
changes is that the allocated folio will end up in a wrong node.
This is still a footgun, but I don't see it as a big deal.
Let's revisit it after -rc1 and please make sure to cc "MEMORY MAPPING"
folks for insights about how to better track VMA changes or their absence.
> Then mfill_copy_folio_retry() drops all locks for
> the copy_from_user retry. After mfill_get_vma() re-acquires them,
> state->vma may now point to a replacement VMA, but ops is still the
> stale pointer from before the drop.
And this is a bug in my uffd refactoring, and it needs to be fixed ASAP
with a simple comparison of old ops and new ops.
> > Second, I have reservations about vma_snapshot implementation. What
> > invariant does it exactly enforce?
>
> The invariant I was going for: "the folio we allocated is still
> compatible with the VMA we're about to install it into." Since
> alloc_folio() allocates from the VMA's backing file (inode), checking
> that vm_file is still the same after re-acquiring locks ensures the
> folio matches the inode.
Again, it's not that folio matches the inode, but folio is allocated using
the correct mempolicy.
> The vm_flags comparison was a secondary guard against permission/type
> changes during the window.
Permissions should be fine, they are checked in userfaultfd_register.
Some other flags that don't matter to uffd operation may change during the
window, though and then a comparison of vm_flags will give a false
positive.
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-04-02 3:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 13:41 [PATCH v4] mm/userfaultfd: detect VMA replacement after copy retry in mfill_copy_folio_retry() David Carlier
2026-04-01 3:01 ` Andrew Morton
2026-04-01 7:49 ` Mike Rapoport
2026-04-01 8:06 ` David CARLIER
2026-04-01 15:23 ` Peter Xu
2026-04-01 18:34 ` David CARLIER
2026-04-01 19:22 ` Peter Xu
2026-04-01 20:05 ` David CARLIER
2026-04-02 4:02 ` Mike Rapoport
2026-04-02 5:59 ` David CARLIER
2026-04-02 13:29 ` Peter Xu
2026-04-09 11:20 ` Mike Rapoport
2026-04-10 15:10 ` Peter Xu
2026-04-02 3:58 ` Mike Rapoport [this message]
2026-04-02 13:42 ` Peter Xu
2026-04-09 11:31 ` Mike Rapoport
2026-04-10 15:26 ` Peter Xu
2026-04-12 15:46 ` Mike Rapoport
2026-04-13 12:53 ` Peter Xu
2026-04-07 10:17 ` Lorenzo Stoakes (Oracle)
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=ac3paYh6sPHr3EJd@kernel.org \
--to=rppt@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=devnexen@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=peterx@redhat.com \
--cc=vbabka@kernel.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.