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

Message ID 20231102112850.3448745-2-ubizjak@gmail.com
State New
Headers
Series Fix and unify call thunks assembly snippets |

Commit Message

Uros Bizjak Nov. 2, 2023, 11:25 a.m. UTC
  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@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
 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
  

Patch

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[];