[tip: x86/asm] x86/asm/segment: Remove unnecessary "memory" clobber from savesegment()

From: tip-bot2 for Uros Bizjak

Date: Mon Mar 30 2026 - 03:18:14 EST


The following commit has been merged into the x86/asm branch of tip:

Commit-ID: 8379ca68a01c38485b620d36a72d8aeeca86e743
Gitweb: https://git.kernel.org/tip/8379ca68a01c38485b620d36a72d8aeeca86e743
Author: Uros Bizjak <ubizjak@xxxxxxxxx>
AuthorDate: Mon, 30 Mar 2026 07:57:43 +02:00
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
CommitterDate: Mon, 30 Mar 2026 09:10:15 +02:00

x86/asm/segment: Remove unnecessary "memory" clobber from savesegment()

The savesegment() macro uses inline assembly to copy a segment register
into a general-purpose register:

movl %seg, reg

This instruction does not access memory, yet the inline asm currently
declares a "memory" clobber, which unnecessarily acts as a compiler
barrier and may inhibit optimization.

Remove the "memory" clobber and mark the asm as `asm volatile` instead.
Segment register loads in the kernel are implemented using `asm volatile`,
so the compiler will not schedule segment register reads before those
loads. Using `asm volatile` preserves the intended ordering with other
segment register operations without imposing an unnecessary global memory
barrier.

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Link: https://patch.msgid.link/20260330055823.5793-2-ubizjak@xxxxxxxxx
---
arch/x86/include/asm/segment.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
index 9f5be2b..3fe3a31 100644
--- a/arch/x86/include/asm/segment.h
+++ b/arch/x86/include/asm/segment.h
@@ -348,7 +348,7 @@ static inline void __loadsegment_fs(unsigned short value)
* Save a segment register away:
*/
#define savesegment(seg, value) \
- asm("movl %%" #seg ",%k0" : "=r" (value) : : "memory")
+ asm volatile("movl %%" #seg ",%k0" : "=r" (value))

#endif /* !__ASSEMBLER__ */
#endif /* __KERNEL__ */