arch/x86/include/asm/elf.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
The following commit has been merged into the x86/asm branch of tip:
Commit-ID: 47d2f007615ace34c5ec9026cd5f286833c62c1b
Gitweb: https://git.kernel.org/tip/47d2f007615ace34c5ec9026cd5f286833c62c1b
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Mon, 30 Mar 2026 10:59:20 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 31 Mar 2026 09:50:10 +02:00
x86/elf: Use savesegment() for segment register reads in ELF core dump
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>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://patch.msgid.link/20260330085938.67985-1-ubizjak@gmail.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 2ba5f16..c7f9897 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 */
© 2016 - 2026 Red Hat, Inc.