2008-02-18 16:58:21

by Hennerich, Michael

[permalink] [raw]
Subject: [BUG][RFC] [GENERIC IRQ] irq_chip_set_defaults shutdown / disable

RESENT: Add Maintainers

free_irq() does not disable/mask the irq, in case disable or shutdown in struct irq_chip is left uninitilazied.

/**
* struct irq_chip - hardware interrupt chip descriptor
*
* @name: name for /proc/interrupts
* @startup: start up the interrupt (defaults to ->enable if NULL)
* @shutdown: shut down the interrupt (defaults to ->disable if NULL)
* @enable: enable the interrupt (defaults to chip->unmask if NULL)
* @disable: disable the interrupt (defaults to chip->mask if NULL)


According to linux/irq.h struct irq_chip information,
chip->disable should default to chip->mask if NULL.
However irq_chip_set_defaults(struct irq_chip *chip) will set it to default_disable an empty function.

In earlier kernel versions such as 2.6.19 default_disable called chip->mask.
In 2.6.22 and 2.6.24 default_disable is an empty function.

Looking through various architectures, it's still pretty common that disable and shutdown is NULL.

Do I miss something here?

Signed-off-by: Michael Hennerich <[email protected]>

Index: irq/chip.c
===================================================================
--- irq/chip.c (revision 4276)
+++ irq/chip.c (working copy)
@@ -233,6 +233,10 @@
*/
static void default_disable(unsigned int irq) {
+ struct irq_desc *desc = irq_desc + irq;
+
+ desc->chip->mask(irq);
+ desc->status |= IRQ_MASKED;
}

