Subject: [PATCH] Vr41xx unaligned access update

From: Geert Uytterhoeven <[email-masked]>
Date: Fri, 23 May 2003 15:53:50 +0200 (MEST)

Hi Ralf,

Update fix for some (Vr41xx?) CPUs, where if an unaligned access happens in a
branch delay slot and the branch is not taken, EPC may point at the branch
instruction while the BD bit in the cause register is not set:
  - Remove tests for unconditional jumps, since they are always taken
  - Add test for a branch in a branch delay slot

--- linux-mips-2.4.x/arch/mips/kernel/unaligned.c	Mon May  5 16:23:43 2003
+++ linux/arch/mips/kernel/unaligned.c	Tue May  6 14:24:56 2003
@@ -99,6 +99,7 @@
 	union mips_instruction insn;
 	unsigned long value, fixup;
 	unsigned int res;
+	int branch = 0;
 
 	regs->regs[0] = 0;
 	*regptr=NULL;
@@ -145,8 +146,6 @@
 	 * but the BD bit in the cause register is not set.
 	 */
 	case bcond_op:
-	case j_op:
-	case jal_op:
 	case beq_op:
 	case bne_op:
 	case blez_op:
@@ -155,7 +154,11 @@
 	case bnel_op:
 	case blezl_op:
 	case bgtzl_op:
-	case jalx_op:
+		if (branch) {
+		    /* branch in a branch delay slot */
+		    goto sigill;
+		}
+		branch = 1;
 		pc += 4;
 		goto retry;

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email-masked]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

---

From: "Maciej W. Rozycki" <[email-masked]>
Date: Fri, 23 May 2003 16:12:20 +0200 (MET DST)

Hmm, what tree is it against?  I can't see code matching these hunks in
our tree at linux-mips.org.

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email-masked], PGP key available        +

---

From: Geert Uytterhoeven <[email-masked]>
Date: Fri, 23 May 2003 16:19:42 +0200 (MEST)

> our tree at linux-mips.org.

Check out the 2.4.x branch. I did verify that all patches apply.

Gr{oetje,eeting}s,

						Geert

---

From: "Maciej W. Rozycki" <[email-masked]>
Date: Fri, 23 May 2003 16:59:43 +0200 (MET DST)

> Check out the 2.4.x branch. I did verify that all patches apply.

 Being much surprised I've double checked this before replying, both a
nightly snapshot at my local system here and directly at
ftp.linux-mips.org.  I'm using a branch tagged as "linux_2_4".  AFAIK, it
is *the* 2.4 branch.  And AFAIK, it is the only branch that is actively
maintained these days.

 Also I recall the discussion on the BD issue on these chips once, but I
can't recall any results of it going into the CVS.

---

From: Geert Uytterhoeven <[email-masked]>
Date: Fri, 23 May 2003 17:14:40 +0200 (MEST)

> can't recall any results of it going into the CVS. 

Sorry, my fault. My `clean' Linux/MIPS CVS tree wasn't as clean as I thought.
So please ignore.

Gr{oetje,eeting}s,

						Geert