mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Naman Jain <namjain@linux.microsoft.com>
To: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
	tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org, luto@kernel.org,
	peterz@infradead.org
Cc: dave.hansen@intel.com, hpa@zytor.com, riel@surriel.com,
	mhklinux@outlook.com, schandna@linux.microsoft.com,
	namjain@linux.microsoft.com, qq570070308@gmail.com,
	houwenlong.hwl@antgroup.com, zhouchuyi@bytedance.com,
	jgross@suse.com, linux-hyperv@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 0/5] x86/hyperv: Account for lazy mm_cpumask maintenance
Date: Tue,  1 Dec 2026 04:36:37 +0000	[thread overview]
Message-ID: <20261201043642.1054258-1-namjain@linux.microsoft.com> (raw)

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


             reply	other threads:[~2026-12-01  4:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  4:36 Naman Jain [this message]
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:36 ` [PATCH v3 5/5] x86/hyperv: Request mask cleanup when no remote target remains Naman Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201043642.1054258-1-namjain@linux.microsoft.com \
    --to=namjain@linux.microsoft.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=houwenlong.hwl@antgroup.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=qq570070308@gmail.com \
    --cc=riel@surriel.com \
    --cc=schandna@linux.microsoft.com \
    --cc=tglx@kernel.org \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    --cc=zhouchuyi@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®