/*

Best regards,
Michael

------------------------------------------------------------------
********* Analog Devices GmbH [email protected]
** ***** Systems Engineering
** ** Wilhelm-Wagenfeld-Strasse 6
** ***** D-80807 Munich
********* Germany
Registergericht M?nchen HRB 40368, Gesch?ftsf?hrer: Thomas Wessel, Vincent Roche, Joseph E. McDonough


2008-02-18 17:49:43

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [BUG][RFC] [GENERIC IRQ] irq_chip_set_defaults shutdown / disable

On Mon, 18 Feb 2008, Hennerich, Michael wrote:
> RESENT: Add Maintainers
>
> free_irq() does not disable/mask the irq, in case disable or shutdown in struct irq_chip is left uninitilazied.
>
> /**
> * struct irq_chip - hardware interrupt chip descriptor
> *
> * @name: name for /proc/interrupts
> * @startup: start up the interrupt (defaults to ->enable if NULL)
> * @shutdown: shut down the interrupt (defaults to ->disable if NULL)
> * @enable: enable the interrupt (defaults to chip->unmask if NULL)
> * @disable: disable the interrupt (defaults to chip->mask if NULL)
>
>
> According to linux/irq.h struct irq_chip information,
> chip->disable should default to chip->mask if NULL.
> However irq_chip_set_defaults(struct irq_chip *chip) will set it to default_disable an empty function.
>
> In earlier kernel versions such as 2.6.19 default_disable called chip->mask.
> In 2.6.22 and 2.6.24 default_disable is an empty function.
>
> Looking through various architectures, it's still pretty common that disable and shutdown is NULL.

Yeah, you are right. This was broken by commit
76d2160147f43f982dfe881404cfde9fd0a9da21

> Do I miss something here?

Just a small detail. The commit optimized the irq_disable/enable logic
by defaulting to delayed disable. So we want to keep that logic intact
in case that we still have a device which is handling this
interrupt. For the free_irq() case your patch is correct.

The patch below fixes the shutdown case and keeps the delayed disable
logic intact.

How did you notice ? I guess you got spurious interrupts after calling
free_irq(), right ?

Thanks for analyzing and reporting,

tglx

------------->
Subject: genirq: do not leave interupts enabled on free_irq
From: Thomas Gleixner <[email protected]>
Date: Mon, 18 Feb 2008 18:25:17 +0100

The default_disable() function was changed in commit:

76d2160147f43f982dfe881404cfde9fd0a9da21
genirq: do not mask interrupts by default

It removed the mask function in favour of the default delayed
interrupt disable handling. Unfortunately this also broke the shutdown
in free_irq() when the last handler is removed from the interrupt for
those architectures which rely on the default implementations. Now we
can end up with a enabled interrupt line after the last handler was
removed.

Fix this by adding a default_shutdown function, which is only
installed, when the irqchip implementation does provide neither a
shutdown nor a disable function.

Pointed-out-by: Michael Hennerich <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
CC: [email protected]

---
kernel/irq/chip.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

Index: linux-2.6/kernel/irq/chip.c
===================================================================
--- linux-2.6.orig/kernel/irq/chip.c
+++ linux-2.6/kernel/irq/chip.c
@@ -246,6 +246,17 @@ static unsigned int default_startup(unsi
}

/*
+ * default shutdown function
+ */
+static void default_shutdown(unsigned int irq)
+{
+ struct irq_desc *desc = irq_desc + irq;
+
+ desc->chip->mask(irq);
+ desc->status &= ~IRQ_MASKED;
+}
+
+/*
* Fixup enable/disable function pointers
*/
void irq_chip_set_defaults(struct irq_chip *chip)
@@ -257,7 +268,8 @@ void irq_chip_set_defaults(struct irq_ch
if (!chip->startup)
chip->startup = default_startup;
if (!chip->shutdown)
- chip->shutdown = chip->disable;
+ chip->shutdown = chip->disable != default_disable ?
+ chip_disable : default_shutdown;
if (!chip->name)
chip->name = chip->typename;
if (!chip->end)

2008-02-18 18:05:48

by Hennerich, Michael

[permalink] [raw]
Subject: RE: [BUG][RFC] [GENERIC IRQ] irq_chip_set_defaults shutdown / disable



>From: Thomas Gleixner Montag, 18. Februar 2008 18:49
>
>On Mon, 18 Feb 2008, Hennerich, Michael wrote:
>> RESENT: Add Maintainers
>>
>> free_irq() does not disable/mask the irq, in case disable or shutdown
in
>struct irq_chip is left uninitilazied.
>>
>> /**
>> * struct irq_chip - hardware interrupt chip descriptor
>> *
>> * @name: name for /proc/interrupts
>> * @startup: start up the interrupt (defaults to ->enable if NULL)
>> * @shutdown: shut down the interrupt (defaults to ->disable
if NULL)
>> * @enable: enable the interrupt (defaults to chip->unmask
if
>NULL)
>> * @disable: disable the interrupt (defaults to chip->mask if NULL)
>>
>>
>> According to linux/irq.h struct irq_chip information,
>> chip->disable should default to chip->mask if NULL.
>> However irq_chip_set_defaults(struct irq_chip *chip) will set it to
>default_disable an empty function.
>>
>> In earlier kernel versions such as 2.6.19 default_disable called
chip-
>>mask.
>> In 2.6.22 and 2.6.24 default_disable is an empty function.
>>
>> Looking through various architectures, it's still pretty common that
>disable and shutdown is NULL.
>
>Yeah, you are right. This was broken by commit
>76d2160147f43f982dfe881404cfde9fd0a9da21
>
>> Do I miss something here?
>
>Just a small detail. The commit optimized the irq_disable/enable logic
>by defaulting to delayed disable. So we want to keep that logic intact
>in case that we still have a device which is handling this
>interrupt. For the free_irq() case your patch is correct.
>
>The patch below fixes the shutdown case and keeps the delayed disable
>logic intact.
>
>How did you notice ? I guess you got spurious interrupts after calling
>free_irq(), right ?

Exactly

-Michael


>
>Thanks for analyzing and reporting,
>
> tglx
>
>------------->
>Subject: genirq: do not leave interupts enabled on free_irq
>From: Thomas Gleixner <[email protected]>
>Date: Mon, 18 Feb 2008 18:25:17 +0100
>
>The default_disable() function was changed in commit:
>
> 76d2160147f43f982dfe881404cfde9fd0a9da21
> genirq: do not mask interrupts by default
>
>It removed the mask function in favour of the default delayed
>interrupt disable handling. Unfortunately this also broke the shutdown
>in free_irq() when the last handler is removed from the interrupt for
>those architectures which rely on the default implementations. Now we
>can end up with a enabled interrupt line after the last handler was
>removed.
>
>Fix this by adding a default_shutdown function, which is only
>installed, when the irqchip implementation does provide neither a
>shutdown nor a disable function.
>
>Pointed-out-by: Michael Hennerich <[email protected]>
>Signed-off-by: Thomas Gleixner <[email protected]>
>CC: [email protected]
>
>---
> kernel/irq/chip.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
>Index: linux-2.6/kernel/irq/chip.c
>===================================================================
>--- linux-2.6.orig/kernel/irq/chip.c
>+++ linux-2.6/kernel/irq/chip.c
>@@ -246,6 +246,17 @@ static unsigned int default_startup(unsi
> }
>
> /*
>+ * default shutdown function
>+ */
>+static void default_shutdown(unsigned int irq)
>+{
>+ struct irq_desc *desc = irq_desc + irq;
>+
>+ desc->chip->mask(irq);
>+ desc->status &= ~IRQ_MASKED;
>+}
>+
>+/*
> * Fixup enable/disable function pointers
> */
> void irq_chip_set_defaults(struct irq_chip *chip)
>@@ -257,7 +268,8 @@ void irq_chip_set_defaults(struct irq_ch
> if (!chip->startup)
> chip->startup = default_startup;
> if (!chip->shutdown)
>- chip->shutdown = chip->disable;
>+ chip->shutdown = chip->disable != default_disable ?
>+ chip_disable : default_shutdown;
> if (!chip->name)
> chip->name = chip->typename;
> if (!chip->end)

2008-02-18 20:38:28

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [BUG][RFC] [GENERIC IRQ] irq_chip_set_defaults shutdown / disable

On Mon, 18 Feb 2008, Hennerich, Michael wrote:
> >The patch below fixes the shutdown case and keeps the delayed disable
> >logic intact.
>
> >How did you notice ? I guess you got spurious interrupts after calling
> >free_irq(), right ?
>
> Exactly

Can you please confirm, whether my version of the fix works for you as
well.

Thanks,

tglx

2008-02-18 20:47:44

by Thomas Gleixner

[permalink] [raw]
Subject: RE: [BUG][RFC] [GENERIC IRQ] irq_chip_set_defaults shutdown / disable

On Mon, 18 Feb 2008, Hennerich, Michael wrote:
> >From: Thomas Gleixner Montag, 18. Februar 2008 18:49
> >+static void default_shutdown(unsigned int irq)
> >+{
> >+ struct irq_desc *desc = irq_desc + irq;
> >+
> >+ desc->chip->mask(irq);
> >+ desc->status &= ~IRQ_MASKED;

Needs to be |= IRQ_MASKED of course.

Thanks, Michael for pointing it out.

tglx

2008-02-19 08:58:51

by Hennerich, Michael

[permalink] [raw]
Subject: RE: [BUG][RFC] [GENERIC IRQ] irq_chip_set_defaults shutdown / disable

>From: Thomas Gleixner Montag, 18. Februar 2008 21:38
>
>On Mon, 18 Feb 2008, Hennerich, Michael wrote:
>> >The patch below fixes the shutdown case and keeps the delayed
disable
>> >logic intact.
>>
>> >How did you notice ? I guess you got spurious interrupts after
calling
>> >free_irq(), right ?
>>
>> Exactly
>
>Can you please confirm, whether my version of the fix works for you as
>well.
>
>Thanks,
>
> tglx

Thomas,

Works - no problems.
There was another typo

>+ chip_disable : default_shutdown;
Should be better:
+ chip->disable : default_shutdown;

Best regards,
Michael

Signed-off-by: Michael Hennerich <[email protected]>

Index: kernel/irq/chip.c
===================================================================
--- kernel/irq/chip.c (revision 4270)
+++ kernel/irq/chip.c (working copy)
@@ -245,7 +245,20 @@
return 0;
}

+
/*
+ * default shutdown function
+ */
+static void default_shutdown(unsigned int irq)
+{
+ struct irq_desc *desc = irq_desc + irq;
+
+ desc->chip->mask(irq);
+ desc->status |= IRQ_MASKED;
+}
+
+
+/*
* Fixup enable/disable function pointers
*/
void irq_chip_set_defaults(struct irq_chip *chip)
@@ -257,7 +270,8 @@
if (!chip->startup)
chip->startup = default_startup;
if (!chip->shutdown)
- chip->shutdown = chip->disable;
+ chip->shutdown = chip->disable != default_disable ?
+ chip->disable : default_shutdown;
if (!chip->name)
chip->name = chip->typename;
if (!chip->end)

2008-02-19 09:13:06

by Thomas Gleixner

[permalink] [raw]
Subject: RE: [BUG][RFC] [GENERIC IRQ] irq_chip_set_defaults shutdown / disable

On Tue, 19 Feb 2008, Hennerich, Michael wrote:
> >Can you please confirm, whether my version of the fix works for you as
> >well.
> >
> >Thanks,
> >
> > tglx
>
> Thomas,
>
> Works - no problems.
> There was another typo
>
> >+ chip_disable : default_shutdown;
> Should be better:
> + chip->disable : default_shutdown;

Noticed when I tested it myself :(

Thanks,

tglx

2008-02-19 10:25:32

by Hennerich, Michael

[permalink] [raw]
Subject: [BUG][RFC][GENERIC IRQ] linux-2.6.24 (delayed) disable IRQ feature not functional for handle_simple_irq

Thomas,

I have reasonable doubt that the delayed disable feature on linux-2.6.24 for handle_simple_irq is broken.

In 2.6.22 there was something like this:

if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
if (desc->chip->mask)
desc->chip->mask(irq);
...

However in 2.6.24 the "DISABLED" IRQ in case it happens is never going to be masked.

if (unlikely(!action || (desc->status & IRQ_DISABLED)))
goto out_unlock;


I see a disabled IRQ being invoked in an endless loop.

-Michael

------------------------------------------------------------------
********* Analog Devices GmbH [email protected]
** ***** Systems Engineering
** ** Wilhelm-Wagenfeld-Strasse 6
** ***** D-80807 Munich
********* Germany
Registergericht M?nchen HRB 40368, Gesch?ftsf?hrer: Thomas Wessel, Vincent Roche, Joseph E. McDonough

2008-02-19 10:49:31

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [BUG][RFC][GENERIC IRQ] linux-2.6.24 (delayed) disable IRQ feature not functional for handle_simple_irq

On Tue, 19 Feb 2008, Hennerich, Michael wrote:
> Thomas,
>
> I have reasonable doubt that the delayed disable feature on
> linux-2.6.24 for handle_simple_irq is broken.
>
> In 2.6.22 there was something like this:
>
> if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
> if (desc->chip->mask)
> desc->chip->mask(irq);
> ...
>
> However in 2.6.24 the "DISABLED" IRQ in case it happens is never going to be masked.
>
> if (unlikely(!action || (desc->status & IRQ_DISABLED)))
> goto out_unlock;
>
>
> I see a disabled IRQ being invoked in an endless loop.

Simple irq's are special, see the comment above handle_simple_irq:

Simple interrupts are either sent from a demultiplexing interrupt
handler or come from hardware, where no interrupt hardware control
is necessary.

Note: The caller is expected to handle the ack, clear, mask and
unmask issues if necessary.

Simple irqs are used for low level demultiplex handlers, where the full
control of the irqchip is in the low level handler.

See also the commit log of 971e5b35fb02c5088d49e6c024aab73582a35b71

In commit 76d2160147f43f982dfe881404cfde9fd0a9da21 lazy irq disabling
was implemented, and the simple irq handler had a masking set to it.

Remy Bohmer discovered that some devices in the ARM architecture
would trigger the mask, but never unmask it. His patch to do the
unmasking was questioned by Russell King about masking simple irqs
to begin with. Looking further, it was discovered that the problems
Remy was seeing was due to improper use of the simple handler by
devices, and he later submitted patches to fix those. But the issue
that was uncovered was that the simple handler should never mask.

This patch reverts the masking in the simple handler.

Thanks,

tglx

2008-02-19 11:51:37

by Hennerich, Michael

[permalink] [raw]
Subject: RE: [BUG][RFC][GENERIC IRQ] linux-2.6.24 (delayed) disable IRQ feature not functional for handle_simple_irq


>From: Thomas Gleixner, Dienstag, 19. Februar 2008 11:49
>Subject: Re: [BUG][RFC][GENERIC IRQ] linux-2.6.24 (delayed) disable IRQ
>feature not functional for handle_simple_irq
>
>On Tue, 19 Feb 2008, Hennerich, Michael wrote:
>> Thomas,
>>
>> I have reasonable doubt that the delayed disable feature on
>> linux-2.6.24 for handle_simple_irq is broken.
>>
>> In 2.6.22 there was something like this:
>>
>> if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
>> if (desc->chip->mask)
>> desc->chip->mask(irq);
>> ...
>>
>> However in 2.6.24 the "DISABLED" IRQ in case it happens is never
going to
>be masked.
>>
>> if (unlikely(!action || (desc->status & IRQ_DISABLED)))
>> goto out_unlock;
>>
>>
>> I see a disabled IRQ being invoked in an endless loop.
>
>Simple irq's are special, see the comment above handle_simple_irq:
>
>Simple interrupts are either sent from a demultiplexing interrupt
>handler or come from hardware, where no interrupt hardware control
>is necessary.
>
>Note: The caller is expected to handle the ack, clear, mask and
>unmask issues if necessary.
>
>Simple irqs are used for low level demultiplex handlers, where the full
>control of the irqchip is in the low level handler.
>
>See also the commit log of 971e5b35fb02c5088d49e6c024aab73582a35b71
>
> In commit 76d2160147f43f982dfe881404cfde9fd0a9da21 lazy irq
disabling
> was implemented, and the simple irq handler had a masking set to
it.
>
> Remy Bohmer discovered that some devices in the ARM architecture
> would trigger the mask, but never unmask it. His patch to do the
> unmasking was questioned by Russell King about masking simple irqs
> to begin with. Looking further, it was discovered that the problems
> Remy was seeing was due to improper use of the simple handler by
> devices, and he later submitted patches to fix those. But the issue
> that was uncovered was that the simple handler should never mask.
>
> This patch reverts the masking in the simple handler.
>
>Thanks,
>
> tglx


Ok - I see no problem that the simple handler doesn't mask the IRQ by
default like the level irq handler does.

However if I use disable_irq(irq) I would expect that the irq is somehow
disabled afterwards.

Our internal system IRQs doesn't need to be acked on the System
Interrupt Controller Level and we have simply just mask and unmask.


So I think I have two alternatives.

1) Bypass the delayed disable feature by implementing chip->disable and
chip->enable (simply map to mask and unmask)

2) Use level irq

Best regards,
Michael