[PATCH v3 2/5] x86/tlb: Make should_flush_tlb() available to Hyper-V
From: Naman Jain
Date: Mon Nov 30 2026 - 23:37:07 EST
Make should_flush_tlb() available to the Hyper-V PV TLB flush
functions so they can use the same checks as native_flush_tlb_multi().
Use a const struct flush_tlb_info pointer for direct callers. This
preserves the read-only request passed by hyperv_flush_tlb_multi()
without a cast and lets the compiler check the argument type. Keep a
small wrapper for on_each_cpu_cond_mask(), which takes void *.
No functional changes.
Signed-off-by: Naman Jain <namjain@xxxxxxxxxxxxxxxxxxx>
---
arch/x86/include/asm/tlbflush.h | 1 +
arch/x86/mm/tlb.c | 17 +++++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index 70098d448e999..1d1852ecaf084 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -263,6 +263,7 @@ void flush_tlb_one_user(unsigned long addr);
void flush_tlb_one_kernel(unsigned long addr);
void flush_tlb_multi(const struct cpumask *cpumask,
const struct flush_tlb_info *info);
+bool should_flush_tlb(int cpu, const struct flush_tlb_info *info);
static inline bool is_dyn_asid(u16 asid)
{
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 53dcab39566f2..2990aab1f8ca3 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -1279,10 +1279,14 @@ static void flush_tlb_func(void *info)
nr_invalidate);
}
-static bool should_flush_tlb(int cpu, void *data)
+/*
+ * Callers must bypass should_flush_tlb() when freeing page tables or
+ * during a global ASID transition, so CPUs in lazy TLB mode also
+ * receive callbacks.
+ */
+bool should_flush_tlb(int cpu, const struct flush_tlb_info *info)
{
struct mm_struct *loaded_mm = per_cpu(cpu_tlbstate.loaded_mm, cpu);
- struct flush_tlb_info *info = data;
/*
* Order the 'loaded_mm' and 'is_lazy' against their
@@ -1317,6 +1321,11 @@ static bool should_flush_tlb(int cpu, void *data)
return false;
}
+static bool should_flush_tlb_wrapper(int cpu, void *data)
+{
+ return should_flush_tlb(cpu, data);
+}
+
static bool should_trim_cpumask(struct mm_struct *mm)
{
if (time_after(jiffies, READ_ONCE(mm->context.next_trim_cpumask))) {
@@ -1357,8 +1366,8 @@ STATIC_NOPV void native_flush_tlb_multi(const struct cpumask *cpumask,
if (info->freed_tables || mm_in_asid_transition(info->mm))
on_each_cpu_mask(cpumask, flush_tlb_func, (void *)info, true);
else
- on_each_cpu_cond_mask(should_flush_tlb, flush_tlb_func,
- (void *)info, 1, cpumask);
+ on_each_cpu_cond_mask(should_flush_tlb_wrapper, flush_tlb_func,
+ (void *)info, 1, cpumask);
}
void flush_tlb_multi(const struct cpumask *cpumask,
--
2.43.0