[PATCH 14/32] mm/huge_memory: split huge zero PMDs on unshare faults
From: David Hildenbrand (Arm)
Date: Sun Nov 29 2026 - 05:11:28 EST
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>
---
mm/huge_memory.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index b15e5b22b1801..0b4834f843c73 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2182,6 +2182,10 @@ static vm_fault_t do_huge_zero_wp_pmd(struct vm_fault *vmf)
struct folio *folio;
vm_fault_t ret = 0;
+ /* map_anon_folio_pmd_pf() does not handle unsharing correctly yet. */
+ if (vmf->flags & FAULT_FLAG_UNSHARE)
+ return VM_FAULT_FALLBACK;
+
folio = vma_alloc_anon_folio_pmd(vma, vmf->address);
if (unlikely(!folio))
return VM_FAULT_FALLBACK;
@@ -2224,7 +2228,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf)
if (!(ret & VM_FAULT_FALLBACK))
return ret;
- /* Fallback to splitting PMD if THP cannot be allocated */
+ /* Fall back to PTE level. */
goto fallback;
}
--
2.56.1