All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: intel_oc_wdt: Stop the watchdog during system sleep
@ 2026-11-19 21:03 Paul Menzel
  2026-11-19 21:16 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Menzel @ 2026-11-19 21:03 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck, Kees Cook, Tony Luck,
	Guilherme G. Piccoli, Diogo Ivo
  Cc: Paul Menzel, linux-watchdog, linux-kernel

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` result 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.

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 the Dell XPS 13 9310 with the patched module built for
7.4.0-rc1 and systemd RuntimeWatchdogSec=30s: rtcwake -m freeze -s 120
resumed normally on the same boot, the OC watchdog enable bit (I/O
0x1854, 0x0080601d) was set before and after, and the watchdog kept
running afterwards. The stock module reset the machine in 2 of 2
attempts.

Fixes: 535d1784d8a9 ("watchdog: Add driver for Intel OC WDT")
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---

Notes:
    Tool use: Claude Code (claude-opus-5-5) found the reset while
    measuring s2idle power on ortiz, wrote the change and the commit
    message; compile-tested with W=1 (CONFIG_PM_SLEEP=y/n) and
    checkpatch-clean.

 drivers/watchdog/intel_oc_wdt.c | 42 +++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/watchdog/intel_oc_wdt.c b/drivers/watchdog/intel_oc_wdt.c
index 0b012aeb18e15..da93db34dfd2f 100644
--- a/drivers/watchdog/intel_oc_wdt.c
+++ b/drivers/watchdog/intel_oc_wdt.c
@@ -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,45 @@ 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->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 +264,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,
 };
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] watchdog: intel_oc_wdt: Stop the watchdog during system sleep
  2026-11-19 21:03 [PATCH] watchdog: intel_oc_wdt: Stop the watchdog during system sleep Paul Menzel
@ 2026-11-19 21:16 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 21:16 UTC (permalink / raw)
  To: Paul Menzel; +Cc: linux-watchdog

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] watchdog: intel_oc_wdt: timeout not restored in
  intel_oc_wdt_resume_noirq()
--

commit 4da4626fae8bd66b23127eb234a7132f8de0ce8a
Author: Paul Menzel <pmenzel@molgen.mpg.de>

watchdog: intel_oc_wdt: Stop the watchdog during system sleep

This commit adds noirq suspend and resume callbacks to stop the Intel OC
watchdog during system sleep and restart it on resume.

> diff --git a/drivers/watchdog/intel_oc_wdt.c b/drivers/watchdog/intel_oc_wdt.c
> index a78fe1e5f410b..6e32536fae4b9 100644
> --- a/drivers/watchdog/intel_oc_wdt.c
> +++ b/drivers/watchdog/intel_oc_wdt.c
[ ... ]
> @@ -212,6 +214,45 @@ 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->suspended)
> +		return 0;
> +
> +	intel_oc_wdt_start(&oc_wdt->wdd);
> +	intel_oc_wdt_ping(&oc_wdt->wdd);
> +	oc_wdt->suspended = false;
> +
> +	return 0;
> +}

[Severity: Medium]
Should intel_oc_wdt_resume_noirq() also restore INTEL_OC_WDT_TOV via
intel_oc_wdt_set_timeout(&oc_wdt->wdd, oc_wdt->wdd.timeout)?

Across hibernation (or S3 if platform firmware resets the control
register), the hardware register loses any runtime timeout set via
WDIOC_SETTIMEOUT and reverts to the boot or probe default
(INTEL_OC_WDT_DEF_TOV, 60 seconds).  Because intel_oc_wdt_start() only
sets INTEL_OC_WDT_EN and intel_oc_wdt_ping() reloads from the current
INTEL_OC_WDT_TOV field, a userspace daemon configured with a longer
timeout and a matching ping interval can hit an unexpected watchdog reset
after resume.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119210358.610521-1-pmenzel@molgen.mpg.de?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 21:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 21:03 [PATCH] watchdog: intel_oc_wdt: Stop the watchdog during system sleep Paul Menzel
2026-11-19 21:16 ` sashiko-bot

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.