Skip to content

Commit 1fee9db

Browse files
author
Marc Zyngier
committed
irqchip/mips: Fix RCU violation when using irqdomain lookup on interrupt entry
Since d4a45c6 ("irqdomain: Protect the linear revmap with RCU"), any irqdomain lookup requires the RCU read lock to be held. This assumes that the architecture code will be structured such as irq_enter() will be called *before* the interrupt is looked up in the irq domain. However, this isn't the case for MIPS, and a number of drivers are structured to do it the other way around when handling an interrupt in their root irqchip (secondary irqchips are OK by construction). This results in a RCU splat on a lockdep-enabled kernel when the kernel takes an interrupt from idle, as reported by Guenter Roeck. Note that this could have fired previously if any driver had used tree-based irqdomain, which always had the RCU requirement. To solve this, provide a MIPS-specific helper (do_domain_IRQ()) as the pendent of do_IRQ() that will do thing in the right order (and maybe save some cycles in the process). Ideally, MIPS would be moved over to using handle_domain_irq(), but that's much more ambitious. Reported-by: Guenter Roeck <[email protected]> Tested-by: Guenter Roeck <[email protected]> [maz: add dependency on CONFIG_IRQ_DOMAIN after report from the kernelci bot] Signed-off-by: Marc Zyngier <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Serge Semin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 0e3c1f3 commit 1fee9db

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

arch/mips/include/asm/irq.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ asmlinkage void plat_irq_dispatch(void);
5757

5858
extern void do_IRQ(unsigned int irq);
5959

60+
struct irq_domain;
61+
extern void do_domain_IRQ(struct irq_domain *domain, unsigned int irq);
62+
6063
extern void arch_init_irq(void);
6164
extern void spurious_interrupt(void);
6265

arch/mips/kernel/irq.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/kallsyms.h>
2222
#include <linux/kgdb.h>
2323
#include <linux/ftrace.h>
24+
#include <linux/irqdomain.h>
2425

2526
#include <linux/atomic.h>
2627
#include <linux/uaccess.h>
@@ -107,3 +108,18 @@ void __irq_entry do_IRQ(unsigned int irq)
107108
irq_exit();
108109
}
109110

111+
#ifdef CONFIG_IRQ_DOMAIN
112+
void __irq_entry do_domain_IRQ(struct irq_domain *domain, unsigned int hwirq)
113+
{
114+
struct irq_desc *desc;
115+
116+
irq_enter();
117+
check_stack_overflow();
118+
119+
desc = irq_resolve_mapping(domain, hwirq);
120+
if (likely(desc))
121+
handle_irq_desc(desc);
122+
123+
irq_exit();
124+
}
125+
#endif

drivers/irqchip/irq-mips-cpu.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static struct irq_chip mips_mt_cpu_irq_controller = {
127127
asmlinkage void __weak plat_irq_dispatch(void)
128128
{
129129
unsigned long pending = read_c0_cause() & read_c0_status() & ST0_IM;
130-
unsigned int virq;
131130
int irq;
132131

133132
if (!pending) {
@@ -137,12 +136,15 @@ asmlinkage void __weak plat_irq_dispatch(void)
137136

138137
pending >>= CAUSEB_IP;
139138
while (pending) {
139+
struct irq_domain *d;
140+
140141
irq = fls(pending) - 1;
141142
if (IS_ENABLED(CONFIG_GENERIC_IRQ_IPI) && irq < 2)
142-
virq = irq_linear_revmap(ipi_domain, irq);
143+
d = ipi_domain;
143144
else
144-
virq = irq_linear_revmap(irq_domain, irq);
145-
do_IRQ(virq);
145+
d = irq_domain;
146+
147+
do_domain_IRQ(d, irq);
146148
pending &= ~BIT(irq);
147149
}
148150
}

drivers/irqchip/irq-mips-gic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ static void gic_handle_shared_int(bool chained)
169169
generic_handle_domain_irq(gic_irq_domain,
170170
GIC_SHARED_TO_HWIRQ(intr));
171171
else
172-
do_IRQ(irq_find_mapping(gic_irq_domain,
173-
GIC_SHARED_TO_HWIRQ(intr)));
172+
do_domain_IRQ(gic_irq_domain,
173+
GIC_SHARED_TO_HWIRQ(intr));
174174
}
175175
}
176176

@@ -320,8 +320,8 @@ static void gic_handle_local_int(bool chained)
320320
generic_handle_domain_irq(gic_irq_domain,
321321
GIC_LOCAL_TO_HWIRQ(intr));
322322
else
323-
do_IRQ(irq_find_mapping(gic_irq_domain,
324-
GIC_LOCAL_TO_HWIRQ(intr)));
323+
do_domain_IRQ(gic_irq_domain,
324+
GIC_LOCAL_TO_HWIRQ(intr));
325325
}
326326
}
327327

drivers/irqchip/irq-pic32-evic.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ static void __iomem *evic_base;
4242

4343
asmlinkage void __weak plat_irq_dispatch(void)
4444
{
45-
unsigned int irq, hwirq;
45+
unsigned int hwirq;
4646

4747
hwirq = readl(evic_base + REG_INTSTAT) & 0xFF;
48-
irq = irq_linear_revmap(evic_irq_domain, hwirq);
49-
do_IRQ(irq);
48+
do_domain_IRQ(evic_irq_domain, hwirq);
5049
}
5150

5251
static struct evic_chip_data *irqd_to_priv(struct irq_data *data)

0 commit comments

Comments
 (0)