]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
x86/returnthunk: Allow different return thunks
authorPeter Zijlstra <peterz@infradead.org>
Thu, 15 Sep 2022 11:11:25 +0000 (13:11 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 17 Oct 2022 14:41:14 +0000 (16:41 +0200)
In preparation for call depth tracking on Intel SKL CPUs, make it possible
to patch in a SKL specific return thunk.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220915111147.680469665@infradead.org
arch/x86/include/asm/nospec-branch.h
arch/x86/kernel/alternative.c
arch/x86/kernel/ftrace.c
arch/x86/kernel/static_call.c
arch/x86/net/bpf_jit_comp.c

index c936ce9f0c47c896efc83fc1f9370db429be142b..f10ca334dd752cd8d115c4e47aab4ae0b1e4d209 100644 (file)
@@ -208,6 +208,12 @@ extern void __x86_return_thunk(void);
 extern void zen_untrain_ret(void);
 extern void entry_ibpb(void);
 
+#ifdef CONFIG_CALL_THUNKS
+extern void (*x86_return_thunk)(void);
+#else
+#define x86_return_thunk       (&__x86_return_thunk)
+#endif
+
 #ifdef CONFIG_RETPOLINE
 
 #define GEN(reg) \
index 963872d1770756413923f5d103e4dba3274cfa9f..04d1e3d35b0e7f656452ab3234b42316d30e1163 100644 (file)
@@ -518,6 +518,11 @@ void __init_or_module noinline apply_retpolines(s32 *start, s32 *end)
 }
 
 #ifdef CONFIG_RETHUNK
+
+#ifdef CONFIG_CALL_THUNKS
+void (*x86_return_thunk)(void) __ro_after_init = &__x86_return_thunk;
+#endif
+
 /*
  * Rewrite the compiler generated return thunk tail-calls.
  *
@@ -533,14 +538,18 @@ static int patch_return(void *addr, struct insn *insn, u8 *bytes)
 {
        int i = 0;
 
-       if (cpu_feature_enabled(X86_FEATURE_RETHUNK))
-               return -1;
+       if (cpu_feature_enabled(X86_FEATURE_RETHUNK)) {
+               if (x86_return_thunk == __x86_return_thunk)
+                       return -1;
 
-       bytes[i++] = RET_INSN_OPCODE;
+               i = JMP32_INSN_SIZE;
+               __text_gen_insn(bytes, JMP32_INSN_OPCODE, addr, x86_return_thunk, i);
+       } else {
+               bytes[i++] = RET_INSN_OPCODE;
+       }
 
        for (; i < insn->length;)
                bytes[i++] = INT3_INSN_OPCODE;
-
        return i;
 }
 
index 00eac455a3a1ff563fbd2c73bd598398f084943c..4ac6692d5ef822083c8b94055b3f684d7153cd89 100644 (file)
@@ -359,7 +359,7 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
 
        ip = trampoline + size;
        if (cpu_feature_enabled(X86_FEATURE_RETHUNK))
-               __text_gen_insn(ip, JMP32_INSN_OPCODE, ip, &__x86_return_thunk, JMP32_INSN_SIZE);
+               __text_gen_insn(ip, JMP32_INSN_OPCODE, ip, x86_return_thunk, JMP32_INSN_SIZE);
        else
                memcpy(ip, retq, sizeof(retq));
 
index aaaba85d6d7ff01e596f8b77c42ac72c707b0f0d..5d3844a98373e2008b68acab77788e7ae48c94b4 100644 (file)
@@ -52,7 +52,7 @@ static void __ref __static_call_transform(void *insn, enum insn_type type,
 
        case RET:
                if (cpu_feature_enabled(X86_FEATURE_RETHUNK))
-                       code = text_gen_insn(JMP32_INSN_OPCODE, insn, &__x86_return_thunk);
+                       code = text_gen_insn(JMP32_INSN_OPCODE, insn, x86_return_thunk);
                else
                        code = &retinsn;
                break;
index 99620428ad7851d7bd3bb3d4cd46d1c927d33ad8..0df391ecd4d8398ffde96655d20bdc5ece2cc4e7 100644 (file)
@@ -432,7 +432,7 @@ static void emit_return(u8 **pprog, u8 *ip)
        u8 *prog = *pprog;
 
        if (cpu_feature_enabled(X86_FEATURE_RETHUNK)) {
-               emit_jump(&prog, &__x86_return_thunk, ip);
+               emit_jump(&prog, x86_return_thunk, ip);
        } else {
                EMIT1(0xC3);            /* ret */
                if (IS_ENABLED(CONFIG_SLS))