* [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context
@ 2026-02-05 10:39 Cosmin Tanislav
2026-02-05 12:04 ` Sebastian Andrzej Siewior
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Cosmin Tanislav @ 2026-02-05 10:39 UTC (permalink / raw)
To: Geert Uytterhoeven, Linus Walleij, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Bartosz Golaszewski,
Cosmin Tanislav
Cc: linux-renesas-soc, linux-gpio, linux-kernel, linux-rt-devel
The rzt2h_gpio_get_direction() function is called from
gpiod_get_direction(), which ends up being used within the __setup_irq()
call stack when requesting an interrupt.
__setup_irq() holds a raw_spinlock_t with IRQs disabled, which creates
an atomic context. spinlock_t cannot be used within atomic context
when PREEMPT_RT is enabled, since it may become a sleeping lock.
An "[ BUG: Invalid wait context ]" splat is observed when running with
CONFIG_PROVE_LOCKING enabled, describing exactly the aforementioned call
stack.
__setup_irq() needs to hold a raw_spinlock_t with IRQs disabled to
serialize access against a concurrent hard interrupt.
Switch to raw_spinlock_t to fix this.
Fixes: 829dde3369a9 ("pinctrl: renesas: rzt2h: Add GPIO IRQ chip to handle interrupts")
Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
---
V2:
* reword commit message to better describe why
rzt2h_gpio_get_direction() needs to use raw_spinlock_t
drivers/pinctrl/renesas/pinctrl-rzt2h.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/pinctrl/renesas/pinctrl-rzt2h.c b/drivers/pinctrl/renesas/pinctrl-rzt2h.c
index 9949108a35bb..d810dc0dae95 100644
--- a/drivers/pinctrl/renesas/pinctrl-rzt2h.c
+++ b/drivers/pinctrl/renesas/pinctrl-rzt2h.c
@@ -85,7 +85,7 @@ struct rzt2h_pinctrl {
struct gpio_chip gpio_chip;
struct pinctrl_gpio_range gpio_range;
DECLARE_BITMAP(used_irqs, RZT2H_INTERRUPTS_NUM);
- spinlock_t lock; /* lock read/write registers */
+ raw_spinlock_t lock; /* lock read/write registers */
struct mutex mutex; /* serialize adding groups and functions */
bool safety_port_enabled;
atomic_t wakeup_path;
@@ -145,7 +145,7 @@ static void rzt2h_pinctrl_set_pfc_mode(struct rzt2h_pinctrl *pctrl,
u64 reg64;
u16 reg16;
- guard(spinlock_irqsave)(&pctrl->lock);
+ guard(raw_spinlock_irqsave)(&pctrl->lock);
/* Set pin to 'Non-use (Hi-Z input protection)' */
reg16 = rzt2h_pinctrl_readw(pctrl, port, PM(port));
@@ -474,7 +474,7 @@ static int rzt2h_gpio_request(struct gpio_chip *chip, unsigned int offset)
if (ret)
return ret;
- guard(spinlock_irqsave)(&pctrl->lock);
+ guard(raw_spinlock_irqsave)(&pctrl->lock);
/* Select GPIO mode in PMC Register */
rzt2h_pinctrl_set_gpio_en(pctrl, port, bit, true);
@@ -487,7 +487,7 @@ static void rzt2h_gpio_set_direction(struct rzt2h_pinctrl *pctrl, u32 port,
{
u16 reg;
- guard(spinlock_irqsave)(&pctrl->lock);
+ guard(raw_spinlock_irqsave)(&pctrl->lock);
reg = rzt2h_pinctrl_readw(pctrl, port, PM(port));
reg &= ~PM_PIN_MASK(bit);
@@ -509,7 +509,7 @@ static int rzt2h_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
if (ret)
return ret;
- guard(spinlock_irqsave)(&pctrl->lock);
+ guard(raw_spinlock_irqsave)(&pctrl->lock);
if (rzt2h_pinctrl_readb(pctrl, port, PMC(port)) & BIT(bit)) {
/*
@@ -547,7 +547,7 @@ static int rzt2h_gpio_set(struct gpio_chip *chip, unsigned int offset,
u8 bit = RZT2H_PIN_ID_TO_PIN(offset);
u8 reg;
- guard(spinlock_irqsave)(&pctrl->lock);
+ guard(raw_spinlock_irqsave)(&pctrl->lock);
reg = rzt2h_pinctrl_readb(pctrl, port, P(port));
if (value)
@@ -964,7 +964,7 @@ static int rzt2h_pinctrl_probe(struct platform_device *pdev)
if (ret)
return ret;
- spin_lock_init(&pctrl->lock);
+ raw_spin_lock_init(&pctrl->lock);
mutex_init(&pctrl->mutex);
platform_set_drvdata(pdev, pctrl);
--
2.52.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context
2026-02-05 10:39 [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context Cosmin Tanislav
@ 2026-02-05 12:04 ` Sebastian Andrzej Siewior
2026-02-05 14:30 ` Cosmin-Gabriel Tanislav
2026-02-16 22:36 ` Linus Walleij
2026-03-03 13:49 ` Geert Uytterhoeven
2 siblings, 1 reply; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-02-05 12:04 UTC (permalink / raw)
To: Cosmin Tanislav
Cc: Geert Uytterhoeven, Linus Walleij, Clark Williams, Steven Rostedt,
Bartosz Golaszewski, linux-renesas-soc, linux-gpio, linux-kernel,
linux-rt-devel
On 2026-02-05 12:39:30 [+0200], Cosmin Tanislav wrote:
> The rzt2h_gpio_get_direction() function is called from
> gpiod_get_direction(), which ends up being used within the __setup_irq()
> call stack when requesting an interrupt.
>
> __setup_irq() holds a raw_spinlock_t with IRQs disabled, which creates
> an atomic context. spinlock_t cannot be used within atomic context
> when PREEMPT_RT is enabled, since it may become a sleeping lock.
>
> An "[ BUG: Invalid wait context ]" splat is observed when running with
> CONFIG_PROVE_LOCKING enabled, describing exactly the aforementioned call
> stack.
>
> __setup_irq() needs to hold a raw_spinlock_t with IRQs disabled to
> serialize access against a concurrent hard interrupt.
>
> Switch to raw_spinlock_t to fix this.
I don't like the reasoning here because it looks like "lockdep
complained lets switch the locks and everything is fine now".
It is required to make the suggested change because the lock is used
in hardirq context and only while accessing the HW's register.
I just don't want that a lockdep splat becomes a green card for these
kind of changes without understanding the consequences.
> Fixes: 829dde3369a9 ("pinctrl: renesas: rzt2h: Add GPIO IRQ chip to handle interrupts")
> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Sebastian
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context
2026-02-05 12:04 ` Sebastian Andrzej Siewior
@ 2026-02-05 14:30 ` Cosmin-Gabriel Tanislav
2026-02-05 16:00 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 6+ messages in thread
From: Cosmin-Gabriel Tanislav @ 2026-02-05 14:30 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: Geert Uytterhoeven, Linus Walleij, Clark Williams, Steven Rostedt,
Bartosz Golaszewski, linux-renesas-soc@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rt-devel@lists.linux.dev
> From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Sent: Thursday, February 5, 2026 2:05 PM
>
> On 2026-02-05 12:39:30 [+0200], Cosmin Tanislav wrote:
> > The rzt2h_gpio_get_direction() function is called from
> > gpiod_get_direction(), which ends up being used within the __setup_irq()
> > call stack when requesting an interrupt.
> >
> > __setup_irq() holds a raw_spinlock_t with IRQs disabled, which creates
> > an atomic context. spinlock_t cannot be used within atomic context
> > when PREEMPT_RT is enabled, since it may become a sleeping lock.
> >
> > An "[ BUG: Invalid wait context ]" splat is observed when running with
> > CONFIG_PROVE_LOCKING enabled, describing exactly the aforementioned call
> > stack.
> >
> > __setup_irq() needs to hold a raw_spinlock_t with IRQs disabled to
> > serialize access against a concurrent hard interrupt.
> >
> > Switch to raw_spinlock_t to fix this.
>
> I don't like the reasoning here because it looks like "lockdep
> complained lets switch the locks and everything is fine now".
>
> It is required to make the suggested change because the lock is used
> in hardirq context and only while accessing the HW's register.
>
> I just don't want that a lockdep splat becomes a green card for these
> kind of changes without understanding the consequences.
>
Hi Sebastian, thank you for your feedback.
I agree that a lockdep splat should not warrant a spinlock_t to
raw_spinlock_t conversion since that's not always the correct solution
for it.
This driver delegates masking/unmasking to the parent IRQ chip, and none
of the local irq_chip callbacks take the pctrl->lock.
The pctrl->lock is taken in the gpio_chip->request, ->get_direction,
->direction_input, ->direction_output, pinmux_ops->set_mux and
gpio_irq_chip->child_to_parent_hwirq implementations.
My understanding is that the only issue is that ->get_direction takes a
spinlock_t while being called from __setup_irq() which holds a
raw_spinlock_t with IRQs disabled, rather than spinlock_t being taken
inside a hardirq context, which is what I tried to describe in the
commit message.
Am I missing something?
> > Fixes: 829dde3369a9 ("pinctrl: renesas: rzt2h: Add GPIO IRQ chip to handle interrupts")
> > Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
>
> Sebastian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: RE: [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context
2026-02-05 14:30 ` Cosmin-Gabriel Tanislav
@ 2026-02-05 16:00 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-02-05 16:00 UTC (permalink / raw)
To: Cosmin-Gabriel Tanislav
Cc: Geert Uytterhoeven, Linus Walleij, Clark Williams, Steven Rostedt,
Bartosz Golaszewski, linux-renesas-soc@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rt-devel@lists.linux.dev
On 2026-02-05 14:30:36 [+0000], Cosmin-Gabriel Tanislav wrote:
> Hi Sebastian, thank you for your feedback.
>
> I agree that a lockdep splat should not warrant a spinlock_t to
> raw_spinlock_t conversion since that's not always the correct solution
> for it.
>
> This driver delegates masking/unmasking to the parent IRQ chip, and none
> of the local irq_chip callbacks take the pctrl->lock.
>
> The pctrl->lock is taken in the gpio_chip->request, ->get_direction,
> ->direction_input, ->direction_output, pinmux_ops->set_mux and
> gpio_irq_chip->child_to_parent_hwirq implementations.
>
> My understanding is that the only issue is that ->get_direction takes a
> spinlock_t while being called from __setup_irq() which holds a
> raw_spinlock_t with IRQs disabled, rather than spinlock_t being taken
> inside a hardirq context, which is what I tried to describe in the
> commit message.
>
> Am I missing something?
I see. Usually there is also mask/ unmask which makes this mandatory for
this as well. In that case it is probably just the invocation from
__setup(). Instead of nitpicking here
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
and you said that the splat does warrant for the lock splat so I hope
the best ;)
Sebastian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context
2026-02-05 10:39 [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context Cosmin Tanislav
2026-02-05 12:04 ` Sebastian Andrzej Siewior
@ 2026-02-16 22:36 ` Linus Walleij
2026-03-03 13:49 ` Geert Uytterhoeven
2 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2026-02-16 22:36 UTC (permalink / raw)
To: Cosmin Tanislav, Geert Uytterhoeven
Cc: Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Bartosz Golaszewski, linux-renesas-soc, linux-gpio, linux-kernel,
linux-rt-devel
On Thu, Feb 5, 2026 at 11:40 AM Cosmin Tanislav
<cosmin-gabriel.tanislav.xa@renesas.com> wrote:
> The rzt2h_gpio_get_direction() function is called from
> gpiod_get_direction(), which ends up being used within the __setup_irq()
> call stack when requesting an interrupt.
>
> __setup_irq() holds a raw_spinlock_t with IRQs disabled, which creates
> an atomic context. spinlock_t cannot be used within atomic context
> when PREEMPT_RT is enabled, since it may become a sleeping lock.
>
> An "[ BUG: Invalid wait context ]" splat is observed when running with
> CONFIG_PROVE_LOCKING enabled, describing exactly the aforementioned call
> stack.
>
> __setup_irq() needs to hold a raw_spinlock_t with IRQs disabled to
> serialize access against a concurrent hard interrupt.
>
> Switch to raw_spinlock_t to fix this.
>
> Fixes: 829dde3369a9 ("pinctrl: renesas: rzt2h: Add GPIO IRQ chip to handle interrupts")
> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
I'm waiting for Geert's verdict on this one, I can merge it directly
for fixes unless Geert want to accumulate a few fixes first.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context
2026-02-05 10:39 [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context Cosmin Tanislav
2026-02-05 12:04 ` Sebastian Andrzej Siewior
2026-02-16 22:36 ` Linus Walleij
@ 2026-03-03 13:49 ` Geert Uytterhoeven
2 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2026-03-03 13:49 UTC (permalink / raw)
To: Cosmin Tanislav
Cc: Linus Walleij, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Bartosz Golaszewski, linux-renesas-soc,
linux-gpio, linux-kernel, linux-rt-devel
On Thu, 5 Feb 2026 at 11:40, Cosmin Tanislav
<cosmin-gabriel.tanislav.xa@renesas.com> wrote:
> The rzt2h_gpio_get_direction() function is called from
> gpiod_get_direction(), which ends up being used within the __setup_irq()
> call stack when requesting an interrupt.
>
> __setup_irq() holds a raw_spinlock_t with IRQs disabled, which creates
> an atomic context. spinlock_t cannot be used within atomic context
> when PREEMPT_RT is enabled, since it may become a sleeping lock.
>
> An "[ BUG: Invalid wait context ]" splat is observed when running with
> CONFIG_PROVE_LOCKING enabled, describing exactly the aforementioned call
> stack.
>
> __setup_irq() needs to hold a raw_spinlock_t with IRQs disabled to
> serialize access against a concurrent hard interrupt.
>
> Switch to raw_spinlock_t to fix this.
>
> Fixes: 829dde3369a9 ("pinctrl: renesas: rzt2h: Add GPIO IRQ chip to handle interrupts")
> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> ---
>
> V2:
> * reword commit message to better describe why
> rzt2h_gpio_get_direction() needs to use raw_spinlock_t
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
i.e. will queue in renesas-pinctrl-fixes for v7.0.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-03 13:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05 10:39 [PATCH v2] pinctrl: renesas: rzt2h: fix invalid wait context Cosmin Tanislav
2026-02-05 12:04 ` Sebastian Andrzej Siewior
2026-02-05 14:30 ` Cosmin-Gabriel Tanislav
2026-02-05 16:00 ` Sebastian Andrzej Siewior
2026-02-16 22:36 ` Linus Walleij
2026-03-03 13:49 ` Geert Uytterhoeven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox