x86/mm: Fix false positive warning in switch_mm_irqs_off()
authorPeter Zijlstra <peterz@infradead.org>
Wed, 30 Apr 2025 08:11:54 +0000 (10:11 +0200)
committerIngo Molnar <mingo@kernel.org>
Tue, 6 May 2025 09:28:57 +0000 (11:28 +0200)
commit7f9958230d8a79d474829bee25ec9426397335ce
tree93bad6046e7f47fe93c3bad0d4c1da06927bfbda
parent43c2df7e2b08db6d65ce9707e4090f1f0c61f2f6
x86/mm: Fix false positive warning in switch_mm_irqs_off()

Multiple testers reported the following new warning:

WARNING: CPU: 0 PID: 0 at arch/x86/mm/tlb.c:795

Which corresponds to:

if (IS_ENABLED(CONFIG_DEBUG_VM) && WARN_ON_ONCE(prev != &init_mm &&
    !cpumask_test_cpu(cpu, mm_cpumask(next))))
cpumask_set_cpu(cpu, mm_cpumask(next));

So the problem is that unuse_temporary_mm() explicitly clears
that bit; and it has to, because otherwise the flush_tlb_mm_range() in
__text_poke() will try sending IPIs, which are not at all needed.

See also:

   https://lore.kernel.org/all/20241113095550.GBZzR3pg-RhJKPDazS@fat_crate.local/

Notably, the whole {,un}use_temporary_mm() thing requires preemption to
be disabled across it with the express purpose of keeping all TLB
nonsense CPU local, such that invalidations can also stay local etc.

However, as a side-effect, we violate this above WARN(), which sorta
makes sense for the normal case, but very much doesn't make sense here.

Change unuse_temporary_mm() to mark the mm_struct such that a further
exception (beyond init_mm) can be grafted, to keep the warning for all
the other cases.

Reported-by: Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>
Reported-by: Jani Nikula <jani.nikula@linux.intel.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Rik van Riel <riel@surriel.com>
Link: https://lore.kernel.org/r/20250430081154.GH4439@noisy.programming.kicks-ass.net
arch/x86/include/asm/mmu.h
arch/x86/include/asm/mmu_context.h
arch/x86/mm/init.c
arch/x86/mm/tlb.c
arch/x86/platform/efi/efi_64.c