Skip to contentSkip to conversation

MIPS: Fix a long-standing mistake in mips_atomic_set()

PATCH In review Huacai Chen 3 participants 3 messages Jun 22, 2017

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

PATCH 1/1 MIPS: Fix a long-standing mistake in mips_atomic_set()

This mistake comes from the commit f1e39a4a616cd99 ("MIPS: Rewrite sysmips(MIPS_ATOMIC_SET, ...) in C with inline assembler"). In the common case 'bnez' should be 'beqz' (as same as older kernels before 2.6.32), otherwise this syscall may cause an endless loop.

---
 arch/mips/kernel/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kernel/syscall.c +1 -1
index 1dfa7f5..95e1b30 100644
@@ -134,7 +134,7 @@ static inline int mips_atomic_set(unsigned long addr, unsigned long new)
 		"1:	ll	%[old], (%[addr])			\n"
 		"	move	%[tmp], %[new]				\n"
 		"2:	sc	%[tmp], (%[addr])			\n"
-		"	bnez	%[tmp], 4f				\n"
+		"	beqz	%[tmp], 4f				\n"
 		"3:							\n"
 		"	.insn						\n"
 		"	.subsection 2					\n"
Signature · 1 line
2.7.0
#1 lore raw

Hi Huacai,

Quoted 7 lines · Huacai Chen

This mistake comes from the commit f1e39a4a616cd99 ("MIPS: Rewrite sysmips(MIPS_ATOMIC_SET, ...) in C with inline assembler"). In the common case 'bnez' should be 'beqz' (as same as older kernels before 2.6.32), otherwise this syscall may cause an endless loop.

Thats a coincidence. 8 years its been broken and I submitted an identical patch only a few weeks ago, along with some other related fixes:

https://patchwork.linux-mips.org/project/linux-mips/list/?series=313&state=*

Cheers
James

Quoted 23 lines
---
 arch/mips/kernel/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kernel/syscall.c +1 -1
index 1dfa7f5..95e1b30 100644
@@ -134,7 +134,7 @@ static inline int mips_atomic_set(unsigned long addr, unsigned long new)
 		"1:	ll	%[old], (%[addr])			\n"
 		"	move	%[tmp], %[new]				\n"
 		"2:	sc	%[tmp], (%[addr])			\n"
-		"	bnez	%[tmp], 4f				\n"
+		"	beqz	%[tmp], 4f				\n"
 		"3:							\n"
 		"	.insn						\n"
 		"	.subsection 2					\n"
Signature · 1 line
2.7.0
#2 lore raw
Quoted 8 lines · James Hogan

Hi Huacai,

Quoted 5 lines · Huacai Chen

This mistake comes from the commit f1e39a4a616cd99 ("MIPS: Rewrite sysmips(MIPS_ATOMIC_SET, ...) in C with inline assembler"). In the common case 'bnez' should be 'beqz' (as same as older kernels before 2.6.32), otherwise this syscall may cause an endless loop.

Quoted 8 lines
Quoted 2 lines

Thats a coincidence. 8 years its been broken and I submitted an identical patch only a few weeks ago, along with some other related fixes:

https://patchwork.linux-mips.org/project/linux-mips/list/?series=313&state=*

I take it as a proof that everybody is using LL/SC (or the LL/SC emulation) these days and sysmips(MIPS_ATOMIC_SET) finally has been obsoleted and is only useful for stoneage binary compatibility.

Which is really good. Unless people are using silly hacks such as $k0/$k1 being overwriten by exception handlers ...

Ralf