summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2026-10-27 09:02:57 -0700
committerGuenter Roeck <linux@roeck-us.net>2026-11-16 13:26:11 -0800
commitd22343336beb0fdfa583da80a08684f8e18878ec (patch)
tree6b238f6b6494cc7f7b1870e03327cec5cef0d699
parent4da537f3b55220b31e5967466d54daaa38203660 (diff)
watchdog: core: Prevent ping worker from re-arming timer on suspend
In watchdog_dev_suspend(), hrtimer_cancel() is called before kthread_cancel_work_sync(). If the timer expired just before hrtimer_cancel() and queued watchdog_ping_work(), the worker can run and acquire wd_data->lock while kthread_cancel_work_sync() waits for it to finish. Because no state flag indicates that the watchdog is suspended, watchdog_worker_should_ping() returns true and __watchdog_ping() re-arms wd_data->timer while the device is suspended. Add a _WDOG_SUSPENDED internal status bit to wd_data->status, set it under wd_data->lock in watchdog_dev_suspend(), clear it under wd_data->lock in watchdog_dev_resume(), and check it in watchdog_worker_should_ping(), watchdog_need_worker(), and __watchdog_ping() so the timer cannot be armed while suspended. Fixes: 60bcd91aafd2 ("watchdog: introduce watchdog_dev_suspend/resume") Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Link: https://patch.msgid.link/20261027160302.2519282-4-linux@roeck-us.net Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/watchdog/watchdog_core.h1
-rw-r--r--drivers/watchdog/watchdog_dev.c15
2 files changed, 12 insertions, 4 deletions
diff --git a/drivers/watchdog/watchdog_core.h b/drivers/watchdog/watchdog_core.h
index ab825d9f9248..c6df5a584357 100644
--- a/drivers/watchdog/watchdog_core.h
+++ b/drivers/watchdog/watchdog_core.h
@@ -60,6 +60,7 @@ struct watchdog_core_data {
#define _WDOG_DEV_OPEN 0 /* Opened ? */
#define _WDOG_ALLOW_RELEASE 1 /* Did we receive the magic char ? */
#define _WDOG_KEEPALIVE 2 /* Did we receive a keepalive ? */
+#define _WDOG_SUSPENDED 3 /* Suspended ? */
};
/*
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 50224877ff49..e38f1ef8e683 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -81,6 +81,9 @@ static inline bool watchdog_need_worker(struct watchdog_device *wdd)
unsigned int hm = wdd->max_hw_heartbeat_ms;
unsigned int t = wdd->timeout * 1000;
+ if (test_bit(_WDOG_SUSPENDED, &wdd->wd_data->status))
+ return false;
+
/*
* A worker to generate heartbeat requests is needed if all of the
* following conditions are true.
@@ -154,9 +157,10 @@ static int __watchdog_ping(struct watchdog_device *wdd)
now = ktime_get();
if (ktime_after(earliest_keepalive, now)) {
- hrtimer_start(&wd_data->timer,
- ktime_sub(earliest_keepalive, now),
- HRTIMER_MODE_REL_HARD);
+ if (!test_bit(_WDOG_SUSPENDED, &wd_data->status))
+ hrtimer_start(&wd_data->timer,
+ ktime_sub(earliest_keepalive, now),
+ HRTIMER_MODE_REL_HARD);
return 0;
}
@@ -207,7 +211,7 @@ static bool watchdog_worker_should_ping(struct watchdog_core_data *wd_data)
{
struct watchdog_device *wdd = wd_data->wdd;
- if (!wdd)
+ if (!wdd || test_bit(_WDOG_SUSPENDED, &wd_data->status))
return false;
if (watchdog_active(wdd))
@@ -1318,6 +1322,8 @@ int watchdog_dev_suspend(struct watchdog_device *wdd)
mutex_lock(&wd_data->lock);
if (watchdog_worker_should_ping(wd_data))
ret = __watchdog_ping(wd_data->wdd);
+ if (!ret)
+ set_bit(_WDOG_SUSPENDED, &wd_data->status);
mutex_unlock(&wd_data->lock);
if (ret)
@@ -1346,6 +1352,7 @@ int watchdog_dev_resume(struct watchdog_device *wdd)
* ping worker if needed.
*/
mutex_lock(&wd_data->lock);
+ clear_bit(_WDOG_SUSPENDED, &wd_data->status);
if (watchdog_worker_should_ping(wd_data))
ret = __watchdog_ping(wd_data->wdd);
mutex_unlock(&wd_data->lock);