[PATCH -tip v2 3/3] x86/kexec: Use savesegment_mem16() for segment register save in crash_setup_regs()
From: Uros Bizjak
Date: Wed Apr 01 2026 - 05:05:00 EST
Replace open-coded inline assembly used to read segment registers
(ss, cs, and on 32-bit ds/es) in crash_setup_regs() with
savesegment_mem16() helper.
This function only stores the segment selector into a u16 field
and does not require the value in a general-purpose register. Using
savesegment_mem16() avoids the unnecessary register intermediate
and better matches the intended use.
The generated code is improved from, e.g.:
131: 8c d0 mov %ss,%eax
133: 66 89 84 24 a0 00 00 mov %ax,0xa0(%rsp)
13a: 00
to a single direct store:
131: 8c 94 24 a0 00 00 00 mov %ss,0xa0(%rsp)
This is a mechanical follow-up to the introduction of
savesegment_mem16(), with no functional change.
Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
---
v2: New patch.
---
arch/x86/include/asm/kexec.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h
index 5cfb27f26583..90a8d7ca7cf8 100644
--- a/arch/x86/include/asm/kexec.h
+++ b/arch/x86/include/asm/kexec.h
@@ -106,11 +106,11 @@ static inline void crash_setup_regs(struct pt_regs *newregs,
asm volatile("mov %%r14,%0" : "=m"(newregs->r14));
asm volatile("mov %%r15,%0" : "=m"(newregs->r15));
#endif
- asm volatile("mov %%ss,%k0" : "=a"(newregs->ss));
- asm volatile("mov %%cs,%k0" : "=a"(newregs->cs));
+ savesegment_mem16(ss, newregs->ss);
+ savesegment_mem16(cs, newregs->cs);
#ifdef CONFIG_X86_32
- asm volatile("mov %%ds,%k0" : "=a"(newregs->ds));
- asm volatile("mov %%es,%k0" : "=a"(newregs->es));
+ savesegment_mem16(ds, newregs->ds);
+ savesegment_mem16(es, newregs->es);
#endif
asm volatile("pushf\n\t"
"pop %0" : "=m"(newregs->flags));
--
2.53.0