Re: [PATCH 14/32] mm/huge_memory: split huge zero PMDs on unshare faults

From: David Hildenbrand (Arm)

Date: Wed Dec 02 2026 - 10:31:45 EST


On 12/1/26 14:51, Gregory Price (Meta) wrote:
> On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote:
>> FAULT_FLAG_UNSHARE breaks COW without making the mapping writable.
>> Unlike FAULT_FLAG_WRITE, it must leave write protection in place so
>> that a later write still faults.
>>
>> A read-only long-term pin can trigger an unshare fault on a huge zero
>> PMD. do_huge_zero_wp_pmd() treats it as a write fault: it marks the
>> replacement THP dirty, makes it writable if the VMA allows writes, and
>> drops any UFFD write protection.
>>
>> Consequently, a later write no longer faults, which, for example,
>> bypasses UFFD write protection.
>>
>> Let's fix it by returning VM_FAULT_FALLBACK for unshare faults, so the
>> caller splits the PMD. The PTE fault path already handles unsharing
>> while keeping the mapping read-only and preserving UFFD write protection
>> and soft-dirty state.
>>
>> This has low urgency, as it requires a read-only long-term pin of a huge
>> zero PMD. No need to CC stable.
>>
>> Fixes: 1ced09e0331f ("mm: allocate THP on hugezeropage wp-fault")
>> Reported-by: Chris Mason <mason@xxxxxxxxxx>
>> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> I continue to think UFFD is the un-gift that keeps on un-giving :[


You're not alone brother ... :)


--
Cheers,

David