Skip to contentSkip to conversation

MIPS: io: Add barrier after register read in inX()

PATCH RESEND In review Huacai Chen 2 participants 5 messages Jun 12, 2018 – Jun 13, 2018

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

PATCH RESEND 1/2 MIPS: io: Add barrier after register read in inX()

While a barrier is present in the outX() functions before the register write, a similar barrier is missing in the inX() functions after the register read. This could allow memory accesses following inX() to observe stale data.

This patch is very similar to commit a1cc7034e33d12dc1 ("MIPS: io: Add barrier after register read in readX()"). Because war_io_reorder_wmb() is both used by writeX() and outX(), if readX() need a barrier then so does inX().

---
 arch/mips/include/asm/io.h | 2 ++
 1 file changed, 2 insertions(+)
arch/mips/include/asm/io.h +2 -0
index a7d0b83..cea8ad8 100644
@@ -414,6 +414,8 @@ static inline type pfx##in##bwlq##p(unsigned long port)			\
 	__val = *__addr;						\
 	slow;								\
 									\
+	/* prevent prefetching of coherent DMA data prematurely */	\
+	rmb();								\
 	return pfx##ioswab##bwlq(__addr, __val);			\
 }
 
Signature · 1 line
2.7.0
#1 lore raw

PATCH RESEND 2/2 MIPS: mcs lock: implement arch_mcs_spin_lock_contended() for Loongson-3

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 need a mb() after every READ_ONCE().

This patch introduce a MIPS-specific mcs_spinlock.h and revert to the old implementation of arch_mcs_spin_lock_contended() for Loongson-3.

---
 arch/mips/include/asm/Kbuild         |  1 -
 arch/mips/include/asm/mcs_spinlock.h | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/include/asm/mcs_spinlock.h
arch/mips/include/asm/Kbuild +0 -1
index 45d541b..7076627 100644
@@ -6,7 +6,6 @@ generic-y += emergency-restart.h
 generic-y += export.h
 generic-y += irq_work.h
 generic-y += local64.h
-generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
 generic-y += parport.h
 generic-y += percpu.h
arch/mips/include/asm/mcs_spinlock.h new file +14 -0
new file mode 100644
index 0000000..063df4e
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_MCS_LOCK_H
+#define __ASM_MCS_LOCK_H
+
+/* Loongson-3 need a mb() after every READ_ONCE() */
+#if defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_SMP)
+#define arch_mcs_spin_lock_contended(l)					\
+do {									\
+	while (!(smp_load_acquire(l)))					\
+		cpu_relax();						\
+} while (0)
+#endif	/* CONFIG_CPU_LOONGSON3 && CONFIG_SMP */
+
+#endif	/* __ASM_MCS_LOCK_H */
Signature · 1 line
2.7.0
#2 lore raw

Re: [PATCH Resend 2/2] MIPS: mcs lock: implement arch_mcs_spin_lock_contended() for Loongson-3

Hi Huacai,

Quoted 3 lines · Huacai Chen

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 need a mb() after every READ_ONCE().

Why do you need that mb()?

Could you describe what is actually happening with the current code, in order to explain what requires the mb() you mention here? What's being held in the SFB & why is that problematic?

Most importantly if smp_cond_load_acquire() isn't working as expected on Loongson CPUs then fixing that would be a much better path forwards than trying to avoid using it.

Could it be that Loongson requires an implementation of (smp_)read_barrier_depends()?

Additionally you have "Resend" in the subject of this email, but I don't see any previous submissions of this patch - given that commit 7f56b58a92aaf2c ("locking/mcs: Use smp_cond_load_acquire() in MCS spin loop") is very recent I doubt there were any. Please try to be factual, and if you have 2 patches that are unrelated please send them separately rather than as a series.

Thanks,
Paul

Quoted 45 lines

This patch introduce a MIPS-specific mcs_spinlock.h and revert to the old implementation of arch_mcs_spin_lock_contended() for Loongson-3.

---
 arch/mips/include/asm/Kbuild         |  1 -
 arch/mips/include/asm/mcs_spinlock.h | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/include/asm/mcs_spinlock.h
arch/mips/include/asm/Kbuild +0 -1
index 45d541b..7076627 100644
@@ -6,7 +6,6 @@ generic-y += emergency-restart.h
 generic-y += export.h
 generic-y += irq_work.h
 generic-y += local64.h
-generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
 generic-y += parport.h
 generic-y += percpu.h
arch/mips/include/asm/mcs_spinlock.h new file +14 -0
new file mode 100644
index 0000000..063df4e
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_MCS_LOCK_H
+#define __ASM_MCS_LOCK_H
+
+/* Loongson-3 need a mb() after every READ_ONCE() */
+#if defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_SMP)
+#define arch_mcs_spin_lock_contended(l)					\
+do {									\
+	while (!(smp_load_acquire(l)))					\
+		cpu_relax();						\
+} while (0)
+#endif	/* CONFIG_CPU_LOONGSON3 && CONFIG_SMP */
+
+#endif	/* __ASM_MCS_LOCK_H */
Signature · 1 line
2.7.0
#3 lore raw

Re: [PATCH Resend 2/2] MIPS: mcs lock: implement arch_mcs_spin_lock_contended() for Loongson-3

Hi, Paul,

Quoted 13 lines · Paul Burton

Hi Huacai,

Quoted 3 lines · Huacai Chen

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 need a mb() after every READ_ONCE().

Why do you need that mb()?

Could you describe what is actually happening with the current code, in order to explain what requires the mb() you mention here? What's being held in the SFB & why is that problematic?

Quoted 6 lines

Most importantly if smp_cond_load_acquire() isn't working as expected on Loongson CPUs then fixing that would be a much better path forwards than trying to avoid using it.

Could it be that Loongson requires an implementation of (smp_)read_barrier_depends()?

Yes, we should fix smp_cond_load_acquire(), not arch_mcs_spin_lock_contended(). Thank you very much.

Quoted 7 lines

Additionally you have "Resend" in the subject of this email, but I don't see any previous submissions of this patch - given that commit 7f56b58a92aaf2c ("locking/mcs: Use smp_cond_load_acquire() in MCS spin loop") is very recent I doubt there were any. Please try to be factual, and if you have 2 patches that are unrelated please send them separately rather than as a series.

I send another patch in this series because it is so simple and should be merged in the previous release, but it is ignored again and again. In practise, my
single patch in linux-mips usually be ignored (even they are very simple and well described)....
For example:
https://patchwork.linux-mips.org/patch/17723/
https://patchwork.linux-mips.org/patch/18587/
https://patchwork.linux-mips.org/patch/19184/

Some of them are promised by James to review, but still ignored until now.

Huacai

Quoted 49 lines

Thanks,
Paul

Quoted 45 lines

This patch introduce a MIPS-specific mcs_spinlock.h and revert to the old implementation of arch_mcs_spin_lock_contended() for Loongson-3.

---
 arch/mips/include/asm/Kbuild         |  1 -
 arch/mips/include/asm/mcs_spinlock.h | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/include/asm/mcs_spinlock.h
arch/mips/include/asm/Kbuild +0 -1
index 45d541b..7076627 100644
@@ -6,7 +6,6 @@ generic-y += emergency-restart.h
 generic-y += export.h
 generic-y += irq_work.h
 generic-y += local64.h
-generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
 generic-y += parport.h
 generic-y += percpu.h
arch/mips/include/asm/mcs_spinlock.h new file +14 -1
new file mode 100644
index 0000000..063df4e
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_MCS_LOCK_H
+#define __ASM_MCS_LOCK_H
+
+/* Loongson-3 need a mb() after every READ_ONCE() */
+#if defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_SMP)
+#define arch_mcs_spin_lock_contended(l)                                      \
+do {                                                                 \
+     while (!(smp_load_acquire(l)))                                  \
+             cpu_relax();                                            \
+} while (0)
+#endif       /* CONFIG_CPU_LOONGSON3 && CONFIG_SMP */
+
+#endif       /* __ASM_MCS_LOCK_H */
--

2.7.0

#4 lore raw

Re: [PATCH Resend 2/2] MIPS: mcs lock: implement arch_mcs_spin_lock_contended() for Loongson-3

Hi Huacai,

Quoted 16 lines · Huacai Chen
Quoted 6 lines

Additionally you have "Resend" in the subject of this email, but I don't see any previous submissions of this patch - given that commit 7f56b58a92aaf2c ("locking/mcs: Use smp_cond_load_acquire() in MCS spin loop") is very recent I doubt there were any. Please try to be factual, and if you have 2 patches that are unrelated please send them separately rather than as a series.

I send another patch in this series because it is so simple and should be merged in the previous release, but it is ignored again and again. In practise, my
single patch in linux-mips usually be ignored (even they are very simple and well described)....
For example:
https://patchwork.linux-mips.org/patch/17723/
https://patchwork.linux-mips.org/patch/18587/
https://patchwork.linux-mips.org/patch/19184/

Quoted 1 line

Some of them are promised by James to review, but still ignored until now.

Both James & Ralf have been busy with things outside of kernel development recently, so I'm sure it's just the case that they've not had as much time to spend on maintenance as would have been ideal. I know that has been frustrating, but the reasons for that haven't always been controllable & I feel confident saying that it was nobody's intent to ignore you or your contributions.

Going forwards I'm now listed in MAINTAINERS & after v4.18-rc1 is released I intend to start merging patches ready for v4.19. I've started looking though pending patches but haven't gotten as far as the ones you linked yet.

A couple of those look like they could be candidates for a fixes pull in the 4.18 cycle so I'll try to take a closer look at those sooner.

I'm still getting up to speed & there is a backlog of patches to review, but please be assured that if your patch is still listed as "New" or "Under Review" in patchwork then I intend to look at it, and there's no need to resend it.

Thanks,
Paul