mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH -tip 1/4] x86/elf: Use savesegment() for segment register reads in ELF core dump
@ 2026-03-30  8:59 Uros Bizjak
  2026-03-30  8:59 ` [PATCH -tip 2/4] x86/process/64: Use savesegment() in __show_regs() instead of inline asm Uros Bizjak
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Uros Bizjak @ 2026-03-30  8:59 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, H. Peter Anvin

ELF_CORE_COPY_REGS() currently reads %ds, %es, %fs, and %gs using
inline assembly and manual zero-extension. This results in redundant
instructions like `mov %eax,%eax`.

Replace the inline assembly with the `savesegment()` helper, which
automatically zero-extends the value to the full register width,
eliminating unnecessary instructions.

For example, the %ds load sequence changes from:

  d03: 8c d8                 mov    %ds,%eax
  d05: 89 c0                 mov    %eax,%eax
  d07: 48 89 84 24 38 01 00  mov    %rax,0x138(%rsp)
  d0e: 00

to:

  ce8: 8c d8                 mov    %ds,%eax
  cea: 48 89 84 24 38 01 00  mov    %rax,0x138(%rsp)
  cf1: 00

thus eliminating the unnecessary zero-extending `mov %eax,%eax`.

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/elf.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
index 2ba5f166e58f..c7f98977663c 100644
--- a/arch/x86/include/asm/elf.h
+++ b/arch/x86/include/asm/elf.h
@@ -187,7 +187,6 @@ void set_personality_ia32(bool);
 
 #define ELF_CORE_COPY_REGS(pr_reg, regs)			\
 do {								\
-	unsigned v;						\
 	(pr_reg)[0] = (regs)->r15;				\
 	(pr_reg)[1] = (regs)->r14;				\
 	(pr_reg)[2] = (regs)->r13;				\
@@ -211,10 +210,10 @@ do {								\
 	(pr_reg)[20] = (regs)->ss;				\
 	(pr_reg)[21] = x86_fsbase_read_cpu();			\
 	(pr_reg)[22] = x86_gsbase_read_cpu_inactive();		\
-	asm("movl %%ds,%0" : "=r" (v)); (pr_reg)[23] = v;	\
-	asm("movl %%es,%0" : "=r" (v)); (pr_reg)[24] = v;	\
-	asm("movl %%fs,%0" : "=r" (v)); (pr_reg)[25] = v;	\
-	asm("movl %%gs,%0" : "=r" (v)); (pr_reg)[26] = v;	\
+	savesegment(ds, (pr_reg)[23]);				\
+	savesegment(es, (pr_reg)[24]);				\
+	savesegment(fs, (pr_reg)[25]);				\
+	savesegment(gs, (pr_reg)[26]);				\
 } while (0);
 
 /* I'm not sure if we can use '-' here */
-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-03-31  8:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-30  8:59 [PATCH -tip 1/4] x86/elf: Use savesegment() for segment register reads in ELF core dump Uros Bizjak
2026-03-30  8:59 ` [PATCH -tip 2/4] x86/process/64: Use savesegment() in __show_regs() instead of inline asm Uros Bizjak
2026-03-31  8:02   ` [tip: x86/asm] " tip-bot2 for Uros Bizjak
2026-03-30  8:59 ` [PATCH -tip 3/4] x86/process/32: Use correct type for 'gs' variable in __show_regs() to avoid zero-extension Uros Bizjak
2026-03-31  8:02   ` [tip: x86/asm] " tip-bot2 for Uros Bizjak
2026-03-30  8:59 ` [PATCH -tip 4/4] x86/tls: Clean up 'sel' variable usage in do_set_thread_area Uros Bizjak
2026-03-31  8:02   ` [tip: x86/asm] x86/tls: Clean up 'sel' variable usage in do_set_thread_area() tip-bot2 for Uros Bizjak
2026-03-31  8:02 ` [tip: x86/asm] x86/elf: Use savesegment() for segment register reads in ELF core dump tip-bot2 for Uros Bizjak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome