From: Peter Xu <peterx@redhat.com>
To: David CARLIER <devnexen@gmail.com>
Cc: Mike Rapoport <rppt@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
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: Wed, 1 Apr 2026 11:23:17 -0400 [thread overview]
Message-ID: <ac04ZeFdz7yvByRp@x1.local> (raw)
In-Reply-To: <CA+XhMqzdQLZD4YWzyZfTwd_+sDnLqj24APqBRgum97_=8EcM2Q@mail.gmail.com>
On Wed, Apr 01, 2026 at 09:06:36AM +0100, David CARLIER wrote:
> 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. The vm_flags comparison was a secondary guard
> against permission/type changes during the window.
>
> That said, I can see the vma_snapshot abstraction is doing too much for
> what's really needed. Would a simpler approach work better — just
> saving vm_file (with get_file/fput) before the drop and comparing it
> directly after re-acquiring? That makes the invariant explicit: "same
> backing file means the folio is valid for this VMA."
IMHO the flags is needed, consider a shared shmem vma remapped to a private
shmem vma. That needs to be covered in the fix.
Actually instead of reducing checks, maybe we also need to check the offset
of the mapping too, that is: vma->vm_pgoff can't change otherwise it may
also affect how the back store would behave on this UFFDIO_COPY request.
For that, see the example of shmem_get_pgoff_policy() where it seems we can
apply different policies to different ranges of the back store.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2026-04-01 15:23 UTC|newest]
Thread overview: 13+ 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 [this message]
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-02 3:58 ` Mike Rapoport
2026-04-02 13:42 ` Peter Xu
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=ac04ZeFdz7yvByRp@x1.local \
--to=peterx@redhat.com \
--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=rppt@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox