Re: [PATCH]: use spin_lock_irqsave in try_one_irq()

From: Yong Zhang
Date: Tue Nov 03 2009 - 09:58:59 EST


> This happens because the &desc->lock is taken with spin_lock_irqsave and
> just a spin_lock. ÂIn the try_one_irq(), this lock really should be a
> spin_lock_irqsave().
>

Cc'ed Ingo and Thomas.

The reason is that try_one_irq() is called both from hardirq context and softirq
context. And by default the timer handler poll_all_shared_irqs() is
called with irq enabled.
Then the two usage will cause inconsistent.

So I think the following patch is also workable to you.

diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c
index 114e704..11affbc 100644
--- a/kernel/irq/spurious.c
+++ b/kernel/irq/spurious.c
@@ -111,6 +111,7 @@ static void poll_all_shared_irqs(void)

for_each_irq_desc(i, desc) {
unsigned int status;
+ unsigned long flags;

if (!i)
continue;
@@ -121,7 +122,9 @@ static void poll_all_shared_irqs(void)
if (!(status & IRQ_SPURIOUS_DISABLED))
continue;

+ local_irq_save(flags);
try_one_irq(i, desc);
+ local_irq_restore(flags);
}
}

> I have not yet narrowed down the reason for the spurious interrupt (although
> I suspect it maybe to do with the radeon driver).
>
> Successfully tested by me.
>
> Signed-off-by: Prarit Bhargava <prarit@xxxxxxxxxx>
>
> --- linux-2.6.31.x86_64.orig/kernel/irq/spurious.c   Â2009-09-09 18:13:59.000000000 -0400
> +++ linux-2.6.31.x86_64/kernel/irq/spurious.c  2009-10-26 10:55:56.709845786 -0400
> @@ -27,8 +27,9 @@ static int try_one_irq(int irq, struct i
> Â{
> Â Â Â Âstruct irqaction *action;
> Â Â Â Âint ok = 0, work = 0;
> + Â Â Â unsigned long flags;
>
> - Â Â Â spin_lock(&desc->lock);
> + Â Â Â spin_lock_irqsave(&desc->lock, flags);
> Â Â Â Â/* Already running on another processor */
> Â Â Â Âif (desc->status & IRQ_INPROGRESS) {
> Â Â Â Â Â Â Â Â/*
> @@ -37,13 +38,13 @@ static int try_one_irq(int irq, struct i
> Â Â Â Â Â Â Â Â */
> Â Â Â Â Â Â Â Âif (desc->action && (desc->action->flags & IRQF_SHARED))
> Â Â Â Â Â Â Â Â Â Â Â Âdesc->status |= IRQ_PENDING;
> - Â Â Â Â Â Â Â spin_unlock(&desc->lock);
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&desc->lock, flags);
> Â Â Â Â Â Â Â Âreturn ok;
> Â Â Â Â}
> Â Â Â Â/* Honour the normal IRQ locking */
> Â Â Â Âdesc->status |= IRQ_INPROGRESS;
> Â Â Â Âaction = desc->action;
> - Â Â Â spin_unlock(&desc->lock);
> + Â Â Â spin_unlock_irqrestore(&desc->lock, flags);
>
> Â Â Â Âwhile (action) {
> Â Â Â Â Â Â Â Â/* Only shared IRQ handlers are safe to call */
> @@ -56,7 +57,7 @@ static int try_one_irq(int irq, struct i
> Â Â Â Â}
> Â Â Â Âlocal_irq_disable();
> Â Â Â Â/* Now clean up the flags */
> - Â Â Â spin_lock(&desc->lock);
> + Â Â Â spin_lock_irqsave(&desc->lock, flags);
> Â Â Â Âaction = desc->action;
>
> Â Â Â Â/*
> @@ -68,9 +69,9 @@ static int try_one_irq(int irq, struct i
> Â Â Â Â Â Â Â Â * Perform real IRQ processing for the IRQ we deferred
> Â Â Â Â Â Â Â Â */
> Â Â Â Â Â Â Â Âwork = 1;
> - Â Â Â Â Â Â Â spin_unlock(&desc->lock);
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&desc->lock, flags);
> Â Â Â Â Â Â Â Âhandle_IRQ_event(irq, action);
> - Â Â Â Â Â Â Â spin_lock(&desc->lock);
> + Â Â Â Â Â Â Â spin_lock_irqsave(&desc->lock, flags);
> Â Â Â Â Â Â Â Âdesc->status &= ~IRQ_PENDING;
> Â Â Â Â}
> Â Â Â Âdesc->status &= ~IRQ_INPROGRESS;
> @@ -80,7 +81,7 @@ static int try_one_irq(int irq, struct i
> Â Â Â Â */
> Â Â Â Âif (work && desc->chip && desc->chip->end)
> Â Â Â Â Â Â Â Âdesc->chip->end(irq);
> - Â Â Â spin_unlock(&desc->lock);
> + Â Â Â spin_unlock_irqrestore(&desc->lock, flags);
>
> Â Â Â Âreturn ok;
> Â}
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/