mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RESEND v4 1/4] x86/fsgsbase: Remove unnecessary "memory" clobbers from FS/GS base accessors
@ 2026-03-30  5:57 Uros Bizjak
  2026-03-30  5:57 ` [PATCH RESEND v4 2/4] x86/segment: Remove unnecessary memory clobber from savesegment() Uros Bizjak
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Uros Bizjak @ 2026-03-30  5:57 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: Uros Bizjak, Peter Zijlstra (Intel),
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin

The rdfsbase() and rdgsbase() helpers currently include a "memory"
clobber in their inline assembly definitions. However, the RDFSBASE
and RDGSBASE instructions only read the FS/GS base MSRs into a
general-purpose register and do not access memory. The "memory" clobber,
which acts as a compiler barrier and may inhibit optimization,
is therefore unnecessary.

The "memory" clobber was historically used as a scheduling constraint
to prevent the compiler from moving the instructions before preceding
segment register loads. This is not required because both the segment
register loads and the RDFSBASE/RDGSBASE accessors are implemented
with `asm volatile`, which already prevents reordering between them.

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Acked-by: "Peter Zijlstra (Intel)" <peterz@infradead.org>
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: Note that the "memory" clobber was historically
    used as a scheduling constraint.
---
 arch/x86/include/asm/fsgsbase.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/fsgsbase.h b/arch/x86/include/asm/fsgsbase.h
index ab2547f97c2c..70ff4ef457b1 100644
--- a/arch/x86/include/asm/fsgsbase.h
+++ b/arch/x86/include/asm/fsgsbase.h
@@ -25,7 +25,7 @@ static __always_inline unsigned long rdfsbase(void)
 {
 	unsigned long fsbase;
 
-	asm volatile("rdfsbase %0" : "=r" (fsbase) :: "memory");
+	asm volatile("rdfsbase %0" : "=r" (fsbase));
 
 	return fsbase;
 }
@@ -34,7 +34,7 @@ static __always_inline unsigned long rdgsbase(void)
 {
 	unsigned long gsbase;
 
-	asm volatile("rdgsbase %0" : "=r" (gsbase) :: "memory");
+	asm volatile("rdgsbase %0" : "=r" (gsbase));
 
 	return gsbase;
 }
-- 
2.53.0


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

end of thread, other threads:[~2026-03-30  7:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-30  5:57 [PATCH RESEND v4 1/4] x86/fsgsbase: Remove unnecessary "memory" clobbers from FS/GS base accessors Uros Bizjak
2026-03-30  5:57 ` [PATCH RESEND v4 2/4] x86/segment: Remove unnecessary memory clobber from savesegment() Uros Bizjak
2026-03-30  7:17   ` [tip: x86/asm] x86/asm/segment: Remove unnecessary "memory" " tip-bot2 for Uros Bizjak
2026-03-30  5:57 ` [PATCH RESEND v4 3/4] x86/segment: Use ASM_INPUT_RM in __loadsegment_fs() Uros Bizjak
2026-03-30  7:16   ` [tip: x86/asm] x86/asm/segment: " tip-bot2 for Uros Bizjak
2026-03-30  5:57 ` [PATCH RESEND v4 4/4] x86/segment: Implement loadsegment()/savesegment() macros with static inline helpers Uros Bizjak
2026-03-30  7:16   ` [tip: x86/asm] x86/asm/segment: " tip-bot2 for Uros Bizjak
2026-03-30  7:17 ` [tip: x86/asm] x86/asm/fsgsbase: Remove unnecessary "memory" clobbers from FS/GS base (read-) accessors 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