* [PATCH RFC] watchdog: core: Ignore userspace keepalives once the system goes down
@ 2026-11-19 16:53 ` Arun Iyengar via B4 Relay
0 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar @ 2026-11-19 16:53 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: linux-watchdog, linux-kernel, Primoz Fiser, Arun Iyengar
A watchdog left running through a reboot should reset a system whose
reboot hangs. But a daemon still pinging after reboot(2), such as
systemd after "systemctl reboot -ff", keeps a hang in device_shutdown()
from ever being reset.
Ignore userspace keepalives once system_state is past SYSTEM_RUNNING,
as da9062_wdt and da9063_wdt do since commit 2f61b3a74699 ("watchdog:
da9062: da9063: prevent pings ahead of machine reset").
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
RFC: this changes every driver. A reboot or power-off whose
device_shutdown() outlasts the timeout now ends in a watchdog reset.
Tested on an Orange Pi Zero2 (H616, sunxi_wdt) on 7.3.5 with a test
module that oopses holding a device lock: "systemctl reboot -ff" was
reset after 14 s in 6 of 6 runs. Without the patch there was no reset
within 90 s (one run, older 7.3 build). Other drivers and kexec are
not tested.
Developed with Claude (Anthropic) as a coding assistant, which wrote
the code and the commit message. I reviewed and tested it.
---
drivers/watchdog/watchdog_dev.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index aad3f1f1b4ce..0f149da49a69 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -201,6 +201,9 @@ static int watchdog_ping(struct watchdog_device *wdd)
if (!watchdog_hw_running(wdd))
return 0;
+ if (system_state > SYSTEM_RUNNING)
+ return 0;
+
set_bit(_WDOG_KEEPALIVE, &wd_data->status);
wd_data->last_keepalive = ktime_get();
---
base-commit: 865c2d0f1dd3f0937865dd11819eeb59298a814c
change-id: 20261119-watchdog-reboot-keepalive-fd50f4b828f2
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RFC] watchdog: core: Ignore userspace keepalives once the system goes down
@ 2026-11-19 16:53 ` Arun Iyengar via B4 Relay
0 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-19 16:53 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: linux-watchdog, linux-kernel, Primoz Fiser, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
A watchdog left running through a reboot should reset a system whose
reboot hangs. But a daemon still pinging after reboot(2), such as
systemd after "systemctl reboot -ff", keeps a hang in device_shutdown()
from ever being reset.
Ignore userspace keepalives once system_state is past SYSTEM_RUNNING,
as da9062_wdt and da9063_wdt do since commit 2f61b3a74699 ("watchdog:
da9062: da9063: prevent pings ahead of machine reset").
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
RFC: this changes every driver. A reboot or power-off whose
device_shutdown() outlasts the timeout now ends in a watchdog reset.
Tested on an Orange Pi Zero2 (H616, sunxi_wdt) on 7.3.5 with a test
module that oopses holding a device lock: "systemctl reboot -ff" was
reset after 14 s in 6 of 6 runs. Without the patch there was no reset
within 90 s (one run, older 7.3 build). Other drivers and kexec are
not tested.
Developed with Claude (Anthropic) as a coding assistant, which wrote
the code and the commit message. I reviewed and tested it.
---
drivers/watchdog/watchdog_dev.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index aad3f1f1b4ce..0f149da49a69 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -201,6 +201,9 @@ static int watchdog_ping(struct watchdog_device *wdd)
if (!watchdog_hw_running(wdd))
return 0;
+ if (system_state > SYSTEM_RUNNING)
+ return 0;
+
set_bit(_WDOG_KEEPALIVE, &wd_data->status);
wd_data->last_keepalive = ktime_get();
---
base-commit: 865c2d0f1dd3f0937865dd11819eeb59298a814c
change-id: 20261119-watchdog-reboot-keepalive-fd50f4b828f2
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] watchdog: core: Ignore userspace keepalives once the system goes down
2026-11-19 16:53 ` Arun Iyengar via B4 Relay
(?)
@ 2026-11-19 17:07 ` sashiko-bot
-1 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-19 17:07 UTC (permalink / raw)
To: Arun Iyengar; +Cc: linux-watchdog
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] watchdog: core: partial execution of WDIOC_SETTIMEOUT during
shutdown
--
commit aaa4c1cf2a5820b51fb679779e0af90fdf817cba
Author: Arun Iyengar <aiyengar1990@gmail.com>
watchdog: core: Ignore userspace keepalives once the system goes down
This commit makes watchdog_ping() return early without pinging the
watchdog once system_state is past SYSTEM_RUNNING.
> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> index aad3f1f1b4ce8..0f149da49a694 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c
> @@ -201,6 +201,9 @@ static int watchdog_ping(struct watchdog_device *wdd)
> if (!watchdog_hw_running(wdd))
> return 0;
>
> + if (system_state > SYSTEM_RUNNING)
> + return 0;
[Severity: Medium]
Should watchdog_set_timeout() also check system_state > SYSTEM_RUNNING?
In watchdog_ioctl(), WDIOC_SETTIMEOUT runs watchdog_set_timeout() and
then calls watchdog_ping() to apply the new timeout:
drivers/watchdog/watchdog_dev.c:watchdog_ioctl() {
...
case WDIOC_SETTIMEOUT:
...
err = watchdog_set_timeout(wdd, val);
if (err < 0)
break;
/* If the watchdog is active then we send a keepalive ping
* to make sure that the watchdog keep's running (and if
* possible that it takes the new timeout) */
err = watchdog_ping(wdd);
...
}
When system_state > SYSTEM_RUNNING, watchdog_set_timeout() still runs
while watchdog_ping() becomes a no-op. For drivers whose ops->set_timeout
reloads the hardware timer directly (such as sunxi_wdt_set_timeout()) or
that use the keepalive worker updated by watchdog_update_worker(), a
daemon issuing WDIOC_SETTIMEOUT can still reset or extend the countdown
during shutdown. For drivers that rely on the subsequent ping to program
wdd->timeout into hardware and restart pretimeout_timer, wdd->timeout,
wdd->pretimeout, and wd_data->timer are updated out of sync with the
running hardware timer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-watchdog-reboot-keepalive-v1-1-c5902d959796@gmail.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] watchdog: core: Ignore userspace keepalives once the system goes down
2026-11-19 16:53 ` Arun Iyengar via B4 Relay
(?)
(?)
@ 2026-11-19 17:10 ` Guenter Roeck
2026-11-20 7:00 ` Arun Iyengar
-1 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2026-11-19 17:10 UTC (permalink / raw)
To: aiyengar1990, Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Primoz Fiser
On 11/19/26 08:53, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> A watchdog left running through a reboot should reset a system whose
> reboot hangs. But a daemon still pinging after reboot(2), such as
> systemd after "systemctl reboot -ff", keeps a hang in device_shutdown()
> from ever being reset.
>
If systemd is still running and able to send watchdog pings, the system
is not really hanging.
> Ignore userspace keepalives once system_state is past SYSTEM_RUNNING,
> as da9062_wdt and da9063_wdt do since commit 2f61b3a74699 ("watchdog:
> da9062: da9063: prevent pings ahead of machine reset").
>
Those drivers have a very specific reason to stop pings during poweroff,
because not doing so could result in failed restart / poweroff sequences
(as the commit message explains).
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
> ---
> RFC: this changes every driver. A reboot or power-off whose
> device_shutdown() outlasts the timeout now ends in a watchdog reset.
>
Which would be unacceptable.
I don't know what problem you are actually trying to solve, but in
its current form this is a NACK.
Guenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] watchdog: core: Ignore userspace keepalives once the system goes down
2026-11-19 17:10 ` Guenter Roeck
@ 2026-11-20 7:00 ` Arun Iyengar
0 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar @ 2026-11-20 7:00 UTC (permalink / raw)
To: Guenter Roeck
Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, Primoz Fiser
On 11/19/26 09:10, Guenter Roeck wrote:
> I don't know what problem you are actually trying to solve, but in
> its current form this is a NACK.
Thank you for your review!
The case was a driver that oopsed in probe while holding its
device lock: device_shutdown() then blocked forever during "systemctl
reboot -ff" while systemd kept pinging. I take the point that a slow
shutdown must not turn into a reset, so I'll drop this.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-20 7:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 16:53 [PATCH RFC] watchdog: core: Ignore userspace keepalives once the system goes down Arun Iyengar
2026-11-19 16:53 ` Arun Iyengar via B4 Relay
2026-11-19 17:07 ` sashiko-bot
2026-11-19 17:10 ` Guenter Roeck
2026-11-20 7:00 ` Arun Iyengar
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.