* [PATCH RESEND] x86/kexec: store segment registers directly to memory in crash_setup_regs()
@ 2026-09-06 18:39 Uros Bizjak
2026-09-07 1:33 ` H. Peter Anvin
0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2026-09-06 18:39 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
crash_setup_regs() currently moves segment registers (ss, cs, ds, es)
into pt_regs via a general purpose register (%eax). Update the code to
avoid the intermediate register and store segment registers directly
to their destination fields. This reduces the generated code from:
131: 8c d0 mov %ss,%eax
133: 66 89 84 24 a0 00 00 mov %ax,0xa0(%rsp)
13a: 00
13b: 8c c8 mov %cs,%eax
13d: 66 89 84 24 88 00 00 mov %ax,0x88(%rsp)
144: 00
to:
131: 8c 94 24 a0 00 00 00 mov %ss,0xa0(%rsp)
138: 8c 8c 24 88 00 00 00 mov %cs,0x88(%rsp)
No functional change intended.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
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..ad7ef567452b 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));
+ asm volatile("mov %%ss,%0" : "=m"(newregs->ss));
+ asm volatile("mov %%cs,%0" : "=m"(newregs->cs));
#ifdef CONFIG_X86_32
- asm volatile("mov %%ds,%k0" : "=a"(newregs->ds));
- asm volatile("mov %%es,%k0" : "=a"(newregs->es));
+ asm volatile("mov %%ds,%0" : "=m"(newregs->ds));
+ asm volatile("mov %%es,%0" : "=m"(newregs->es));
#endif
asm volatile("pushf\n\t"
"pop %0" : "=m"(newregs->flags));
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] x86/kexec: store segment registers directly to memory in crash_setup_regs()
2026-09-06 18:39 [PATCH RESEND] x86/kexec: store segment registers directly to memory in crash_setup_regs() Uros Bizjak
@ 2026-09-07 1:33 ` H. Peter Anvin
2026-09-07 4:42 ` Uros Bizjak
0 siblings, 1 reply; 3+ messages in thread
From: H. Peter Anvin @ 2026-09-07 1:33 UTC (permalink / raw)
To: Uros Bizjak, x86, linux-kernel
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
On 2026-09-06 11:39, Uros Bizjak wrote:
> crash_setup_regs() currently moves segment registers (ss, cs, ds, es)
> into pt_regs via a general purpose register (%eax). Update the code to
> avoid the intermediate register and store segment registers directly
> to their destination fields. This reduces the generated code from:
>
> diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h
> index 5cfb27f26583..ad7ef567452b 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));
> + asm volatile("mov %%ss,%0" : "=m"(newregs->ss));
> + asm volatile("mov %%cs,%0" : "=m"(newregs->cs));
> #ifdef CONFIG_X86_32
> - asm volatile("mov %%ds,%k0" : "=a"(newregs->ds));
> - asm volatile("mov %%es,%k0" : "=a"(newregs->es));
> + asm volatile("mov %%ds,%0" : "=m"(newregs->ds));
> + asm volatile("mov %%es,%0" : "=m"(newregs->es));
> #endif
> asm volatile("pushf\n\t"
> "pop %0" : "=m"(newregs->flags));
Why not use "=rm"? "=a" seems odd in the extreme.
-hpa
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] x86/kexec: store segment registers directly to memory in crash_setup_regs()
2026-09-07 1:33 ` H. Peter Anvin
@ 2026-09-07 4:42 ` Uros Bizjak
0 siblings, 0 replies; 3+ messages in thread
From: Uros Bizjak @ 2026-09-07 4:42 UTC (permalink / raw)
To: H. Peter Anvin
Cc: x86, linux-kernel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen
On Mon, Sep 7, 2026 at 3:33 AM H. Peter Anvin <hpa@zytor.com> wrote:
>
> On 2026-09-06 11:39, Uros Bizjak wrote:
> > crash_setup_regs() currently moves segment registers (ss, cs, ds, es)
> > into pt_regs via a general purpose register (%eax). Update the code to
> > avoid the intermediate register and store segment registers directly
> > to their destination fields. This reduces the generated code from:
> >
>
> > diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h
> > index 5cfb27f26583..ad7ef567452b 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));
> > + asm volatile("mov %%ss,%0" : "=m"(newregs->ss));
> > + asm volatile("mov %%cs,%0" : "=m"(newregs->cs));
> > #ifdef CONFIG_X86_32
> > - asm volatile("mov %%ds,%k0" : "=a"(newregs->ds));
> > - asm volatile("mov %%es,%k0" : "=a"(newregs->es));
> > + asm volatile("mov %%ds,%0" : "=m"(newregs->ds));
> > + asm volatile("mov %%es,%0" : "=m"(newregs->es));
> > #endif
> > asm volatile("pushf\n\t"
> > "pop %0" : "=m"(newregs->flags));
>
> Why not use "=rm"? "=a" seems odd in the extreme.
"=rm" will produce assembly using an intermediate register due to GCC
PR124209 [1]. clang also has issues with "=rm", please see the
definition of ASM_OUTPUT_RM in compiler-clang.h. Using "=m" will
always create optimal code on both compilers.
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124209
Uros.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-07 4:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-06 18:39 [PATCH RESEND] x86/kexec: store segment registers directly to memory in crash_setup_regs() Uros Bizjak
2026-09-07 1:33 ` H. Peter Anvin
2026-09-07 4:42 ` Uros Bizjak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®