Skip to content

Commit 010c4a4

Browse files
pa1guptaingomolnar
authored andcommitted
x86/speculation: Simplify and make CALL_NOSPEC consistent
CALL_NOSPEC macro is used to generate Spectre-v2 mitigation friendly indirect branches. At compile time the macro defaults to indirect branch, and at runtime those can be patched to thunk based mitigations. This approach is opposite of what is done for the rest of the kernel, where the compile time default is to replace indirect calls with retpoline thunk calls. Make CALL_NOSPEC consistent with the rest of the kernel, default to retpoline thunk at compile time when CONFIG_MITIGATION_RETPOLINE is enabled. Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Andrew Cooper <andrew.cooper3@citrix.com Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20250228-call-nospec-v3-1-96599fed0f33@linux.intel.com
1 parent 7eb1721 commit 010c4a4

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

arch/x86/include/asm/nospec-branch.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,11 @@ static inline void call_depth_return_thunk(void) {}
424424
* Inline asm uses the %V modifier which is only in newer GCC
425425
* which is ensured when CONFIG_MITIGATION_RETPOLINE is defined.
426426
*/
427-
# define CALL_NOSPEC \
428-
ALTERNATIVE_2( \
429-
ANNOTATE_RETPOLINE_SAFE \
430-
"call *%[thunk_target]\n", \
431-
"call __x86_indirect_thunk_%V[thunk_target]\n", \
432-
X86_FEATURE_RETPOLINE, \
433-
"lfence;\n" \
434-
ANNOTATE_RETPOLINE_SAFE \
435-
"call *%[thunk_target]\n", \
436-
X86_FEATURE_RETPOLINE_LFENCE)
427+
#ifdef CONFIG_MITIGATION_RETPOLINE
428+
#define CALL_NOSPEC "call __x86_indirect_thunk_%V[thunk_target]\n"
429+
#else
430+
#define CALL_NOSPEC "call *%[thunk_target]\n"
431+
#endif
437432

438433
# define THUNK_TARGET(addr) [thunk_target] "r" (addr)
439434

0 commit comments

Comments
 (0)