Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
 arch/x86/include/asm/nospec-branch.h |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -438,6 +438,9 @@ static inline void call_depth_return_thu
 #define CALL_NOSPEC    __CS_PREFIX("%V[thunk_target]") \
                        "call __x86_indirect_thunk_%V[thunk_target]\n"
 
+#define JMP_NOSPEC     __CS_PREFIX("%V[thunk_target]") \
+                       "jmp __x86_indirect_thunk_%V[thunk_target]\n"
+
 # define THUNK_TARGET(addr) [thunk_target] "r" (addr)
 
 #else /* CONFIG_X86_32 */
@@ -468,10 +471,31 @@ static inline void call_depth_return_thu
        "call *%[thunk_target]\n",                              \
        X86_FEATURE_RETPOLINE_LFENCE)
 
+# define JMP_NOSPEC                                            \
+       ALTERNATIVE_2(                                          \
+       ANNOTATE_RETPOLINE_SAFE                                 \
+       "jmp *%[thunk_target]\n",                               \
+       "       jmp    901f;\n"                                 \
+       "       .align 16\n"                                    \
+       "901:   call   903f;\n"                                 \
+       "902:   pause;\n"                                       \
+       "       lfence;\n"                                      \
+       "       jmp    902b;\n"                                 \
+       "       .align 16\n"                                    \
+       "903:   lea    4(%%esp), %%esp;\n"                      \
+       "       pushl  %[thunk_target];\n"                      \
+       "       ret;\n",                                        \
+       X86_FEATURE_RETPOLINE,                                  \
+       "lfence;\n"                                             \
+       ANNOTATE_RETPOLINE_SAFE                                 \
+       "jmp *%[thunk_target]\n",                               \
+       X86_FEATURE_RETPOLINE_LFENCE)
+
 # define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
 #endif
 #else /* No retpoline for C / inline asm */
 # define CALL_NOSPEC "call *%[thunk_target]\n"
+# define JMP_NOSPEC "jmp *%[thunk_target]\n"
 # define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
 #endif
 



Reply via email to