[PATCH v2 5/5] x86/hyperv: Request mask cleanup when no remote target remains
From: Naman Jain
Date: Tue Nov 17 2026 - 04:15:58 EST
Filtering avoids unnecessary hypercalls but leaves historical CPU-mask
entries in place. These entries can keep later flushes on the multi-CPU
path even when only local work is needed.
When no remote target remains after filtering, request native trimming
of the original candidate mask instead of waiting for the periodic trim.
Copy the const request so only this call requests cleanup.
The native predicate still skips lazy CPUs, so cleanup may not leave a
local-only mask. The new early return also makes the empty basic
processor-mask check unnecessary.
Signed-off-by: Naman Jain <namjain@xxxxxxxxxxxxxxxxxxx>
---
arch/x86/hyperv/mmu.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
index 833eaea1d3fa8..545a25fcf6c34 100644
--- a/arch/x86/hyperv/mmu.c
+++ b/arch/x86/hyperv/mmu.c
@@ -102,6 +102,21 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
}
}
+ /*
+ * No remote target remains after filtering. Request native cleanup
+ * of stale, non-lazy memberships so later flushes can take the local
+ * fast path when possible. Lazy memberships may remain.
+ */
+ if (cpumask_any_but(flush_cpus, smp_processor_id()) >= nr_cpu_ids) {
+ /* Keep the caller's const request unchanged. */
+ struct flush_tlb_info trim_info = *info;
+
+ trim_info.trim_cpumask = 1;
+ local_irq_restore(flags);
+ native_flush_tlb_multi(cpus, &trim_info);
+ return;
+ }
+
if (info->mm) {
/*
* AddressSpace argument must match the CR3 with PCID bits
@@ -148,12 +163,6 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
__set_bit(vcpu, (unsigned long *)
&flush->processor_mask);
}
-
- /* nothing to flush if 'processor_mask' ends up being empty */
- if (!flush->processor_mask) {
- local_irq_restore(flags);
- return;
- }
}
/*
--
2.43.0