* [PATCH 1/2] pinctrl: ocelot: use a raw spinlock for the GPIO regmap
2026-11-09 13:50 [PATCH 0/2] pinctrl: ocelot: fix the GPIO irqchip context handling Jens Emil Schulz Østergaard
@ 2026-11-09 13:50 ` Jens Emil Schulz Østergaard
2026-11-09 13:50 ` [PATCH 2/2] pinctrl: ocelot: do not use the chained irqchip behind a sleeping bus Jens Emil Schulz Østergaard
1 sibling, 0 replies; 3+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-11-09 13:50 UTC (permalink / raw)
To: Linus Walleij, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Horatiu Vultur, Colin Foster, Andy Shevchenko,
Lee Jones, Vladimir Oltean
Cc: Alexandre Belloni, linux-gpio, linux-kernel, linux-rt-devel,
Jens Emil Schulz Østergaard
The irq_chip callbacks .irq_mask, .irq_unmask and .irq_ack access the
GPIO regmap. genirq calls them with the raw spinlock irq_desc::lock
held, for example from irq_startup() in __setup_irq(). The regmap is
created with devm_regmap_init_mmio() and guarded by a spinlock_t, which
is a sleeping lock on PREEMPT_RT and must not be taken under a raw
spinlock.
Make the GPIO regmap use a raw spinlock. Its accesses are short MMIO
reads and writes. The other regmaps of the driver are not used from the
irq_chip callbacks and are left unchanged.
The issue was found with CONFIG_PROVE_RAW_LOCK_NESTING on a lan9668
board (pcb8385), when a level low interrupt on one of its GPIOs is
requested, and was seen on lan969x when a PHY interrupt on a GPIO is
requested:
=============================
[ BUG: Invalid wait context ]
-----------------------------
swapper/0/1 is trying to lock:
c3046c10 (pinctrl_ocelot:34:(config)->lock){....}-{3:3}, at: regmap_lock_spinlock+0xc/0x40
other info that might help us debug this:
context-{5:5}
locks held by swapper/0/1: 6, last CPU#0:
...
#4: c3200b5c (request_class){+.+.}-{4:4}, at: __setup_irq+0x140/0x840
#5: c3200a7c (lock_class){....}-{2:2}, at: __setup_irq+0x168/0x840
stack backtrace:
...
_raw_spin_lock_irqsave from regmap_lock_spinlock+0xc/0x40
regmap_lock_spinlock from regmap_read+0x2c/0x80
regmap_read from ocelot_irq_unmask_level+0x6c/0x240
ocelot_irq_unmask_level from irq_enable+0x38/0xc0
irq_enable from __irq_startup+0x70/0xc0
__irq_startup from irq_startup+0xb8/0x180
irq_startup from __setup_irq+0x4d0/0x840
__setup_irq from request_threaded_irq+0xbc/0x180
request_threaded_irq from devm_request_threaded_irq+0x70/0x140
With the fix the report is gone on the lan9668 board.
Fixes: c297561bc98a ("pinctrl: ocelot: Fix interrupt controller")
Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
---
drivers/pinctrl/pinctrl-ocelot.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/pinctrl/pinctrl-ocelot.c b/drivers/pinctrl/pinctrl-ocelot.c
index 58d3cde9f964..06dd49782d74 100644
--- a/drivers/pinctrl/pinctrl-ocelot.c
+++ b/drivers/pinctrl/pinctrl-ocelot.c
@@ -2440,6 +2440,7 @@ static int ocelot_pinctrl_probe(struct platform_device *pdev)
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
+ .use_raw_spinlock = true,
};
info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
--
2.52.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 2/2] pinctrl: ocelot: do not use the chained irqchip behind a sleeping bus
2026-11-09 13:50 [PATCH 0/2] pinctrl: ocelot: fix the GPIO irqchip context handling Jens Emil Schulz Østergaard
2026-11-09 13:50 ` [PATCH 1/2] pinctrl: ocelot: use a raw spinlock for the GPIO regmap Jens Emil Schulz Østergaard
@ 2026-11-09 13:50 ` Jens Emil Schulz Østergaard
1 sibling, 0 replies; 3+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-11-09 13:50 UTC (permalink / raw)
To: Linus Walleij, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Horatiu Vultur, Colin Foster, Andy Shevchenko,
Lee Jones, Vladimir Oltean
Cc: Alexandre Belloni, linux-gpio, linux-kernel, linux-rt-devel,
Jens Emil Schulz Østergaard
Since the driver can use a regmap on a bus that can sleep, as for
VSC7512 attached over SPI, it still registers the gpiochip as not
sleeping and adds the chained irqchip when the node has an interrupt.
The chained handler and the irq_chip callbacks run in atomic context and
access the registers through that regmap, and consumers may use the
lines of a gpiochip that is not marked as sleeping from atomic context.
Mark the gpiochip as sleeping when the regmap can sleep, and do not
register the chained irqchip in that case.
The issue was found by code inspection and reproduced on a lan9668
board (pcb8385) with a lan9645x attached over SPI, whose pinctrl node
has an interrupt, by requesting an edge interrupt on one of its GPIOs
through the GPIO character device:
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:623
in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 420, name: gpiomon
preempt_count: 1, expected: 0
locks held by gpiomon/420: 3, last CPU#0:
#0: 84463cd0 (&gdev->srcu){.+.+}-{0:0}, at: lineinfo_get+0x13f/0x140
#1: 838bbd30 (request_class){+.+.}-{4:4}, at: __setup_irq+0xe8/0x5c0
#2: 838bbc70 (lock_class){-...}-{2:2}, at: __setup_irq+0x104/0x5c0
...
Call trace:
...
mutex_lock_nested from regmap_update_bits_base+0x1c/0x80
regmap_update_bits_base from ocelot_irq_unmask+0x42/0x80
ocelot_irq_unmask from irq_enable+0x1e/0x80
irq_enable from irq_startup+0x64/0xc0
irq_startup from __setup_irq+0x38c/0x5c0
__setup_irq from request_threaded_irq+0x86/0x140
request_threaded_irq from edge_detector_setup+0x1d8/0x240
edge_detector_setup from linereq_create+0x3e2/0x540
linereq_create from gpio_ioctl+0xa4/0x240
With the fix the lan9645x gpiochip is registered as sleeping and
without the chained irqchip, the request fails with -ENXIO instead and
without lockdep reports.
Fixes: 181f604b33cd ("pinctrl: ocelot: add ability to be used in a non-mmio configuration")
Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
---
drivers/pinctrl/pinctrl-ocelot.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/pinctrl-ocelot.c b/drivers/pinctrl/pinctrl-ocelot.c
index 06dd49782d74..90a1f859db67 100644
--- a/drivers/pinctrl/pinctrl-ocelot.c
+++ b/drivers/pinctrl/pinctrl-ocelot.c
@@ -2367,8 +2367,9 @@ static int ocelot_gpiochip_register(struct platform_device *pdev,
gc->parent = &pdev->dev;
gc->base = -1;
gc->label = "ocelot-gpio";
+ gc->can_sleep = regmap_might_sleep(info->map);
- irq = platform_get_irq_optional(pdev, 0);
+ irq = gc->can_sleep ? 0 : platform_get_irq_optional(pdev, 0);
if (irq > 0) {
girq = &gc->irq;
gpio_irq_chip_set_chip(girq, &ocelot_irqchip);
--
2.52.0
^ permalink raw reply [flat|nested] 3+ messages in thread