Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/retbleed: Move call depth to percpu hot section

No functional change.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250303165246.2175811-6-brgerst@gmail.com

authored by

Brian Gerst and committed by
Ingo Molnar
839be161 01c7bc51

+15 -12
-3
arch/x86/include/asm/current.h
··· 14 14 15 15 struct pcpu_hot { 16 16 struct task_struct *current_task; 17 - #ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING 18 - u64 call_depth; 19 - #endif 20 17 unsigned long top_of_stack; 21 18 void *hardirq_stack_ptr; 22 19 u16 softirq_pending;
+6 -5
arch/x86/include/asm/nospec-branch.h
··· 12 12 #include <asm/msr-index.h> 13 13 #include <asm/unwind_hints.h> 14 14 #include <asm/percpu.h> 15 - #include <asm/current.h> 16 15 17 16 /* 18 17 * Call depth tracking for Intel SKL CPUs to address the RSB underflow ··· 77 78 #include <asm/asm-offsets.h> 78 79 79 80 #define CREDIT_CALL_DEPTH \ 80 - movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth); 81 + movq $-1, PER_CPU_VAR(__x86_call_depth); 81 82 82 83 #define RESET_CALL_DEPTH \ 83 84 xor %eax, %eax; \ 84 85 bts $63, %rax; \ 85 - movq %rax, PER_CPU_VAR(pcpu_hot + X86_call_depth); 86 + movq %rax, PER_CPU_VAR(__x86_call_depth); 86 87 87 88 #define RESET_CALL_DEPTH_FROM_CALL \ 88 89 movb $0xfc, %al; \ 89 90 shl $56, %rax; \ 90 - movq %rax, PER_CPU_VAR(pcpu_hot + X86_call_depth); \ 91 + movq %rax, PER_CPU_VAR(__x86_call_depth); \ 91 92 CALL_THUNKS_DEBUG_INC_CALLS 92 93 93 94 #define INCREMENT_CALL_DEPTH \ 94 - sarq $5, PER_CPU_VAR(pcpu_hot + X86_call_depth); \ 95 + sarq $5, PER_CPU_VAR(__x86_call_depth); \ 95 96 CALL_THUNKS_DEBUG_INC_CALLS 96 97 97 98 #else ··· 385 386 ALTERNATIVE("", \ 386 387 __stringify(INCREMENT_CALL_DEPTH), \ 387 388 X86_FEATURE_CALL_DEPTH) 389 + 390 + DECLARE_PER_CPU_CACHE_HOT(u64, __x86_call_depth); 388 391 389 392 #ifdef CONFIG_CALL_THUNKS_DEBUG 390 393 DECLARE_PER_CPU(u64, __x86_call_count);
-3
arch/x86/kernel/asm-offsets.c
··· 109 109 OFFSET(TSS_sp2, tss_struct, x86_tss.sp2); 110 110 OFFSET(X86_top_of_stack, pcpu_hot, top_of_stack); 111 111 OFFSET(X86_current_task, pcpu_hot, current_task); 112 - #ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING 113 - OFFSET(X86_call_depth, pcpu_hot, call_depth); 114 - #endif 115 112 #if IS_ENABLED(CONFIG_CRYPTO_ARIA_AESNI_AVX_X86_64) 116 113 /* Offset for fields in aria_ctx */ 117 114 BLANK();
+8
arch/x86/kernel/cpu/common.c
··· 2075 2075 EXPORT_PER_CPU_SYMBOL(__preempt_count); 2076 2076 2077 2077 #ifdef CONFIG_X86_64 2078 + /* 2079 + * Note: Do not make this dependant on CONFIG_MITIGATION_CALL_DEPTH_TRACKING 2080 + * so that this space is reserved in the hot cache section even when the 2081 + * mitigation is disabled. 2082 + */ 2083 + DEFINE_PER_CPU_CACHE_HOT(u64, __x86_call_depth); 2084 + EXPORT_PER_CPU_SYMBOL(__x86_call_depth); 2085 + 2078 2086 static void wrmsrl_cstar(unsigned long val) 2079 2087 { 2080 2088 /*
+1 -1
arch/x86/lib/retpoline.S
··· 343 343 * case. 344 344 */ 345 345 CALL_THUNKS_DEBUG_INC_RETS 346 - shlq $5, PER_CPU_VAR(pcpu_hot + X86_call_depth) 346 + shlq $5, PER_CPU_VAR(__x86_call_depth) 347 347 jz 1f 348 348 ANNOTATE_UNRET_SAFE 349 349 ret