[PATCH 1/3] x86/callthunks: Move call thunk template to .S file

From: Uros Bizjak
Date: Thu Nov 02 2023 - 07:29:10 EST


Currently INCREMENT_CALL_DEPTH explicitly defines %gs: segment
register prefix for its percpu variable. This is not compatible
with !CONFIG_SMP, which requires non-prefixed percpu variables.

Move call thunk template to its own callthunks-tmpl.S assembly file
where PER_CPU_VAR macro from percpu.h can be used to conditionally
use %gs: segment register prefix, depending on CONFIG_SMP.

Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
---
arch/x86/kernel/Makefile | 2 +-
arch/x86/kernel/callthunks-tmpl.S | 11 +++++++++++
arch/x86/kernel/callthunks.c | 10 ----------
3 files changed, 12 insertions(+), 11 deletions(-)
create mode 100644 arch/x86/kernel/callthunks-tmpl.S

diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 3269a0e23d3a..6b6b68ef4c3b 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -143,7 +143,7 @@ obj-$(CONFIG_AMD_MEM_ENCRYPT) += sev.o

obj-$(CONFIG_CFI_CLANG) += cfi.o

-obj-$(CONFIG_CALL_THUNKS) += callthunks.o
+obj-$(CONFIG_CALL_THUNKS) += callthunks.o callthunks-tmpl.o

obj-$(CONFIG_X86_CET) += cet.o

diff --git a/arch/x86/kernel/callthunks-tmpl.S b/arch/x86/kernel/callthunks-tmpl.S
new file mode 100644
index 000000000000..e82c473bd1b1
--- /dev/null
+++ b/arch/x86/kernel/callthunks-tmpl.S
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <asm/nospec-branch.h>
+
+ .section .rodata
+ .global skl_call_thunk_template
+ .global skl_call_thunk_tail
+
+skl_call_thunk_template:
+ INCREMENT_CALL_DEPTH
+skl_call_thunk_tail:
diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c
index e9ad518a5003..d0922cf94c90 100644
--- a/arch/x86/kernel/callthunks.c
+++ b/arch/x86/kernel/callthunks.c
@@ -62,16 +62,6 @@ static const struct core_text builtin_coretext = {
.name = "builtin",
};

-asm (
- ".pushsection .rodata \n"
- ".global skl_call_thunk_template \n"
- "skl_call_thunk_template: \n"
- __stringify(INCREMENT_CALL_DEPTH)" \n"
- ".global skl_call_thunk_tail \n"
- "skl_call_thunk_tail: \n"
- ".popsection \n"
-);
-
extern u8 skl_call_thunk_template[];
extern u8 skl_call_thunk_tail[];

--
2.41.0