Skip to contentSkip to conversation

x86/locking: Use sfence for wmb() if SSE is available

PATCH Applied Yao Zi 3 participants 3 messages Aug 1 – Aug 7

Subsystems (2)
lore
Share & tools
lore

Yao Zi

author
#0 lore raw

PATCH 1/1 x86/locking: Use sfence for wmb() if SSE is available

When adding cc clobber to wmb()'s definition, the alternative() condition to use sfence was incorrectly raised from X86_FEATURE_XMM to X86_FEATURE_XMM2.

Restore the correct constraint for potential better performance on machines without SSE2.

Fixes bd922477d935 ("locking/x86: Add cc clobber for ADDL")
---
 arch/x86/include/asm/barrier.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/barrier.h +1 -1
index b0096b5645a9..e0e59da15748 100644
@@ -17,7 +17,7 @@
 #define rmb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "lfence", \
 				       X86_FEATURE_XMM2) ::: "memory", "cc")
 #define wmb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "sfence", \
-				       X86_FEATURE_XMM2) ::: "memory", "cc")
+				       X86_FEATURE_XMM) ::: "memory", "cc")
 #else
 #define __mb()	asm volatile("mfence":::"memory")
 #define __rmb()	asm volatile("lfence":::"memory")
Signature · 1 line
2.54.0
#1 lore raw
Quoted 6 lines · Yao Zi

When adding cc clobber to wmb()'s definition, the alternative() condition to use sfence was incorrectly raised from X86_FEATURE_XMM to X86_FEATURE_XMM2.

Restore the correct constraint for potential better performance on machines without SSE2.

So Google tells me that SSE was introduced with P-III, while SSE2 was introduced with P4, so this affects only P-III.

Anything earlier won't care, and anything later will have DTRT.

I suppose we can do this, for those few people that still care about P-III... *sigh*.

Quoted 23 lines
Fixes bd922477d935 ("locking/x86: Add cc clobber for ADDL")
---
 arch/x86/include/asm/barrier.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/barrier.h +1 -1
index b0096b5645a9..e0e59da15748 100644
@@ -17,7 +17,7 @@
 #define rmb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "lfence", \
 				       X86_FEATURE_XMM2) ::: "memory", "cc")
 #define wmb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "sfence", \
-				       X86_FEATURE_XMM2) ::: "memory", "cc")
+				       X86_FEATURE_XMM) ::: "memory", "cc")
 #else
 #define __mb()	asm volatile("mfence":::"memory")
 #define __rmb()	asm volatile("lfence":::"memory")
Signature · 1 line
2.54.0
merge bot Applied
#2 lore raw
In reply to Yao Zi
The following commit has been merged into the x86/core branch of tip:

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

Commit-ID:     d824ed1307680dd482f607b0e707c575f70668c4
Gitweb:        https://git.kernel.org/tip/d824ed1307680dd482f607b0e707c575f70668c4
Author:        Yao Zi <[email protected]>
AuthorDate:    Sat, 01 Aug 2026 18:29:53 
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Fri, 07 Aug 2026 18:27:07 +02:00

x86/locking: Use sfence for wmb() if SSE is available

When adding cc clobber to wmb()'s definition, the alternative() condition to use sfence was incorrectly raised from X86_FEATURE_XMM to X86_FEATURE_XMM2.

Restore the correct constraint for potential better performance on machines without SSE2.

Fixes bd922477d935 ("locking/x86: Add cc clobber for ADDL")
---
 arch/x86/include/asm/barrier.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/barrier.h +1 -1
index db70832..3e78bb7 100644
@@ -17,7 +17,7 @@
 #define rmb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "lfence", \
 				       X86_FEATURE_XMM2) ::: "memory", "cc")
 #define wmb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "sfence", \
-				       X86_FEATURE_XMM2) ::: "memory", "cc")
+				       X86_FEATURE_XMM) ::: "memory", "cc")
 #else
 #define __mb()	asm volatile("mfence":::"memory")
 #define __rmb()	asm volatile("lfence":::"memory")