* [PATCH v2 1/5] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too
2026-12-05 3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
@ 2026-12-05 3:11 ` Rosen Penev
2026-12-05 21:14 ` Linus Walleij
2026-12-05 3:11 ` [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock Rosen Penev
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Rosen Penev @ 2026-12-05 3:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
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 6c2bcc5d749c..ab350c8686e3 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>
@@ -1163,7 +1163,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] 12+ messages in thread* Re: [PATCH v2 1/5] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too
2026-12-05 3:11 ` [PATCH v2 1/5] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too Rosen Penev
@ 2026-12-05 21:14 ` Linus Walleij
0 siblings, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2026-12-05 21:14 UTC (permalink / raw)
To: Rosen Penev
Cc: Bartosz Golaszewski, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Gregory CLEMENT, Rob Herring, Thierry Reding,
Ralph Sennhauser, Andrew Lunn, Bartosz Golaszewski, linux-gpio,
linux-rt-devel
On Sat, Dec 5, 2026 at 4:11 AM Rosen Penev <rosenp@gmail.com> wrote:
> 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>
Makes sense,
Reviewed-by: Linus Walleij <linusw@kernel.org>
> - 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 this starts to appear in several drivers we should consider factoring out
a helper for this and maybe merge into <linux/regmap.h>.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock
2026-12-05 3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
2026-12-05 3:11 ` [PATCH v2 1/5] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too Rosen Penev
@ 2026-12-05 3:11 ` Rosen Penev
2026-12-05 21:14 ` Linus Walleij
2026-12-05 3:11 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Rosen Penev @ 2026-12-05 3:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
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 ab350c8686e3..a2974515b408 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] 12+ messages in thread* Re: [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock
2026-12-05 3:11 ` [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock Rosen Penev
@ 2026-12-05 21:14 ` Linus Walleij
0 siblings, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2026-12-05 21:14 UTC (permalink / raw)
To: Rosen Penev
Cc: Bartosz Golaszewski, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Gregory CLEMENT, Rob Herring, Thierry Reding,
Ralph Sennhauser, Andrew Lunn, Bartosz Golaszewski, linux-gpio,
linux-rt-devel
On Sat, Dec 5, 2026 at 4:11 AM Rosen Penev <rosenp@gmail.com> wrote:
> 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>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume
2026-12-05 3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
2026-12-05 3:11 ` [PATCH v2 1/5] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too Rosen Penev
2026-12-05 3:11 ` [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock Rosen Penev
@ 2026-12-05 3:11 ` Rosen Penev
2026-12-05 3:25 ` sashiko-bot
2026-12-05 21:15 ` Linus Walleij
2026-12-05 3:11 ` [PATCH v2 4/5] gpio: mvebu: don't request the PWM GPIO under a spinlock Rosen Penev
2026-12-05 3:11 ` [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit Rosen Penev
4 siblings, 2 replies; 12+ messages in thread
From: Rosen Penev @ 2026-12-05 3:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel
mvebu_gpio_resume() writes back the mask registers saved at suspend
time, ANDed with the irqchip mask cache. A line that was masked at
suspend time and unmasked before mvebu_gpio_resume() runs, for example
by enable_irq() in another driver's resume_noirq callback, is set in
both the cache and the hardware, but not in the saved value. The
restore then masks it again behind genirq's back and its interrupts
are lost.
Include the current register value when restoring: keep a line
unmasked if it was unmasked at suspend time or is unmasked now, and
only while the cache still has it unmasked. After a power loss the
mask registers come back as zero, so this changes nothing there.
Fixes: 02af7eac17bc ("gpio: mvebu: keep resume masks within the irqchip cache")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpio/gpio-mvebu.c | 55 +++++++++++++++++++++++++++------------
1 file changed, 38 insertions(+), 17 deletions(-)
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index a2974515b408..eda52cfaa145 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -996,6 +996,20 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
},
};
+/*
+ * Keep a line unmasked if it was unmasked at suspend time or has been unmasked
+ * since, for example by enable_irq() from another driver's resume_noirq
+ * callback, and only while the irqchip cache still has it unmasked.
+ */
+static void mvebu_gpio_restore_mask(struct regmap *map, unsigned int reg,
+ u32 saved, u32 cache)
+{
+ u32 cur;
+
+ regmap_read(map, reg, &cur);
+ regmap_write(map, reg, (saved | cur) & cache);
+}
+
static void
mvebu_gpio_restore_irq_masks(struct mvebu_gpio_chip *mvchip, u32 level_cache,
u32 edge_cache)
@@ -1005,29 +1019,35 @@ mvebu_gpio_restore_irq_masks(struct mvebu_gpio_chip *mvchip, u32 level_cache,
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);
+ mvebu_gpio_restore_mask(mvchip->regs,
+ GPIO_EDGE_MASK_OFF + mvchip->offset,
+ mvchip->edge_mask_regs[0], edge_cache);
+ mvebu_gpio_restore_mask(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);
+ mvebu_gpio_restore_mask(mvchip->regs,
+ GPIO_EDGE_MASK_MV78200_OFF(i),
+ mvchip->edge_mask_regs[i],
+ edge_cache);
+ mvebu_gpio_restore_mask(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);
+ mvebu_gpio_restore_mask(mvchip->percpu_regs,
+ GPIO_EDGE_MASK_ARMADAXP_OFF(i),
+ mvchip->edge_mask_regs[i],
+ edge_cache);
+ mvebu_gpio_restore_mask(mvchip->percpu_regs,
+ GPIO_LEVEL_MASK_ARMADAXP_OFF(i),
+ mvchip->level_mask_regs[i],
+ level_cache);
}
break;
default:
@@ -1103,7 +1123,8 @@ static int mvebu_gpio_resume(struct platform_device *pdev)
/*
* genirq skips mask_irq() for a line it already considers masked, so
* unmasking one behind its back leaves an asserted level line that
- * nobody masks. Restore only bits the irqchip cache still has set.
+ * nobody masks. Restore only bits the irqchip cache still has set; see
+ * mvebu_gpio_restore_mask().
*
* Hold gc->lock across the writes so the restore cannot race the
* mask/unmask handlers, which update the cache and write the mask
--
2.56.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume
2026-12-05 3:11 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
@ 2026-12-05 3:25 ` sashiko-bot
2026-12-05 21:15 ` Linus Walleij
1 sibling, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-12-05 3:25 UTC (permalink / raw)
To: Rosen Penev; +Cc: linux-gpio, linux-rt-devel, linux-kernel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] gpio: mvebu: Fixes trailer cites 02af7eac17bc instead of
b5b7b487431b
--
commit 274be6d5e8aaf9eb8607be44d3ba9ffbf49f09e2
Author: Rosen Penev <rosenp@gmail.com>
> gpio: mvebu: don't re-mask irqs unmasked during early resume
>
> mvebu_gpio_resume() writes back the mask registers saved at suspend
> time, ANDed with the irqchip mask cache. A line that was masked at
> suspend time and unmasked before mvebu_gpio_resume() runs, for example
> by enable_irq() in another driver's resume_noirq callback, is set in
> both the cache and the hardware, but not in the saved value. The
> restore then masks it again behind genirq's back and its interrupts
> are lost.
>
> Include the current register value when restoring: keep a line
> unmasked if it was unmasked at suspend time or is unmasked now, and
> only while the cache still has it unmasked. After a power loss the
> mask registers come back as zero, so this changes nothing there.
>
> Fixes: 02af7eac17bc ("gpio: mvebu: keep resume masks within the irqchip cache")
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
[Severity: Low]
Should the Fixes trailer point to b5b7b487431b ("gpio: mvebu: add
suspend/resume support") instead of 02af7eac17bc ("gpio: mvebu: keep resume
masks within the irqchip cache")?
mvebu_gpio_resume() has overwritten the mask registers with suspend-time saved
values since b5b7b487431b ("gpio: mvebu: add suspend/resume support"), which
already re-masked lines unmasked during early resume. Masking the saved value
with the irqchip cache did not change the outcome when the saved bit is 0.
Citing the introducing commit helps stable trees with suspend/resume support
track the fix:
Fixes: b5b7b487431b ("gpio: mvebu: add suspend/resume support")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205031111.12306-1-rosenp@gmail.com?part=3
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume
2026-12-05 3:11 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
2026-12-05 3:25 ` sashiko-bot
@ 2026-12-05 21:15 ` Linus Walleij
1 sibling, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2026-12-05 21:15 UTC (permalink / raw)
To: Rosen Penev
Cc: Bartosz Golaszewski, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Gregory CLEMENT, Rob Herring, Thierry Reding,
Ralph Sennhauser, Andrew Lunn, Bartosz Golaszewski, linux-gpio,
linux-rt-devel
On Sat, Dec 5, 2026 at 4:11 AM Rosen Penev <rosenp@gmail.com> wrote:
> mvebu_gpio_resume() writes back the mask registers saved at suspend
> time, ANDed with the irqchip mask cache. A line that was masked at
> suspend time and unmasked before mvebu_gpio_resume() runs, for example
> by enable_irq() in another driver's resume_noirq callback, is set in
> both the cache and the hardware, but not in the saved value. The
> restore then masks it again behind genirq's back and its interrupts
> are lost.
>
> Include the current register value when restoring: keep a line
> unmasked if it was unmasked at suspend time or is unmasked now, and
> only while the cache still has it unmasked. After a power loss the
> mask registers come back as zero, so this changes nothing there.
>
> Fixes: 02af7eac17bc ("gpio: mvebu: keep resume masks within the irqchip cache")
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 4/5] gpio: mvebu: don't request the PWM GPIO under a spinlock
2026-12-05 3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
` (2 preceding siblings ...)
2026-12-05 3:11 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
@ 2026-12-05 3:11 ` Rosen Penev
2026-12-05 21:15 ` Linus Walleij
2026-12-05 3:11 ` [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit Rosen Penev
4 siblings, 1 reply; 12+ messages in thread
From: Rosen Penev @ 2026-12-05 3:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel
mvebu_pwm_request() calls gpiochip_request_own_desc() with mvpwm->lock
held and interrupts disabled, and mvebu_pwm_free() does the same with
gpiochip_free_own_desc(). Both can sleep: requesting the line goes
through gpiochip_generic_request() and sets the direction through
pinctrl, which takes the pinctrl mutex.
The PWM core already calls .request and .free with pwm_lock held, so
the spinlock adds nothing there. Drop it from both callbacks.
Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpio/gpio-mvebu.c | 36 ++++++++++++++----------------------
1 file changed, 14 insertions(+), 22 deletions(-)
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index eda52cfaa145..0672528e97dc 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -662,39 +662,31 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
struct gpio_desc *desc;
- unsigned long flags;
- int ret = 0;
- spin_lock_irqsave(&mvpwm->lock, flags);
+ /*
+ * The PWM core calls .request and .free with pwm_lock held, which
+ * serialises them; gpiochip_request_own_desc() may sleep, so it must
+ * not run under mvpwm->lock.
+ */
+ if (mvpwm->gpiod)
+ return -EBUSY;
- if (mvpwm->gpiod) {
- ret = -EBUSY;
- } else {
- desc = gpiochip_request_own_desc(&mvchip->chip,
- pwm->hwpwm, "mvebu-pwm",
- GPIO_ACTIVE_HIGH,
- GPIOD_OUT_LOW);
- if (IS_ERR(desc)) {
- ret = PTR_ERR(desc);
- goto out;
- }
+ desc = gpiochip_request_own_desc(&mvchip->chip, pwm->hwpwm, "mvebu-pwm",
+ GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW);
+ if (IS_ERR(desc))
+ return PTR_ERR(desc);
- mvpwm->gpiod = desc;
- }
-out:
- spin_unlock_irqrestore(&mvpwm->lock, flags);
- return ret;
+ mvpwm->gpiod = desc;
+
+ return 0;
}
static void mvebu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
- unsigned long flags;
- spin_lock_irqsave(&mvpwm->lock, flags);
gpiochip_free_own_desc(mvpwm->gpiod);
mvpwm->gpiod = NULL;
- spin_unlock_irqrestore(&mvpwm->lock, flags);
}
static int mvebu_pwm_get_state(struct pwm_chip *chip,
--
2.56.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v2 4/5] gpio: mvebu: don't request the PWM GPIO under a spinlock
2026-12-05 3:11 ` [PATCH v2 4/5] gpio: mvebu: don't request the PWM GPIO under a spinlock Rosen Penev
@ 2026-12-05 21:15 ` Linus Walleij
0 siblings, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2026-12-05 21:15 UTC (permalink / raw)
To: Rosen Penev
Cc: Bartosz Golaszewski, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Gregory CLEMENT, Rob Herring, Thierry Reding,
Ralph Sennhauser, Andrew Lunn, Bartosz Golaszewski, linux-gpio,
linux-rt-devel
On Sat, Dec 5, 2026 at 4:11 AM Rosen Penev <rosenp@gmail.com> wrote:
> mvebu_pwm_request() calls gpiochip_request_own_desc() with mvpwm->lock
> held and interrupts disabled, and mvebu_pwm_free() does the same with
> gpiochip_free_own_desc(). Both can sleep: requesting the line goes
> through gpiochip_generic_request() and sets the direction through
> pinctrl, which takes the pinctrl mutex.
>
> The PWM core already calls .request and .free with pwm_lock held, so
> the spinlock adds nothing there. Drop it from both callbacks.
>
> Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Good find!
Reviewed-by: Linus Walleij <linusw@kernel.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit
2026-12-05 3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
` (3 preceding siblings ...)
2026-12-05 3:11 ` [PATCH v2 4/5] gpio: mvebu: don't request the PWM GPIO under a spinlock Rosen Penev
@ 2026-12-05 3:11 ` Rosen Penev
2026-12-05 21:16 ` Linus Walleij
4 siblings, 1 reply; 12+ messages in thread
From: Rosen Penev @ 2026-12-05 3:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel
mvebu_pwm_get_state() reads GPIO_BLINK_EN and reports the PWM as
enabled if any bit in it is set. The register has one bit per line,
so any blink bit on another line of the bank, for example one left set
by the boot loader, makes a disabled PWM read back as enabled. The PWM
core uses get_state() to read the initial state of the PWM, so a
consumer then starts from the wrong state.
Check only the bit for this PWM's line.
Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpio/gpio-mvebu.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 0672528e97dc..bfe4721eaa9a 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -720,10 +720,7 @@ static int mvebu_pwm_get_state(struct pwm_chip *chip,
state->period = DIV_ROUND_UP_ULL(val * NSEC_PER_SEC, mvpwm->clk_rate);
regmap_read(mvchip->regs, GPIO_BLINK_EN_OFF + mvchip->offset, &u);
- if (u)
- state->enabled = true;
- else
- state->enabled = false;
+ state->enabled = !!(u & BIT(pwm->hwpwm));
spin_unlock_irqrestore(&mvpwm->lock, flags);
--
2.56.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit
2026-12-05 3:11 ` [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit Rosen Penev
@ 2026-12-05 21:16 ` Linus Walleij
0 siblings, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2026-12-05 21:16 UTC (permalink / raw)
To: Rosen Penev
Cc: Bartosz Golaszewski, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Gregory CLEMENT, Rob Herring, Thierry Reding,
Ralph Sennhauser, Andrew Lunn, Bartosz Golaszewski, linux-gpio,
linux-rt-devel
On Sat, Dec 5, 2026 at 4:11 AM Rosen Penev <rosenp@gmail.com> wrote:
> mvebu_pwm_get_state() reads GPIO_BLINK_EN and reports the PWM as
> enabled if any bit in it is set. The register has one bit per line,
> so any blink bit on another line of the bank, for example one left set
> by the boot loader, makes a disabled PWM read back as enabled. The PWM
> core uses get_state() to read the initial state of the PWM, so a
> consumer then starts from the wrong state.
>
> Check only the bit for this PWM's line.
>
> Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread