]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
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)
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

index 8b8055a8eb9ee5a76a0625cdf992f1cd3a2db55a..0fe9c569d1717060603b9e80ba4abf349855a237 100644 (file)
@@ -16,6 +16,8 @@
 #define MM_CONTEXT_LOCK_LAM            2
 /* Allow LAM and SVA coexisting */
 #define MM_CONTEXT_FORCE_TAGGED_SVA    3
+/* Tracks mm_cpumask */
+#define MM_CONTEXT_NOTRACK             4
 
 /*
  * x86 has arch-specific MMU state beyond what lives in mm_struct.
@@ -44,9 +46,7 @@ typedef struct {
        struct ldt_struct       *ldt;
 #endif
 
-#ifdef CONFIG_X86_64
        unsigned long flags;
-#endif
 
 #ifdef CONFIG_ADDRESS_MASKING
        /* Active LAM mode:  X86_CR3_LAM_U48 or X86_CR3_LAM_U57 or 0 (disabled) */
index c511f8584ae4b1b5c0325e410b0e217fe26c1b41..73bf3b1b44e8508de18ca1ccf1ae6adaaea04550 100644 (file)
@@ -247,6 +247,16 @@ static inline bool is_64bit_mm(struct mm_struct *mm)
 }
 #endif
 
+static inline bool is_notrack_mm(struct mm_struct *mm)
+{
+       return test_bit(MM_CONTEXT_NOTRACK, &mm->context.flags);
+}
+
+static inline void set_notrack_mm(struct mm_struct *mm)
+{
+       set_bit(MM_CONTEXT_NOTRACK, &mm->context.flags);
+}
+
 /*
  * We only want to enforce protection keys on the current process
  * because we effectively have no access to PKRU for other
index f8c74d19bebb2eca4f68db62594ba007b1017556..aa56d9ac0b8f404e53831757b7a18af20bea012b 100644 (file)
@@ -28,6 +28,7 @@
 #include <asm/text-patching.h>
 #include <asm/memtype.h>
 #include <asm/paravirt.h>
+#include <asm/mmu_context.h>
 
 /*
  * We need to define the tracepoints somewhere, and tlb.c
@@ -830,6 +831,8 @@ void __init poking_init(void)
        /* Xen PV guests need the PGD to be pinned. */
        paravirt_enter_mmap(text_poke_mm);
 
+       set_notrack_mm(text_poke_mm);
+
        /*
         * Randomize the poking address, but make sure that the following page
         * will be mapped at the same PMD. We need 2 pages, so find space for 3,
index 39761c7765bdd2569a3fde4c9a9b7c8eb371bf24..f5b990e46d7b224f9bbdf70cba3969ea4025df59 100644 (file)
@@ -847,7 +847,8 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next,
                 * mm_cpumask. The TLB shootdown code can figure out from
                 * cpu_tlbstate_shared.is_lazy whether or not to send an IPI.
                 */
-               if (IS_ENABLED(CONFIG_DEBUG_VM) && WARN_ON_ONCE(prev != &init_mm &&
+               if (IS_ENABLED(CONFIG_DEBUG_VM) &&
+                   WARN_ON_ONCE(prev != &init_mm && !is_notrack_mm(prev) &&
                                 !cpumask_test_cpu(cpu, mm_cpumask(next))))
                        cpumask_set_cpu(cpu, mm_cpumask(next));
 
index a5d3496d32a517785169a1a09c0c6eaa04309801..ce4c08adca88bf7cbd60a1e988b144ecfdfc9013 100644 (file)
@@ -89,6 +89,7 @@ int __init efi_alloc_page_tables(void)
        efi_mm.pgd = efi_pgd;
        mm_init_cpumask(&efi_mm);
        init_new_context(NULL, &efi_mm);
+       set_notrack_mm(&efi_mm);
 
        return 0;