All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Wim Van Sebroeck <wim@linux-watchdog.org>,
	Guenter Roeck <linux@roeck-us.net>,
	Serge Semin <Sergey.Semin@baikalelectronics.ru>,
	linux-watchdog@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 2/6] watchdog: dw_wdt: Guard shared IRQ handler during system suspend and resume
Date: Thu,  3 Dec 2026 17:30:05 +0000	[thread overview]
Message-ID: <20261203173039.1142495-3-lee@kernel.org> (raw)
In-Reply-To: <20261203173039.1142495-1-lee@kernel.org>

dw_wdt_irq() is registered with IRQF_SHARED and unconditionally reads
WDOG_INTERRUPT_STATUS_REG_OFFSET.  Because dw_wdt_suspend() asserts
reset and disables the clocks during normal dpm_suspend() before
suspend_device_irqs() runs (and resume_device_irqs() runs before
dw_wdt_resume() re-enables them), a shared interrupt firing in either
window causes an unclocked register read while the watchdog is in reset.

Track suspended state with acquire/release ordering and synchronise
with any in-flight IRQ handler via synchronize_irq() before asserting
reset and gating clocks in dw_wdt_suspend().

Fixes: 46a1946314bf ("watchdog: dw_wdt: Add pre-timeouts support")
Closes: https://sashiko.dev/#/bug/linux-f2a43bc3-4f5e-47b2-8d47-8fd4d6ed485f
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/watchdog/dw_wdt.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index b9a34857810b..3bf3f54b9356 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -89,6 +89,8 @@ struct dw_wdt {
 	struct dw_wdt_timeout	timeouts[DW_WDT_NUM_TOPS];
 	struct watchdog_device	wdd;
 	struct reset_control	*rst;
+	int			irq;
+	bool			suspended;
 	/* Save/restore */
 	u32			control;
 	u32			timeout;
@@ -363,6 +365,10 @@ static irqreturn_t dw_wdt_irq(int irq, void *devid)
 	struct dw_wdt *dw_wdt = devid;
 	u32 val;
 
+	/* Pairs with smp_store_release() in dw_wdt_resume() and error path. */
+	if (smp_load_acquire(&dw_wdt->suspended))
+		return IRQ_NONE;
+
 	/*
 	 * We don't clear the IRQ status. It's supposed to be done by the
 	 * following ping operations.
@@ -384,9 +390,16 @@ static int dw_wdt_suspend(struct device *dev)
 	dw_wdt->control = readl(dw_wdt->regs + WDOG_CONTROL_REG_OFFSET);
 	dw_wdt->timeout = readl(dw_wdt->regs + WDOG_TIMEOUT_RANGE_REG_OFFSET);
 
+	WRITE_ONCE(dw_wdt->suspended, true);
+	if (dw_wdt->irq > 0)
+		synchronize_irq(dw_wdt->irq);
+
 	err = reset_control_assert(dw_wdt->rst);
-	if (err)
+	if (err) {
+		/* Pairs with smp_load_acquire() in dw_wdt_irq(). */
+		smp_store_release(&dw_wdt->suspended, false);
 		return err;
+	}
 
 	clk_disable_unprepare(dw_wdt->pclk);
 	clk_disable_unprepare(dw_wdt->clk);
@@ -416,6 +429,9 @@ static int dw_wdt_resume(struct device *dev)
 
 	dw_wdt_ping(&dw_wdt->wdd);
 
+	/* Pairs with smp_load_acquire() in dw_wdt_irq(). */
+	smp_store_release(&dw_wdt->suspended, false);
+
 	return 0;
 
 unprepare_pclk:
@@ -619,7 +635,8 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 	 */
 	ret = platform_get_irq_optional(pdev, 0);
 	if (ret > 0) {
-		ret = devm_request_irq(dev, ret, dw_wdt_irq,
+		dw_wdt->irq = ret;
+		ret = devm_request_irq(dev, dw_wdt->irq, dw_wdt_irq,
 				       IRQF_SHARED | IRQF_TRIGGER_RISING,
 				       pdev->name, dw_wdt);
 		if (ret)
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-03 17:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 17:30 [PATCH 0/6] watchdog: Fix High issues reported by Sashiko Lee Jones
2026-12-03 17:30 ` [PATCH 1/6] watchdog: da9063: Stop ping worker on system suspend Lee Jones
2026-12-03 18:31   ` sashiko-bot
2026-12-03 17:30 ` Lee Jones [this message]
2026-12-03 19:00   ` [PATCH 2/6] watchdog: dw_wdt: Guard shared IRQ handler during system suspend and resume sashiko-bot
2026-12-03 17:30 ` [PATCH 3/6] watchdog: npcm: Enable clock before checking running state in probe Lee Jones
2026-12-04  1:02   ` Guenter Roeck
2026-12-03 17:30 ` [PATCH 4/6] watchdog: sbsa: Evaluate MediaTek WS0 workaround after IRQ fallback Lee Jones
2026-12-04  1:03   ` Guenter Roeck
2026-12-03 17:30 ` [PATCH 5/6] watchdog: octeon-wdt: Serialise countdown and IRQ state with raw spinlock Lee Jones
2026-12-03 19:45   ` sashiko-bot
2026-12-03 17:30 ` [PATCH 6/6] watchdog: rzv2h: Avoid 32-bit overflow in max_hw_heartbeat_ms calculation Lee Jones
2026-12-04  1:04   ` Guenter Roeck
2026-12-04  1:08 ` [PATCH 0/6] watchdog: Fix High issues reported by Sashiko Guenter Roeck

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=20261203173039.1142495-3-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=Sergey.Semin@baikalelectronics.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=stable@vger.kernel.org \
    --cc=wim@linux-watchdog.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.