|
@@ -7,50 +7,6 @@
|
|
#include <asm/alternative-asm.h>
|
|
#include <asm/alternative-asm.h>
|
|
#include <asm/cpufeatures.h>
|
|
#include <asm/cpufeatures.h>
|
|
|
|
|
|
-/*
|
|
|
|
- * Fill the CPU return stack buffer.
|
|
|
|
- *
|
|
|
|
- * Each entry in the RSB, if used for a speculative 'ret', contains an
|
|
|
|
- * infinite 'pause; lfence; jmp' loop to capture speculative execution.
|
|
|
|
- *
|
|
|
|
- * This is required in various cases for retpoline and IBRS-based
|
|
|
|
- * mitigations for the Spectre variant 2 vulnerability. Sometimes to
|
|
|
|
- * eliminate potentially bogus entries from the RSB, and sometimes
|
|
|
|
- * purely to ensure that it doesn't get empty, which on some CPUs would
|
|
|
|
- * allow predictions from other (unwanted!) sources to be used.
|
|
|
|
- *
|
|
|
|
- * We define a CPP macro such that it can be used from both .S files and
|
|
|
|
- * inline assembly. It's possible to do a .macro and then include that
|
|
|
|
- * from C via asm(".include <asm/nospec-branch.h>") but let's not go there.
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-#define RSB_CLEAR_LOOPS 32 /* To forcibly overwrite all entries */
|
|
|
|
-#define RSB_FILL_LOOPS 16 /* To avoid underflow */
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- * Google experimented with loop-unrolling and this turned out to be
|
|
|
|
- * the optimal version — two calls, each with their own speculation
|
|
|
|
- * trap should their return address end up getting used, in a loop.
|
|
|
|
- */
|
|
|
|
-#define __FILL_RETURN_BUFFER(reg, nr, sp) \
|
|
|
|
- mov $(nr/2), reg; \
|
|
|
|
-771: \
|
|
|
|
- call 772f; \
|
|
|
|
-773: /* speculation trap */ \
|
|
|
|
- pause; \
|
|
|
|
- lfence; \
|
|
|
|
- jmp 773b; \
|
|
|
|
-772: \
|
|
|
|
- call 774f; \
|
|
|
|
-775: /* speculation trap */ \
|
|
|
|
- pause; \
|
|
|
|
- lfence; \
|
|
|
|
- jmp 775b; \
|
|
|
|
-774: \
|
|
|
|
- dec reg; \
|
|
|
|
- jnz 771b; \
|
|
|
|
- add $(BITS_PER_LONG/8) * nr, sp;
|
|
|
|
-
|
|
|
|
#ifdef __ASSEMBLY__
|
|
#ifdef __ASSEMBLY__
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -121,17 +77,10 @@
|
|
#endif
|
|
#endif
|
|
.endm
|
|
.endm
|
|
|
|
|
|
- /*
|
|
|
|
- * A simpler FILL_RETURN_BUFFER macro. Don't make people use the CPP
|
|
|
|
- * monstrosity above, manually.
|
|
|
|
- */
|
|
|
|
-.macro FILL_RETURN_BUFFER reg:req nr:req ftr:req
|
|
|
|
|
|
+/* This clobbers the BX register */
|
|
|
|
+.macro FILL_RETURN_BUFFER nr:req ftr:req
|
|
#ifdef CONFIG_RETPOLINE
|
|
#ifdef CONFIG_RETPOLINE
|
|
- ANNOTATE_NOSPEC_ALTERNATIVE
|
|
|
|
- ALTERNATIVE "jmp .Lskip_rsb_\@", \
|
|
|
|
- __stringify(__FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP)) \
|
|
|
|
- \ftr
|
|
|
|
-.Lskip_rsb_\@:
|
|
|
|
|
|
+ ALTERNATIVE "", "call __clear_rsb", \ftr
|
|
#endif
|
|
#endif
|
|
.endm
|
|
.endm
|
|
|
|
|
|
@@ -206,15 +155,10 @@ extern char __indirect_thunk_end[];
|
|
static inline void vmexit_fill_RSB(void)
|
|
static inline void vmexit_fill_RSB(void)
|
|
{
|
|
{
|
|
#ifdef CONFIG_RETPOLINE
|
|
#ifdef CONFIG_RETPOLINE
|
|
- unsigned long loops;
|
|
|
|
-
|
|
|
|
- asm volatile (ANNOTATE_NOSPEC_ALTERNATIVE
|
|
|
|
- ALTERNATIVE("jmp 910f",
|
|
|
|
- __stringify(__FILL_RETURN_BUFFER(%0, RSB_CLEAR_LOOPS, %1)),
|
|
|
|
- X86_FEATURE_RETPOLINE)
|
|
|
|
- "910:"
|
|
|
|
- : "=r" (loops), ASM_CALL_CONSTRAINT
|
|
|
|
- : : "memory" );
|
|
|
|
|
|
+ alternative_input("",
|
|
|
|
+ "call __fill_rsb",
|
|
|
|
+ X86_FEATURE_RETPOLINE,
|
|
|
|
+ ASM_NO_INPUT_CLOBBER(_ASM_BX, "memory"));
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
|
|
|