linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe().
@ 2022-05-09 14:04 Sebastian Andrzej Siewior
  2022-05-16 10:18 ` Lukas Wunner
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-05-09 14:04 UTC (permalink / raw)
  To: linux-kernel, Thomas Gleixner
  Cc: Bartosz Golaszewski, Basavaraj Natikar, Hans de Goede,
	Linus Walleij, Mark Gross, Michael Buesch,
	Rafał Miłecki, Shyam Sundar S K, linux-gpio,
	linux-wireless, platform-driver-x86

Provide generic_handle_domain_irq_safe() which can used from any context.
This similar to commit
   509853f9e1e7b ("genirq: Provide generic_handle_irq_safe()")

but this time for the irq-domains interface. It has been reported for
the amd-pinctrl driver via bugzilla
   https://bugzilla.kernel.org/show_bug.cgi?id=215954

I looked around and added a few users so it is not just one user API :)
Instead of generic_handle_irq(irq_find_mapping)) one can use
generic_handle_domain_irq().

The problem with generic_handle_domain_irq() is that with `threadirqs'
it will trigger "WARN_ON_ONCE(!in_hardirq())". That interrupt handler
can't be marked non-threaded because it is a shared handler (it is
marked as such and I can't tell the interrupt can be really shared on
the system).
Ignoring the just mentioned warning, on PREEMPT_RT the threaded handler
is invoked with enabled interrupts leading other problems.

Do we do this?

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/bcma/driver_gpio.c                 |  2 +-
 drivers/gpio/gpio-mlxbf2.c                 |  6 ++----
 drivers/pinctrl/pinctrl-amd.c              |  2 +-
 drivers/platform/x86/intel/int0002_vgpio.c |  3 +--
 drivers/ssb/driver_gpio.c                  |  6 ++++--
 include/linux/irqdesc.h                    |  1 +
 kernel/irq/irqdesc.c                       | 24 ++++++++++++++++++++++
 7 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/drivers/bcma/driver_gpio.c b/drivers/bcma/driver_gpio.c
index 1e74ec1c7f231..ed2730a21e7c4 100644
--- a/drivers/bcma/driver_gpio.c
+++ b/drivers/bcma/driver_gpio.c
@@ -113,7 +113,7 @@ static irqreturn_t bcma_gpio_irq_handler(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	for_each_set_bit(gpio, &irqs, gc->ngpio)
-		generic_handle_irq(irq_find_mapping(gc->irq.domain, gpio));
+		generic_handle_domain_irq_safe(gc->irq.domain, gpio);
 	bcma_chipco_gpio_polarity(cc, irqs, val & irqs);
 
 	return IRQ_HANDLED;
diff --git a/drivers/gpio/gpio-mlxbf2.c b/drivers/gpio/gpio-mlxbf2.c
index 3d89912a05b87..d4916f32fee73 100644
--- a/drivers/gpio/gpio-mlxbf2.c
+++ b/drivers/gpio/gpio-mlxbf2.c
@@ -273,10 +273,8 @@ static irqreturn_t mlxbf2_gpio_irq_handler(int irq, void *ptr)
 	pending = readl(gs->gpio_io + YU_GPIO_CAUSE_OR_CAUSE_EVTEN0);
 	writel(pending, gs->gpio_io + YU_GPIO_CAUSE_OR_CLRCAUSE);
 
-	for_each_set_bit(level, &pending, gc->ngpio) {
-		int gpio_irq = irq_find_mapping(gc->irq.domain, level);
-		generic_handle_irq(gpio_irq);
-	}
+	for_each_set_bit(level, &pending, gc->ngpio)
+		generic_handle_domain_irq_safe(gc->irq.domain, level);
 
 	return IRQ_RETVAL(pending);
 }
diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 1a7d686494ffb..ce6fa6a76d1f6 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -638,7 +638,7 @@ static bool do_amd_gpio_irq_handler(int irq, void *dev_id)
 			if (!(regval & PIN_IRQ_PENDING) ||
 			    !(regval & BIT(INTERRUPT_MASK_OFF)))
 				continue;
-			generic_handle_domain_irq(gc->irq.domain, irqnr + i);
+			generic_handle_domain_irq_safe(gc->irq.domain, irqnr + i);
 
 			/* Clear interrupt.
 			 * We must read the pin register again, in case the
diff --git a/drivers/platform/x86/intel/int0002_vgpio.c b/drivers/platform/x86/intel/int0002_vgpio.c
index 617dbf98980ec..97cfbc520a02c 100644
--- a/drivers/platform/x86/intel/int0002_vgpio.c
+++ b/drivers/platform/x86/intel/int0002_vgpio.c
@@ -125,8 +125,7 @@ static irqreturn_t int0002_irq(int irq, void *data)
 	if (!(gpe_sts_reg & GPE0A_PME_B0_STS_BIT))
 		return IRQ_NONE;
 
-	generic_handle_irq(irq_find_mapping(chip->irq.domain,
-					    GPE0A_PME_B0_VIRT_GPIO_PIN));
+	generic_handle_domain_irq_safe(chip->irq.domain, GPE0A_PME_B0_VIRT_GPIO_PIN);
 
 	pm_wakeup_hard_event(chip->parent);
 
diff --git a/drivers/ssb/driver_gpio.c b/drivers/ssb/driver_gpio.c
index 2de3896489c84..897cb8db5084f 100644
--- a/drivers/ssb/driver_gpio.c
+++ b/drivers/ssb/driver_gpio.c
@@ -132,7 +132,8 @@ static irqreturn_t ssb_gpio_irq_chipco_handler(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	for_each_set_bit(gpio, &irqs, bus->gpio.ngpio)
-		generic_handle_irq(ssb_gpio_to_irq(&bus->gpio, gpio));
+		generic_handle_domain_irq_safe(bus->irq_domain, gpio);
+
 	ssb_chipco_gpio_polarity(chipco, irqs, val & irqs);
 
 	return IRQ_HANDLED;
@@ -330,7 +331,8 @@ static irqreturn_t ssb_gpio_irq_extif_handler(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	for_each_set_bit(gpio, &irqs, bus->gpio.ngpio)
-		generic_handle_irq(ssb_gpio_to_irq(&bus->gpio, gpio));
+		generic_handle_domain_irq_safe(bus->irq_domain, gpio);
+
 	ssb_extif_gpio_polarity(extif, irqs, val & irqs);
 
 	return IRQ_HANDLED;
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index a77584593f7d1..98253955e2ae7 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -169,6 +169,7 @@ int generic_handle_irq_safe(unsigned int irq);
  * conversion failed.
  */
 int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwirq);
+int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int hwirq);
 int generic_handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq);
 #endif
 
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 0099b87dd8530..48c34d47255cc 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -706,6 +706,30 @@ int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwirq)
 }
 EXPORT_SYMBOL_GPL(generic_handle_domain_irq);
 
+ /**
+ * generic_handle_irq_safe - Invoke the handler for a HW irq belonging
+ *			     to a domain from any context.
+ * @domain:	The domain where to perform the lookup
+ * @hwirq:	The HW irq number to convert to a logical one
+ *
+ * Returns:	0 on success, a negative value on error.
+ *
+ * This function can be called from any context (IRQ or process context). It
+ * will report an error if not invoked from IRQ context and the irq has been
+ * marked to enforce IRQ-context only.
+ */
+int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int hwirq)
+{
+	unsigned long flags;
+	int ret;
+
+	local_irq_save(flags);
+	ret = handle_irq_desc(irq_resolve_mapping(domain, hwirq));
+	local_irq_restore(flags);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(generic_handle_domain_irq_safe);
+
 /**
  * generic_handle_domain_nmi - Invoke the handler for a HW nmi belonging
  *                             to a domain.
-- 
2.36.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe().
  2022-05-09 14:04 [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe() Sebastian Andrzej Siewior
@ 2022-05-16 10:18 ` Lukas Wunner
  2022-05-16 11:23   ` Sebastian Andrzej Siewior
  2022-09-19 13:25 ` [tip: irq/core] bcma: gpio: Use generic_handle_irq_safe() tip-bot2 for Sebastian Andrzej Siewior
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Lukas Wunner @ 2022-05-16 10:18 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-kernel, Thomas Gleixner, Bartosz Golaszewski,
	Basavaraj Natikar, Hans de Goede, Linus Walleij, Mark Gross,
	Michael Buesch, Rafa?? Mi??ecki, Shyam Sundar S K, linux-gpio,
	linux-wireless, platform-driver-x86

On Mon, May 09, 2022 at 04:04:08PM +0200, Sebastian Andrzej Siewior wrote:
> The problem with generic_handle_domain_irq() is that with `threadirqs'
> it will trigger "WARN_ON_ONCE(!in_hardirq())".

Now silenced by:
https://git.kernel.org/linus/792ea6a074ae


> +int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int hwirq)
> +{
> +	unsigned long flags;
> +	int ret;
> +
> +	local_irq_save(flags);
> +	ret = handle_irq_desc(irq_resolve_mapping(domain, hwirq));
> +	local_irq_restore(flags);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(generic_handle_domain_irq_safe);

AFAICS you don't need to disable hardirqs at least for the "threadirqs"
case because irq_forced_thread_fn() already does that.


>  drivers/bcma/driver_gpio.c                 |  2 +-
>  drivers/gpio/gpio-mlxbf2.c                 |  6 ++----
>  drivers/pinctrl/pinctrl-amd.c              |  2 +-
>  drivers/platform/x86/intel/int0002_vgpio.c |  3 +--
>  drivers/ssb/driver_gpio.c                  |  6 ++++--

From a quick look, the proper solution for all of those drivers is
probably to just add IRQF_NO_THREAD and be done with it.

Thanks,

Lukas

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe().
  2022-05-16 10:18 ` Lukas Wunner
@ 2022-05-16 11:23   ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-05-16 11:23 UTC (permalink / raw)
  To: Lukas Wunner
  Cc: linux-kernel, Thomas Gleixner, Bartosz Golaszewski,
	Basavaraj Natikar, Hans de Goede, Linus Walleij, Mark Gross,
	Michael Buesch, Rafa?? Mi??ecki, Shyam Sundar S K, linux-gpio,
	linux-wireless, platform-driver-x86

On 2022-05-16 12:18:14 [+0200], Lukas Wunner wrote:
> On Mon, May 09, 2022 at 04:04:08PM +0200, Sebastian Andrzej Siewior wrote:
> > The problem with generic_handle_domain_irq() is that with `threadirqs'
> > it will trigger "WARN_ON_ONCE(!in_hardirq())".
> 
> Now silenced by:
> https://git.kernel.org/linus/792ea6a074ae
> 
> 
> > +int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int hwirq)
> > +{
> > +	unsigned long flags;
> > +	int ret;
> > +
> > +	local_irq_save(flags);
> > +	ret = handle_irq_desc(irq_resolve_mapping(domain, hwirq));
> > +	local_irq_restore(flags);
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(generic_handle_domain_irq_safe);
> 
> AFAICS you don't need to disable hardirqs at least for the "threadirqs"
> case because irq_forced_thread_fn() already does that.

PREEMPT_RT does not disable interrupts. Also completions in softirq
won't disable interrupts.

> 
> >  drivers/bcma/driver_gpio.c                 |  2 +-
> >  drivers/gpio/gpio-mlxbf2.c                 |  6 ++----
> >  drivers/pinctrl/pinctrl-amd.c              |  2 +-
> >  drivers/platform/x86/intel/int0002_vgpio.c |  3 +--
> >  drivers/ssb/driver_gpio.c                  |  6 ++++--
> 
> From a quick look, the proper solution for all of those drivers is
> probably to just add IRQF_NO_THREAD and be done with it.

I think I mentioned that part in the commit description: IRQF_NO_THREAD
must be specified by all handlers of a shared interrupt. It is an option
for the handler that owns an interrupt exclusive.

> Thanks,
> 
> Lukas

Sebastian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip: irq/core] bcma: gpio: Use generic_handle_irq_safe()
  2022-05-09 14:04 [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe() Sebastian Andrzej Siewior
  2022-05-16 10:18 ` Lukas Wunner
@ 2022-09-19 13:25 ` tip-bot2 for Sebastian Andrzej Siewior
  2022-09-19 13:25 ` [tip: irq/core] gpio: mlxbf2: " tip-bot2 for Sebastian Andrzej Siewior
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2022-09-19 13:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Thomas Gleixner, x86, linux-kernel, maz

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     94ec234a16cf3acdb319f05917b1efec9642222e
Gitweb:        https://git.kernel.org/tip/94ec234a16cf3acdb319f05917b1efec9642222e
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Mon, 19 Sep 2022 14:46:16 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 19 Sep 2022 15:08:39 +02:00

bcma: gpio: Use generic_handle_irq_safe()

On PREEMPT_RT enabled kernels the demultiplex interrupt handler is force
threaded and runs with interrupts enabled. The invocation of
generic_handle_irq() with interrupts enabled triggers a lockdep warning due
to a non-irq safe lock acquisition.

Instead of disabling interrupts on the driver level, use
generic_handle_domain_irq_safe().

[ tglx: Split out from combo patch ]

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/YnkfWFzvusFFktSt@linutronix.de
---
 drivers/bcma/driver_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/bcma/driver_gpio.c b/drivers/bcma/driver_gpio.c
index fac8ff9..65fb9ba 100644
--- a/drivers/bcma/driver_gpio.c
+++ b/drivers/bcma/driver_gpio.c
@@ -115,7 +115,7 @@ static irqreturn_t bcma_gpio_irq_handler(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	for_each_set_bit(gpio, &irqs, gc->ngpio)
-		generic_handle_irq(irq_find_mapping(gc->irq.domain, gpio));
+		generic_handle_domain_irq_safe(gc->irq.domain, gpio);
 	bcma_chipco_gpio_polarity(cc, irqs, val & irqs);
 
 	return IRQ_HANDLED;

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: irq/core] gpio: mlxbf2: Use generic_handle_irq_safe()
  2022-05-09 14:04 [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe() Sebastian Andrzej Siewior
  2022-05-16 10:18 ` Lukas Wunner
  2022-09-19 13:25 ` [tip: irq/core] bcma: gpio: Use generic_handle_irq_safe() tip-bot2 for Sebastian Andrzej Siewior
@ 2022-09-19 13:25 ` tip-bot2 for Sebastian Andrzej Siewior
  2022-09-19 13:25 ` [tip: irq/core] platform/x86: intel_int0002_vgpio: " tip-bot2 for Sebastian Andrzej Siewior
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2022-09-19 13:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Thomas Gleixner, x86, linux-kernel, maz

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     118c3ba24d04f084eadd9d4a0ab7830f495e9106
Gitweb:        https://git.kernel.org/tip/118c3ba24d04f084eadd9d4a0ab7830f495e9106
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Mon, 19 Sep 2022 14:45:18 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 19 Sep 2022 15:08:38 +02:00

gpio: mlxbf2: Use generic_handle_irq_safe()

On PREEMPT_RT enabled kernels the demultiplex interrupt handler is force
threaded and runs with interrupts enabled. The invocation of
generic_handle_irq() with interrupts enabled triggers a lockdep warning due
to a non-irq safe lock acquisition.

Instead of disabling interrupts on the driver level, use
generic_handle_domain_irq_safe().

[ tglx: Split out from combo patch ]

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/YnkfWFzvusFFktSt@linutronix.de
---
 drivers/gpio/gpio-mlxbf2.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-mlxbf2.c b/drivers/gpio/gpio-mlxbf2.c
index 64cb060..77a4115 100644
--- a/drivers/gpio/gpio-mlxbf2.c
+++ b/drivers/gpio/gpio-mlxbf2.c
@@ -273,10 +273,8 @@ static irqreturn_t mlxbf2_gpio_irq_handler(int irq, void *ptr)
 	pending = readl(gs->gpio_io + YU_GPIO_CAUSE_OR_CAUSE_EVTEN0);
 	writel(pending, gs->gpio_io + YU_GPIO_CAUSE_OR_CLRCAUSE);
 
-	for_each_set_bit(level, &pending, gc->ngpio) {
-		int gpio_irq = irq_find_mapping(gc->irq.domain, level);
-		generic_handle_irq(gpio_irq);
-	}
+	for_each_set_bit(level, &pending, gc->ngpio)
+		generic_handle_domain_irq_safe(gc->irq.domain, level);
 
 	return IRQ_RETVAL(pending);
 }

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: irq/core] platform/x86: intel_int0002_vgpio: Use generic_handle_irq_safe()
  2022-05-09 14:04 [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe() Sebastian Andrzej Siewior
                   ` (2 preceding siblings ...)
  2022-09-19 13:25 ` [tip: irq/core] gpio: mlxbf2: " tip-bot2 for Sebastian Andrzej Siewior
@ 2022-09-19 13:25 ` tip-bot2 for Sebastian Andrzej Siewior
  2022-09-19 13:25 ` [tip: irq/core] ssb: gpio: " tip-bot2 for Sebastian Andrzej Siewior
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2022-09-19 13:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Thomas Gleixner, x86, linux-kernel, maz

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     c6a91405ac5cd5baa03fea061e11b05788223160
Gitweb:        https://git.kernel.org/tip/c6a91405ac5cd5baa03fea061e11b05788223160
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Mon, 19 Sep 2022 14:44:28 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 19 Sep 2022 15:08:38 +02:00

platform/x86: intel_int0002_vgpio: Use generic_handle_irq_safe()

On PREEMPT_RT enabled kernels the demultiplex interrupt handler is force
threaded and runs with interrupts enabled. The invocation of
generic_handle_irq() with interrupts enabled triggers a lockdep warning due
to a non-irq safe lock acquisition.

Instead of disabling interrupts on the driver level, use
generic_handle_domain_irq_safe().

[ tglx: Split out from combo patch ]

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/YnkfWFzvusFFktSt@linutronix.de
---
 drivers/platform/x86/intel/int0002_vgpio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/platform/x86/intel/int0002_vgpio.c b/drivers/platform/x86/intel/int0002_vgpio.c
index 617dbf9..97cfbc5 100644
--- a/drivers/platform/x86/intel/int0002_vgpio.c
+++ b/drivers/platform/x86/intel/int0002_vgpio.c
@@ -125,8 +125,7 @@ static irqreturn_t int0002_irq(int irq, void *data)
 	if (!(gpe_sts_reg & GPE0A_PME_B0_STS_BIT))
 		return IRQ_NONE;
 
-	generic_handle_irq(irq_find_mapping(chip->irq.domain,
-					    GPE0A_PME_B0_VIRT_GPIO_PIN));
+	generic_handle_domain_irq_safe(chip->irq.domain, GPE0A_PME_B0_VIRT_GPIO_PIN);
 
 	pm_wakeup_hard_event(chip->parent);
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: irq/core] ssb: gpio: Use generic_handle_irq_safe()
  2022-05-09 14:04 [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe() Sebastian Andrzej Siewior
                   ` (3 preceding siblings ...)
  2022-09-19 13:25 ` [tip: irq/core] platform/x86: intel_int0002_vgpio: " tip-bot2 for Sebastian Andrzej Siewior
@ 2022-09-19 13:25 ` tip-bot2 for Sebastian Andrzej Siewior
  2022-09-19 13:25 ` [tip: irq/core] pinctrl: amd: " tip-bot2 for Sebastian Andrzej Siewior
  2022-09-19 13:25 ` [tip: irq/core] genirq: Provide generic_handle_domain_irq_safe() tip-bot2 for Sebastian Andrzej Siewior
  6 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2022-09-19 13:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Thomas Gleixner, x86, linux-kernel, maz

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     f285de79569f9e674816a67308316206e4eb30ee
Gitweb:        https://git.kernel.org/tip/f285de79569f9e674816a67308316206e4eb30ee
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Mon, 19 Sep 2022 14:43:46 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 19 Sep 2022 15:08:38 +02:00

ssb: gpio: Use generic_handle_irq_safe()

On PREEMPT_RT enabled kernels the demultiplex interrupt handler is force
threaded and runs with interrupts enabled. The invocation of
generic_handle_domain_irq() with interrupts enabled triggers a lockdep
warning due to a non-irq safe lock acquisition.

Instead of disabling interrupts on the driver level, use
generic_handle_domain_irq_safe().

[ tglx: Split out from combo patch ]

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/YnkfWFzvusFFktSt@linutronix.de
---
 drivers/ssb/driver_gpio.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/ssb/driver_gpio.c b/drivers/ssb/driver_gpio.c
index 2de3896..897cb8d 100644
--- a/drivers/ssb/driver_gpio.c
+++ b/drivers/ssb/driver_gpio.c
@@ -132,7 +132,8 @@ static irqreturn_t ssb_gpio_irq_chipco_handler(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	for_each_set_bit(gpio, &irqs, bus->gpio.ngpio)
-		generic_handle_irq(ssb_gpio_to_irq(&bus->gpio, gpio));
+		generic_handle_domain_irq_safe(bus->irq_domain, gpio);
+
 	ssb_chipco_gpio_polarity(chipco, irqs, val & irqs);
 
 	return IRQ_HANDLED;
@@ -330,7 +331,8 @@ static irqreturn_t ssb_gpio_irq_extif_handler(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	for_each_set_bit(gpio, &irqs, bus->gpio.ngpio)
-		generic_handle_irq(ssb_gpio_to_irq(&bus->gpio, gpio));
+		generic_handle_domain_irq_safe(bus->irq_domain, gpio);
+
 	ssb_extif_gpio_polarity(extif, irqs, val & irqs);
 
 	return IRQ_HANDLED;

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: irq/core] pinctrl: amd: Use generic_handle_irq_safe()
  2022-05-09 14:04 [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe() Sebastian Andrzej Siewior
                   ` (4 preceding siblings ...)
  2022-09-19 13:25 ` [tip: irq/core] ssb: gpio: " tip-bot2 for Sebastian Andrzej Siewior
@ 2022-09-19 13:25 ` tip-bot2 for Sebastian Andrzej Siewior
  2022-09-19 13:25 ` [tip: irq/core] genirq: Provide generic_handle_domain_irq_safe() tip-bot2 for Sebastian Andrzej Siewior
  6 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2022-09-19 13:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Thomas Gleixner, x86, linux-kernel, maz

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     f460c70125bcb1b753f152d9d0c9cee3ddbc2d91
Gitweb:        https://git.kernel.org/tip/f460c70125bcb1b753f152d9d0c9cee3ddbc2d91
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Mon, 19 Sep 2022 14:42:54 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 19 Sep 2022 15:08:38 +02:00

pinctrl: amd: Use generic_handle_irq_safe()

On PREEMPT_RT enabled kernels the demultiplex interrupt handler is force
threaded and runs with interrupts enabled. The invocation of
generic_handle_domain_irq() with interrupts enabled triggers a lockdep
warning due to a non-irq safe lock acquisition.

Instead of disabling interrupts on the driver level, use
generic_handle_domain_irq_safe().

[ tglx: Split out from combo patch ]

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/YnkfWFzvusFFktSt@linutronix.de
Link: https://bugzilla.kernel.org/show_bug.cgi?id=215954
---
 drivers/pinctrl/pinctrl-amd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 4691a33..4ed2b4b 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -639,7 +639,7 @@ static bool do_amd_gpio_irq_handler(int irq, void *dev_id)
 			if (!(regval & PIN_IRQ_PENDING) ||
 			    !(regval & BIT(INTERRUPT_MASK_OFF)))
 				continue;
-			generic_handle_domain_irq(gc->irq.domain, irqnr + i);
+			generic_handle_domain_irq_safe(gc->irq.domain, irqnr + i);
 
 			/* Clear interrupt.
 			 * We must read the pin register again, in case the

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: irq/core] genirq: Provide generic_handle_domain_irq_safe().
  2022-05-09 14:04 [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe() Sebastian Andrzej Siewior
                   ` (5 preceding siblings ...)
  2022-09-19 13:25 ` [tip: irq/core] pinctrl: amd: " tip-bot2 for Sebastian Andrzej Siewior
@ 2022-09-19 13:25 ` tip-bot2 for Sebastian Andrzej Siewior
  6 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2022-09-19 13:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Thomas Gleixner, x86, linux-kernel, maz

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     6a164c646999847b843e651f71c53dfaceb2c2b4
Gitweb:        https://git.kernel.org/tip/6a164c646999847b843e651f71c53dfaceb2c2b4
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Mon, 09 May 2022 16:04:08 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 19 Sep 2022 15:08:38 +02:00

genirq: Provide generic_handle_domain_irq_safe().

commit 509853f9e1e7b ("genirq: Provide generic_handle_irq_safe()")
addressed the problem of demultiplexing interrupt handlers which are force
threaded on PREEMPT_RT enabled kernels which means that the demultiplexed
handler is invoked with interrupts enabled which triggers a lockdep
warning due to a non-irq safe lock acquisition.

The same problem exists for the irq domain based interrupt handling via
generic_handle_domain_irq() which has been reported against the AMD
pin-ctrl driver.

Provide generic_handle_domain_irq_safe() which can used from any context.

[ tglx: Split the usage sites out and massaged changelog ]

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/YnkfWFzvusFFktSt@linutronix.de
Link: https://bugzilla.kernel.org/show_bug.cgi?id=215954
---
 include/linux/irqdesc.h |  1 +
 kernel/irq/irqdesc.c    | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index 1cd4e36..844a8e3 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -169,6 +169,7 @@ int generic_handle_irq_safe(unsigned int irq);
  * conversion failed.
  */
 int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwirq);
