Linux-HyperV List
 help / color / mirror / Atom feed
* [PATCH v3 0/5] x86/hyperv: Account for lazy mm_cpumask maintenance
@ 2026-12-01  4:36 Naman Jain
  2026-12-01  4:36 ` [PATCH v3 1/5] x86/hyperv: Reject unrepresentable TLB flush VP sets Naman Jain
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Naman Jain @ 2026-12-01  4:36 UTC (permalink / raw)
  To: haiyangz, wei.liu, decui, tglx, mingo, bp, dave.hansen, x86, luto,
	peterz
  Cc: dave.hansen, hpa, riel, mhklinux, schandna, namjain, qq570070308,
	houwenlong.hwl, zhouchuyi, jgross, linux-hyperv, linux-kernel

Lazy mm_cpumask maintenance leaves a CPU's bit set after it switches to
another address space. Linux removes stale bits by running
flush_tlb_func() on the target CPUs. A Hyper-V TLB flush hypercall
invalidates translations but does not run this function. Stale bits can
therefore remain and cause unnecessary remote invalidations.

hyperv_flush_tlb_multi() can also select HV_FLUSH_ALL_PROCESSORS from a
mask containing stale bits before reaching its per-CPU lazy-TLB checks.

The regression was found in SuperBench's eight-GPU PyTorch LSTM training
on Azure MI300X VMs when comparing Linux 6.8 and 7.0. Recreating
DataLoader workers each epoch caused host-to-GPU copy stalls and
timeouts. Bisection identified commit 209954cbc7d0 ("x86/mm/tlb: Update
mm_cpumask lazily") as the cause of the regression.

Patches 1-3 prepare for target filtering in patch 4 while patch 5 adds
immediate cleanup.

Patch 1 falls back to native flushing if VP-set conversion returns zero.
This can happen when the maximum VP index is at least 4096. The check is
defensive; the issue has not been seen in practice.

Patch 2 lets the Hyper-V PV TLB flush functions call should_flush_tlb().
Its argument is const because the function only reads the request.
A wrapper keeps the void * argument required by on_each_cpu_cond_mask().

Patch 3 uses native flushing when mask trimming is requested or a global
ASID transition is in progress. This lets flush_tlb_func() run on the
target CPUs to clear stale mask bits or switch to the global ASID.

Patch 4 uses should_flush_tlb() to decide which CPUs to include in a
Hyper-V flush before choosing the hypercall format or the all-processors
flag. When freeing page tables, it keeps the full mask to include CPUs
in lazy TLB mode. Stale bits can still cause all-processor flushes in
that case.

Patch 5 requests native cleanup if filtering leaves no remote CPU that
needs a flush. Removing stale mm_cpumask() bits lets later flushes take
the local-only path when possible. Lazy CPUs are still skipped, so some
bits may remain.

The earlier mask-weight > mm_users experiment on a 32-vCPU Hyper-V VM
found that lazy bits could keep the comparison true across 10,000 flush
requests. With three remote readers, mm_users was 4 and mask weights
were 26-32. Each reader received 10,000 native callbacks; the
corresponding run using cleanup only when no remote target remained used
hypercalls.
A doubled threshold and a rate-limited policy have not been tested.

On a 32-vCPU Hyper-V VM, after a single-threaded process visited all
CPUs and returned to one CPU, the reproducer's median time per iteration
(two mprotect() calls and a write) dropped from 17.235 us to 1.622 us
with the fix. On the reporter's 96-vCPU VM, the application hit the
600-second timeout without the fix and completed in 424 and 436 seconds
with it.

Changes since v2:
https://lore.kernel.org/all/20261117091507.2088642-1-namjain@linux.microsoft.com/
* Replace vague descriptions with function names in commit messages and
  comments (Dave, Michael).
* Describe the VP-set limit as theoretical and remove the confusing
  explanation about filtering an all-present mask (Michael).
* Use the agreed wording about successfully taking the Hyper-V hypercall
  path, and the accepted patch 3 commit message (Michael).
* Make the cleanup comment conditional and name mm_cpumask() explicitly
  in its commit message (Michael).
* Clarify that page-table-freeing flushes can still target stale members
  (Sahil).

Changes since v1:
https://lore.kernel.org/all/20261029064234.362385-1-namjain@linux.microsoft.com/
* Split the change into five patches with separate explanations (Dave).
* Add the workload and regression context (Michael).
* Explain ASID handling and filtering exceptions separately (Dave).
* Test the mm_users heuristic and keep immediate cleanup separate for
  policy review (Dave).

Naman Jain (5):
  x86/hyperv: Reject unrepresentable TLB flush VP sets
  x86/tlb: Make should_flush_tlb() available to Hyper-V
  x86/hyperv: Use native flushes for mask trimming and ASID transitions
  x86/hyperv: Filter TLB targets before building hypercalls
  x86/hyperv: Request mask cleanup when no remote target remains

 arch/x86/hyperv/mmu.c           | 71 +++++++++++++++++++++++----------
 arch/x86/include/asm/tlbflush.h |  1 +
 arch/x86/mm/tlb.c               | 17 ++++++--
 3 files changed, 64 insertions(+), 25 deletions(-)


base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-01  4:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  4:36 [PATCH v3 0/5] x86/hyperv: Account for lazy mm_cpumask maintenance Naman Jain
2026-12-01  4:36 ` [PATCH v3 1/5] x86/hyperv: Reject unrepresentable TLB flush VP sets Naman Jain
2026-12-01  4:36 ` [PATCH v3 2/5] x86/tlb: Make should_flush_tlb() available to Hyper-V Naman Jain
2026-12-01  4:36 ` [PATCH v3 3/5] x86/hyperv: Use native flushes for mask trimming and ASID transitions Naman Jain
2026-12-01  4:36 ` [PATCH v3 4/5] x86/hyperv: Filter TLB targets before building hypercalls Naman Jain
2026-12-01  4:44   ` sashiko-bot
2026-12-01  4:36 ` [PATCH v3 5/5] x86/hyperv: Request mask cleanup when no remote target remains Naman Jain
2026-12-01  4:53   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox