[PATCH] mm: clear pmd in pmdp_invalidate()

From: Guilherme Giacomo Simoes

Date: Tue Oct 27 2026 - 07:41:03 EST


when attempt to do a madvise in a chunk of memory allocated by mmap, the
folio_split is called to split a portion of memory, and despite the path
leads to pmd_mkinvalid() they do not clear the pmd and clearer wording,
leading to a BUG_ON inside page_table_check_set() because the map count
is more than 1.

Call the page_table_check_pmd_clear() inside pmdp_invalidate() generic
function to ensure that the pmd will have they map count decrement.

Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@xxxxxxxxx>
---
mm/pgtable-generic.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
index b91b1a98029c..7fa5351c75a0 100644
--- a/mm/pgtable-generic.c
+++ b/mm/pgtable-generic.c
@@ -203,6 +203,7 @@ pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
{
VM_WARN_ON_ONCE(!pmd_present(*pmdp));
pmd_t old = pmdp_establish(vma, address, pmdp, pmd_mkinvalid(*pmdp));
+ page_table_check_pmd_clear(vma->vm_mm, address, old);
flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
return old;
}
--
2.52.0