[RFC PATCH 01/27] x86/entry: Parameterize kernel shadow stack handling at FRED entry
From: K Prateek Nayak
Date: Sun Nov 29 2026 - 17:31:36 EST
From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Picked from feedback on Dave's RFC.
Link: https://lore.kernel.org/lkml/47f352d9-1ad8-44c9-bcf2-af1dbf14b626@xxxxxxxxxx/
(Not-yet-)Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
---
arch/x86/entry/entry_64_fred.S | 42 +++++++++++++---------------------
1 file changed, 16 insertions(+), 26 deletions(-)
diff --git a/arch/x86/entry/entry_64_fred.S b/arch/x86/entry/entry_64_fred.S
index 1a2b39d9f7d3..9ff32e2a9103 100644
--- a/arch/x86/entry/entry_64_fred.S
+++ b/arch/x86/entry/entry_64_fred.S
@@ -16,35 +16,27 @@
.code64
.section .noinstr.text, "ax"
-/*
- * Kernel-mode events: save the SSP of the shadow stack frame FRED
- * pushed (old SSP, LIP, CS) just below pt_regs. See struct
- * fred_kernel_frame.
- */
-.macro PUSH_KERNEL_EVENT_SSP
-#ifdef CONFIG_X86_USER_SHADOW_STACK
- xorl %eax, %eax
- rdsspq %rax /* nop if shadow stacks are off */
- pushq %rax
- UNWIND_HINT_REGS offset=8
-#endif
-.endm
-
-.macro POP_KERNEL_EVENT_SSP
-#ifdef CONFIG_X86_USER_SHADOW_STACK
- addq $8, %rsp
-#endif
-.endm
-
-.macro FRED_ENTER
+.macro FRED_ENTER ssp=0
UNWIND_HINT_END_OF_STACK
ANNOTATE_NOENDBR
PUSH_AND_CLEAR_REGS
ENCODE_FRAME_POINTER
movq %rsp, %rdi /* %rdi -> pt_regs */
+
+#ifdef CONFIG_X86_KERN_SHADOW_STACK
+ .if \ssp
+ rdsspq %rax /* NOP if SHSTK is off. Pre-zeroed. */
+ push %rax
+ .endif
+#endif
.endm
-.macro FRED_EXIT
+.macro FRED_EXIT ssp=0
+#ifdef CONFIG_X86_KERN_SHADOW_STACK
+ .if \ssp
+ pop %rax /* Any dead register */
+ .endif
+#endif
UNWIND_HINT_REGS
POP_REGS
.endm
@@ -73,11 +65,9 @@ SYM_CODE_END(asm_fred_entrypoint_user)
*/
.org asm_fred_entrypoint_user + 256, 0xcc
SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
- FRED_ENTER
- PUSH_KERNEL_EVENT_SSP
+ FRED_ENTER ssp=1
call fred_entry_from_kernel
- POP_KERNEL_EVENT_SSP
- FRED_EXIT
+ FRED_EXIT ssp=1
ERETS
SYM_CODE_END(asm_fred_entrypoint_kernel)
--
2.43.0