The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] gpio: dwapb: Add robust error handling in interrupt handler
@ 2026-07-03 13:48 Liang Hao
  2026-07-03 21:21 ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Liang Hao @ 2026-07-03 13:48 UTC (permalink / raw)
  To: hoan, linusw, brgl; +Cc: linux-gpio, linux-kernel, Liang Hao

The current interrupt handler silently continues if an interrupt
handling fails, which may lead to interrupt storms. Add proper
error handling to gracefully recover from failed interrupt
handling.

When generic_handle_irq() fails, the following recovery actions are
taken:
  - Write EOI to clear the pending interrupt
  - Mask the interrupt to prevent immediate re-triggering
  - Disable the interrupt to stop further interrupts on this line

These measures prevent the system from being overwhelmed by repeated
unhandled interrupts while logging a rate-limited warning for
debugging purposes.

Signed-off-by: Liang Hao <haohlliang@gmail.com>
---
 drivers/gpio/gpio-dwapb.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 7b92b233fafe..dec700e3cfb0 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -209,8 +209,20 @@ static u32 dwapb_do_irq(struct dwapb_gpio *gpio)
 	for_each_set_bit(hwirq, &irq_status, DWAPB_MAX_GPIOS) {
 		int gpio_irq = irq_find_mapping(gen_gc->gc.irq.domain, hwirq);
 		u32 irq_type = irq_get_trigger_type(gpio_irq);
-
-		generic_handle_irq(gpio_irq);
+		int ret;
+		u32 val_intmask, val_inten;
+
+		ret = generic_handle_irq(gpio_irq);
+		if (ret) {
+			dev_warn_ratelimited(gpio->dev, "Failed to handle irq %d\n", gpio_irq);
+			/* Clear the interrupt */
+			dwapb_write(gpio, GPIO_PORTA_EOI, BIT(hwirq));
+			val_intmask = dwapb_read(gpio, GPIO_INTMASK);
+			dwapb_write(gpio, GPIO_INTMASK, val_intmask | BIT(hwirq));
+			val_inten = dwapb_read(gpio, GPIO_INTEN);
+			dwapb_write(gpio, GPIO_INTEN, val_inten & ~BIT(hwirq));
+			continue;
+		}
 
 		if ((irq_type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
 			dwapb_toggle_trigger(gpio, hwirq);
-- 
2.50.1 (Apple Git-155)


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

* Re: [PATCH] gpio: dwapb: Add robust error handling in interrupt handler
  2026-07-03 13:48 [PATCH] gpio: dwapb: Add robust error handling in interrupt handler Liang Hao
@ 2026-07-03 21:21 ` Linus Walleij
  2026-07-03 21:40   ` Thomas Gleixner
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2026-07-03 21:21 UTC (permalink / raw)
  To: Liang Hao, Thomas Gleixner; +Cc: hoan, brgl, linux-gpio, linux-kernel

Hi Liang,

thanks for your patch!

Top posting so tglx get the context...

On Fri, Jul 3, 2026 at 3:49 PM Liang Hao <haohlliang@gmail.com> wrote:

> The current interrupt handler silently continues if an interrupt
> handling fails, which may lead to interrupt storms. Add proper
> error handling to gracefully recover from failed interrupt
> handling.
>
> When generic_handle_irq() fails, the following recovery actions are
> taken:
>   - Write EOI to clear the pending interrupt
>   - Mask the interrupt to prevent immediate re-triggering
>   - Disable the interrupt to stop further interrupts on this line
>
> These measures prevent the system from being overwhelmed by repeated
> unhandled interrupts while logging a rate-limited warning for
> debugging purposes.
>
> Signed-off-by: Liang Hao <haohlliang@gmail.com>
> ---
>  drivers/gpio/gpio-dwapb.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
> index 7b92b233fafe..dec700e3cfb0 100644
> --- a/drivers/gpio/gpio-dwapb.c
> +++ b/drivers/gpio/gpio-dwapb.c
> @@ -209,8 +209,20 @@ static u32 dwapb_do_irq(struct dwapb_gpio *gpio)
>         for_each_set_bit(hwirq, &irq_status, DWAPB_MAX_GPIOS) {
>                 int gpio_irq = irq_find_mapping(gen_gc->gc.irq.domain, hwirq);
>                 u32 irq_type = irq_get_trigger_type(gpio_irq);
> -
> -               generic_handle_irq(gpio_irq);
> +               int ret;
> +               u32 val_intmask, val_inten;
> +
> +               ret = generic_handle_irq(gpio_irq);
> +               if (ret) {
> +                       dev_warn_ratelimited(gpio->dev, "Failed to handle irq %d\n", gpio_irq);
> +                       /* Clear the interrupt */
> +                       dwapb_write(gpio, GPIO_PORTA_EOI, BIT(hwirq));
> +                       val_intmask = dwapb_read(gpio, GPIO_INTMASK);
> +                       dwapb_write(gpio, GPIO_INTMASK, val_intmask | BIT(hwirq));
> +                       val_inten = dwapb_read(gpio, GPIO_INTEN);
> +                       dwapb_write(gpio, GPIO_INTEN, val_inten & ~BIT(hwirq));
> +                       continue;
> +               }
>
>                 if ((irq_type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
>                         dwapb_toggle_trigger(gpio, hwirq);

Ugh I don't know if that is how you'r supposed to deal with the return value
from generic_handle_irq(), we better get tglx eyes on this.

Yours,
Linus Walleij

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

* Re: [PATCH] gpio: dwapb: Add robust error handling in interrupt handler
  2026-07-03 21:21 ` Linus Walleij
@ 2026-07-03 21:40   ` Thomas Gleixner
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2026-07-03 21:40 UTC (permalink / raw)
  To: Linus Walleij, Liang Hao; +Cc: hoan, brgl, linux-gpio, linux-kernel

On Fri, Jul 03 2026 at 23:21, Linus Walleij wrote:
> On Fri, Jul 3, 2026 at 3:49 PM Liang Hao <haohlliang@gmail.com> wrote:
>
>> The current interrupt handler silently continues if an interrupt
>> handling fails, which may lead to interrupt storms. Add proper
>> error handling to gracefully recover from failed interrupt
>> handling.
>>
>> When generic_handle_irq() fails, the following recovery actions are
>> taken:
>>   - Write EOI to clear the pending interrupt
>>   - Mask the interrupt to prevent immediate re-triggering
>>   - Disable the interrupt to stop further interrupts on this line

This completely fails to explain WHY generic_handle_irq() fails.

There are only two reasons for that:

      1) The interrupt descriptor is not available (EINVAL)

      2) The platform mandates that the interrupt has to be handled in
         hard interrupt context (EPERM). This also emits a warning.

There is also zero information whether the irq mapping lookup returns a
valid interrupt in this scenario, so it's hard to tell what's really
going on.

As there is no mention of the warning I assume that's #1. Which means
this is papering over some underlying problem in that driver. Looking at
the counter measures makes it entirely clear:

    EOI, mask, disable

If there is no interrupt descriptor then the driver failed to mask and
disable the interrupt line at some point.

So this is just a lazy debugging aid for something which is not supposed
to happen in a sane and production ready driver.

Thanks,

        tglx





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

end of thread, other threads:[~2026-07-03 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03 13:48 [PATCH] gpio: dwapb: Add robust error handling in interrupt handler Liang Hao
2026-07-03 21:21 ` Linus Walleij
2026-07-03 21:40   ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox