x86,static_call: Fix static-call vs return-thunk
authorPeter Zijlstra <peterz@infradead.org>
Fri, 22 Sep 2023 10:12:25 +0000 (10:12 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Fri, 22 Sep 2023 16:58:24 +0000 (18:58 +0200)
Commit

  7825451fa4dc ("static_call: Add call depth tracking support")

failed to realize the problem fixed there is not specific to call depth
tracking but applies to all return-thunk uses.

Move the fix to the appropriate place and condition.

Fixes: ee88d363d156 ("x86,static_call: Use alternative RET encoding")
Reported-by: David Kaplan <David.Kaplan@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: <stable@kernel.org>
arch/x86/kernel/alternative.c
arch/x86/kernel/callthunks.c

index c850f5a..517ee01 100644 (file)
@@ -720,6 +720,9 @@ void __init_or_module noinline apply_returns(s32 *start, s32 *end)
 {
        s32 *s;
 
+       if (cpu_feature_enabled(X86_FEATURE_RETHUNK))
+               static_call_force_reinit();
+
        for (s = start; s < end; s++) {
                void *dest = NULL, *addr = (void *)s + *s;
                struct insn insn;
index c06bfc0..faa9f22 100644 (file)
@@ -272,7 +272,6 @@ void __init callthunks_patch_builtin_calls(void)
        pr_info("Setting up call depth tracking\n");
        mutex_lock(&text_mutex);
        callthunks_setup(&cs, &builtin_coretext);
-       static_call_force_reinit();
        thunks_initialized = true;
        mutex_unlock(&text_mutex);
 }