mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Fixup cmpxchg sematic for memory barrier
@ 2023-08-01  1:15 guoren
  2023-08-01  2:29 ` WANG Rui
  2023-08-01  3:10 ` Xi Ruoyao
  0 siblings, 2 replies; 14+ messages in thread
From: guoren @ 2023-08-01  1:15 UTC (permalink / raw)
  To: chenhuacai, kernel, arnd, andi.shyti, wangrui, andrzej.hajda,
	peterz, will, boqun.feng, mark.rutland, guoren
  Cc: loongarch, linux-kernel, Guo Ren

From: Guo Ren <guoren@linux.alibaba.com>

When cmpxchg failed, no memory barrier was needed to take. Only
when cmpxchg success and the new value is written, then the memory
barriers needed.

 - cmpxchg_asm:   Unnecessary __WEAK_LLSC_WB for the fail path would
		  reduce the performance of the cmpxchg loop trying.
 - cmpxchg_small: Miss an necessary __WEAK_LLSC_WB when sc succeeds.
		  It's a bug because there is no memory synchronization
		  when sc succeeds.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
---
 arch/loongarch/include/asm/cmpxchg.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/loongarch/include/asm/cmpxchg.h b/arch/loongarch/include/asm/cmpxchg.h
index 979fde61bba8..6a05b92814b6 100644
--- a/arch/loongarch/include/asm/cmpxchg.h
+++ b/arch/loongarch/include/asm/cmpxchg.h
@@ -102,8 +102,8 @@ __arch_xchg(volatile void *ptr, unsigned long x, int size)
 	"	move	$t0, %z4			\n"		\
 	"	" st "	$t0, %1				\n"		\
 	"	beqz	$t0, 1b				\n"		\
-	"2:						\n"		\
 	__WEAK_LLSC_MB							\
+	"2:						\n"		\
 	: "=&r" (__ret), "=ZB"(*m)					\
 	: "ZB"(*m), "Jr" (old), "Jr" (new)				\
 	: "t0", "memory");						\
@@ -148,10 +148,8 @@ static inline unsigned int __cmpxchg_small(volatile void *ptr, unsigned int old,
 	"	or		%1, %1, %z6	\n"
 	"	sc.w		%1, %2		\n"
 	"	beqz		%1, 1b		\n"
-	"	b		3f		\n"
-	"2:					\n"
 	__WEAK_LLSC_MB
-	"3:					\n"
+	"2:					\n"
 	: "=&r" (old32), "=&r" (temp), "=ZC" (*ptr32)
 	: "ZC" (*ptr32), "Jr" (mask), "Jr" (old), "Jr" (new)
 	: "memory");
-- 
2.36.1


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

end of thread, other threads:[~2023-08-02  2:23 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-01  1:15 [PATCH] LoongArch: Fixup cmpxchg sematic for memory barrier guoren
2023-08-01  2:29 ` WANG Rui
2023-08-01  8:32   ` Will Deacon
2023-08-01  9:30     ` WANG Rui
2023-08-01  9:02   ` Guo Ren
2023-08-01  9:05     ` Guo Ren
2023-08-01  9:31       ` WANG Rui
2023-08-01 10:49         ` Guo Ren
2023-08-01 11:23           ` Xi Ruoyao
2023-08-01 11:28             ` Xi Ruoyao
2023-08-01 16:36           ` WANG Rui
2023-08-01 23:17             ` Guo Ren
2023-08-02  2:23               ` WANG Rui
2023-08-01  3:10 ` Xi Ruoyao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®