All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] MIPS: implement smp_cond_load_acquire() for Loongson-3
@ 2018-07-09  2:26 Huacai Chen
  2018-07-09 16:49 ` Paul Burton
  0 siblings, 1 reply; 18+ messages in thread
From: Huacai Chen @ 2018-07-09  2:26 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: Paul Burton, James Hogan, linux-mips, Fuxin Zhang, Zhangjin Wu,
	Huacai Chen, Huacai Chen, stable

After commit 7f56b58a92aaf2c ("locking/mcs: Use smp_cond_load_acquire()
in MCS spin loop") Loongson-3 fails to boot. This is because Loongson-3
has SFB (Store Fill Buffer) and the weak-ordering may cause READ_ONCE()
to get an old value in a tight loop. So in smp_cond_load_acquire() we
need a __smp_rmb() before the READ_ONCE() loop.

This patch introduce a Loongson-specific smp_cond_load_acquire(). And
it should be backported to as early as linux-4.5, in which release the
smp_cond_acquire() is introduced.

There may be other cases where memory barriers is needed, we will fix
them one by one.

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhc@lemote.com>
---
 arch/mips/include/asm/barrier.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
index a5eb1bb..e8c4c63 100644
--- a/arch/mips/include/asm/barrier.h
+++ b/arch/mips/include/asm/barrier.h
@@ -222,6 +222,24 @@
 #define __smp_mb__before_atomic()	__smp_mb__before_llsc()
 #define __smp_mb__after_atomic()	smp_llsc_mb()
 
+#ifdef CONFIG_CPU_LOONGSON3
+/* Loongson-3 need a __smp_rmb() before READ_ONCE() loop */
+#define smp_cond_load_acquire(ptr, cond_expr)			\
+({								\
+	typeof(ptr) __PTR = (ptr);				\
+	typeof(*ptr) VAL;					\
+	__smp_rmb();						\
+	for (;;) {						\
+		VAL = READ_ONCE(*__PTR);			\
+		if (cond_expr)					\
+			break;					\
+		cpu_relax();					\
+	}							\
+	__smp_rmb();						\
+	VAL;							\
+})
+#endif	/* CONFIG_CPU_LOONGSON3 */
+
 #include <asm-generic/barrier.h>
 
 #endif /* __ASM_BARRIER_H */
-- 
2.7.0

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

end of thread, other threads:[~2018-07-11 11:44 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-09  2:26 [PATCH V2] MIPS: implement smp_cond_load_acquire() for Loongson-3 Huacai Chen
2018-07-09 16:49 ` Paul Burton
2018-07-10  4:26   ` Huacai Chen
2018-07-10  9:36     ` Peter Zijlstra
2018-07-10 10:54       ` Peter Zijlstra
2018-07-10 11:45         ` 陈华才
2018-07-10 12:17           ` Peter Zijlstra
2018-07-10 16:14             ` Paul E. McKenney
2018-07-10 17:10             ` Paul Burton
2018-07-10 17:10               ` Paul Burton
2018-07-10 17:10               ` Paul Burton
2018-07-11 10:04               ` David Laight
2018-07-11 10:55                 ` Peter Zijlstra
2018-07-11 10:05             ` Jiaxun Yang
2018-07-11 10:21               ` Will Deacon
2018-07-11 11:09                 ` Peter Zijlstra
2018-07-11 11:46                   ` David Laight
2018-07-11  9:43           ` Will Deacon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.