* [PATCH 1/2] gpio: mvebu: restore suspend-time irq masks under gc->lock
2026-12-03 22:58 [PATCH 0/2] gpio: mvebu: resume and PREEMPT_RT irq mask fixes Rosen Penev
@ 2026-12-03 22:58 ` Rosen Penev
2026-12-03 23:14 ` sashiko-bot
2026-12-03 22:58 ` [PATCH 2/2] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too Rosen Penev
1 sibling, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2026-12-03 22:58 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Rosen Penev, Gregory CLEMENT
Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel
mvebu_gpio_resume() snapshots the irqchip's mask_cache_priv under
gc->lock, drops the lock, and only then writes the saved edge/level
masks ANDed with that snapshot back to hardware. A mask or unmask
handler running in that window updates the cache and the register, and
the restore then overwrites the register with the stale value. A line
masked in the window ends up unmasked behind genirq's back, so an
asserted level line has nobody to ack it and the chained handler
storms; a line unmasked in the window stays masked in hardware and
loses its interrupts.
Hold gc->lock for the whole restore, as the mask/unmask handlers
already do for their cache update and register write, so the two
cannot interleave. Move the per-variant register writes into
mvebu_gpio_restore_irq_masks() to keep the locked section readable,
and replace the BUG() on an unknown SoC variant with WARN_ON_ONCE().
Controllers without an irq domain no longer have their mask registers
written on resume. Nothing unmasks lines on such a controller, so the
registers it saved at suspend time are not ones the driver set.
Fixes: 02af7eac17bc ("gpio: mvebu: keep resume masks within the irqchip cache")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpio/gpio-mvebu.c | 88 ++++++++++++++++++++-------------------
1 file changed, 46 insertions(+), 42 deletions(-)
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 6c2bcc5d749c..c202b946f595 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -996,6 +996,45 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
},
};
+static void
+mvebu_gpio_restore_irq_masks(struct mvebu_gpio_chip *mvchip, u32 level_cache,
+ u32 edge_cache)
+{
+ int i;
+
+ switch (mvchip->soc_variant) {
+ case MVEBU_GPIO_SOC_VARIANT_ORION:
+ case MVEBU_GPIO_SOC_VARIANT_A8K:
+ regmap_write(mvchip->regs, GPIO_EDGE_MASK_OFF + mvchip->offset,
+ mvchip->edge_mask_regs[0] & edge_cache);
+ regmap_write(mvchip->regs, GPIO_LEVEL_MASK_OFF + mvchip->offset,
+ mvchip->level_mask_regs[0] & level_cache);
+ break;
+ case MVEBU_GPIO_SOC_VARIANT_MV78200:
+ for (i = 0; i < 2; i++) {
+ regmap_write(mvchip->regs,
+ GPIO_EDGE_MASK_MV78200_OFF(i),
+ mvchip->edge_mask_regs[i] & edge_cache);
+ regmap_write(mvchip->regs,
+ GPIO_LEVEL_MASK_MV78200_OFF(i),
+ mvchip->level_mask_regs[i] & level_cache);
+ }
+ break;
+ case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
+ for (i = 0; i < 4; i++) {
+ regmap_write(mvchip->percpu_regs,
+ GPIO_EDGE_MASK_ARMADAXP_OFF(i),
+ mvchip->edge_mask_regs[i] & edge_cache);
+ regmap_write(mvchip->percpu_regs,
+ GPIO_LEVEL_MASK_ARMADAXP_OFF(i),
+ mvchip->level_mask_regs[i] & level_cache);
+ }
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ }
+}
+
static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
{
struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
@@ -1051,9 +1090,6 @@ static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
static int mvebu_gpio_resume(struct platform_device *pdev)
{
struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
- u32 edge_cache = ~0U, level_cache = ~0U;
- unsigned long flags;
- int i;
regmap_write(mvchip->regs, GPIO_OUT_OFF + mvchip->offset,
mvchip->out_reg);
@@ -1069,50 +1105,18 @@ static int mvebu_gpio_resume(struct platform_device *pdev)
* unmasking one behind its back leaves an asserted level line that
* nobody masks. Restore only bits the irqchip cache still has set.
*
- * Snapshot the caches under the raw spinlock, but release it before
- * the regmap writes below: regmap_write() takes a sleepable lock on
- * PREEMPT_RT.
+ * Hold gc->lock across the writes so the restore cannot race the
+ * mask/unmask handlers, which update the cache and write the mask
+ * registers under the same lock.
*/
if (mvchip->domain) {
struct irq_chip_generic *gc;
gc = irq_get_domain_generic_chip(mvchip->domain, 0);
- raw_spin_lock_irqsave(&gc->lock, flags);
- level_cache = gc->chip_types[0].mask_cache_priv;
- edge_cache = gc->chip_types[1].mask_cache_priv;
- raw_spin_unlock_irqrestore(&gc->lock, flags);
- }
-
- switch (mvchip->soc_variant) {
- case MVEBU_GPIO_SOC_VARIANT_ORION:
- case MVEBU_GPIO_SOC_VARIANT_A8K:
- regmap_write(mvchip->regs, GPIO_EDGE_MASK_OFF + mvchip->offset,
- mvchip->edge_mask_regs[0] & edge_cache);
- regmap_write(mvchip->regs, GPIO_LEVEL_MASK_OFF + mvchip->offset,
- mvchip->level_mask_regs[0] & level_cache);
- break;
- case MVEBU_GPIO_SOC_VARIANT_MV78200:
- for (i = 0; i < 2; i++) {
- regmap_write(mvchip->regs,
- GPIO_EDGE_MASK_MV78200_OFF(i),
- mvchip->edge_mask_regs[i] & edge_cache);
- regmap_write(mvchip->regs,
- GPIO_LEVEL_MASK_MV78200_OFF(i),
- mvchip->level_mask_regs[i] & level_cache);
- }
- break;
- case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
- for (i = 0; i < 4; i++) {
- regmap_write(mvchip->percpu_regs,
- GPIO_EDGE_MASK_ARMADAXP_OFF(i),
- mvchip->edge_mask_regs[i] & edge_cache);
- regmap_write(mvchip->percpu_regs,
- GPIO_LEVEL_MASK_ARMADAXP_OFF(i),
- mvchip->level_mask_regs[i] & level_cache);
- }
- break;
- default:
- BUG();
+ guard(raw_spinlock_irqsave)(&gc->lock);
+ mvebu_gpio_restore_irq_masks(mvchip,
+ gc->chip_types[0].mask_cache_priv,
+ gc->chip_types[1].mask_cache_priv);
}
if (IS_REACHABLE(CONFIG_PWM) && mvchip->mvpwm)
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too
2026-12-03 22:58 [PATCH 0/2] gpio: mvebu: resume and PREEMPT_RT irq mask fixes Rosen Penev
2026-12-03 22:58 ` [PATCH 1/2] gpio: mvebu: restore suspend-time irq masks under gc->lock Rosen Penev
@ 2026-12-03 22:58 ` Rosen Penev
1 sibling, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-12-03 22:58 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Rosen Penev, Gregory CLEMENT
Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel
Commit 42269cdb3d3b ("gpio: mvebu: fix sleeping-while-atomic in
mvebu_gpio_level_irq_mask()") made the driver's MMIO regmaps use raw
spinlocks, because the irq_chip mask/unmask callbacks write the mask
registers while holding the generic chip's raw gc->lock. That only
covers the regmaps the driver creates itself. On Armada 7K/8K
("marvell,armada-8k-gpio") the GPIO block sits inside a system
controller and the driver uses the parent's syscon regmap, which syscon
creates with an ordinary spinlock. On PREEMPT_RT that lock sleeps, so
masking or unmasking a GPIO interrupt there still sleeps in atomic
context.
The syscon regmap's lock cannot be changed from here, and nothing else
accesses the GPIO bank's registers at its offset, so the shared lock is
not protecting anything this driver needs. Map the parent's register
range again and create a regmap of our own with the raw-locked
mvebu_gpio_regmap_config, as the non-syscon path already does. The
mapping is not requested, as syscon does not request it either.
Fixes: b6730b20837e ("gpio: mvebu: Add support for the Armada 7K/8K SoCs")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpio/gpio-mvebu.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index c202b946f595..a2974515b408 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -42,8 +42,8 @@
#include <linux/irq.h>
#include <linux/irqchip/chained_irq.h>
#include <linux/irqdomain.h>
-#include <linux/mfd/syscon.h>
#include <linux/of.h>
+#include <linux/of_address.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
#include <linux/property.h>
@@ -1167,7 +1167,29 @@ static int mvebu_gpio_probe_raw(struct platform_device *pdev,
static int mvebu_gpio_probe_syscon(struct platform_device *pdev,
struct mvebu_gpio_chip *mvchip)
{
- mvchip->regs = syscon_node_to_regmap(pdev->dev.parent->of_node);
+ struct device_node *np = pdev->dev.parent->of_node;
+ void __iomem *base;
+ struct resource res;
+ int ret;
+
+ /*
+ * The GPIO registers live inside the parent system controller, but
+ * don't use its syscon regmap: that one is created with a normal
+ * spinlock, which sleeps on PREEMPT_RT, and the irq_chip callbacks
+ * write the mask registers under the raw gc->lock. This driver is
+ * the only user of the registers at its offset, so map the parent's
+ * range again and access it through a raw-locked regmap of our own.
+ */
+ ret = of_address_to_resource(np, 0, &res);
+ if (ret)
+ return ret;
+
+ base = devm_ioremap(&pdev->dev, res.start, resource_size(&res));
+ if (!base)
+ return -ENOMEM;
+
+ mvchip->regs = devm_regmap_init_mmio(&pdev->dev, base,
+ &mvebu_gpio_regmap_config);
if (IS_ERR(mvchip->regs))
return PTR_ERR(mvchip->regs);
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread