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

From: Jose A. Perez de Azpillaga

Date: Wed Nov 11 2026 - 09:56:58 EST


On 11/11/26 10:37 AM, 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


LGTM:

Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>

--
cheers,
jose a. p-a