Skip to contentSkip to conversation

ARM: vic: re-read status register before dispatching each IRQ handler

PATCH New Will Deacon 2 participants 3 messages Apr 4, 2012 – Apr 5, 2012 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: vic: re-read status register before dispatching each IRQ handler

handle_IRQ may briefly cause interrupts to be re-enabled during soft IRQ processing on the exit path, leading to nested handling of VIC interrupts.

Since the current code does not re-read the VIC_IRQ_STATUS register, this can lead to multiple invocations of the same interrupt handler and spurious interrupts to be reported.

This patch changes the VIC interrupt dispatching code to re-read the status register each time, avoiding duplicate invocations of the same handler.

---

Taken against v3.4-rc1 and tested on Versatile AB 926 (+ PL011 NULL pointer fix). I'll put this in the patch system tomorrow if there aren't any objections.

 arch/arm/common/vic.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
arch/arm/common/vic.c +1 -3
index 7a66311..6b1de5d 100644
@@ -435,11 +435,9 @@ static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs)
 	u32 stat, irq;
 	int handled = 0;
 
-	stat = readl_relaxed(vic->base + VIC_IRQ_STATUS);
-	while (stat) {
+	while ((stat = readl_relaxed(vic->base + VIC_IRQ_STATUS))) {
 		irq = ffs(stat) - 1;
 		handle_IRQ(irq_find_mapping(vic->domain, irq), regs);
-		stat &= ~(1 << irq);
 		handled = 1;
 	}
 
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/1 ARM: vic: re-read status register before dispatching each IRQ handler

Quoted 30 lines · Will Deacon

handle_IRQ may briefly cause interrupts to be re-enabled during soft IRQ processing on the exit path, leading to nested handling of VIC interrupts.

Since the current code does not re-read the VIC_IRQ_STATUS register, this can lead to multiple invocations of the same interrupt handler and spurious interrupts to be reported.

This patch changes the VIC interrupt dispatching code to re-read the status register each time, avoiding duplicate invocations of the same handler.

---

Taken against v3.4-rc1 and tested on Versatile AB 926 (+ PL011 NULL pointer fix). I'll put this in the patch system tomorrow if there aren't any objections.

 arch/arm/common/vic.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
arch/arm/common/vic.c +0 -0
index 7a66311..6b1de5d 100644
@@ -435,11 +435,9 @@ static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs)
 	u32 stat, irq;

arch/arm/common/vic.c static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs) · line 442

Quoted 10 lines
arch/arm/common/vic.c +1 -3
 	int handled = 0;
 
-	stat = readl_relaxed(vic->base + VIC_IRQ_STATUS);
-	while (stat) {
+	while ((stat = readl_relaxed(vic->base + VIC_IRQ_STATUS))) {
 		irq = ffs(stat) - 1;
 		handle_IRQ(irq_find_mapping(vic->domain, irq), regs);
-		stat &= ~(1 << irq);
 		handled = 1;
 	}

You probably should fix the comment above the function:

/*
* Handle each interrupt in a single VIC. Returns non-zero if we've
* handled at least one interrupt. This does a single read of the
* status register and handles all interrupts in order from LSB first. */

You are no longer doing a single read. You might mention the problem caused by the single read so that no one tries to "optimize" the loop and reintroduce the problem.

Regards,
Hartley

#2 lore raw

PATCH 1/1 ARM: vic: re-read status register before dispatching each IRQ handler

Quoted 9 lines · H Hartley Sweeten
Quoted 8 lines · Will Deacon
arch/arm/common/vic.c +0 -0
index 7a66311..6b1de5d 100644
@@ -435,11 +435,9 @@ static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs)
 	u32 stat, irq;
 	int handled = 0;
 
Quoted 10 lines

arch/arm/common/vic.c static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs) · line 442

Quoted 8 lines
arch/arm/common/vic.c +1 -3
-	stat = readl_relaxed(vic->base + VIC_IRQ_STATUS);
-	while (stat) {
+	while ((stat = readl_relaxed(vic->base + VIC_IRQ_STATUS))) {
 		irq = ffs(stat) - 1;
 		handle_IRQ(irq_find_mapping(vic->domain, irq), regs);
-		stat &= ~(1 << irq);
 		handled = 1;
 	}

You probably should fix the comment above the function:

Sorry, missed that. v2 below.

Thanks,

Will

Author: Will Deacon <[email protected]>
Date:   Wed Apr 4 10:13:49 2012 +0100

ARM: vic: re-read status register before dispatching each IRQ handler

handle_IRQ may briefly cause interrupts to be re-enabled during soft IRQ processing on the exit path, leading to nested handling of VIC interrupts.

Since the current code does not re-read the VIC_IRQ_STATUS register, this can lead to multiple invocations of the same interrupt handler and spurious interrupts to be reported.

This patch changes the VIC interrupt dispatching code to re-read the status register each time, avoiding duplicate invocations of the same handler.

arch/arm/common/vic.c +4 -5
index 7a66311..7e288f9 100644
@@ -427,19 +427,18 @@ int __init vic_of_init(struct device_node *node, struct device_node *parent)
 
 /*
  * Handle each interrupt in a single VIC.  Returns non-zero if we've
- * handled at least one interrupt.  This does a single read of the
- * status register and handles all interrupts in order from LSB first.
+ * handled at least one interrupt.  This reads the status register
+ * before handling each interrupt, which is necessary given that
+ * handle_IRQ may briefly re-enable interrupts for soft IRQ handling.
  */
 static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs)
 {
        u32 stat, irq;
        int handled = 0;
 
-       stat = readl_relaxed(vic->base + VIC_IRQ_STATUS);
-       while (stat) {
+       while ((stat = readl_relaxed(vic->base + VIC_IRQ_STATUS))) {
                irq = ffs(stat) - 1;
                handle_IRQ(irq_find_mapping(vic->domain, irq), regs);
-               stat &= ~(1 << irq);
                handled = 1;
        }