public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: Uros Bizjak <ubizjak@gmail.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@kernel.org>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH -tip v2 3/3] x86/kexec: Use savesegment_mem16() for segment register save in crash_setup_regs()
Date: Wed,  1 Apr 2026 10:58:12 +0200	[thread overview]
Message-ID: <20260401085832.285121-3-ubizjak@gmail.com> (raw)
In-Reply-To: <20260401085832.285121-1-ubizjak@gmail.com>

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@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>
---
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


      parent reply	other threads:[~2026-04-01  8:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01  8:58 [PATCH -tip v2 1/3] x86/segment: Introduce savesegment_mem16() helper to write segment selectors to memory Uros Bizjak
2026-04-01  8:58 ` [PATCH -tip v2 2/3] x86/process: Use savesegment_mem16() when saving segment selectors Uros Bizjak
2026-04-01  8:58 ` Uros Bizjak [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260401085832.285121-3-ubizjak@gmail.com \
    --to=ubizjak@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox