Re: [PATCH] mm/userfaultfd: check exclusivity of the page being moved
From: David Hildenbrand (Arm)
Date: Tue Nov 17 2026 - 16:16:25 EST
On 11/17/26 20:52, Mike Rapoport wrote:
> 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.
You could construct something odd even without that by using MADV_DONTFORK on
parts of the folio to then fork().
--
Cheers,
David