Skip to contentSkip to conversation

MIPS: __delay CPU_DADDI_WORKAROUNDS bug fix

PATCH Superseded Maciej W. Rozycki 2 participants 4 messages Mar 31, 2014 – Apr 8, 2014 MIPS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 MIPS: __delay CPU_DADDI_WORKAROUNDS bug fix

With CPU_DADDI_WORKAROUNDS enabled __delay assembles with a macro in a branch delay slot:

{standard input}: Assembler messages:
{standard input}:18: Warning: Macro instruction expanded into multiple instructions in a branch delay slot

and broken code results:

0000000000000000 <__delay>:
0: 1480ffff bnez a0,0 <__delay>
4: 24010001 li at,1
8: 0081202f dsubu a0,a0,at
c: 03e00008 jr ra
10: 00000000 nop
14: 00000000 nop

Consequently the function loops indefinitely, showing up prominently as a hang in the delay loop calibration at bootstrap.

This change corrects the problem by forcing the immediate 1 into a register while keeping code produced identical where CPU_DADDI_WORKAROUNDS is disabled.

---
linux-mips-delay-nodaddi-fix.patch

arch/mips/lib/delay.c +10 -4
Index: linux-20140329-4maxp64/arch/mips/lib/delay.c
===================================================================
@@ -6,7 +6,7 @@
  * Copyright (C) 1994 by Waldorf Electronics
  * Copyright (C) 1995 - 2000, 01, 03 by Ralf Baechle
  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
- * Copyright (C) 2007  Maciej W. Rozycki
+ * Copyright (C) 2007, 2014 Maciej W. Rozycki
  */
 #include <linux/module.h>
 #include <linux/param.h>
@@ -15,6 +15,12 @@
 #include <asm/compiler.h>
 #include <asm/war.h>
 
+#ifndef CONFIG_CPU_DADDI_WORKAROUNDS
+#define GCC_DADDI_IMM_ASM() "I"
+#else
+#define GCC_DADDI_IMM_ASM() "r"
+#endif
+
 void __delay(unsigned long loops)
 {
 	__asm__ __volatile__ (
@@ -22,13 +28,13 @@ void __delay(unsigned long loops)
 	"	.align	3					\n"
 	"1:	bnez	%0, 1b					\n"
 #if BITS_PER_LONG == 32
-	"	subu	%0, 1					\n"
+	"	subu	%0, %1					\n"
 #else
-	"	dsubu	%0, 1					\n"
+	"	dsubu	%0, %1					\n"
 #endif
 	"	.set	reorder					\n"
 	: "=r" (loops)
-	: "0" (loops));
+	: GCC_DADDI_IMM_ASM() (1), "0" (loops));
 }
 EXPORT_SYMBOL(__delay);
 
#1 lore raw

PATCH 3/3 MIPS: csum_partial.S CPU_DADDI_WORKAROUNDS bug fix

This change reverts most of commit 60724ca59eda766a30be57aec6b49bc3e2bead91 [MIPS: IP checksums: Remove unncessary .set pseudos] that introduced warnings with the CPU_DADDI_WORKAROUNDS option set:

arch/mips/lib/csum_partial.S: Assembler messages:
arch/mips/lib/csum_partial.S:450: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:450: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:450: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:452: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:452: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:452: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:454: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:454: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:454: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:456: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:456: Warning: used $3 with ".set at=$3" arch/mips/lib/csum_partial.S:456: Warning: used $3 with ".set at=$3" [and so on, and so on...]

The warnings are benign and good code is produced regardless because no macros that'd use the assembler's temporary register are involved, however the `.set noat' directives removed by the commit referred are crucial to guarantee this is still going to be the case after any changes in the future. Therefore they need to be brought back to place which this change does.

---
Ralf,

It take it is because of the lack of -Werror enabled for this file it
took so long to discover the problem. What would those "meaningful warnings" you referred to in 60724ca59eda766a30be57aec6b49bc3e2bead91 be anyway?

Maciej

linux-mips-csum-partial-nodaddi-fix.patch

arch/mips/lib/csum_partial.S +9 -0
Index: linux-20140329-4maxp64/arch/mips/lib/csum_partial.S
===================================================================
@@ -55,14 +55,20 @@
 #define UNIT(unit)  ((unit)*NBYTES)
 
 #define ADDC(sum,reg)						\
+	.set	push;						\
+	.set	noat;						\
 	ADD	sum, reg;					\
 	sltu	v1, sum, reg;					\
 	ADD	sum, v1;					\
+	.set	pop
 
 #define ADDC32(sum,reg)						\
+	.set	push;						\
+	.set	noat;						\
 	addu	sum, reg;					\
 	sltu	v1, sum, reg;					\
 	addu	sum, v1;					\
+	.set	pop
 
 #define CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3)	\
 	LOAD	_t0, (offset + UNIT(0))(src);			\
@@ -662,6 +668,8 @@ EXC(	sb	t0, NBYTES-2(dst), .Ls_exc)
 	ADDC(sum, t2)
 .Ldone:
 	/* fold checksum */
+	.set	push
+	.set	noat
 #ifdef USE_DOUBLE
 	dsll32	v1, sum, 0
 	daddu	sum, v1
@@ -684,6 +692,7 @@ EXC(	sb	t0, NBYTES-2(dst), .Ls_exc)
 	or	sum, sum, t0
 1:
 #endif
+	.set	pop
 	.set reorder
 	ADDC32(sum, psum)
 	jr	ra
#2 lore raw
In reply to Maciej W. Rozycki

arch/mips/lib/delay.c

Quoted 5 lines · Maciej W. Rozycki

linux-mips-delay-nodaddi-fix.patch
Index: linux-20140329-4maxp64/arch/mips/lib/delay.c
===================================================================

arch/mips/lib/delay.c +0 -0

No comments about the patch. I'm simply curious why you don't use git?

#3 lore raw
Quoted 1 line · Matt Turner

No comments about the patch. I'm simply curious why you don't use git?

The tools I use work just fine for me, I don't feel compelled to switch.

Maciej