Skip to content

Commit 4bc1033

Browse files
pa1guptagregkh
authored andcommitted
x86/speculation: Simplify and make CALL_NOSPEC consistent
commit cfceff8526a426948b53445c02bcb98453c7330d upstream. 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_RETPOLINE is enabled. [ pawan: s/CONFIG_MITIGATION_RETPOLINE/CONFIG_RETPOLINE/ ] Signed-off-by: Pawan Gupta <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Andrew Cooper <[email protected] Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent db734ba commit 4bc1033

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,11 @@ extern void (*x86_return_thunk)(void);
284284
* Inline asm uses the %V modifier which is only in newer GCC
285285
* which is ensured when CONFIG_RETPOLINE is defined.
286286
*/
287-
# define CALL_NOSPEC \
288-
ALTERNATIVE_2( \
289-
ANNOTATE_RETPOLINE_SAFE \
290-
"call *%[thunk_target]\n", \
291-
"call __x86_indirect_thunk_%V[thunk_target]\n", \
292-
X86_FEATURE_RETPOLINE, \
293-
"lfence;\n" \
294-
ANNOTATE_RETPOLINE_SAFE \
295-
"call *%[thunk_target]\n", \
296-
X86_FEATURE_RETPOLINE_LFENCE)
287+
#ifdef CONFIG_RETPOLINE
288+
#define CALL_NOSPEC "call __x86_indirect_thunk_%V[thunk_target]\n"
289+
#else
290+
#define CALL_NOSPEC "call *%[thunk_target]\n"
291+
#endif
297292

298293
# define THUNK_TARGET(addr) [thunk_target] "r" (addr)
299294

0 commit comments

Comments
 (0)