Skip to contentSkip to conversation

locking/atomic/x86: Introduce read64_nonatomic macro to x86_32 with cx8

PATCH RESEND Applied Uros Bizjak 2 participants 4 messages Jun 5, 2024 – Jul 17, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/2 locking/atomic/x86: Introduce read64_nonatomic macro to x86_32 with cx8

As described in:

commit e73c4e34a0e9 ("locking/atomic/x86: Introduce arch_atomic64_read_nonatomic() to x86_32")

the value preload before the cmpxchg loop does not need to be atomic. Introduce read64_nonatomic macro to load the value from atomic_t location in a faster non-atomic way and use it in atomic64_cx8_32.S.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/lib/atomic64_cx8_32.S | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/lib/atomic64_cx8_32.S +7 -2
index 90afb488b396..b2eff07d65e4 100644
@@ -16,6 +16,11 @@
 	cmpxchg8b (\reg)
 .endm
 
+.macro read64_nonatomic reg
+	movl (\reg), %eax
+	movl 4(\reg), %edx
+.endm
+
 SYM_FUNC_START(atomic64_read_cx8)
 	read64 %ecx
 	RET
@@ -51,7 +56,7 @@ SYM_FUNC_START(atomic64_\func\()_return_cx8)
 	movl %edx, %edi
 	movl %ecx, %ebp
 
-	read64 %ecx
+	read64_nonatomic %ecx
 1:
 	movl %eax, %ebx
 	movl %edx, %ecx
@@ -79,7 +84,7 @@ addsub_return sub sub sbb
 SYM_FUNC_START(atomic64_\func\()_return_cx8)
 	pushl %ebx
 
-	read64 %esi
+	read64_nonatomic %esi
 1:
 	movl %eax, %ebx
 	movl %edx, %ecx
Signature · 1 line
2.42.0
#1 lore raw

PATCH RESEND 2/2 locking/atomic/x86: Redeclare x86_32 arch_atomic64_{add,sub}() as void

Correct the return type of x86_32 arch_atomic64_add() and arch_atomic64_sub() functions to void and remove redundant return.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/include/asm/atomic64_32.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/include/asm/atomic64_32.h +2 -4
index 8db2ec4d6cda..1f650b4dde50 100644
@@ -163,20 +163,18 @@ static __always_inline s64 arch_atomic64_dec_return(atomic64_t *v)
 }
 #define arch_atomic64_dec_return arch_atomic64_dec_return
 
-static __always_inline s64 arch_atomic64_add(s64 i, atomic64_t *v)
+static __always_inline void arch_atomic64_add(s64 i, atomic64_t *v)
 {
 	__alternative_atomic64(add, add_return,
 			       ASM_OUTPUT2("+A" (i), "+c" (v)),
 			       ASM_NO_INPUT_CLOBBER("memory"));
-	return i;
 }
 
-static __always_inline s64 arch_atomic64_sub(s64 i, atomic64_t *v)
+static __always_inline void arch_atomic64_sub(s64 i, atomic64_t *v)
 {
 	__alternative_atomic64(sub, sub_return,
 			       ASM_OUTPUT2("+A" (i), "+c" (v)),
 			       ASM_NO_INPUT_CLOBBER("memory"));
-	return i;
 }
 
 static __always_inline void arch_atomic64_inc(atomic64_t *v)
Signature · 1 line
2.42.0
merge bot Applied
#2 lore raw

[tip: locking/core] locking/atomic/x86: Redeclare x86_32 arch_atomic64_{add,sub}() as void

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

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

Commit-ID:     dce2a224763ce968445e14c43b49321936309c75
Gitweb:        https://git.kernel.org/tip/dce2a224763ce968445e14c43b49321936309c75
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Wed, 05 Jun 2024 20:13:16 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Wed, 17 Jul 2024 16:28:19 +02:00

locking/atomic/x86: Redeclare x86_32 arch_atomic64_{add,sub}() as void

Correct the return type of x86_32 arch_atomic64_add() and arch_atomic64_sub() functions to 'void' and remove redundant return.

---
 arch/x86/include/asm/atomic64_32.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/include/asm/atomic64_32.h +2 -4
index 8db2ec4..1f650b4 100644
@@ -163,20 +163,18 @@ static __always_inline s64 arch_atomic64_dec_return(atomic64_t *v)
 }
 #define arch_atomic64_dec_return arch_atomic64_dec_return
 
-static __always_inline s64 arch_atomic64_add(s64 i, atomic64_t *v)
+static __always_inline void arch_atomic64_add(s64 i, atomic64_t *v)
 {
 	__alternative_atomic64(add, add_return,
 			       ASM_OUTPUT2("+A" (i), "+c" (v)),
 			       ASM_NO_INPUT_CLOBBER("memory"));
-	return i;
 }
 
-static __always_inline s64 arch_atomic64_sub(s64 i, atomic64_t *v)
+static __always_inline void arch_atomic64_sub(s64 i, atomic64_t *v)
 {
 	__alternative_atomic64(sub, sub_return,
 			       ASM_OUTPUT2("+A" (i), "+c" (v)),
 			       ASM_NO_INPUT_CLOBBER("memory"));
-	return i;
 }
 
 static __always_inline void arch_atomic64_inc(atomic64_t *v)
merge bot Applied
#3 lore raw

[tip: locking/core] locking/atomic/x86: Introduce the read64_nonatomic macro to x86_32 with cx8

In reply to Uros Bizjak
The following commit has been merged into the locking/core branch of tip:

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

Commit-ID:     6e30a7c98a9fda2f894e970e9cd637657f39c59d
Gitweb:        https://git.kernel.org/tip/6e30a7c98a9fda2f894e970e9cd637657f39c59d
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Wed, 05 Jun 2024 20:13:15 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Wed, 17 Jul 2024 16:28:11 +02:00

locking/atomic/x86: Introduce the read64_nonatomic macro to x86_32 with cx8

As described in commit:

e73c4e34a0e9 ("locking/atomic/x86: Introduce arch_atomic64_read_nonatomic() to x86_32")

the value preload before the CMPXCHG loop does not need to be atomic.

Introduce the read64_nonatomic assembly macro to load the value from a atomic_t location in a faster non-atomic way and use it in atomic64_cx8_32.S.

---
 arch/x86/lib/atomic64_cx8_32.S |  9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/lib/atomic64_cx8_32.S +7 -2
index 90afb48..b2eff07 100644
@@ -16,6 +16,11 @@
 	cmpxchg8b (\reg)
 .endm
 
+.macro read64_nonatomic reg
+	movl (\reg), %eax
+	movl 4(\reg), %edx
+.endm
+
 SYM_FUNC_START(atomic64_read_cx8)
 	read64 %ecx
 	RET
@@ -51,7 +56,7 @@ SYM_FUNC_START(atomic64_\func\()_return_cx8)
 	movl %edx, %edi
 	movl %ecx, %ebp
 
-	read64 %ecx
+	read64_nonatomic %ecx
 1:
 	movl %eax, %ebx
 	movl %edx, %ecx
@@ -79,7 +84,7 @@ addsub_return sub sub sbb
 SYM_FUNC_START(atomic64_\func\()_return_cx8)
 	pushl %ebx
 
-	read64 %esi
+	read64_nonatomic %esi
 1:
 	movl %eax, %ebx
 	movl %edx, %ecx