[PATCH 0/2] x86: Fix bloated SafeRET fixup alternatives

From: Ard Biesheuvel

Date: Wed Dec 02 2026 - 07:28:52 EST


From: Ard Biesheuvel <ardb@xxxxxxxxxx>

The SafeRET fixup helpers are expanded into the entry code using
alternatives patching, even though most of the code can happily be
placed out of line. The remaining logic can be expressed more
succinctly, resulting in less code bloat in the entry code itself.

This reduces the size of the alternative from 67 to 25 bytes (or 49 to
22 bytes for the NMI variety)

I spotted this while working on RIP-relative codegen for vmlinux.

Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Tom Lendacky <thomas.lendacky@xxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Cc: Pawan Gupta <pawan.kumar.gupta@xxxxxxxxxxxxxxx>
Cc: Atish Patra <atishp@xxxxxxxx>

Ard Biesheuvel (2):
x86/entry: Move __FIXUP_INTR_SAFERET fixup out of line
x86/entry: Implement the SafeRET fixup check more compactly

arch/x86/entry/entry_64.S | 6 +--
arch/x86/include/asm/nospec-branch.h | 53 +++++++++++---------
2 files changed, 33 insertions(+), 26 deletions(-)

--
2.56.1.915.g69d5ec7298-goog