This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM5728: omap gpio driver does not lock pin for irq use on linux kernel 5.10.168

Part Number: AM5728

Hello,

I recently encouter a set of warning messages from libgpio that complains gpio pin is lock as irq when using as irq pin.

Jun 26 14:06:43 localhost kernel: [   36.071899] ------------[ cut here ]------------
Jun 26 14:06:43 localhost kernel: [   36.071899] WARNING: CPU: 0 PID: 855 at drivers/gpio/gpiolib.c:3335 cm_ic_cascade_irq1+0x70/0x80
Jun 26 14:06:43 localhost kernel: [   36.071929] Modules linked in: rcksapi_common(OE) sch_tbf(E) rcksapi_layer2(OE) rcksapi(OE) br_netfilter(E) bridge(E) stp(E) llc(E) iptable_nat(E) ip_tables(E) nf_nat(E) nf_conntrack(E) nf_defrag_ipv6(E) nf_defrag_ipv4(E) x_tables(E) dummy(E) xhci_plat_hcd(E) xhci_hcd(E) irq_pruss_intc(E) dwc3(E) prueth(E) pru_rproc(E) hsr(E) icss_iep(E) ptp(E) pruss(E) dwc3_omap(E) lm75(E) uio_pdrv_genirq(E) configfs(E)
Jun 26 14:06:43 localhost kernel: [   36.072143] CPU: 0 PID: 855 Comm: irq/117-4805500 Tainted: G           OE     5.10-rox2 #1
Jun 26 14:06:43 localhost kernel: [   36.072143] Hardware name: Generic DRA74X (Flattened Device Tree)
Jun 26 14:06:43 localhost kernel: [   36.072143] [<c0210424>] (unwind_backtrace) from [<c020b9b0>] (show_stack+0x10/0x14)
Jun 26 14:06:43 localhost kernel: [   36.072174] [<c020b9b0>] (show_stack) from [<c0997950>] (dump_stack+0x88/0x9c)
Jun 26 14:06:43 localhost kernel: [   36.072204] [<c0997950>] (dump_stack) from [<c02380f0>] (__warn+0x88/0xe4)
Jun 26 14:06:43 localhost kernel: [   36.072204] [<c02380f0>] (__warn) from [<c0994c10>] (warn_slowpath_fmt+0x68/0x7c)
Jun 26 14:06:43 localhost kernel: [   36.072235] [<c0994c10>] (warn_slowpath_fmt) from [<c07e2218>] (cm_ic_cascade_irq1+0x70/0x80)
Jun 26 14:06:43 localhost kernel: [   36.072265] [<c07e2218>] (cm_ic_cascade_irq1) from [<c028f3dc>] (generic_handle_irq+0x34/0x44)
Jun 26 14:06:43 localhost kernel: [   36.072265] [<c028f3dc>] (generic_handle_irq) from [<c05f9698>] (omap_gpio_irq_handler+0xd4/0x1a0)
Jun 26 14:06:43 localhost kernel: [   36.072296] [<c05f9698>] (omap_gpio_irq_handler) from [<c0290f68>] (irq_forced_thread_fn+0x28/0x9c)
Jun 26 14:06:43 localhost kernel: [   36.072296] [<c0290f68>] (irq_forced_thread_fn) from [<c0291380>] (irq_thread+0x180/0x230)
Jun 26 14:06:43 localhost kernel: [   36.072326] [<c0291380>] (irq_thread) from [<c025ac30>] (kthread+0x198/0x1bc)
Jun 26 14:06:43 localhost kernel: [   36.072326] [<c025ac30>] (kthread) from [<c0200138>] (ret_from_fork+0x14/0x3c)
Jun 26 14:06:43 localhost kernel: [   36.072357] Exception stack(0xc1fa1fb0 to 0xc1fa1ff8)
Jun 26 14:06:43 localhost kernel: [   36.072357] 1fa0:                                     00000000 00000000 00000000 00000000
Jun 26 14:06:43 localhost kernel: [   36.072357] 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Jun 26 14:06:43 localhost kernel: [   36.072387] 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000
Jun 26 14:06:43 localhost kernel: [   36.072387] ---[ end trace 0000000000000002 ]---
Jun 26 14:06:43 localhost kernel: [   37.107727] ------------[ cut here ]------------
Jun 26 14:06:43 localhost kernel: [   37.107757] WARNING: CPU: 0 PID: 855 at drivers/gpio/gpiolib.c:3345 gpiochip_irq_unmask+0x18/0x30
Jun 26 14:06:43 localhost kernel: [   37.107788] Modules linked in: rcksapi_common(OE) sch_tbf(E) rcksapi_layer2(OE) rcksapi(OE) br_netfilter(E) bridge(E) stp(E) llc(E) iptable_nat(E) ip_tables(E) nf_nat(E) nf_conntrack(E) nf_defrag_ipv6(E) nf_defrag_ipv4(E) x_tables(E) dummy(E) xhci_plat_hcd(E) xhci_hcd(E) irq_pruss_intc(E) dwc3(E) prueth(E) pru_rproc(E) hsr(E) icss_iep(E) ptp(E) pruss(E) dwc3_omap(E) lm75(E) uio_pdrv_genirq(E) configfs(E)
Jun 26 14:06:43 localhost kernel: [   37.107910] CPU: 0 PID: 855 Comm: irq/117-4805500 Tainted: G        W  OE     5.10-rox2 #1
Jun 26 14:06:43 localhost kernel: [   37.107910] Hardware name: Generic DRA74X (Flattened Device Tree)
Jun 26 14:06:43 localhost kernel: [   37.107910] [<c0210424>] (unwind_backtrace) from [<c020b9b0>] (show_stack+0x10/0x14)
Jun 26 14:06:43 localhost kernel: [   37.107940] [<c020b9b0>] (show_stack) from [<c0997950>] (dump_stack+0x88/0x9c)
Jun 26 14:06:43 localhost kernel: [   37.107971] [<c0997950>] (dump_stack) from [<c02380f0>] (__warn+0x88/0xe4)
Jun 26 14:06:43 localhost kernel: [   37.107971] [<c02380f0>] (__warn) from [<c0994c10>] (warn_slowpath_fmt+0x68/0x7c)
Jun 26 14:06:43 localhost kernel: [   37.108001] [<c0994c10>] (warn_slowpath_fmt) from [<c05ef54c>] (gpiochip_irq_unmask+0x18/0x30)
Jun 26 14:06:43 localhost kernel: [   37.108001] [<c05ef54c>] (gpiochip_irq_unmask) from [<c028f3dc>] (generic_handle_irq+0x34/0x44)
Jun 26 14:06:43 localhost kernel: [   37.108032] [<c028f3dc>] (generic_handle_irq) from [<c05f9698>] (omap_gpio_irq_handler+0xd4/0x1a0)
Jun 26 14:06:43 localhost kernel: [   37.108032] [<c05f9698>] (omap_gpio_irq_handler) from [<c0290f68>] (irq_forced_thread_fn+0x28/0x9c)
Jun 26 14:06:43 localhost kernel: [   37.108062] [<c0290f68>] (irq_forced_thread_fn) from [<c0291380>] (irq_thread+0x180/0x230)
Jun 26 14:06:43 localhost kernel: [   37.108062] [<c0291380>] (irq_thread) from [<c025ac30>] (kthread+0x198/0x1bc)
Jun 26 14:06:43 localhost kernel: [   37.108093] [<c025ac30>] (kthread) from [<c0200138>] (ret_from_fork+0x14/0x3c)
Jun 26 14:06:43 localhost kernel: [   37.108093] Exception stack(0xc1fa1fb0 to 0xc1fa1ff8)
Jun 26 14:06:43 localhost kernel: [   37.108093] 1fa0:                                     00000000 00000000 00000000 00000000
Jun 26 14:06:43 localhost kernel: [   37.108093] 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Jun 26 14:06:43 localhost kernel: [   37.108123] 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000
Jun 26 14:06:43 localhost kernel: [   37.108123] ---[ end trace 0000000000000003 ]---
Those pins are mapped as interrupts in out dts as:
interrupts-extended = <
            &gpio2 7 IRQ_TYPE_LEVEL_LOW
            &gpio2 8 IRQ_TYPE_LEVEL_LOW
            &gpio7 12 IRQ_TYPE_LEVEL_LOW
            &gpio7 6 IRQ_TYPE_LEVEL_LOW
            &gpio7 5 IRQ_TYPE_LEVEL_LOW
        >;
And mapped in our custom kernel module using code like:
cm_ic->virq_0 = irq_of_parse_and_map(node, 0);
irq_set_handler_data(cm_ic->virq_0, cm_ic);
irq_set_chained_handler(cm_ic->virq_0, cm_ic_cascade_irq0);
Inside gpiolib.c the code is checking FLAG_USED_AS_IRQ everytime gpiochip_disable_irq and gpiochip_enable_irq is called.
However inside gpio-map.c when setting up gpio pin as interrupt, no gpiolib api is called to set FLAG_USED_AS_IRQ.
I think this is a bug inside gpio-omap.c code. And I wonder if you guys have a patch to fix this?


  • Hello Hao,

    I will look into this and I will get back to you by next week at the latest.

    Josue

  • Hello Hao,

    Can you share some more information about your custom kernel module? The code you share does not give very much context.

    Have you checked that the GPIOs are also not being used for anything else?

    We do not have a patch for this.

    -Josue

  • Hi Josue,

    I cannot share more about our custom kernel module. We do no have this GPIO setup for any other use.

  • I have made a small patch that can get rid of this warning on gpio-omap.c. Can you guys take a look see if it is safe?

    From b799e4e5fa8bdab97072c3e8bb3713c434c0cfa8 Mon Sep 17 00:00:00 2001
    From: Hao Zhang <hzzhang.hao@siemens.com>
    Date: Tue, 8 Aug 2023 09:41:36 -0400
    Subject: [PATCH] P93403: fixing omap gpio lock irq

    need to lock gpiochip irq.

    Change-Id: I5c6baa6dfab1f5df4ca15034f4dd0960daecbfa5
    ---
     drivers/gpio/gpio-omap.c | 4 ++++
     1 file changed, 4 insertions(+)

    diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
    index 56152263ab38..957e878a25d8 100644
    --- a/drivers/gpio/gpio-omap.c
    +++ b/drivers/gpio/gpio-omap.c
    @@ -625,6 +625,7 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank)
     static unsigned int omap_gpio_irq_startup(struct irq_data *d)
     {
        struct gpio_bank *bank = omap_irq_data_get_bank(d);
    +   struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
        unsigned long flags;
        unsigned offset = d->hwirq;
     
    @@ -636,6 +637,7 @@ static unsigned int omap_gpio_irq_startup(struct irq_data *d)
        bank->irq_usage |= BIT(offset);
     
        raw_spin_unlock_irqrestore(&bank->lock, flags);
    +   gpiochip_lock_as_irq(chip, offset);
        omap_gpio_unmask_irq(d);
     
        return 0;
    @@ -644,6 +646,7 @@ static unsigned int omap_gpio_irq_startup(struct irq_data *d)
     static void omap_gpio_irq_shutdown(struct irq_data *d)
     {
        struct gpio_bank *bank = omap_irq_data_get_bank(d);
    +   struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
        unsigned long flags;
        unsigned offset = d->hwirq;
     
    @@ -656,6 +659,7 @@ static void omap_gpio_irq_shutdown(struct irq_data *d)
            omap_clear_gpio_debounce(bank, offset);
        omap_disable_gpio_module(bank, offset);
        raw_spin_unlock_irqrestore(&bank->lock, flags);
    +   gpiochip_unlock_as_irq(chip, offset);
     }
     
     static void omap_gpio_irq_bus_lock(struct irq_data *data)
    --
    2.20.1
  • Hello Hao,

    It doesn't look like it would be unsafe. Have you tried running it?

    I am in the process of porting it.

    Do you see any errors?

    Would you be ok posting this upstream for feedback?

    -Josue

  • Hi Josue, I have been running this code locally. I haven't see any error so far. I am fine with posting this upstream.

  • Hao,

    I have not yet managed to get this running on a TI EVM.

    Does your patch solve your issue?

    -Josue

  • it seems to be working so far