watchdog: intel_oc_wdt: Stop the watchdog during system sleep
PATCH v2 1/1 watchdog: intel_oc_wdt: Stop the watchdog during system sleep
The driver has no system sleep callbacks, so a running watchdog keeps counting in suspend-to-idle. Suspend-to-idle stops the tick, so neither user space nor the watchdog core can ping it, and the watchdog resets the machine once the timeout expires.
On a Dell XPS 13 9310 (Tiger Lake, BIOS 3.17.0, no ACPI S3) with systemd RuntimeWatchdogSec=30s on /dev/watchdog-oc, both rtcwake -m freeze -s 900 and rtcwake -m freeze -s 60 resulted in a reset about 30 s after entering suspend, without any message in the journal or in pstore. With the systemd runtime watchdog disabled, the system stayed in suspend-to-idle for 900 s and resumed normally.
Stop the watchdog in the noirq suspend phase and restart it, with a reload, in the noirq resume phase, as iTCO_wdt does. Check the enable bit in hardware rather than watchdog_active(), so a watchdog started by the firmware, which only the watchdog core pings, is covered too. If the control register is locked, the watchdog cannot be stopped, so leave it alone.
Also program the timeout again on resume, whether or not the watchdog was running: the platform firmware may reset the control register, and when resuming from hibernation, it holds the timeout the boot kernel set. intel_oc_wdt_start() only sets the enable bit, so a timeout set with WDIOC_SETTIMEOUT would otherwise be lost.
Unlike iTCO_wdt, do this for all sleep states and not only for suspend-to-idle, as it is not documented whether the platform firmware stops the OC watchdog in ACPI S3 or S4. Hangs in the device suspend and resume callbacks outside the noirq phases are still caught.
Tested on a Dell XPS 13 9310 (BIOS 3.17.0) with the module built for 7.4.0-rc1 and systemd RuntimeWatchdogSec=30s:
- rtcwake -m freeze -s 120 resumes normally; the stock module reset the machine in 2 of 2 attempts.
- TOV restore: with the watchdog armed, overwrite TOV with 0x3b (60 s) via outl, as the firmware might, then rtcwake -m freeze -s 60. v1: register 0x0080603b after resume (TOV 60 s kept). v2: 0x0080601d (TOV 30 s restored, EN set), watchdog still running 40 s later.
---
Notes:
Changes in v2:
- Program the timeout (TOV) again on resume, also when the watchdog was not running, as the firmware or, after hibernation, the boot kernel may have changed it (Sashiko review of v1)
v1: https://lore.kernel.org/all/[email protected]/
Tool use: Claude Code (claude-opus-5-5) found the reset while measuring s2idle power, wrote the change and the commit message; compile-tested with W=1 (CONFIG_PM_SLEEP=y/n), checkpatch-clean.
drivers/watchdog/intel_oc_wdt.c | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
drivers/watchdog/intel_oc_wdt.c +52 -0
@@ -44,6 +44,7 @@ struct intel_oc_wdt {struct resource *ctrl_res;struct watchdog_info info;bool locked; +bool suspended; };static int heartbeat;
@@ -204,6 +205,7 @@ static int intel_oc_wdt_probe(struct platform_device *pdev)if (ret)return ret; +platform_set_drvdata (pdev, oc_wdt);watchdog_set_drvdata (wdd, oc_wdt);watchdog_set_nowayout (wdd, nowayout);watchdog_stop_on_reboot (wdd);
@@ -212,6 +214,55 @@ static int intel_oc_wdt_probe(struct platform_device *pdev)return devm_watchdog_register_device (dev, wdd); } +/* +* Neither user space nor the watchdog core can ping the watchdog while the +* system sleeps, and in suspend-to-idle the counter keeps running, so stop the +* watchdog late in suspend and restart it early in resume. Check the hardware +* enable bit, as the watchdog may also have been started by the firmware. +*/ +static int intel_oc_wdt_suspend_noirq (struct device *dev) +{ +struct intel_oc_wdt *oc_wdt =dev_get_drvdata (dev); + + oc_wdt->suspended = false; + +if (oc_wdt->locked || + !(inl (INTEL_OC_WDT_CTRL_REG (oc_wdt)) &INTEL_OC_WDT_EN )) +return 0 ; + +intel_oc_wdt_stop (&oc_wdt->wdd); + oc_wdt->suspended = true; + +return 0 ; +} + +static int intel_oc_wdt_resume_noirq (struct device *dev) +{ +struct intel_oc_wdt *oc_wdt =dev_get_drvdata (dev); + +if (oc_wdt->locked) +return 0 ; + +/* +* The timeout in hardware may have been reset by the platform firmware +* or, when resuming from hibernation, set by the boot kernel, and +* intel_oc_wdt_start() does not program it. +*/ +intel_oc_wdt_set_timeout (&oc_wdt->wdd, oc_wdt->wdd.timeout); + +if (!oc_wdt->suspended) +return 0 ; + +intel_oc_wdt_start (&oc_wdt->wdd); +intel_oc_wdt_ping (&oc_wdt->wdd); + oc_wdt->suspended = false; + +return 0 ; +} + +static DEFINE_NOIRQ_DEV_PM_OPS(intel_oc_wdt_pm_ops, intel_oc_wdt_suspend_noirq, + intel_oc_wdt_resume_noirq); +static const struct acpi_device_id intel_oc_wdt_match[] = { {"INT3F0D" }, {"INTC1099" },
@@ -223,6 +274,7 @@ static struct platform_driver intel_oc_wdt_platform_driver = { .driver = { .name = DRV_NAME, .acpi_match_table = intel_oc_wdt_match, + .pm = pm_sleep_ptr(&intel_oc_wdt_pm_ops), }, .probe = intel_oc_wdt_probe, };
Signature · 1 line
2.54.0
Quoted 40 lines · Paul Menzel
The driver has no system sleep callbacks, so a running watchdog keeps counting in suspend-to-idle. Suspend-to-idle stops the tick, so neither user space nor the watchdog core can ping it, and the watchdog resets the machine once the timeout expires.
On a Dell XPS 13 9310 (Tiger Lake, BIOS 3.17.0, no ACPI S3) with systemd
RuntimeWatchdogSec=30son/dev/watchdog-oc, bothrtcwake -m freeze -s 900andrtcwake -m freeze -s 60resulted in a reset about 30 s after entering suspend, without any message in the journal or in pstore. With the systemd runtime watchdog disabled, the system stayed in suspend-to-idle for 900 s and resumed normally.Stop the watchdog in the noirq suspend phase and restart it, with a reload, in the noirq resume phase, as
iTCO_wdtdoes. Check the enable bit in hardware rather thanwatchdog_active(), so a watchdog started by the firmware, which only the watchdog core pings, is covered too. If the control register is locked, the watchdog cannot be stopped, so leave it alone.Also program the timeout again on resume, whether or not the watchdog was running: the platform firmware may reset the control register, and when resuming from hibernation, it holds the timeout the boot kernel set.
intel_oc_wdt_start()only sets the enable bit, so a timeout set withWDIOC_SETTIMEOUTwould otherwise be lost.Unlike
iTCO_wdt, do this for all sleep states and not only for suspend-to-idle, as it is not documented whether the platform firmware stops the OC watchdog in ACPI S3 or S4. Hangs in the device suspend and resume callbacks outside the noirq phases are still caught.Tested on a Dell XPS 13 9310 (BIOS 3.17.0) with the module built for 7.4.0-rc1 and systemd RuntimeWatchdogSec=30s:
- rtcwake -m freeze -s 120 resumes normally; the stock module reset the machine in 2 of 2 attempts.
- TOV restore: with the watchdog armed, overwrite TOV with0x3b(60 s) via outl, as the firmware might, then rtcwake -m freeze -s 60. v1: register0x0080603bafter resume (TOV 60 s kept). v2:0x0080601d(TOV 30 s restored, EN set), watchdog still running 40 s later.
Quoted 2 lines
Fixes 535d1784d8a9 ("watchdog: Add driver for Intel OC WDT")Signed-off-by Paul Menzel <[email protected]>
Applied.
Thanks,
Guenter