From: Mike Rapoport <rppt@kernel.org>
To: nakixii <nakixii@gmail.com>
Cc: Mike Rapoport <rppt@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Xu <peterx@redhat.com>,
David Hildenbrand <david@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Lokesh Gidra <lokeshgidra@google.com>,
Kairui Song <kasong@tencent.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/userfaultfd: check exclusivity of the page being moved
Date: Tue, 17 Nov 2026 21:52:27 +0200 [thread overview]
Message-ID: <20261117195228.2675563-1-rppt@kernel.org> (raw)
In-Reply-To: <20261117191853.1314834-1-nakixii@gmail.com>
On Wed, Nov 18, 2026 at 03:18:53AM +0800, nakixii wrote:
> move_pages_ptes() gets the folio of a present source PTE and then checks
> PageAnonExclusive() on the first page of that folio. PG_anon_exclusive
> is per page, so for a PTE-mapped large folio this can give the wrong
> answer for the page that is actually being moved.
>
> This happens after fork(). fork() clears the flag on every page of the
> folio. Once the child exits, a write fault in the parent can reuse the
> large folio, and do_wp_page() sets the flag again only on the faulting
> page.
COW reuse of PTE-mapped large folios only appeared with commit
1da190f4d0a6 ("mm: Copy-on-Write (COW) reuse support for PTE-mapped
THP"), so this scenario didn't exist when UFFDIO_MOVE was added.
> Reclaim can leave the same state behind when try_to_unmap()
> replaces the earlier pages with swap entries and then fails on a later
> one.
This one, and fork() with a single page of a PTE-mapped large folio
pinned, could produce a mix of exclusive and shared pages in a folio
before that, so the Fixes tag is right, but please make it clear in the
changelog that the fork() + reuse case is a later addition.
> Moving that page with UFFDIO_MOVE then fails with -EBUSY, even though
> the folio could be split and the page moved. Callers that fall back to
> UFFDIO_COPY on -EBUSY end up copying instead.
It also works the other way around: if the first page is exclusive and
the page being moved is not, we needlessly split the folio before the
retry notices the page is shared and returns -EBUSY.
Worth mentioning that as well.
...
> Signed-off-by: nakixii <nakixii@gmail.com>
Please use a known identity in Signed-off-by rather than a nickname, see
"Developer's Certificate of Origin" in
Documentation/process/submitting-patches.rst.
...
> - folio = vm_normal_folio(src_vma, src_addr, orig_src_pte);
> - if (!folio || !PageAnonExclusive(&folio->page)) {
> + /*
> + * PG_anon_exclusive is per page. The first page of a
> + * large folio can be shared while the page mapped here
> + * is still exclusive, so check the page being moved.
> + */
> + page = vm_normal_page(src_vma, src_addr, orig_src_pte);
> + folio = page ? page_folio(page) : NULL;
> + if (!folio || !PageAnonExclusive(page)) {
This would be simpler as
page = vm_normal_page(src_vma, src_addr, orig_src_pte);
if (!page || !PageAnonExclusive(page)) {
spin_unlock(src_ptl);
ret = -EBUSY;
goto out;
}
folio = page_folio(page);
> spin_unlock(src_ptl);
> ret = -EBUSY;
> goto out;
With that addressed
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-11-17 19:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 19:18 nakixii
2026-11-17 19:52 ` Mike Rapoport [this message]
2026-11-17 21:16 ` David Hildenbrand (Arm)
2026-11-17 21:15 ` David Hildenbrand (Arm)
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=20261117195228.2675563-1-rppt@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lokeshgidra@google.com \
--cc=nakixii@gmail.com \
--cc=peterx@redhat.com \
--cc=surenb@google.com \
/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
all inboxes | Powered by JetHome®