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 2/2] x86/process: Use storesegment() when saving segment selectors
Date: Tue, 31 Mar 2026 08:38:19 +0200 [thread overview]
Message-ID: <20260331063838.108857-2-ubizjak@gmail.com> (raw)
In-Reply-To: <20260331063838.108857-1-ubizjak@gmail.com>
Switch segment save sites in copy_thread() and save_fsgs() from
savesegment() to the newly introduced storesegment() helper.
These call sites only store the segment selector into a u16 field
and do not require the value in a general-purpose register. Using
storesegment() avoids the unnecessary register intermediate and
better matches the intended use.
The generated code is improved from, e.g.:
34f: 8c c0 mov %es,%eax
351: 66 89 83 08 0c 00 00 mov %ax,0xc08(%rbx)
to a single direct store:
34f: 8c 83 08 0c 00 00 mov %es,0xc08(%rbx)
This is a mechanical follow-up to the introduction of
storesegment(), 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>
---
arch/x86/kernel/process.c | 4 ++--
arch/x86/kernel/process_64.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 4c718f8adc59..10e2ba668a14 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -197,8 +197,8 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
p->thread.gsindex = current->thread.gsindex;
p->thread.gsbase = current->thread.gsbase;
- savesegment(es, p->thread.es);
- savesegment(ds, p->thread.ds);
+ storesegment(es, p->thread.es);
+ storesegment(ds, p->thread.ds);
if (p->mm && (clone_flags & (CLONE_VM | CLONE_VFORK)) == CLONE_VM)
set_bit(MM_CONTEXT_LOCK_LAM, &p->mm->context.flags);
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index b85e715ebb30..fe391961ed86 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -275,8 +275,8 @@ static __always_inline void save_base_legacy(struct task_struct *prev_p,
static __always_inline void save_fsgs(struct task_struct *task)
{
- savesegment(fs, task->thread.fsindex);
- savesegment(gs, task->thread.gsindex);
+ storesegment(fs, task->thread.fsindex);
+ storesegment(gs, task->thread.gsindex);
if (static_cpu_has(X86_FEATURE_FSGSBASE)) {
/*
* If FSGSBASE is enabled, we can't make any useful guesses
--
2.53.0
next prev parent reply other threads:[~2026-03-31 6:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 6:38 [PATCH 1/2] x86/segment: Introduce storesegment() helper to write segment selectors to memory Uros Bizjak
2026-03-31 6:38 ` Uros Bizjak [this message]
2026-03-31 6:56 ` Ingo Molnar
2026-03-31 9:53 ` Uros Bizjak
2026-03-31 9:59 ` Uros Bizjak
2026-04-01 6:40 ` Ingo Molnar
2026-04-01 6:59 ` Uros Bizjak
2026-04-01 7:02 ` Ingo Molnar
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=20260331063838.108857-2-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