[RFC PATCH 05/27] x86/sync_core: Don't use IRET-to-self with kernel shadow stacks

From: K Prateek Nayak

Date: Sun Nov 29 2026 - 17:31:49 EST


On CPUs without SERIALIZE (Zen6), sync_core() serializes with
IRET-to-self. With kernel shadow stacks enabled, IRET at CPL0 also pops
a {SSP, LIP, CS} frame from the shadow stack and checks it against the
RIP and CS it returns to.

IRET-to-self only builds the frame on the regular stack, so the IRET
raises:

Unexpected kernel mode #CP, error_code: far/iret
WARNING: arch/x86/kernel/cet.c:42 at exc_control_protection+0xe2/0x3b0
RIP: 0010:do_sync_core+0x24/0x30
smp_call_function_many_cond+0x3e7/0x5f0
smp_text_poke_batch_finish+0x12f/0x590
arch_jump_label_transform_apply+0x1a/0x30
static_key_disable_cpuslocked+0x90/0xa0

LFENCE is not enough for cross-modifying code and making IRET-to-self
shadow stack compatible would need three CALLs plus three WRSSs to fake
the frame.

Use write-to-cr2 as the serializing operation for systems that have
X86_FEATURE_KERN_SHSTK but don't support SERIALIZE instruction.

Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
---
arch/x86/include/asm/sync_core.h | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/arch/x86/include/asm/sync_core.h b/arch/x86/include/asm/sync_core.h
index df22113db9cd..b056444407b5 100644
--- a/arch/x86/include/asm/sync_core.h
+++ b/arch/x86/include/asm/sync_core.h
@@ -66,6 +66,17 @@ static __always_inline void sync_core(void)
return;
}

+ /*
+ * IRET-to-self fabricates a frame on the regular stack only. With
+ * supervisor shadow stacks enabled, IRET (and ERETS) also pop and
+ * verify a {SSP, LIP, CS} frame from the shadow stack, which isn't
+ * there -> #CP(FAR-RET/IRET). Use MOV-to-CR2 to serialize.
+ */
+ if (cpu_feature_enabled(X86_FEATURE_KERN_SHSTK)) {
+ native_write_cr2(native_read_cr2());
+ return;
+ }
+
/*
* For all other processors, there are quite a few ways to do this.
* IRET-to-self is nice because it works on every CPU, at any CPL
--
2.43.0