From: Rosen Penev <rosenp@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Rosen Penev <rosenp@gmail.com>,
Gregory CLEMENT <gregory.clement@bootlin.com>
Cc: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
linux-gpio@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: [PATCH 1/2] gpio: mvebu: restore suspend-time irq masks under gc->lock
Date: Thu, 3 Dec 2026 14:58:19 -0800 [thread overview]
Message-ID: <20261203225820.83277-2-rosenp@gmail.com> (raw)
In-Reply-To: <20261203225820.83277-1-rosenp@gmail.com>
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
next prev parent reply other threads:[~2026-12-03 22:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-03 22:58 ` [PATCH 2/2] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too Rosen Penev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203225820.83277-2-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=bigeasy@linutronix.de \
--cc=brgl@kernel.org \
--cc=clrkwllms@kernel.org \
--cc=gregory.clement@bootlin.com \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox