Skip to contentSkip to conversation

gpio: mvebu: use raw spinlock for MMIO regmaps

PATCH Superseded Rosen Penev 2 participants 2 messages Sep 15 – Sep 16

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: mvebu: use raw spinlock for MMIO regmaps

The mask/unmask handlers run with the generic irqchip's raw spinlock held and call regmap_read()/regmap_write() on the GPIO regmaps. By default regmap protects itself with a plain spinlock, which becomes a sleeping rt_mutex on CONFIG_PREEMPT_RT; taking it while holding the raw irqchip lock trips might_sleep(), and PROVE_RAW_LOCK_NESTING flags the same nesting on non-RT builds.

Configure both GPIO regmaps with .use_raw_spinlock = true so the MMIO accesses stay atomic in hardirq and raw-locked context.

Assisted-by LLM
---
 drivers/gpio/gpio-mvebu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpio/gpio-mvebu.c +8 -0
index 03e977c2a629..674feeb31774 100644
@@ -598,11 +598,18 @@ static void mvebu_gpio_irq_handler(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
+/*
+ * These regmaps are accessed from the mask/unmask handlers while the
+ * irqchip's raw spinlock is held, so they must use a raw spinlock
+ * internally. A plain spinlock becomes a sleeping rt_mutex on
+ * CONFIG_PREEMPT_RT and would trip might_sleep() from that context.
+ */
 static const struct regmap_config mvebu_gpio_regmap_config = {
 	.name = "gpio",
 	.reg_bits = 32,
 	.reg_stride = 4,
 	.val_bits = 32,
+	.use_raw_spinlock = true,
 };
 
 static const struct regmap_config mvebu_gpio_percpu_regmap_config = {
@@ -610,6 +617,7 @@ static const struct regmap_config mvebu_gpio_percpu_regmap_config = {
 	.reg_bits = 32,
 	.reg_stride = 4,
 	.val_bits = 32,
+	.use_raw_spinlock = true,
 };
 
 static const struct regmap_config mvebu_pwm_regmap_config = {
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Rosen Penev

The mask/unmask handlers run with the generic irqchip's raw spinlock held and call regmap_read()/regmap_write() on the GPIO regmaps. By default regmap protects itself with a plain spinlock, which becomes a sleeping rt_mutex on CONFIG_PREEMPT_RT; taking it while holding the raw

sleeping lock

Quoted 9 lines

irqchip lock trips might_sleep(), and PROVE_RAW_LOCK_NESTING flags the same nesting on non-RT builds.

Configure both GPIO regmaps with .use_raw_spinlock = true so the MMIO accesses stay atomic in hardirq and raw-locked context.

Assisted-by LLM

---

other than the comments,

Quoted 8 lines
 drivers/gpio/gpio-mvebu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpio/gpio-mvebu.c +0 -0
index 03e977c2a629..674feeb31774 100644

drivers/gpio/gpio-mvebu.c static void mvebu_gpio_irq_handler(struct irq_desc *desc) · line 606

Quoted 9 lines
drivers/gpio/gpio-mvebu.c +6 -0
@@ -598,11 +598,18 @@ static void mvebu_gpio_irq_handler(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
+/*
+ * These regmaps are accessed from the mask/unmask handlers while the
+ * irqchip's raw spinlock is held, so they must use a raw spinlock
+ * internally. A plain spinlock becomes a sleeping rt_mutex on
+ * CONFIG_PREEMPT_RT and would trip might_sleep() from that context.
+ */

IRQ delivery path must hold raw_spinlock_t. This is not special to this driver but must be done in every gpio chip. I wouldn't add this comment.

Quoted 19 lines
drivers/gpio/gpio-mvebu.c +2 -0
 static const struct regmap_config mvebu_gpio_regmap_config = {
 	.name = "gpio",
 	.reg_bits = 32,
 	.reg_stride = 4,
 	.val_bits = 32,
+	.use_raw_spinlock = true,
 };
 
 static const struct regmap_config mvebu_gpio_percpu_regmap_config = {
@@ -610,6 +617,7 @@ static const struct regmap_config mvebu_gpio_percpu_regmap_config = {
 	.reg_bits = 32,
 	.reg_stride = 4,
 	.val_bits = 32,
+	.use_raw_spinlock = true,
 };
 
 static const struct regmap_config mvebu_pwm_regmap_config = {
Signature · 1 line
2.55.0

Sebastian