From: Michael Kelley <mhklinux@outlook.com>
To: Naman Jain <namjain@linux.microsoft.com>,
"haiyangz@microsoft.com" <haiyangz@microsoft.com>,
"wei.liu@kernel.org" <wei.liu@kernel.org>,
"decui@microsoft.com" <decui@microsoft.com>,
"tglx@kernel.org" <tglx@kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"bp@alien8.de" <bp@alien8.de>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"luto@kernel.org" <luto@kernel.org>,
"peterz@infradead.org" <peterz@infradead.org>
Cc: "hpa@zytor.com" <hpa@zytor.com>,
"riel@surriel.com" <riel@surriel.com>,
"bigeasy@linutronix.de" <bigeasy@linutronix.de>,
"zhouchuyi@bytedance.com" <zhouchuyi@bytedance.com>,
"houwenlong.hwl@antgroup.com" <houwenlong.hwl@antgroup.com>,
"qq570070308@gmail.com" <qq570070308@gmail.com>,
"bastien.curutchet@bootlin.com" <bastien.curutchet@bootlin.com>,
"dianders@chromium.org" <dianders@chromium.org>,
"jgross@suse.com" <jgross@suse.com>,
"hawk@kernel.org" <hawk@kernel.org>,
"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v2 4/5] x86/hyperv: Filter TLB targets before building hypercalls
Date: Tue, 24 Nov 2026 00:16:54 +0000 [thread overview]
Message-ID: <MN2PR02MB6863EA8EE36408EA031F1CEDD4442@MN2PR02MB6863.namprd02.prod.outlook.com> (raw)
In-Reply-To: <20261117091507.2088642-5-namjain@linux.microsoft.com>
From: Naman Jain <namjain@linux.microsoft.com> Sent: Tuesday, November 17, 2026 1:15 AM
>
> SuperBench's eight-GPU PyTorch LSTM training on Azure MI300X VMs regressed
> between Linux 6.8 and 7.0. Recreating DataLoader workers each epoch caused
> host-to-GPU copy stalls and timeouts. The reported bisection identified
> commit 209954cbc7d0 ("x86/mm/tlb: Update mm_cpumask lazily").
>
> That change leaves a CPU's bit set after it switches to another mm.
To be more explicit,
"... leaves a CPU's bit set in the mm_cpumask even after the CPU switches
to another mm".
> Native flush callbacks remove these stale bits, but successful Hyper-V
Again, I'm wondering about the "successful" qualifier.
> hypercalls do not run those callbacks. A CPU actively running another
The word "actively" seems redundant/superfluous here.
> mm need not be in lazy TLB mode, so the existing lazy-TLB check does not
> exclude it. If the mask includes all present CPUs, the backend selects
Be more explicit than just "backend".
> the all-processors shortcut before checking individual CPUs.
>
> Use the native predicate to build a per-CPU target mask before selecting
Be more explicit than "native predicate" (which sounds like AI-speak).
Just say should_flush_tlb().
> the all-processors shortcut or either hypercall format. Keep the full
> candidate mask when freeing page tables. Retain the empty basic-mask
> check because filtering can leave no targets.
>
> This patch does not change when trimming is requested.
I had a little trouble parsing this sentence. I first read it as
"When trimming is requested, this patch does not change.",
which didn't make any sense. Maybe reword as "This patch
does not affect when trimming is requested."
>
> Signed-off-by: Naman Jain <namjain@linux.microsoft.com>
> ---
> arch/x86/hyperv/mmu.c | 40 ++++++++++++++++++++++++++--------------
> 1 file changed, 26 insertions(+), 14 deletions(-)
>
> diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
> index 375f23b157ab3..833eaea1d3fa8 100644
> --- a/arch/x86/hyperv/mmu.c
> +++ b/arch/x86/hyperv/mmu.c
> @@ -1,6 +1,7 @@
> #define pr_fmt(fmt) "Hyper-V: " fmt
>
> #include <linux/log2.h>
> +#include <linux/percpu.h>
> #include <linux/slab.h>
> #include <linux/types.h>
>
> @@ -16,6 +17,8 @@
> /* Each gva in gva_list encodes up to 4096 pages to flush */
> #define HV_TLB_FLUSH_UNIT (4096 * PAGE_SIZE)
>
> +static DEFINE_PER_CPU(struct cpumask, hyperv_tlb_flush_mask);
> +
> static u64 hyperv_flush_tlb_others_ex(const struct cpumask *cpus,
> const struct flush_tlb_info *info);
>
> @@ -51,19 +54,14 @@ static inline int fill_gva_list(u64 gva_list[], int offset,
> return gva_n - offset;
> }
>
> -static bool cpu_is_lazy(int cpu)
> -{
> - return per_cpu(cpu_tlbstate_shared.is_lazy, cpu);
> -}
> -
> static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
> const struct flush_tlb_info *info)
> {
> int cpu, vcpu, gva_n, max_gvas;
> struct hv_tlb_flush *flush;
> + struct cpumask *flush_cpus;
> u64 status;
> unsigned long flags;
> - bool do_lazy = !info->freed_tables;
>
> trace_hyperv_mmu_flush_tlb_multi(cpus, info);
>
> @@ -87,6 +85,23 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
> goto do_native;
> }
>
> + flush_cpus = this_cpu_ptr(&hyperv_tlb_flush_mask);
> + /*
> + * mm_cpumask() may retain CPUs that have switched to another mm.
> + * Use the native predicate for its context-switch ordering and lazy
Again, say should_flush_tlb() instead of "native predicate". And I don't
really know what "context-switch ordering" is trying to get at.
> + * TLB exclusion. Page-table freeing must include lazy CPUs, so keep
> + * the full candidate mask in that case.
> + */
> + if (info->freed_tables) {
> + cpumask_copy(flush_cpus, cpus);
> + } else {
> + cpumask_clear(flush_cpus);
> + for_each_cpu(cpu, cpus) {
> + if (should_flush_tlb(cpu, info))
> + __cpumask_set_cpu(cpu, flush_cpus);
> + }
> + }
> +
> if (info->mm) {
> /*
> * AddressSpace argument must match the CR3 with PCID bits
> @@ -101,7 +116,7 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
> }
>
> flush->processor_mask = 0;
> - if (cpumask_equal(cpus, cpu_present_mask)) {
> + if (cpumask_equal(flush_cpus, cpu_present_mask)) {
> flush->flags |= HV_FLUSH_ALL_PROCESSORS;
> } else {
> /*
> @@ -115,14 +130,12 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
> * must. We will also check all VP numbers when walking the
> * supplied CPU set to remain correct in all cases.
> */
> - cpu = cpumask_last(cpus);
> + cpu = cpumask_last(flush_cpus);
>
> if (cpu < nr_cpumask_bits && hv_cpu_number_to_vp_number(cpu) >= 64)
> goto do_ex_hypercall;
>
> - for_each_cpu(cpu, cpus) {
> - if (do_lazy && cpu_is_lazy(cpu))
> - continue;
> + for_each_cpu(cpu, flush_cpus) {
> vcpu = hv_cpu_number_to_vp_number(cpu);
> if (vcpu == VP_INVAL) {
> local_irq_restore(flags);
> @@ -166,7 +179,7 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
> goto check_status;
>
> do_ex_hypercall:
> - status = hyperv_flush_tlb_others_ex(cpus, info);
> + status = hyperv_flush_tlb_others_ex(flush_cpus, info);
>
> check_status:
> local_irq_restore(flags);
> @@ -205,8 +218,7 @@ static u64 hyperv_flush_tlb_others_ex(const struct cpumask *cpus,
> flush->hv_vp_set.valid_bank_mask = 0;
>
> flush->hv_vp_set.format = HV_GENERIC_SET_SPARSE_4K;
> - nr_bank = cpumask_to_vpset_skip(&flush->hv_vp_set, cpus,
> - info->freed_tables ? NULL : cpu_is_lazy);
> + nr_bank = cpumask_to_vpset(&flush->hv_vp_set, cpus);
> if (nr_bank <= 0)
> return HV_STATUS_INVALID_PARAMETER;
>
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-11-24 0:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 9:15 [PATCH v2 0/5] x86/hyperv: Account for lazy mm_cpumask maintenance Naman Jain
2026-11-17 9:15 ` [PATCH v2 1/5] x86/hyperv: Reject unrepresentable TLB flush VP sets Naman Jain
2026-11-24 0:14 ` Michael Kelley
2026-11-17 9:15 ` [PATCH v2 2/5] x86/tlb: Make the conditional flush predicate reusable Naman Jain
2026-11-23 16:06 ` Dave Hansen
2026-11-24 0:16 ` Michael Kelley
2026-11-17 9:15 ` [PATCH v2 3/5] x86/hyperv: Use native callbacks for trimming and ASID transitions Naman Jain
2026-11-24 0:16 ` Michael Kelley
2026-11-17 9:15 ` [PATCH v2 4/5] x86/hyperv: Filter TLB targets before building hypercalls Naman Jain
2026-11-23 9:57 ` Sahil Chandna
2026-11-23 10:16 ` Naman Jain
2026-11-24 0:16 ` Michael Kelley [this message]
2026-11-17 9:15 ` [PATCH v2 5/5] x86/hyperv: Request mask cleanup when no remote target remains Naman Jain
2026-11-24 0:17 ` Michael Kelley
2026-11-24 0:14 ` [PATCH v2 0/5] x86/hyperv: Account for lazy mm_cpumask maintenance Michael Kelley
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=MN2PR02MB6863EA8EE36408EA031F1CEDD4442@MN2PR02MB6863.namprd02.prod.outlook.com \
--to=mhklinux@outlook.com \
--cc=bastien.curutchet@bootlin.com \
--cc=bigeasy@linutronix.de \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=dianders@chromium.org \
--cc=haiyangz@microsoft.com \
--cc=hawk@kernel.org \
--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=mingo@redhat.com \
--cc=namjain@linux.microsoft.com \
--cc=peterz@infradead.org \
--cc=qq570070308@gmail.com \
--cc=riel@surriel.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®