Skip to contentSkip to conversation

irq: add irq_set_chained_handler_and_data()

PATCH New Russell King 5 participants 6 messages Jun 16, 2015 – Jun 19, 2015

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/9 irq: add irq_set_chained_handler_and_data()

Driver authors seem to get the ordering of irq_set_chained_handler() and irq_set_handler_data() wrong - ordering the former before the latter. This opens a race window where, if there is an interrupt pending, the handler will be called between these two calls, potentially resulting in an oops.

Provide a single interface to set both of these together, especially as that's commonly what is required.

---
It probably makes sense to convert everything over to this new registration function, and kill all users of irq_set_chained_handler() to prevent this problem recurring. Thoughts?

 include/linux/irq.h |  9 +++++++++
 kernel/irq/chip.c   | 45 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 43 insertions(+), 11 deletions(-)
include/linux/irq.h +9 -0
index 62c6901cab55..4942cbc379bb 100644
@@ -517,6 +517,15 @@ irq_set_chained_handler(unsigned int irq, irq_flow_handler_t handle)
 	__irq_set_handler(irq, handle, 1, NULL);
 }
 
+/*
+ * Set a highlevel chained flow handler and its data for a given IRQ.
+ * (a chained handler is automatically enabled and set to
+ *  IRQ_NOREQUEST, IRQ_NOPROBE, and IRQ_NOTHREAD)
+ */
+void
+irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
+				 void *data);
+
 void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set);
 
 static inline void irq_set_status_flags(unsigned int irq, unsigned long set)
kernel/irq/chip.c +34 -11

74 lines not on this page · raw message

Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/1 GPU: ipu: fix lockup caused by pending chained interrupts

Even with the oops fixed by a previous patch, the system still fails to kexec, due to a stuck chained interrupt locking the system. We must disable the child interrupts prior to setting up the irq chip to ensure we don't get stuck here.

---
Maybe this is all that's really needed... would also be nice if this path had an etry in MAINTAINERS...

 drivers/gpu/ipu-v3/ipu-common.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/ipu-v3/ipu-common.c +3 -0
index 6d2f39d36e44..00f2058944e5 100644
@@ -1107,6 +1107,9 @@ static int ipu_irq_init(struct ipu_soc *ipu)
 		return ret;
 	}
 
+	for (i = 0; i < IPU_NUM_IRQS; i += 32)
+		ipu_cm_write(ipu, 0, IPU_INT_CTRL(i / 32));
+
 	for (i = 0; i < IPU_NUM_IRQS; i += 32) {
 		gc = irq_get_domain_generic_chip(ipu->domain, i);
 		gc->reg_base = ipu->cm_reg;
Signature · 1 line
2.1.0
maintainer Applied
#2 lore raw

PATCH 1/1 GPU: ipu: fix lockup caused by pending chained interrupts

Am Dienstag, den 16.06.2015, 23:29 +0100 schrieb Russell King:

Quoted 6 lines

Even with the oops fixed by a previous patch, the system still fails to kexec, due to a stuck chained interrupt locking the system. We must disable the child interrupts prior to setting up the irq chip to ensure we don't get stuck here.

Applied, thank you.

Quoted 2 lines

Maybe this is all that's really needed... would also be nice if this path had an etry in MAINTAINERS...

I'll send a patch to add it to the imx-drm driver section.

regards
Philipp

#3 lore raw

PATCH 1/9 irq: add irq_set_chained_handler_and_data()

In reply to Russell King
Quoted 6 lines · Russell King

Driver authors seem to get the ordering of irq_set_chained_handler() and irq_set_handler_data() wrong - ordering the former before the latter. This opens a race window where, if there is an interrupt pending, the handler will be called between these two calls, potentially resulting in an oops.

Quoted 8 lines

Provide a single interface to set both of these together, especially as that's commonly what is required.

---
It probably makes sense to convert everything over to this new registration function, and kill all users of irq_set_chained_handler() to prevent this problem recurring. Thoughts?

Yes. Classic coccinelle problem. Here is the semantic patch:

@@
expression E1, E2, E3;
@@
-irq_set_chained_handler(E1, E3);
...
-irq_set_handler_data(E1, E2);
+irq_set_chained_handler_and_data(E1, E3, E2);

This finds and corrects all instances which get it wrong:

arch:

 arm/common/locomo.c                   |    3 +--
 arm/common/sa1111.c                   |    3 +--
 arm/mach-gemini/gpio.c                |    4 ++--
 avr32/mach-at32ap/extint.c            |    3 +--
 m68k/mac/psc.c                        |   12 ++++--------
 mips/ath25/ar2315.c                   |    4 ++--
 mips/ath25/ar5312.c                   |    4 ++--
 mips/pci/pci-ar2315.c                 |    4 ++--
 mips/ralink/irq.c                     |    3 +--
 sh/intc/core.c                        |    5 +++--

drivers:

 dma/ipu/ipu_irq.c                     |    6 ++----
 gpio/gpio-bcm-kona.c                  |    5 +++--
 gpio/gpio-davinci.c                   |   10 ++--------
 gpio/gpio-dwapb.c                     |    4 ++--
 gpio/gpio-msic.c                      |    3 +--
 gpio/gpio-mxc.c                       |   10 +++++-----
 gpio/gpio-mxs.c                       |    4 ++--
 gpio/gpio-tegra.c                     |    4 ++--
 gpu/ipu-v3/ipu-common.c               |   13 +++++--------
 irqchip/irq-keystone.c                |    4 ++--
 irqchip/spear-shirq.c                 |    3 +--
 mfd/pm8921-core.c                     |    6 ++----
 mfd/t7l66xb.c                         |    3 +--
 mfd/tc6393xb.c                        |    3 +--
 pci/host/pci-keystone.c               |    7 +++----
 pinctrl/mediatek/pinctrl-mtk-common.c |    3 +--
 pinctrl/pinctrl-adi2.c                |    4 ++--
 pinctrl/pinctrl-st.c                  |    4 ++--
 pinctrl/samsung/pinctrl-exynos.c      |    4 ++--
 pinctrl/samsung/pinctrl-s3c24xx.c     |    3 +--
 pinctrl/samsung/pinctrl-s3c64xx.c     |    8 ++++----
 pinctrl/sunxi/pinctrl-sunxi.c         |    6 +++---
 spmi/spmi-pmic-arb.c                  |    6 ++----
 33 files changed, 70 insertions(+), 98 deletions(-)

If we revert the search pattern we get the ones which got it right:

@@
expression E1, E2, E3;
@@
-irq_set_handler_data(E1, E2);
...
-irq_set_chained_handler(E1, E3);
+irq_set_chained_handler_and_data(E1, E3, E2);

That handles another bunch and leaves us with 135 instances of irq_set_chained_handler() which do not set handler data. So its trivial to change them to

irq_set_chained_handler_and_data(irq, handler, NULL);

and then remove irq_set_chained_handler()

If thats ok for you, then i apply the lot you sent and run the cocci scripts right at rc1. I have another set of transformations in that area pending.

Thanks,

tglx

#4 lore raw

PATCH 1/9 irq: add irq_set_chained_handler_and_data()

Quoted 81 lines · Thomas Gleixner
Quoted 6 lines · Russell King

Driver authors seem to get the ordering of irq_set_chained_handler() and irq_set_handler_data() wrong - ordering the former before the latter. This opens a race window where, if there is an interrupt pending, the handler will be called between these two calls, potentially resulting in an oops.

Quoted 8 lines

Provide a single interface to set both of these together, especially as that's commonly what is required.

---
It probably makes sense to convert everything over to this new registration function, and kill all users of irq_set_chained_handler() to prevent this problem recurring. Thoughts?

Yes. Classic coccinelle problem. Here is the semantic patch:

@@
expression E1, E2, E3;
@@

(quoted diff) +1 -2
-irq_set_chained_handler(E1, E3);
...
-irq_set_handler_data(E1, E2);
+irq_set_chained_handler_and_data(E1, E3, E2);

This finds and corrects all instances which get it wrong:

arch:

 arm/common/locomo.c                   |    3 +--
 arm/common/sa1111.c                   |    3 +--
 arm/mach-gemini/gpio.c                |    4 ++--
 avr32/mach-at32ap/extint.c            |    3 +--
 m68k/mac/psc.c                        |   12 ++++--------
 mips/ath25/ar2315.c                   |    4 ++--
 mips/ath25/ar5312.c                   |    4 ++--
 mips/pci/pci-ar2315.c                 |    4 ++--
 mips/ralink/irq.c                     |    3 +--
 sh/intc/core.c                        |    5 +++--

drivers:

 dma/ipu/ipu_irq.c                     |    6 ++----
 gpio/gpio-bcm-kona.c                  |    5 +++--
 gpio/gpio-davinci.c                   |   10 ++--------
 gpio/gpio-dwapb.c                     |    4 ++--
 gpio/gpio-msic.c                      |    3 +--
 gpio/gpio-mxc.c                       |   10 +++++-----
 gpio/gpio-mxs.c                       |    4 ++--
 gpio/gpio-tegra.c                     |    4 ++--
 gpu/ipu-v3/ipu-common.c               |   13 +++++--------
 irqchip/irq-keystone.c                |    4 ++--
 irqchip/spear-shirq.c                 |    3 +--
 mfd/pm8921-core.c                     |    6 ++----
 mfd/t7l66xb.c                         |    3 +--
 mfd/tc6393xb.c                        |    3 +--
 pci/host/pci-keystone.c               |    7 +++----
 pinctrl/mediatek/pinctrl-mtk-common.c |    3 +--
 pinctrl/pinctrl-adi2.c                |    4 ++--
 pinctrl/pinctrl-st.c                  |    4 ++--
 pinctrl/samsung/pinctrl-exynos.c      |    4 ++--
 pinctrl/samsung/pinctrl-s3c24xx.c     |    3 +--
 pinctrl/samsung/pinctrl-s3c64xx.c     |    8 ++++----
 pinctrl/sunxi/pinctrl-sunxi.c         |    6 +++---
 spmi/spmi-pmic-arb.c                  |    6 ++----
 33 files changed, 70 insertions(+), 98 deletions(-)

If we revert the search pattern we get the ones which got it right:

@@
expression E1, E2, E3;
@@

(quoted diff) +1 -2
-irq_set_handler_data(E1, E2);
...
-irq_set_chained_handler(E1, E3);
+irq_set_chained_handler_and_data(E1, E3, E2);

That handles another bunch and leaves us with 135 instances of irq_set_chained_handler() which do not set handler data. So its trivial to change them to

Quoted 7 lines

irq_set_chained_handler_and_data(irq, handler, NULL);

and then remove irq_set_chained_handler()

If thats ok for you, then i apply the lot you sent and run the cocci scripts right at rc1. I have another set of transformations in that area pending.

Totally fine with that.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
#5 lore raw

[tip:irq/core] irq: Add irq_set_chained_handler_and_data()

In reply to Russell King
irq: Add irq_set_chained_handler_and_data()
Commit-ID:  3b0f95be143bea1aa47beb20134ef82e4e4068dc
Gitweb:     http://git.kernel.org/tip/3b0f95be143bea1aa47beb20134ef82e4e4068dc
Author:     Russell King <[email protected]>
AuthorDate: Tue, 16 Jun 2015 23:06:20 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 18 Jun 2015 14:03:08 +0200

irq: Add irq_set_chained_handler_and_data()

Driver authors seem to get the ordering of irq_set_chained_handler() and irq_set_handler_data() wrong - ordering the former before the latter. This opens a race window where, if there is an interrupt pending, the handler will be called between these two calls, potentially resulting in an oops.

Provide a single interface to set both of these together, especially as that's commonly what is required.

---
 include/linux/irq.h |  9 +++++++++
 kernel/irq/chip.c   | 45 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 43 insertions(+), 11 deletions(-)
include/linux/irq.h +9 -0
index de3213d..42861d2 100644
@@ -525,6 +525,15 @@ irq_set_chained_handler(unsigned int irq, irq_flow_handler_t handle)
 	__irq_set_handler(irq, handle, 1, NULL);
 }
 
+/*
+ * Set a highlevel chained flow handler and its data for a given IRQ.
+ * (a chained handler is automatically enabled and set to
+ *  IRQ_NOREQUEST, IRQ_NOPROBE, and IRQ_NOTHREAD)
+ */
+void
+irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
+				 void *data);
+
 void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set);
 
 static inline void irq_set_status_flags(unsigned int irq, unsigned long set)
kernel/irq/chip.c +34 -11

74 lines not on this page · raw message