From: Peter Xu <peterx@redhat.com>
To: Mike Rapoport <rppt@kernel.org>
Cc: David CARLIER <devnexen@gmail.com>,
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>,
Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH v4] mm/userfaultfd: detect VMA replacement after copy retry in mfill_copy_folio_retry()
Date: Fri, 10 Apr 2026 11:10:40 -0400 [thread overview]
Message-ID: <adkS8DkNZKHh3kmj@x1.local> (raw)
In-Reply-To: <adeLb5G3PgE_zuct@kernel.org>
On Thu, Apr 09, 2026 at 02:20:15PM +0300, Mike Rapoport wrote:
> On Thu, Apr 02, 2026 at 09:29:56AM -0400, Peter Xu wrote:
> > Hi, Mike,
> >
> > On Thu, Apr 02, 2026 at 07:02:40AM +0300, Mike Rapoport wrote:
> > > On Wed, Apr 01, 2026 at 03:22:03PM -0400, Peter Xu wrote:
> > > >
> > > > The other thing is I just noticed the err code was changed to -EINVAL for
> > > > snapshot changed cases, sorry I didn't follow previously as closely on the
> > > > discussion. I think it should be -EAGAIN. It's because the userapp can't
> > > > resolve -EINVAL failures and app will crash. In a VMA change use case, we
> > > > should return -EAGAIN to imply the app to retry, rather than crashing.
> > >
> > > No. The return value should express that the VMA is invalid. -EINVAL could
> > > work, but looking now at the manual -ENOENT would be even better:
> > >
> > > ENOENT (since Linux 4.11)
> > > The faulting process has changed its virtual memory layout
> > > simultaneously with an outstanding UFFDIO_COPY operation.
> >
> > The VMA changed, but it doesn't mean the UFFDIO_COPY becomes illegal, am I
> > right?
>
> I don't think that "munmap + mmap + userfault_register"
> during an outstanding UFFDIO_COPY to the same range is, hmm, the smartest
> thing to do, and I think aborting the outstanding UFFDIO_COPY in such case
> is better than allowing it to continue.
It doesn't need to be unmap+map+register. As mentioned below, I believe
writting 4 to clear_refs will already change VMA flags. There're also many
other ways to change, IIUC, like mprotect() on top of uffd MISSING
registered ranges.
Meanwhile, I also don't think it's about whether it's a smart move.. I
agree most apps shouldn't do complex operations on VMAs when having
userfaultfd involved. Said that, IMHO the whole point of kernel uAPI is to
make sure it works with every (even malicious) userapps, and it shouldn't
crash kernel. So even if the reproducer will require complex VMA setups,
we should still close the gap.
>
> > For example, I wonder if it's possible someone runs soft-dirty concurrently
> > with userfaultfd, we shouldn't fail the userapp if there's a concurrent
> > thread collecting dirty information, which IIUC can cause VMA flag changes,
> > and should be benign, and I think there can be other things causing the
> > interruption too.
>
> Right, we shouldn't fail if some of the VMA flags changed, but we are
> talking about of complete change of the mapping, with potentially
> completely different backing store.
I don't know how to define "complete change of the mapping". Here, IMHO
what we should do is to be strict on vma checks, either using the vma
snapshot or anything that can achieve the same goal, then returning -EAGAIN
is the safest because it won't crash a good citizen userapp. The
re-evaluation will only be done later.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2026-04-10 15:10 UTC|newest]
Thread overview: 18+ 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 [this message]
2026-04-02 3:58 ` Mike Rapoport
2026-04-02 13:42 ` Peter Xu
2026-04-09 11:31 ` Mike Rapoport
2026-04-10 15:26 ` 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=adkS8DkNZKHh3kmj@x1.local \
--to=peterx@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=aarcange@redhat.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