Skip to content

Commit eb98219

Browse files
pa1guptavijay-suman
authored andcommitted
x86/speculation: Add a conditional CS prefix to CALL_NOSPEC
commit 052040e34c08428a5a388b85787e8531970c0c67 upstream. Retpoline mitigation for spectre-v2 uses thunks for indirect branches. To support this mitigation compilers add a CS prefix with -mindirect-branch-cs-prefix. For an indirect branch in asm, this needs to be added manually. CS prefix is already being added to indirect branches in asm files, but not in inline asm. Add CS prefix to CALL_NOSPEC for inline asm as well. There is no JMP_NOSPEC for inline asm. Reported-by: Josh Poimboeuf <[email protected]> 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]> (cherry picked from commit 2d69c40c820a459e940d23321f6fe2a0ca1aefd5) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent 70a0ca6 commit eb98219

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@
119119
.endm
120120

121121
/*
122-
* Equivalent to -mindirect-branch-cs-prefix; emit the 5 byte jmp/call
123-
* to the retpoline thunk with a CS prefix when the register requires
124-
* a RAX prefix byte to encode. Also see apply_retpolines().
122+
* Emits a conditional CS prefix that is compatible with
123+
* -mindirect-branch-cs-prefix.
125124
*/
126125
.macro __CS_PREFIX reg:req
127126
.irp rs,r8,r9,r10,r11,r12,r13,r14,r15
@@ -291,12 +290,24 @@ extern its_thunk_t __x86_indirect_its_thunk_array[];
291290

292291
#ifdef CONFIG_X86_64
293292

293+
/*
294+
* Emits a conditional CS prefix that is compatible with
295+
* -mindirect-branch-cs-prefix.
296+
*/
297+
#define __CS_PREFIX(reg) \
298+
".irp rs,r8,r9,r10,r11,r12,r13,r14,r15\n" \
299+
".ifc \\rs," reg "\n" \
300+
".byte 0x2e\n" \
301+
".endif\n" \
302+
".endr\n"
303+
294304
/*
295305
* Inline asm uses the %V modifier which is only in newer GCC
296306
* which is ensured when CONFIG_RETPOLINE is defined.
297307
*/
298308
#ifdef CONFIG_RETPOLINE
299-
#define CALL_NOSPEC "call __x86_indirect_thunk_%V[thunk_target]\n"
309+
#define CALL_NOSPEC __CS_PREFIX("%V[thunk_target]") \
310+
"call __x86_indirect_thunk_%V[thunk_target]\n"
300311
#else
301312
#define CALL_NOSPEC "call *%[thunk_target]\n"
302313
#endif

0 commit comments

Comments
 (0)