Re: [PATCH v3 2/3] mm/hugetlb_vmemmap: fix PMD split TLB flush race

From: Oscar Salvador (SUSE)

Date: Mon Nov 16 2026 - 05:08:15 EST


On Sat, Nov 14, 2026 at 07:25:22PM +0800, Muchun Song wrote:
> Bulk HVO optimization converts vmemmap PMDs for a list of folios into
> PTE tables before issuing a single global TLB flush. After publishing
> a PTE table, a concurrent single-folio optimization can observe it and
> remap its PTEs before the deferred flush:
>
> CPU0 CPU1
> hugetlb_vmemmap_optimize_folios()
> hugetlb_vmemmap_pteify_folio()
> vmemmap_split_pmd()
> pmd_populate_kernel()
> /* TLB flush deferred */
> hugetlb_vmemmap_optimize_folio()
> vmemmap_pmd_entry()
> /* sees a PTE table */
> vmemmap_optimize_pte()
> set_pte_at()
> flush_tlb_all()
>
> Modern MMUs permit overlapping TLB entries with different mapping
> granularities only when they translate to the same physical address. In
> this race, the stale PMD translation still points at the original vmemmap
> backing range while the new PTE can point at a shared or replacement
> vmemmap page for the same virtual address.
>
> Serialize deferred PMD splitting against PTE remapping with the HVO
> rwsem. Hold it for write across the split-only pteify batch and its TLB
> flush, then downgrade it before remapping the folios' vmemmap pages.
> This guarantees that no PTE remapper can observe a newly split PMD until
> the stale PMD translations have been invalidated.
>
> Fixes: f4b7e3efaddb ("hugetlb: batch PMD split for bulk vmemmap dedup")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> Closes: https://sashiko.dev/#/bug/linux-fbdc3410-a4cf-457e-88e6-684380fbadfe
> Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>

Acked-by: Oscar Salvador (SUSE) <osalvador@xxxxxxxxxx>



--
Oscar Salvador
SUSE Labs