[tip: x86/boot] x86/linkage: Add SYM_PIC_ALIAS() macro helper to emit symbol aliases

From: tip-bot2 for Ard Biesheuvel
Date: Sun May 04 2025 - 10:20:39 EST


The following commit has been merged into the x86/boot branch of tip:

Commit-ID: f932adcc8650eb169efd0fd19f2a450c260d306c
Gitweb: https://git.kernel.org/tip/f932adcc8650eb169efd0fd19f2a450c260d306c
Author: Ard Biesheuvel <ardb@xxxxxxxxxx>
AuthorDate: Sun, 04 May 2025 11:52:43 +02:00
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
CommitterDate: Sun, 04 May 2025 15:59:43 +02:00

x86/linkage: Add SYM_PIC_ALIAS() macro helper to emit symbol aliases

Startup code that may execute from the early 1:1 mapping of memory will
be confined into its own address space, and only be permitted to access
ordinary kernel symbols if this is known to be safe.

Introduce a macro helper SYM_PIC_ALIAS() that emits a __pi_ prefixed
alias for a symbol, which allows startup code to access it.

Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Arnd Bergmann <arnd@xxxxxxxx>
Cc: David Woodhouse <dwmw@xxxxxxxxxxxx>
Cc: Dionna Amalie Glaze <dionnaglaze@xxxxxxxxxx>
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Cc: Kees Cook <keescook@xxxxxxxxxxxx>
Cc: Kevin Loughlin <kevinloughlin@xxxxxxxxxx>
Cc: Len Brown <len.brown@xxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Cc: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Cc: Tom Lendacky <thomas.lendacky@xxxxxxx>
Cc: linux-efi@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/r/20250504095230.2932860-38-ardb+git@xxxxxxxxxx
---
arch/x86/include/asm/linkage.h | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h
index b51d8a4..9d38ae7 100644
--- a/arch/x86/include/asm/linkage.h
+++ b/arch/x86/include/asm/linkage.h
@@ -141,5 +141,15 @@
#define SYM_FUNC_START_WEAK_NOALIGN(name) \
SYM_START(name, SYM_L_WEAK, SYM_A_NONE)

+/*
+ * Expose 'sym' to the startup code in arch/x86/boot/startup/, by emitting an
+ * alias prefixed with __pi_
+ */
+#ifdef __ASSEMBLER__
+#define SYM_PIC_ALIAS(sym) SYM_ALIAS(__pi_ ## sym, sym, SYM_L_GLOBAL)
+#else
+#define SYM_PIC_ALIAS(sym) extern typeof(sym) __PASTE(__pi_, sym) __alias(sym)
+#endif
+
#endif /* _ASM_X86_LINKAGE_H */