PCI: let pci_request_irq properly deal with threaded interrupts
Subsystems (3)
PATCH 1/1 PCI: let pci_request_irq properly deal with threaded interrupts
If we have a threaded interrupt with the handler being NULL, then request_threaded_irq() -> __setup_irq() will complain and bail out if the IRQF_ONESHOT flag isn't set. Therefore check for the handler being NULL and set IRQF_ONESHOT in this case.
This change is needed to migrate the mei_me driver to pci_alloc_irq_vectors() and pci_request_irq().
--- drivers/pci/irq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/irq.c +5 -1
@@ -86,13 +86,17 @@ int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,va_list ap;int ret;char *devname; +unsigned long irqflags =IRQF_SHARED ; + +if (!handler) + irqflags |=IRQF_ONESHOT ;va_start (ap, fmt); devname =kvasprintf (GFP_KERNEL , fmt, ap);va_end (ap); ret =request_threaded_irq (pci_irq_vector (dev, nr), handler, thread_fn, -IRQF_SHARED , devname, dev_id); + irqflags, devname, dev_id);if (ret)kfree (devname);return ret;
Signature · 1 line
2.18.0
[+cc Thomas, Christoph, LKML]
Quoted 9 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>
I'd like an ack from Thomas because this requirement about IRQF_ONESHOT usage isn't mentioned in the request_threaded_irq() function doc or Documentation/
Quoted 30 lines
--- drivers/pci/irq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/irq.c +5
-1@@ -86,13 +86,17 @@ int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,va_list ap;int ret;char *devname; +unsigned long irqflags =IRQF_SHARED ; + +if (!handler) + irqflags |=IRQF_ONESHOT ;va_start (ap, fmt); devname =kvasprintf (GFP_KERNEL , fmt, ap);va_end (ap); ret =request_threaded_irq (pci_irq_vector (dev, nr), handler, thread_fn, -IRQF_SHARED , devname, dev_id); + irqflags, devname, dev_id);if (ret)kfree (devname);return ret;Signature · 1 line
2.18.0
Quoted 8 lines · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
Quoted 5 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.
Quoted 9 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/
Sure.
That's the related comment in __setup_irq():
* The interrupt was requested with handler = NULL, so
* we use the default primary handler for it. But it
* does not have the oneshot flag set. In combination
* with level interrupts this is deadly, because the
* default primary handler just wakes the thread, then
* the irq lines is reenabled, but the device still
* has the level irq asserted. Rinse and repeat.... *
* While this works for edge type interrupts, we play
* it safe and reject unconditionally because we can't
* say for sure which type this interrupt really
* has. The type flags are unreliable as the
* underlying chip implementation can override them. */
Quoted 31 lines
Quoted 30 lines
--- drivers/pci/irq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/irq.c +5
-1@@ -86,13 +86,17 @@ int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,va_list ap;int ret;char *devname; +unsigned long irqflags =IRQF_SHARED ; + +if (!handler) + irqflags |=IRQF_ONESHOT ;va_start (ap, fmt); devname =kvasprintf (GFP_KERNEL , fmt, ap);va_end (ap); ret =request_threaded_irq (pci_irq_vector (dev, nr), handler, thread_fn, -IRQF_SHARED , devname, dev_id); + irqflags, devname, dev_id);if (ret)kfree (devname);return ret;Signature · 1 line
2.18.0
Quoted 8 lines · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
Quoted 5 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.
Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/
* IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler finished.
* Used by threaded interrupts which need to keep the
* irq line disabled until the threaded handler has been run.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Thomas Gleixner
Reviewed-byQuoted 1 line · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
+ Marc
Quoted 6 lines · Heiner Kallweit
Quoted 5 lines
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.
Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/
Right. The documentation really needs some love and care. :(
Yes, request for pure threaded interrupts are rejected if the oneshot flag is not set. The reason is that this would be deadly especially with level triggered interrupts because the primary default handler just wakes the thread and then reenables interrupts, which will make the interrupt come back immediately and the thread won't have a chance to actually shut it up in the device.
That made me look into that code again and I found that we added a flag for irq chips to tell the core that the interrupt is one shot safe, i.e. that it can be requested w/o IRQF_ONESHOT. That was initially added to optimize MSI based interrupts which are oneshot safe by implementation.
dc9b229a58dc ("genirq: Allow irq chips to mark themself oneshot safe")
The original patch added that flag to the x86 MSI irqchip code, but that part was not applied for reasons which slipped from memory. It might be worthwhile to revisit that in order to avoid the mask/unmask overhead for such cases.
Anyway for the patch in question:
Thanks,
tglx
[+cc maintainers of possibly erroneous callers of request_threaded_irq()]
Quoted 8 lines · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
Quoted 5 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.
Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/
Possibly these other request_threaded_irq() callers are similarly broken? I can't tell for sure about tda998x_create(), but all the others certainly call request_threaded_irq() with "handler == NULL" and irqflags that do not contain IRQF_ONESHOT:
max8997_muic_probe()
request_threaded_irq(virq, NULL, ..., IRQF_NO_SUSPEND, ...)
tda998x_create()
request_threaded_irq(client->irq, NULL, ..., irqd_get_trigger_type(), ...) (I can't tell what irqd_get_trigger_type() does)
ab8500_btemp_probe()
ab8500_charger_probe()
request_threaded_irq(irq, NULL, ..., IRQF_SHARED | IRQF_NO_SUSPEND, ...)
lp8788_set_irqs()
request_threaded_irq(virq, NULL, ..., 0, ...)
max77686_rtc_probe()
request_threaded_irq(info->virq, NULL, ..., 0, ...)
wm8350_register_irq()
request_threaded_irq(irq + wm8350->irq_base, NULL, ..., flags, ...) (I think all callers of wm8350_register_irq() supply 0 for "flags")
Quoted 30 lines
Quoted 30 lines
--- drivers/pci/irq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/irq.c +5
-1@@ -86,13 +86,17 @@ int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,va_list ap;int ret;char *devname; +unsigned long irqflags =IRQF_SHARED ; + +if (!handler) + irqflags |=IRQF_ONESHOT ;va_start (ap, fmt); devname =kvasprintf (GFP_KERNEL , fmt, ap);va_end (ap); ret =request_threaded_irq (pci_irq_vector (dev, nr), handler, thread_fn, -IRQF_SHARED , devname, dev_id); + irqflags, devname, dev_id);if (ret)kfree (devname);return ret;Signature · 1 line
2.18.0
Quoted 25 lines · Bjorn Helgaas
[+cc maintainers of possibly erroneous callers of
request_threaded_irq()]Quoted 8 lines · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
Quoted 5 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/Possibly these other
request_threaded_irq()callers are similarly broken? I can't tell for sure abouttda998x_create(), but all the others certainly callrequest_threaded_irq()with "handler == NULL" and irqflags that do not containIRQF_ONESHOT:
Quoted 6 lines
max8997_muic_probe()request_threaded_irq(virq, NULL, ..., IRQF_NO_SUSPEND, ...)
tda998x_create()
request_threaded_irq(client->irq, NULL, ..., irqd_get_trigger_type(), ...)(I can't tell whatirqd_get_trigger_type()does)
It reads the trigger type back from the irq chip (level/edge/polarity) but does not return with the ONESHOT bit set.
Quoted 3 lines
ab8500_btemp_probe()
ab8500_charger_probe()
request_threaded_irq(irq, NULL, ..., IRQF_SHARED | IRQF_NO_SUSPEND, ...)
SHARED is interesting ....
Quoted 9 lines
lp8788_set_irqs()request_threaded_irq(virq, NULL, ..., 0, ...)
max77686_rtc_probe()request_threaded_irq(info->virq, NULL, ..., 0, ...)
wm8350_register_irq()
request_threaded_irq(irq + wm8350->irq_base, NULL, ..., flags, ...)(I think all callers ofwm8350_register_irq()supply 0 for "flags")
Indeed. This all looks pretty much wrong. No idea why nobody ever noticed.
Thanks,
tglx
Quoted 9 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>
Applied with Thomas' reviewed-by to pci/misc for v4.19, thanks!
Quoted 30 lines
--- drivers/pci/irq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/irq.c +5
-1@@ -86,13 +86,17 @@ int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,va_list ap;int ret;char *devname; +unsigned long irqflags =IRQF_SHARED ; + +if (!handler) + irqflags |=IRQF_ONESHOT ;va_start (ap, fmt); devname =kvasprintf (GFP_KERNEL , fmt, ap);va_end (ap); ret =request_threaded_irq (pci_irq_vector (dev, nr), handler, thread_fn, -IRQF_SHARED , devname, dev_id); + irqflags, devname, dev_id);if (ret)kfree (devname);return ret;Signature · 1 line
2.18.0
Quoted 36 lines · Thomas Gleixner
Quoted 1 line · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
+ Marc
Quoted 6 lines · Heiner Kallweit
Quoted 5 lines
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/Right. The documentation really needs some love and care. :(
Yes, request for pure threaded interrupts are rejected if the oneshot flag is not set. The reason is that this would be deadly especially with level triggered interrupts because the primary default handler just wakes the thread and then reenables interrupts, which will make the interrupt come back immediately and the thread won't have a chance to actually shut it up in the device.
That made me look into that code again and I found that we added a flag for irq chips to tell the core that the interrupt is one shot safe, i.e. that it can be requested w/o
IRQF_ONESHOT. That was initially added to optimize MSI based interrupts which are oneshot safe by implementation.
Quoted 6 lines
dc9b229a58dc("genirq: Allow irq chips to mark themself oneshot safe")The original patch added that flag to the x86 MSI irqchip code, but that part was not applied for reasons which slipped from memory. It might be worthwhile to revisit that in order to avoid the mask/unmask overhead for such cases.
Yup, that would actually be beneficial to a range of interrupt controllers (only an obscure GPIO driver makes use of this flag).
We could also consider extending this to support interrupt hierarchies, as __setup_irq() seems only concerned with the top of the stack (an IRQ provided by a generic MSI stack and backed by an irqchip providing IRQCHIP_ONESHOT_SAFE would go unnoticed).
M.
Signature · 1 line
Jazz is not dead, it just smell funny.
Quoted 46 lines · Thomas Gleixner
Quoted 25 lines · Bjorn Helgaas
[+cc maintainers of possibly erroneous callers of
request_threaded_irq()]Quoted 8 lines · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
Quoted 5 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/Possibly these other
request_threaded_irq()callers are similarly broken? I can't tell for sure abouttda998x_create(), but all the others certainly callrequest_threaded_irq()with "handler == NULL" and irqflags that do not containIRQF_ONESHOT:Quoted 6 lines
max8997_muic_probe()request_threaded_irq(virq, NULL, ..., IRQF_NO_SUSPEND, ...)
tda998x_create()
request_threaded_irq(client->irq, NULL, ..., irqd_get_trigger_type(), ...)(I can't tell whatirqd_get_trigger_type()does)It reads the trigger type back from the irq chip (level/edge/polarity) but does not return with the ONESHOT bit set.
Quoted 3 lines
ab8500_btemp_probe()
ab8500_charger_probe()
request_threaded_irq(irq, NULL, ..., IRQF_SHARED | IRQF_NO_SUSPEND, ...)SHARED is interesting ....
Quoted 3 lines
lp8788_set_irqs()request_threaded_irq(virq, NULL, ..., 0, ...)
Quoted 8 lines
Quoted 6 lines
max77686_rtc_probe()request_threaded_irq(info->virq, NULL, ..., 0, ...)
wm8350_register_irq()
request_threaded_irq(irq + wm8350->irq_base, NULL, ..., flags, ...)(I think all callers ofwm8350_register_irq()supply 0 for "flags")Indeed. This all looks pretty much wrong. No idea why nobody ever noticed.
I guess not many people (myself included) know the intricacies well enough to have noticed. This probably coupled with insufficient checking/warning about such practices in the IRQ subsystem.
There are quite a few different devices here, so my assumption would be that interrupt handling still works in these cases.
If we know certain configurations are incorrect or incompatible, might I suggest we add some form of alert to bring these to the attention of unknowing contributors?
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 27 lines · Thomas Gleixner
Quoted 25 lines · Bjorn Helgaas
[+cc maintainers of possibly erroneous callers of
request_threaded_irq()]Quoted 8 lines · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
Quoted 5 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/Possibly these other
request_threaded_irq()callers are similarly broken? I can't tell for sure abouttda998x_create(), but all the others certainly callrequest_threaded_irq()with "handler == NULL" and irqflags that do not containIRQF_ONESHOT:
Quoted 6 lines
Quoted 3 lines
tda998x_create()
request_threaded_irq(client->irq, NULL, ..., irqd_get_trigger_type(), ...)(I can't tell whatirqd_get_trigger_type()does)It reads the trigger type back from the irq chip (level/edge/polarity) but does not return with the ONESHOT bit set.
What tree are you (Bjorn) using there? Looking in my git history, request_threaded_irq() was added in January 2014, as:
+ irqf_trigger =
+ irqd_get_trigger_type(irq_get_irq_data(client->irq));
+ ret = request_threaded_irq(client->irq, NULL,
+ tda998x_irq_thread, + irqf_trigger | IRQF_ONESHOT, + "tda998x", priv);
and updated more recently for the CEC support in ae81553c30ef ("drm/i2c: tda998x: allow interrupt to be shared") to be:
- irqf_trigger =
+ irq_flags =
irqd_get_trigger_type(irq_get_irq_data(client->irq));
+ irq_flags |= IRQF_SHARED | IRQF_ONESHOT;
ret = request_threaded_irq(client->irq, NULL,
- tda998x_irq_thread,
- irqf_trigger | IRQF_ONESHOT,
+ tda998x_irq_thread, irq_flags,
"tda998x", priv);In all cases, IRQF_ONESHOT has been set for this threaded interrupt.
I've also checked drm-next, and it doesn't show anything like what Bjorn quoted.
Confused. Bjorn, can you double check that what you think are erroneous request_threaded_irq() calls are actually as per what you quoted please?
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 13.8Mbps down 630kbps up According to speedtest.net: 13Mbps down 490kbps up
Quoted 36 lines · Bjorn Helgaas
[+cc maintainers of possibly erroneous callers of
request_threaded_irq()]Quoted 8 lines · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
Quoted 5 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/Possibly these other
request_threaded_irq()callers are similarly broken? I can't tell for sure abouttda998x_create(), but all the others certainly callrequest_threaded_irq()with "handler == NULL" and irqflags that do not containIRQF_ONESHOT:
max8997_muic_probe()request_threaded_irq(virq, NULL, ..., IRQF_NO_SUSPEND, ...)
tda998x_create()
request_threaded_irq(client->irq, NULL, ..., irqd_get_trigger_type(), ...)(I can't tell whatirqd_get_trigger_type()does)
ab8500_btemp_probe()
ab8500_charger_probe()
request_threaded_irq(irq, NULL, ..., IRQF_SHARED | IRQF_NO_SUSPEND, ...)
Quoted 5 lines
lp8788_set_irqs()request_threaded_irq(virq, NULL, ..., 0, ...)
max77686_rtc_probe()request_threaded_irq(info->virq, NULL, ..., 0, ...)
max77686 works fine because it it is nested IRQ. Parent has ONESHOT flag set.
Best regards,
Krzysztof
Quoted 58 lines · Russell King - ARM Linux
Quoted 27 lines · Thomas Gleixner
Quoted 25 lines · Bjorn Helgaas
[+cc maintainers of possibly erroneous callers of
request_threaded_irq()]Quoted 8 lines · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
Quoted 5 lines · Heiner Kallweit
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/Possibly these other
request_threaded_irq()callers are similarly broken? I can't tell for sure abouttda998x_create(), but all the others certainly callrequest_threaded_irq()with "handler == NULL" and irqflags that do not containIRQF_ONESHOT:Quoted 6 lines
Quoted 3 lines
tda998x_create()
request_threaded_irq(client->irq, NULL, ..., irqd_get_trigger_type(), ...)(I can't tell whatirqd_get_trigger_type()does)It reads the trigger type back from the irq chip (level/edge/polarity) but does not return with the ONESHOT bit set.
What tree are you (Bjorn) using there? Looking in my git history,
request_threaded_irq()was added in January 2014, as:(quoted diff) +6
-0+ irqf_trigger = + irqd_get_trigger_type(irq_get_irq_data(client->irq)); + ret = request_threaded_irq(client->irq, NULL, + tda998x_irq_thread, + irqf_trigger | IRQF_ONESHOT, + "tda998x", priv);and updated more recently for the CEC support in
ae81553c30ef("drm/i2c: tda998x: allow interrupt to be shared") to be:(quoted diff) +3
-3- irqf_trigger = + irq_flags = irqd_get_trigger_type(irq_get_irq_data(client->irq)); + irq_flags |= IRQF_SHARED | IRQF_ONESHOT; ret = request_threaded_irq(client->irq, NULL, - tda998x_irq_thread, - irqf_trigger | IRQF_ONESHOT, + tda998x_irq_thread, irq_flags, "tda998x", priv);
Quoted 8 lines
In all cases,
IRQF_ONESHOThas been set for this threaded interrupt.I've also checked drm-next, and it doesn't show anything like what Bjorn quoted.
Confused. Bjorn, can you double check that what you think are erroneous
request_threaded_irq()calls are actually as per what you quoted please?
I was looking at v4.18-rc1, but in the case of tda998x_create(), I overlooked this line:
irq_flags |= IRQF_SHARED | IRQF_ONESHOT;
Sorry!
Quoted 40 lines · Marc Zyngier
Quoted 38 lines · Thomas Gleixner
Quoted 1 line · Bjorn Helgaas
[+cc Thomas, Christoph, LKML]
+ Marc
Quoted 6 lines · Heiner Kallweit
Quoted 5 lines
If we have a threaded interrupt with the handler being NULL, then
request_threaded_irq()->__setup_irq()will complain and bail out if theIRQF_ONESHOTflag isn't set. Therefore check for the handler being NULL and setIRQF_ONESHOTin this case.Quoted 8 lines
Quoted 4 lines
This change is needed to migrate the
mei_medriver topci_alloc_irq_vectors()andpci_request_irq().Signed-off-by Heiner Kallweit <[email protected]>I'd like an ack from Thomas because this requirement about
IRQF_ONESHOTusage isn't mentioned in therequest_threaded_irq()function doc orDocumentation/Right. The documentation really needs some love and care. :(
Yes, request for pure threaded interrupts are rejected if the oneshot flag is not set. The reason is that this would be deadly especially with level triggered interrupts because the primary default handler just wakes the thread and then reenables interrupts, which will make the interrupt come back immediately and the thread won't have a chance to actually shut it up in the device.
That made me look into that code again and I found that we added a flag for irq chips to tell the core that the interrupt is one shot safe, i.e. that it can be requested w/o
IRQF_ONESHOT. That was initially added to optimize MSI based interrupts which are oneshot safe by implementation.
dc9b229a58dc("genirq: Allow irq chips to mark themself oneshot safe")
Quoted 8 lines
Quoted 4 lines
The original patch added that flag to the x86 MSI irqchip code, but that part was not applied for reasons which slipped from memory. It might be worthwhile to revisit that in order to avoid the mask/unmask overhead for such cases.
Yup, that would actually be beneficial to a range of interrupt controllers (only an obscure GPIO driver makes use of this flag).
I'm not an expert on that area, but if MSI is oneshot-safe in general, then we could do the following in the framework instead of touching every MSI irq_chip. Opinions?
I tested on X86 and at least my system is still running.
kernel/irq/msi.c +3 -0
@@ -289,6 +289,9 @@ struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,if (info->flags &MSI_FLAG_USE_DEF_CHIP_OPS )msi_domain_update_chip_ops (info); +/* MSI is oneshot-safe in general */ + info->chip->flags |=IRQCHIP_ONESHOT_SAFE ; + domain =irq_domain_create_hierarchy (parent,IRQ_DOMAIN_FLAG_MSI ,0 , fwnode, &msi_domain_ops, info);
--
2.18.0
Quoted 5 lines
We could also consider extending this to support interrupt hierarchies, as
__setup_irq()seems only concerned with the top of the stack (an IRQ provided by a generic MSI stack and backed by an irqchip providingIRQCHIP_ONESHOT_SAFEwould go unnoticed).
Would it be sufficient if one irq_chip in the hierarchy is oneshot-safe? Or what do we have to check for?
Quoted 2 lines
M.
Heiner
Quoted 37 lines · Heiner Kallweit
Quoted 17 lines · Marc Zyngier
Quoted 15 lines · Thomas Gleixner
Yes, request for pure threaded interrupts are rejected if the oneshot flag is not set. The reason is that this would be deadly especially with level triggered interrupts because the primary default handler just wakes the thread and then reenables interrupts, which will make the interrupt come back immediately and the thread won't have a chance to actually shut it up in the device.
That made me look into that code again and I found that we added a flag for irq chips to tell the core that the interrupt is one shot safe, i.e. that it can be requested w/o
IRQF_ONESHOT. That was initially added to optimize MSI based interrupts which are oneshot safe by implementation.
dc9b229a58dc("genirq: Allow irq chips to mark themself oneshot safe")Quoted 8 lines
Quoted 4 lines
The original patch added that flag to the x86 MSI irqchip code, but that part was not applied for reasons which slipped from memory. It might be worthwhile to revisit that in order to avoid the mask/unmask overhead for such cases.
Yup, that would actually be beneficial to a range of interrupt controllers (only an obscure GPIO driver makes use of this flag).
I'm not an expert on that area, but if MSI is oneshot-safe in general, then we could do the following in the framework instead of touching every MSI
irq_chip. Opinions?
I tested on X86 and at least my system is still running.kernel/irq/msi.c +0
-0
kernel/irq/msi.c struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode, · line 295
Quoted 7 lines
kernel/irq/msi.c +3
-0@@ -289,6 +289,9 @@ struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,if (info->flags &MSI_FLAG_USE_DEF_CHIP_OPS )msi_domain_update_chip_ops (info); +/* MSI is oneshot-safe in general */ + info->chip->flags |=IRQCHIP_ONESHOT_SAFE ; + domain = irq_domain_create_hierarchy(parent, IRQ_DOMAIN_FLAG_MSI, 0,
Looks about right, though there might be dragons. MSI is not always as sane as it should be...
Quoted 8 lines
Quoted 5 lines
We could also consider extending this to support interrupt hierarchies, as
__setup_irq()seems only concerned with the top of the stack (an IRQ provided by a generic MSI stack and backed by an irqchip providingIRQCHIP_ONESHOT_SAFEwould go unnoticed).Would it be sufficient if one
irq_chipin the hierarchy is oneshot-safe? Or what do we have to check for?
I think the top most chip is the key, the rest of the hierarchy is irrelevant because the top most chip is the one which is responsible for not creating an interrupt storm after the interrupt got acknowledged.
Thanks,
tglx
Quoted 41 lines · Thomas Gleixner
Quoted 40 lines · Heiner Kallweit
Quoted 17 lines · Marc Zyngier
Quoted 15 lines · Thomas Gleixner
Yes, request for pure threaded interrupts are rejected if the oneshot flag is not set. The reason is that this would be deadly especially with level triggered interrupts because the primary default handler just wakes the thread and then reenables interrupts, which will make the interrupt come back immediately and the thread won't have a chance to actually shut it up in the device.
That made me look into that code again and I found that we added a flag for irq chips to tell the core that the interrupt is one shot safe, i.e. that it can be requested w/o
IRQF_ONESHOT. That was initially added to optimize MSI based interrupts which are oneshot safe by implementation.
dc9b229a58dc("genirq: Allow irq chips to mark themself oneshot safe")Quoted 8 lines
Quoted 4 lines
The original patch added that flag to the x86 MSI irqchip code, but that part was not applied for reasons which slipped from memory. It might be worthwhile to revisit that in order to avoid the mask/unmask overhead for such cases.
Yup, that would actually be beneficial to a range of interrupt controllers (only an obscure GPIO driver makes use of this flag).
I'm not an expert on that area, but if MSI is oneshot-safe in general, then we could do the following in the framework instead of touching every MSI
irq_chip. Opinions?
I tested on X86 and at least my system is still running.kernel/irq/msi.c +0
-0@@ -289,6 +289,9 @@ struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,if (info->flags &MSI_FLAG_USE_DEF_CHIP_OPS )msi_domain_update_chip_ops (info);
Quoted 8 lines
kernel/irq/msi.c struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode, · line 295
Quoted 4 lines
kernel/irq/msi.c +3
-0+/* MSI is oneshot-safe in general */ + info->chip->flags |=IRQCHIP_ONESHOT_SAFE ; + domain = irq_domain_create_hierarchy(parent, IRQ_DOMAIN_FLAG_MSI, 0,Looks about right, though there might be dragons. MSI is not always as sane as it should be...
When saying "MSI isn't always sane", are you referring to the hardware or the controller driver implementation? Basically for me the question is whether we would be able to fix the issue if we meet such a dragon, or whether we would have to revert the change.
Do you think the chance of a dragon is low enough? Or better add the flag only to the X86 PCI MSI irqchip for now?
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
We could also consider extending this to support interrupt hierarchies, as
__setup_irq()seems only concerned with the top of the stack (an IRQ provided by a generic MSI stack and backed by an irqchip providingIRQCHIP_ONESHOT_SAFEwould go unnoticed).
Quoted 7 lines
Quoted 2 lines
Would it be sufficient if one
irq_chipin the hierarchy is oneshot-safe? Or what do we have to check for?I think the top most chip is the key, the rest of the hierarchy is irrelevant because the top most chip is the one which is responsible for not creating an interrupt storm after the interrupt got acknowledged.
Thanks for the explanation, then I'll submit a patch implementing this logic.
Quoted 4 lines
Thanks,
tglx
Heiner
Quoted 18 lines · Heiner Kallweit
Quoted 9 lines · Thomas Gleixner
Quoted 8 lines · Heiner Kallweit
kernel/irq/msi.c +0
-0@@ -289,6 +289,9 @@ struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,if (info->flags &MSI_FLAG_USE_DEF_CHIP_OPS )msi_domain_update_chip_ops (info);Quoted 8 lines
kernel/irq/msi.c struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode, · line 295
Quoted 4 lines
kernel/irq/msi.c +3
-0+/* MSI is oneshot-safe in general */ + info->chip->flags |=IRQCHIP_ONESHOT_SAFE ; + domain = irq_domain_create_hierarchy(parent, IRQ_DOMAIN_FLAG_MSI, 0,Looks about right, though there might be dragons. MSI is not always as sane as it should be...
Quoted 4 lines
When saying "MSI isn't always sane", are you referring to the hardware or the controller driver implementation? Basically for me the question is whether we would be able to fix the issue if we meet such a dragon, or whether we would have to revert the change.
It's hardware unfortunately, so it might be a revert. PCI-MSI should be safe, but the wild MSI variants in SoCs might be the actual dragon caves.
Quoted 2 lines
Do you think the chance of a dragon is low enough? Or better add the flag only to the X86 PCI MSI irqchip for now?
I think PCI-MSI in general would be not too risky. Famous last words.
Thanks,
tglx
Quoted 19 lines · Thomas Gleixner
Quoted 18 lines · Heiner Kallweit
Quoted 17 lines · Thomas Gleixner
kernel/irq/msi.c struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode, · line 295
Quoted 12 lines · Heiner Kallweit
kernel/irq/msi.c +3
-0@@ -289,6 +289,9 @@ struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,if (info->flags &MSI_FLAG_USE_DEF_CHIP_OPS )msi_domain_update_chip_ops (info); +/* MSI is oneshot-safe in general */ + info->chip->flags |=IRQCHIP_ONESHOT_SAFE ; + domain = irq_domain_create_hierarchy(parent, IRQ_DOMAIN_FLAG_MSI, 0,Looks about right, though there might be dragons. MSI is not always as sane as it should be...
Quoted 8 lines
Quoted 4 lines
When saying "MSI isn't always sane", are you referring to the hardware or the controller driver implementation? Basically for me the question is whether we would be able to fix the issue if we meet such a dragon, or whether we would have to revert the change.
It's hardware unfortunately, so it might be a revert. PCI-MSI should be safe, but the wild MSI variants in SoCs might be the actual dragon caves.
pci_msi_create_irq_domain() is used by controller drivers for PCI(e) controllers in SoCs like Mediatek, Armada, ..
I assume you're referring to some other (non-PCI) SoC-internal MSI mechanism when saying "wild variants", right?
Quoted 9 lines
Quoted 2 lines
Do you think the chance of a dragon is low enough? Or better add the flag only to the X86 PCI MSI irqchip for now?
I think PCI-MSI in general would be not too risky. Famous last words.
Thanks,
tglx