Skip to contentSkip to conversation

m68k/mac: Fix apparent race condition in Baboon interrupt dispatch

PATCH Applied Finn Thain 2 participants 2 messages Jan 27, 2018 – Feb 26, 2018

Subsystems (2)
lore
Share & tools
lore

Finn Thain

author
#0 lore raw

PATCH 1/1 m68k/mac: Fix apparent race condition in Baboon interrupt dispatch

The algorithm used in baboon_irq() appears to be subject to a race
condition: an IRQ flag could be lost if asserted between the MOV instructions from and to the interrupt flag register. However, testing shows that the write to the flag register has no effect. Rewrite this loop to remove the apparent race condition.

No-one seems to know how to clear Baboon IRQ flags, or whether that's even possible, so add a comment about this.

---
 arch/m68k/mac/baboon.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)
arch/m68k/mac/baboon.c +8 -19
index c7ea6475ef9b..a7d280220662 100644
@@ -18,10 +18,6 @@
 int baboon_present;
 static volatile struct baboon *baboon;
 
-#if 0
-extern int macide_ack_intr(struct ata_channel *);
-#endif
-
 /*
  * Baboon initialization.
  */
@@ -41,33 +37,26 @@ void __init baboon_init(void)
 }
 
 /*
- * Baboon interrupt handler. This works a lot like a VIA.
+ * Baboon interrupt handler.
+ * XXX how do you clear a pending IRQ? is it even necessary?
  */
 
 static void baboon_irq(struct irq_desc *desc)
 {
-	int irq_bit, irq_num;
-	unsigned char events;
+	short events, irq_bit;
+	int irq_num;
 
 	events = baboon->mb_ifr & 0x07;
-	if (!events)
-		return;
-
 	irq_num = IRQ_BABOON_0;
 	irq_bit = 1;
 	do {
-	        if (events & irq_bit) {
-			baboon->mb_ifr &= ~irq_bit;
+		if (events & irq_bit) {
+			events &= ~irq_bit;
 			generic_handle_irq(irq_num);
 		}
+		++irq_num;
 		irq_bit <<= 1;
-		irq_num++;
-	} while(events >= irq_bit);
-#if 0
-	if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL);
-	/* for now we need to smash all interrupts */
-	baboon->mb_ifr &= ~events;
-#endif
+	} while (events);
 }
 
 /*
Signature · 1 line
2.13.6
maintainer Applied
#1 lore raw
Quoted 11 lines · Finn Thain

The algorithm used in baboon_irq() appears to be subject to a race
condition: an IRQ flag could be lost if asserted between the MOV instructions from and to the interrupt flag register. However, testing shows that the write to the flag register has no effect. Rewrite this loop to remove the apparent race condition.

No-one seems to know how to clear Baboon IRQ flags, or whether that's even possible, so add a comment about this.

Thanks, applied and queue for v4.17.

Gr{oetje,eeting}s,

Geert

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

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