From: David Woodhouse Drivers registering IRQ handlers with SA_SHIRQ really ought to be able to handle an interrupt happening before request_irq() returns. They also ought to be able to handle an interrupt happening during the start of their call to free_irq(). Let's test that hypothesis.... Signed-off-by: David Woodhouse Cc: Arjan van de Ven Signed-off-by: Jesper Juhl Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton --- kernel/irq/manage.c | 33 +++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 9 +++++++++ 2 files changed, 42 insertions(+) diff -puN kernel/irq/manage.c~debug-shared-irqs kernel/irq/manage.c --- devel/kernel/irq/manage.c~debug-shared-irqs 2006-03-23 03:56:13.000000000 -0800 +++ devel-akpm/kernel/irq/manage.c 2006-03-23 03:56:13.000000000 -0800 @@ -251,6 +251,10 @@ mismatch: return -EBUSY; } +#ifdef CONFIG_DEBUG_SHIRQ +static struct pt_regs shirq_fakeregs; +#endif + /** * free_irq - free an interrupt * @irq: Interrupt line to free @@ -270,6 +274,7 @@ void free_irq(unsigned int irq, void *de struct irq_desc *desc; struct irqaction **p; unsigned long flags; + irqreturn_t (*handler)(int, void *, struct pt_regs *) = NULL; WARN_ON(in_interrupt()); if (irq >= NR_IRQS) @@ -309,6 +314,8 @@ void free_irq(unsigned int irq, void *de /* Make sure it's not being used on another CPU */ synchronize_irq(irq); + if (action->flags & SA_SHIRQ) + handler = action->handler; kfree(action); return; } @@ -316,6 +323,15 @@ void free_irq(unsigned int irq, void *de spin_unlock_irqrestore(&desc->lock,flags); return; } +#ifdef CONFIG_DEBUG_SHIRQ + if (handler) { + /* It's a shared IRQ -- the driver ought to be prepared for it to happen + even now it's being freed, so let's make sure.... + We do this after actually deregistering it, to make sure that a 'real' + IRQ doesn't run in parallel with our fake. */ + handler(irq, dev_id, &shirq_fakeregs); + } +#endif } EXPORT_SYMBOL(free_irq); @@ -382,6 +398,23 @@ int request_irq(unsigned int irq, select_smp_affinity(irq); +#ifdef CONFIG_DEBUG_SHIRQ + if (irqflags & SA_SHIRQ) { + /* It's a shared IRQ -- the driver ought to be prepared for it to happen + immediately, so let's make sure.... + We do this before actually registering it, to make sure that a 'real' + IRQ doesn't run in parallel with our fake. */ + if (irqflags & SA_INTERRUPT) { + unsigned long flags; + + local_irq_save(flags); + handler(irq, dev_id, &shirq_fakeregs); + local_irq_restore(flags); + } else + handler(irq, dev_id, &shirq_fakeregs); + } +#endif + retval = setup_irq(irq, action); if (retval) kfree(action); diff -puN lib/Kconfig.debug~debug-shared-irqs lib/Kconfig.debug --- devel/lib/Kconfig.debug~debug-shared-irqs 2006-03-23 03:56:13.000000000 -0800 +++ devel-akpm/lib/Kconfig.debug 2006-03-23 03:56:13.000000000 -0800 @@ -23,6 +23,15 @@ config MAGIC_SYSRQ keys are documented in . Don't say Y unless you really know what this hack does. +config DEBUG_SHIRQ + bool "Debug shared IRQ handlers" + depends on GENERIC_HARDIRQS + help + Enable this to generate a spurious interrupt as soon as a shared interrupt + handler is registered, and just before one is deregistered. Drivers ought + to be able to handle interrupts coming in at those points; some don't and + need to be caught. + config DEBUG_KERNEL bool "Kernel debugging" help _