Message ID | 20240307112452.74220-1-claudiu.beznea.uj@bp.renesas.com |
---|---|
State | Superseded |
Headers | show |
Series | pinctrl: renesas: rzg2l: Execute atomically the interrupt configuration | expand |
Hi Claudiu, Thanks for your patch! On Thu, Mar 7, 2024 at 12:25 PM Claudiu <claudiu.beznea@tuxon.dev> wrote: > From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> > > Lockdep detects a possible deadlock as listed below. This is because it > detects the IA55 interrupt controller .irq_eoi() API is called from > interrupt context while configuration-specific API (e.g., .irq_enable()) > could be called from process context on resume path (by calling > rzg2l_gpio_irq_restore()). To avoid this, protect the call of > rzg2l_gpio_irq_enable() with spin_lock_irqsave()/spin_unlock_irqrestore(). > With this the same approach that is available in __setup_irq() is mimicked > to pinctrl IRQ resume function. You mean __setup_irq() in kernel/irq/manage.c? That one uses the raw spinlock methods? > --- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c > +++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c > @@ -2063,8 +2063,17 @@ static void rzg2l_gpio_irq_restore(struct rzg2l_pinctrl *pctrl) > continue; > } > > - if (!irqd_irq_disabled(data)) > + if (!irqd_irq_disabled(data)) { > + unsigned long flags; > + > + /* > + * This has to be atomically executed to protect against a concurrent > + * interrupt. > + */ > + spin_lock_irqsave(&pctrl->lock, flags); > rzg2l_gpio_irq_enable(data); > + spin_unlock_irqrestore(&pctrl->lock, flags); > + } > } > } Gr{oetje,eeting}s, Geert
Hi, Geert, On 14.03.2024 15:21, Geert Uytterhoeven wrote: > Hi Claudiu, > > Thanks for your patch! > > On Thu, Mar 7, 2024 at 12:25 PM Claudiu <claudiu.beznea@tuxon.dev> wrote: >> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> >> >> Lockdep detects a possible deadlock as listed below. This is because it >> detects the IA55 interrupt controller .irq_eoi() API is called from >> interrupt context while configuration-specific API (e.g., .irq_enable()) >> could be called from process context on resume path (by calling >> rzg2l_gpio_irq_restore()). To avoid this, protect the call of >> rzg2l_gpio_irq_enable() with spin_lock_irqsave()/spin_unlock_irqrestore(). >> With this the same approach that is available in __setup_irq() is mimicked >> to pinctrl IRQ resume function. > > You mean __setup_irq() in kernel/irq/manage.c? Yes! > That one uses the raw spinlock methods? Yes! Would you prefer to have raw spinlock here, too? Thank you, Claudiu Beznea > >> --- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c >> +++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c >> @@ -2063,8 +2063,17 @@ static void rzg2l_gpio_irq_restore(struct rzg2l_pinctrl *pctrl) >> continue; >> } >> >> - if (!irqd_irq_disabled(data)) >> + if (!irqd_irq_disabled(data)) { >> + unsigned long flags; >> + >> + /* >> + * This has to be atomically executed to protect against a concurrent >> + * interrupt. >> + */ >> + spin_lock_irqsave(&pctrl->lock, flags); >> rzg2l_gpio_irq_enable(data); >> + spin_unlock_irqrestore(&pctrl->lock, flags); >> + } >> } >> } > > Gr{oetje,eeting}s, > > Geert >
Hi Claudiu, On Thu, Mar 14, 2024 at 3:11 PM claudiu beznea <claudiu.beznea@tuxon.dev> wrote: > On 14.03.2024 15:21, Geert Uytterhoeven wrote: > > On Thu, Mar 7, 2024 at 12:25 PM Claudiu <claudiu.beznea@tuxon.dev> wrote: > >> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> > >> > >> Lockdep detects a possible deadlock as listed below. This is because it > >> detects the IA55 interrupt controller .irq_eoi() API is called from > >> interrupt context while configuration-specific API (e.g., .irq_enable()) > >> could be called from process context on resume path (by calling > >> rzg2l_gpio_irq_restore()). To avoid this, protect the call of > >> rzg2l_gpio_irq_enable() with spin_lock_irqsave()/spin_unlock_irqrestore(). > >> With this the same approach that is available in __setup_irq() is mimicked > >> to pinctrl IRQ resume function. > > > > You mean __setup_irq() in kernel/irq/manage.c? > > Yes! > > > That one uses the raw spinlock methods? > > Yes! Would you prefer to have raw spinlock here, too? Most pin control driver needing protection in an irq_enable method use raw spinlock, so I think it makes sense to follow that. Gr{oetje,eeting}s, Geert
On 14.03.2024 16:31, Geert Uytterhoeven wrote: > Hi Claudiu, > > On Thu, Mar 14, 2024 at 3:11 PM claudiu beznea <claudiu.beznea@tuxon.dev> wrote: >> On 14.03.2024 15:21, Geert Uytterhoeven wrote: >>> On Thu, Mar 7, 2024 at 12:25 PM Claudiu <claudiu.beznea@tuxon.dev> wrote: >>>> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> >>>> >>>> Lockdep detects a possible deadlock as listed below. This is because it >>>> detects the IA55 interrupt controller .irq_eoi() API is called from >>>> interrupt context while configuration-specific API (e.g., .irq_enable()) >>>> could be called from process context on resume path (by calling >>>> rzg2l_gpio_irq_restore()). To avoid this, protect the call of >>>> rzg2l_gpio_irq_enable() with spin_lock_irqsave()/spin_unlock_irqrestore(). >>>> With this the same approach that is available in __setup_irq() is mimicked >>>> to pinctrl IRQ resume function. >>> >>> You mean __setup_irq() in kernel/irq/manage.c? >> >> Yes! >> >>> That one uses the raw spinlock methods? >> >> Yes! Would you prefer to have raw spinlock here, too? > > Most pin control driver needing protection in an irq_enable > method use raw spinlock, so I think it makes sense to follow that. Ok, I'll update it, thanks! > > Gr{oetje,eeting}s, > > Geert >
diff --git a/drivers/pinctrl/renesas/pinctrl-rzg2l.c b/drivers/pinctrl/renesas/pinctrl-rzg2l.c index eb5a8c654260..76124b860c3f 100644 --- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c +++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c @@ -2063,8 +2063,17 @@ static void rzg2l_gpio_irq_restore(struct rzg2l_pinctrl *pctrl) continue; } - if (!irqd_irq_disabled(data)) + if (!irqd_irq_disabled(data)) { + unsigned long flags; + + /* + * This has to be atomically executed to protect against a concurrent + * interrupt. + */ + spin_lock_irqsave(&pctrl->lock, flags); rzg2l_gpio_irq_enable(data); + spin_unlock_irqrestore(&pctrl->lock, flags); + } } }