+int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int hwirq);
 int generic_handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq);
 #endif
 
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 5db0230..a91f900 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -705,6 +705,30 @@ int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwirq)
 }
 EXPORT_SYMBOL_GPL(generic_handle_domain_irq);
 
+ /**
+ * generic_handle_irq_safe - Invoke the handler for a HW irq belonging
+ *			     to a domain from any context.
+ * @domain:	The domain where to perform the lookup
+ * @hwirq:	The HW irq number to convert to a logical one
+ *
+ * Returns:	0 on success, a negative value on error.
+ *
+ * This function can be called from any context (IRQ or process
+ * context). If the interrupt is marked as 'enforce IRQ-context only' then
+ * the function must be invoked from hard interrupt context.
+ */
+int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int hwirq)
+{
+	unsigned long flags;
+	int ret;
+
+	local_irq_save(flags);
+	ret = handle_irq_desc(irq_resolve_mapping(domain, hwirq));
+	local_irq_restore(flags);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(generic_handle_domain_irq_safe);
+
 /**
  * generic_handle_domain_nmi - Invoke the handler for a HW nmi belonging
  *                             to a domain.

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-09-19 13:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 14:04 [RFC PATCH] genirq: Provide generic_handle_domain_irq_safe() Sebastian Andrzej Siewior
2022-05-16 10:18 ` Lukas Wunner
2022-05-16 11:23   ` Sebastian Andrzej Siewior
2022-09-19 13:25 ` [tip: irq/core] bcma: gpio: Use generic_handle_irq_safe() tip-bot2 for Sebastian Andrzej Siewior
2022-09-19 13:25 ` [tip: irq/core] gpio: mlxbf2: " tip-bot2 for Sebastian Andrzej Siewior
2022-09-19 13:25 ` [tip: irq/core] platform/x86: intel_int0002_vgpio: " tip-bot2 for Sebastian Andrzej Siewior
2022-09-19 13:25 ` [tip: irq/core] ssb: gpio: " tip-bot2 for Sebastian Andrzej Siewior
2022-09-19 13:25 ` [tip: irq/core] pinctrl: amd: " tip-bot2 for Sebastian Andrzej Siewior
2022-09-19 13:25 ` [tip: irq/core] genirq: Provide generic_handle_domain_irq_safe() tip-bot2 for Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).