From: lars@metafoo.de (Lars-Peter Clausen)
To: linux-arm-kernel@lists.infradead.org
Subject: [BUG] genirq: Race condition in ONESHOT IRQ handler disabling IRQ forever
Date: Tue, 07 Feb 2012 14:07:22 +0100 [thread overview]
Message-ID: <4F31220A.2050708@metafoo.de> (raw)
In-Reply-To: <20273.7808.730105.307619@ipc1.ka-ro>
On 02/07/2012 01:52 PM, Lothar Wa?mann wrote:
> Hi,
>
> Yong Zhang writes:
>> On Tue, Feb 07, 2012 at 11:01:06AM +0100, Lothar Wa?mann wrote:
>>> Hi,
>>>
>>>> On Mon, Feb 06, 2012 at 09:14:47AM +0100, Lothar Wa?mann wrote:
>>>>> Hi,
>>>>>
>>>>> I already sent this to <linux-kernel@vger.kernel.org> on Feb. 1, 2012
>>>>> but did not get any response there. So resending to a wider audience
>>>>> with improved subject line:
>>>>>
>>>>> there is a race condition in the threaded IRQ handler code for oneshot
>>>>> interrupts that may lead to disabling an IRQ indefinitely. IRQs are
>>>>> masked before calling the hard-irq handler and are unmasked only after
>>>>> the soft-irq handler has been run. Thus if the hard-irq handler
>>>>> returns IRQ_HANDLED instead of IRQ_WAKE_THREAD, meaning the soft-irq
>>>>> will not be called, the interrupt will remain masked forever.
>>>>>
>>>>> This can happen due to a short pulse on the interrupt line, that
>>>>> triggers the interrupt logic, but goes undetected by the hard-irq
>>>>> handler. The problem can be reproduced with the TSC2007 touch
>>>>> controller driver that uses ONESHOT interrupts.
>>>>
>>>> Isn't it the responsibility of the driver (say TSC2007)?
>>>>
>>>> In this case, TSC2007 should return IRQ_WAKE_THREAD IMHO.
>>>>
>>> That would mean it had to return IRQ_WAKE_THREAD unconditionally
>>> making the return code useless.
>>> And it would cause an extra useless loop through the softirq
>>> handler.
>>
>> Yeah, it's the default behavior when we introduce 'theadirqs',
>> and it's safe.
>>
> So, the correct solution would be to remove the check for
> IRQ_WAKE_THREAD in handle_irq_event_percpu() and always invoke the
> softirq handler?
> Note that this problem is not specific to the TSC2007 driver, but may
> occur with any hardware.
>
> Or maybe do the unmasking in handle_irq_event() as proposed by
> Lars-Peter Clausen in <4F2FAE93.5020205@metafoo.de>?
> Like that:
> diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
> index f7c543a..fbf68c7 100644
> --- a/kernel/irq/chip.c
> +++ b/kernel/irq/chip.c
> @@ -343,6 +343,8 @@ EXPORT_SYMBOL_GPL(handle_simple_irq);
> void
> handle_level_irq(unsigned int irq, struct irq_desc *desc)
> {
> + int ret;
This should be irqreturn_t
> +
> raw_spin_lock(&desc->lock);
> mask_ack_irq(desc);
>
> @@ -360,10 +362,12 @@ handle_level_irq(unsigned int irq, struct irq_desc *desc)
> if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data)))
> goto out_unlock;
>
> - handle_irq_event(desc);
> + ret = handle_irq_event(desc);
>
> - if (!irqd_irq_disabled(&desc->irq_data) && !(desc->istate & IRQS_ONESHOT))
> + if (!irqd_irq_disabled(&desc->irq_data) &&
> + (!(desc->istate & IRQS_ONESHOT) || ret != IRQ_WAKE_THREAD))
As I said, check for the bit, not for the value. This will ensure that will
also work with shared interrupts. So something like this:
!((desc->istate & IRQS_ONESHOT) && (ret & IRQ_WAKE_THREAD)))
> unmask_irq(desc);
> +
> out_unlock:
> raw_spin_unlock(&desc->lock);
> }
>
>
> Lothar Wa?mann
WARNING: multiple messages have this Message-ID (diff)
From: Lars-Peter Clausen <lars@metafoo.de>
To: "Lothar Waßmann" <LW@KARO-electronics.de>
Cc: Yong Zhang <yong.zhang0@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [BUG] genirq: Race condition in ONESHOT IRQ handler disabling IRQ forever
Date: Tue, 07 Feb 2012 14:07:22 +0100 [thread overview]
Message-ID: <4F31220A.2050708@metafoo.de> (raw)
In-Reply-To: <20273.7808.730105.307619@ipc1.ka-ro>
On 02/07/2012 01:52 PM, Lothar Waßmann wrote:
> Hi,
>
> Yong Zhang writes:
>> On Tue, Feb 07, 2012 at 11:01:06AM +0100, Lothar Waßmann wrote:
>>> Hi,
>>>
>>>> On Mon, Feb 06, 2012 at 09:14:47AM +0100, Lothar Waßmann wrote:
>>>>> Hi,
>>>>>
>>>>> I already sent this to <linux-kernel@vger.kernel.org> on Feb. 1, 2012
>>>>> but did not get any response there. So resending to a wider audience
>>>>> with improved subject line:
>>>>>
>>>>> there is a race condition in the threaded IRQ handler code for oneshot
>>>>> interrupts that may lead to disabling an IRQ indefinitely. IRQs are
>>>>> masked before calling the hard-irq handler and are unmasked only after
>>>>> the soft-irq handler has been run. Thus if the hard-irq handler
>>>>> returns IRQ_HANDLED instead of IRQ_WAKE_THREAD, meaning the soft-irq
>>>>> will not be called, the interrupt will remain masked forever.
>>>>>
>>>>> This can happen due to a short pulse on the interrupt line, that
>>>>> triggers the interrupt logic, but goes undetected by the hard-irq
>>>>> handler. The problem can be reproduced with the TSC2007 touch
>>>>> controller driver that uses ONESHOT interrupts.
>>>>
>>>> Isn't it the responsibility of the driver (say TSC2007)?
>>>>
>>>> In this case, TSC2007 should return IRQ_WAKE_THREAD IMHO.
>>>>
>>> That would mean it had to return IRQ_WAKE_THREAD unconditionally
>>> making the return code useless.
>>> And it would cause an extra useless loop through the softirq
>>> handler.
>>
>> Yeah, it's the default behavior when we introduce 'theadirqs',
>> and it's safe.
>>
> So, the correct solution would be to remove the check for
> IRQ_WAKE_THREAD in handle_irq_event_percpu() and always invoke the
> softirq handler?
> Note that this problem is not specific to the TSC2007 driver, but may
> occur with any hardware.
>
> Or maybe do the unmasking in handle_irq_event() as proposed by
> Lars-Peter Clausen in <4F2FAE93.5020205@metafoo.de>?
> Like that:
> diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
> index f7c543a..fbf68c7 100644
> --- a/kernel/irq/chip.c
> +++ b/kernel/irq/chip.c
> @@ -343,6 +343,8 @@ EXPORT_SYMBOL_GPL(handle_simple_irq);
> void
> handle_level_irq(unsigned int irq, struct irq_desc *desc)
> {
> + int ret;
This should be irqreturn_t
> +
> raw_spin_lock(&desc->lock);
> mask_ack_irq(desc);
>
> @@ -360,10 +362,12 @@ handle_level_irq(unsigned int irq, struct irq_desc *desc)
> if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data)))
> goto out_unlock;
>
> - handle_irq_event(desc);
> + ret = handle_irq_event(desc);
>
> - if (!irqd_irq_disabled(&desc->irq_data) && !(desc->istate & IRQS_ONESHOT))
> + if (!irqd_irq_disabled(&desc->irq_data) &&
> + (!(desc->istate & IRQS_ONESHOT) || ret != IRQ_WAKE_THREAD))
As I said, check for the bit, not for the value. This will ensure that will
also work with shared interrupts. So something like this:
!((desc->istate & IRQS_ONESHOT) && (ret & IRQ_WAKE_THREAD)))
> unmask_irq(desc);
> +
> out_unlock:
> raw_spin_unlock(&desc->lock);
> }
>
>
> Lothar Waßmann
next prev parent reply other threads:[~2012-02-07 13:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-06 8:14 [BUG] genirq: Race condition in ONESHOT IRQ handler disabling IRQ forever =?utf-8?Q?Lothar_Wa=C3=9Fmann?=
2012-02-06 8:14 ` =?utf-8?Q?Lothar_Wa=C3=9Fmann?=
2012-02-06 10:42 ` Lars-Peter Clausen
2012-02-06 10:42 ` Lars-Peter Clausen
2012-02-07 9:03 ` Yong Zhang
2012-02-07 9:03 ` Yong Zhang
2012-02-07 10:01 ` Lothar Waßmann
2012-02-07 10:01 ` Lothar Waßmann
2012-02-07 12:34 ` Yong Zhang
2012-02-07 12:34 ` Yong Zhang
2012-02-07 12:52 ` Lothar Waßmann
2012-02-07 12:52 ` Lothar Waßmann
2012-02-07 13:07 ` Lars-Peter Clausen [this message]
2012-02-07 13:07 ` Lars-Peter Clausen
2012-02-07 13:38 ` [PATCH] genirq: Fix race condition in ONESHOT irq handler Lothar Waßmann
2012-02-07 13:38 ` Lothar Waßmann
2012-02-07 17:03 ` Thomas Gleixner
2012-02-07 17:03 ` Thomas Gleixner
2012-02-08 6:05 ` Lothar Waßmann
2012-02-08 6:05 ` Lothar Waßmann
2012-02-08 10:38 ` Thomas Gleixner
2012-02-08 10:38 ` Thomas Gleixner
2012-02-09 8:40 ` Lothar Waßmann
2012-02-09 8:40 ` Lothar Waßmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F31220A.2050708@metafoo.de \
--to=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.