Linux Watchdog driver development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guenter Roeck" <linux@roeck-us.net>
Cc: linux-watchdog@vger.kernel.org
Subject: Re: [PATCH 4/8] watchdog: core: Stop pretimeout hrtimer on suspend
Date: Tue, 29 Sep 2026 13:59:57 +0000	[thread overview]
Message-ID: <20260929135958.530611F0089B@smtp.kernel.org> (raw)
In-Reply-To: <20260929134635.2567137-5-linux@roeck-us.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] watchdog: missed software pretimeout on resume due to timer desynchronization
--

commit b401093697a53f53413364d61f3bff8840d84ffc
Author: Guenter Roeck <linux@roeck-us.net>

watchdog: core: Stop pretimeout hrtimer on suspend

This commit stops the pretimeout hrtimer during system suspend and ensures
it is correctly restarted on resume if the hardware watchdog is running. It
also prevents the timer from starting while the watchdog is suspended.

> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> index d652d6e137c43..f1d14ac433fd9 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c

[ ... ]

> @@ -1350,6 +1351,8 @@ int watchdog_dev_resume(struct watchdog_device *wdd)
>  	clear_bit(_WDOG_SUSPENDED, &wd_data->status);
>  	if (watchdog_worker_should_ping(wd_data))
>  		ret = __watchdog_ping(wd_data->wdd);
> +	if (watchdog_hw_running(wdd) && !ret)
> +		watchdog_hrtimer_pretimeout_start(wdd);

[Severity: High]
Could this explicit restart push the software pretimeout out of sync with the
hardware counter?

If the watchdog is past the open deadline, watchdog_worker_should_ping()
returns false. The kernel intentionally stops pinging the hardware watchdog
so it will reset the system.

When suspended and resumed in this state, __watchdog_ping() is skipped, but
watchdog_hw_running() remains true. Since ret is 0, we restart the pretimeout
timer.

Does this assume the hardware counter was just reset to now, artificially
delaying the software pretimeout beyond the actual hardware reset?

>  	mutex_unlock(&wd_data->lock);
>  
>  	return ret;

[ ... ]

> diff --git a/drivers/watchdog/watchdog_hrtimer_pretimeout.c b/drivers/watchdog/watchdog_hrtimer_pretimeout.c
> index 49a05ea60c979..5c88e6467994b 100644
> --- a/drivers/watchdog/watchdog_hrtimer_pretimeout.c
> +++ b/drivers/watchdog/watchdog_hrtimer_pretimeout.c
> @@ -31,7 +31,8 @@ void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd)
>  {
>  	if (!(wdd->info->options & WDIOF_PRETIMEOUT) &&
>  	    wdd->pretimeout &&
> -	    !watchdog_pretimeout_invalid(wdd, wdd->pretimeout))
> +	    !watchdog_pretimeout_invalid(wdd, wdd->pretimeout) &&
> +	    !test_bit(_WDOG_SUSPENDED, &wdd->wd_data->status))
>  		hrtimer_start(&wdd->wd_data->pretimeout_timer,
>  			      ktime_set(wdd->timeout - wdd->pretimeout, 0),
>  			      HRTIMER_MODE_REL);

[Severity: High]
Since hrtimer_start() here uses HRTIMER_MODE_REL, the timer is always
scheduled strictly relative to now.

If the hardware watchdog was last pinged before the suspend cycle, it will
reboot the system at last_hw_keepalive + timeout.

If the elapsed time (which includes the suspend duration) exceeds pretimeout,
will this relative timer be scheduled to fire after the hardware reset occurs,
causing the pretimeout event to be completely missed?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260929134635.2567137-1-linux@roeck-us.net?part=4

  reply	other threads:[~2026-09-29 13:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 13:46 [PATCH 0/8] watchdog: core: Fix locking, lifetime, suspend, and state management bugs Guenter Roeck
2026-09-29 13:46 ` [PATCH 1/8] watchdog: core: Clear wd_data pointer on errors Guenter Roeck
2026-09-30 11:53   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 2/8] watchdog: core: Add missing locks Guenter Roeck
2026-09-30 11:53   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 3/8] watchdog: core: Prevent ping worker from re-arming timer on suspend Guenter Roeck
2026-09-30 11:53   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 4/8] watchdog: core: Stop pretimeout hrtimer " Guenter Roeck
2026-09-29 13:59   ` sashiko-bot [this message]
2026-09-30 11:54   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 5/8] watchdog: core: Restore WDOG_HW_RUNNING if stopping watchdog fails Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih
2026-09-30 12:37     ` Guenter Roeck
2026-09-29 13:46 ` [PATCH 6/8] watchdog: core: Cancel timer if cdev_device_add() fails Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 7/8] watchdog: core: Fix unbalanced module_put() in watchdog_open() Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 8/8] watchdog: core: Update last_keepalive in watchdog_start() Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih

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=20260929135958.530611F0089B@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox