[PATCH v3 0/3] mm/hugetlb_vmemmap: Fix HVO races and deadlock

Muchun Song posted 3 patches 1 week, 3 days ago
mm/hugetlb_vmemmap.c | 28 +++++++++++++++++++++++-----
mm/hugetlb_vmemmap.h | 24 ++++++++++++++++++++++++
mm/memory-failure.c  |  3 +++
3 files changed, 50 insertions(+), 5 deletions(-)
[PATCH v3 0/3] mm/hugetlb_vmemmap: Fix HVO races and deadlock
Posted by Muchun Song 1 week, 3 days ago
This series fixes three HVO issues reported by Sashiko.

The first patch serializes HWPoison updates and removal against HVO
remapping so raw_hwp_page state cannot be lost or freed while a
replacement vmemmap head page is being installed. The second patch uses
an HVO-private rwsem to prevent deferred PMD splits from racing with PTE
remapping before the TLB flush. The last patch switches the vmemmap walk
to the lockless walker so a PMD split allocation cannot recurse into
init_mm.mmap_lock through reclaim.

v3:
- Serialize unpoison_memory() against HVO head remapping.
- Update the first patch subject and description for the unpoison race.
- Collect Reviewed-by tags from Jiaqi Yan and
  Jose A. Perez de Azpillaga.
- Rebase onto mm/mm-new.

v2: https://lore.kernel.org/20261111093747.50048-1-songmuchun@bytedance.com/
- Add the HWPoison serialization fix reported by Sashiko.
- Use an HVO-private rwsem for deferred PMD split serialization.
- Add the lockless page-table walk fix for the PMD split deadlock.

v1: https://lore.kernel.org/20261110112456.62827-1-songmuchun@bytedance.com/

Muchun Song (3):
  mm/hugetlb_vmemmap: fix HWPoison state races during optimization
  mm/hugetlb_vmemmap: fix PMD split TLB flush race
  mm/hugetlb_vmemmap: fix deadlock during PMD split

 mm/hugetlb_vmemmap.c | 28 +++++++++++++++++++++++-----
 mm/hugetlb_vmemmap.h | 24 ++++++++++++++++++++++++
 mm/memory-failure.c  |  3 +++
 3 files changed, 50 insertions(+), 5 deletions(-)


base-commit: 6ec534d64f85e949a5d58070678dcd7711875a7c
-- 
2.54.0
Re: [PATCH v3 0/3] mm/hugetlb_vmemmap: Fix HVO races and deadlock
Posted by Andrew Morton 4 days, 18 hours ago
On Sat, 14 Nov 2026 19:25:20 +0800 Muchun Song <songmuchun@bytedance.com> wrote:

> This series fixes three HVO issues reported by Sashiko.
> 
> The first patch serializes HWPoison updates and removal against HVO
> remapping so raw_hwp_page state cannot be lost or freed while a
> replacement vmemmap head page is being installed. The second patch uses
> an HVO-private rwsem to prevent deferred PMD splits from racing with PTE
> remapping before the TLB flush. The last patch switches the vmemmap walk
> to the lockless walker so a PMD split allocation cannot recurse into
> init_mm.mmap_lock through reclaim.
> 

Thanks, tested in a VM.  The series did everything it claimed to do and
the LLM couldn't fid a way to break it.

Tested-by: Andrew Morton <akpm@linux-foundation.org>


: I tested the three patches in x86-64 QEMU guests. A had the series
: removed; B had it applied. Both used the same kernel configuration and
: fresh boots. The main tests used four CPUs, two NUMA nodes, 8 GiB RAM
: and 2 MiB HugeTLB pages. I added the same temporary delays and log
: messages to A and B, guarded by the test processes' current->comm, so
: other processes did not take those delays.
: 
: [1/3] mm/hugetlb_vmemmap: fix HWPoison state races during optimization
: 
: I put a three-second pause immediately after HVO copied the vmemmap
: head, then poisoned a tail page during that pause. On A, the HWPoison
: state was lost and the huge page remained in the free pool; B kept it
: out. Poisoning the last 4 KiB tail page gave the same result. For the
: reverse race, I also paused before the copy to poison the page, then
: unpoisoned it during the post-copy pause. A left stale HWPoison flags
: on the head and tail; B cleared them.
: 
: [2/3] mm/hugetlb_vmemmap: fix PMD split TLB flush race
: 
: I put a three-second pause immediately before the deferred
: flush_tlb_all(), after the split PMDs had been published. During that
: pause, separate processes allocated huge pages in the affected range.
: Temporary log messages recorded the old and new backing PFNs at each
: remap. A changed PTE mappings before the flush; B did not. Four
: simultaneous allocations repeated the early remapping on A across
: both split PMD ranges. I did not observe a processor using a stale
: TLB entry.
: 
: [3/3] mm/hugetlb_vmemmap: fix deadlock during PMD split
: 
: This test used a separate four-CPU, one-node, 4 GiB QEMU guest. An
: emulated QXL device initialized TTM. Because QXL's own pages were
: cached, a small test module used TTM's page-pool interfaces to return
: 512 write-combined pages to its pool. A process held about 2.5 GiB
: of guest memory.
: 
: I created an init_mm.mmap_lock writer before HVO entered the PMD
: split. At the split, I released that writer, paused for 300 ms to let
: it wait on the lock, then called TTM's actual shrinker from the HVO
: task. A reached set_pages_wb() and blocked trying to take
: init_mm.mmap_lock; the huge-page allocation did not finish. On B,
: the writer completed, the shrinker freed the pool pages, and the
: allocation finished. The shrinker call was forced at this point.
: This tests TTM's page-freeing path and the lock order, but does not
: show that ordinary reclaim would select TTM at that instant.