Skip to contentSkip to conversation

watchdog: mtk_wdt: Stop a running watchdog over system sleep even if not opened

PATCH Applied zoan37 2 participants 2 messages Oct 11 – Oct 20

Subsystems (2)
lore
Share & tools
lore

zoan37

author
#0 lore raw

PATCH v3 1/1 watchdog: mtk_wdt: Stop a running watchdog over system sleep even if not opened

mtk_wdt_suspend() and mtk_wdt_resume() only stop and restart the watchdog when it is active, that is, when userspace has opened it.

But a watchdog that the bootloader left enabled stays enabled at probe, marked WDOG_HW_RUNNING, and the watchdog core pings it until userspace takes over; that has been the case since
commit bbece05c0d3a ("watchdog: mtk_wdt: Remove mtk_wdt_stop() in probe() to prevent the system freeze and it doesn't reboot by watchdog problem"). If the system suspends before userspace opens the device, or userspace never does, nothing stops the watchdog and nothing pings it while the system sleeps, so it resets the system one timeout (31 s by default) into the sleep.

Also stop it on suspend and restart it on resume when it is running in hardware, like sp805_wdt does.

The watchdog core keeps pinging such a watchdog until mtk_wdt_suspend() stops it, so it stays fed while tasks are frozen before the devices suspend. It may also ping once after resume, before mtk_wdt_resume() has started the watchdog again; that only reloads the counter of a stopped watchdog, and the watchdog stays powered over system sleep (it is what resets the system from s2idle without this patch). watchdog_stop_ping_on_suspend() is deliberately not used: it stops the pings from PM_SUSPEND_PREPARE on, which would leave a running watchdog unfed while tasks are frozen and could reset the system there with a short timeout.

Fixes bbece05c0d3a ("watchdog: mtk_wdt: Remove mtk_wdt_stop() in probe() to prevent the system freeze and it doesn't reboot by watchdog problem")
Assisted-by LLM

---
Changes in v3:
- Drop watchdog_stop_ping_on_suspend() again. It stops the core's pings at PM_SUSPEND_PREPARE, before tasks are frozen, while the watchdog keeps running until mtk_wdt_suspend(); with a short timeout that could reset the system during the freeze (Sashiko review of v2). The ping after resume it was meant to avoid (Sashiko review of v1) is harmless, see the commit message.
- The code is v1 again; the commit message explains the choice.
- v2: https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Call watchdog_stop_ping_on_suspend() in probe.
- v1: https://lore.kernel.org/all/[email protected]/

Testing: on an MT8189 Chromebook (next-20261008 plus MT8189 support) whose firmware leaves the watchdog off; a local module parameter (mtk_wdt.start_timeout=31) starts it in probe the same way a bootloader-enabled watchdog is picked up (WDOG_HW_RUNNING set, fed by the watchdog core, nobody opening /dev/watchdog). Without this patch the board reset about 30 s into s2idle. With this code (= v1): a 10-minute s2idle sleep and 40+ shorter s2idle cycles came back without a reset. Not tested with a watchdog actually left enabled by a bootloader. Built with W=1, checkpatch --strict clean apart from the sign-off.

 drivers/watchdog/mtk_wdt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/watchdog/mtk_wdt.c +4 -2
index 1630ab65d593..ff72e0fb1154 100644
@@ -572,7 +572,8 @@ static int mtk_wdt_suspend(struct device *dev)
 {
 	struct mtk_wdt_dev *mtk_wdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&mtk_wdt->wdt_dev))
+	if (watchdog_active(&mtk_wdt->wdt_dev) ||
+	    watchdog_hw_running(&mtk_wdt->wdt_dev))
 		mtk_wdt_stop(&mtk_wdt->wdt_dev);
 
 	return 0;
@@ -582,7 +583,8 @@ static int mtk_wdt_resume(struct device *dev)
 {
 	struct mtk_wdt_dev *mtk_wdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&mtk_wdt->wdt_dev)) {
+	if (watchdog_active(&mtk_wdt->wdt_dev) ||
+	    watchdog_hw_running(&mtk_wdt->wdt_dev)) {
 		mtk_wdt_start(&mtk_wdt->wdt_dev);
 		mtk_wdt_ping(&mtk_wdt->wdt_dev);
 	}

base-commit: aac26bee2287c88af5be5a5ff96d783b19a28790

Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 27 lines · On Sat, Oct 10, 2026 at 09:36:31PM -0400, zoan37 wrote:

mtk_wdt_suspend() and mtk_wdt_resume() only stop and restart the watchdog when it is active, that is, when userspace has opened it.

But a watchdog that the bootloader left enabled stays enabled at probe, marked WDOG_HW_RUNNING, and the watchdog core pings it until userspace takes over; that has been the case since
commit bbece05c0d3a ("watchdog: mtk_wdt: Remove mtk_wdt_stop() in probe() to prevent the system freeze and it doesn't reboot by watchdog problem"). If the system suspends before userspace opens the device, or userspace never does, nothing stops the watchdog and nothing pings it while the system sleeps, so it resets the system one timeout (31 s by default) into the sleep.

Also stop it on suspend and restart it on resume when it is running in hardware, like sp805_wdt does.

The watchdog core keeps pinging such a watchdog until mtk_wdt_suspend() stops it, so it stays fed while tasks are frozen before the devices suspend. It may also ping once after resume, before mtk_wdt_resume() has started the watchdog again; that only reloads the counter of a stopped watchdog, and the watchdog stays powered over system sleep (it is what resets the system from s2idle without this patch). watchdog_stop_ping_on_suspend() is deliberately not used: it stops the pings from PM_SUSPEND_PREPARE on, which would leave a running watchdog unfed while tasks are frozen and could reset the system there with a short timeout.

Quoted 3 lines
Fixes bbece05c0d3a ("watchdog: mtk_wdt: Remove mtk_wdt_stop() in probe() to prevent the system freeze and it doesn't reboot by watchdog problem")
Assisted-by LLM

Applied.

Thanks,
Guenter