Skip to content

Commit 8d5755b

Browse files
Niklas Casselgroeck
authored andcommitted
watchdog: softdog: fire watchdog even if softirqs do not get to run
Checking for timer expiration is done from the softirq TIMER_SOFTIRQ. Since commit 4cd13c2 ("softirq: Let ksoftirqd do its job"), pending softirqs are no longer always handled immediately, instead, if there are pending softirqs, and ksoftirqd is in state TASK_RUNNING, the handling of the softirqs are deferred, and are instead supposed to be handled by ksoftirqd, when ksoftirqd gets scheduled. If a user space process with a real-time policy starts to misbehave by never relinquishing the CPU while ksoftirqd is in state TASK_RUNNING, what will happen is that all softirqs will get deferred, while ksoftirqd, which is supposed to handle the deferred softirqs, will never get to run. To make sure that the watchdog is able to fire even when we do not get to run softirqs, replace the timers with hrtimers. Signed-off-by: Niklas Cassel <niklas.cassel@axis.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent ed4a9ec commit 8d5755b

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

‎drivers/watchdog/softdog.c‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121

2222
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2323

24+
#include <linux/hrtimer.h>
2425
#include <linux/init.h>
25-
#include <linux/jiffies.h>
2626
#include <linux/kernel.h>
2727
#include <linux/module.h>
2828
#include <linux/moduleparam.h>
2929
#include <linux/reboot.h>
30-
#include <linux/timer.h>
3130
#include <linux/types.h>
3231
#include <linux/watchdog.h>
3332

@@ -54,7 +53,10 @@ module_param(soft_panic, int, 0);
5453
MODULE_PARM_DESC(soft_panic,
5554
"Softdog action, set to 1 to panic, 0 to reboot (default=0)");
5655

57-
static void softdog_fire(unsigned long data)
56+
static struct hrtimer softdog_ticktock;
57+
static struct hrtimer softdog_preticktock;
58+
59+
static enum hrtimer_restart softdog_fire(struct hrtimer *timer)
5860
{
5961
module_put(THIS_MODULE);
6062
if (soft_noboot) {
@@ -67,44 +69,45 @@ static void softdog_fire(unsigned long data)
6769
emergency_restart();
6870
pr_crit("Reboot didn't ?????\n");
6971
}
70-
}
7172

72-
static struct timer_list softdog_ticktock =
73-
TIMER_INITIALIZER(softdog_fire, 0, 0);
73+
return HRTIMER_NORESTART;
74+
}
7475

7576
static struct watchdog_device softdog_dev;
7677

77-
static void softdog_pretimeout(unsigned long data)
78+
static enum hrtimer_restart softdog_pretimeout(struct hrtimer *timer)
7879
{
7980
watchdog_notify_pretimeout(&softdog_dev);
80-
}
8181

82-
static struct timer_list softdog_preticktock =
83-
TIMER_INITIALIZER(softdog_pretimeout, 0, 0);
82+
return HRTIMER_NORESTART;
83+
}
8484

8585
static int softdog_ping(struct watchdog_device *w)
8686
{
87-
if (!mod_timer(&softdog_ticktock, jiffies + (w->timeout * HZ)))
87+
if (!hrtimer_active(&softdog_ticktock))
8888
__module_get(THIS_MODULE);
89+
hrtimer_start(&softdog_ticktock, ktime_set(w->timeout, 0),
90+
HRTIMER_MODE_REL);
8991

9092
if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT)) {
9193
if (w->pretimeout)
92-
mod_timer(&softdog_preticktock, jiffies +
93-
(w->timeout - w->pretimeout) * HZ);
94+
hrtimer_start(&softdog_preticktock,
95+
ktime_set(w->timeout - w->pretimeout, 0),
96+
HRTIMER_MODE_REL);
9497
else
95-
del_timer(&softdog_preticktock);
98+
hrtimer_cancel(&softdog_preticktock);
9699
}
97100

98101
return 0;
99102
}
100103

101104
static int softdog_stop(struct watchdog_device *w)
102105
{
103-
if (del_timer(&softdog_ticktock))
106+
if (hrtimer_cancel(&softdog_ticktock))
104107
module_put(THIS_MODULE);
105108

106109
if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT))
107-
del_timer(&softdog_preticktock);
110+
hrtimer_cancel(&softdog_preticktock);
108111

109112
return 0;
110113
}
@@ -136,8 +139,15 @@ static int __init softdog_init(void)
136139
watchdog_set_nowayout(&softdog_dev, nowayout);
137140
watchdog_stop_on_reboot(&softdog_dev);
138141

139-
if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT))
142+
hrtimer_init(&softdog_ticktock, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
143+
softdog_ticktock.function = softdog_fire;
144+
145+
if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT)) {
140146
softdog_info.options |= WDIOF_PRETIMEOUT;
147+
hrtimer_init(&softdog_preticktock, CLOCK_MONOTONIC,
148+
HRTIMER_MODE_REL);
149+
softdog_preticktock.function = softdog_pretimeout;
150+
}
141151

142152
ret = watchdog_register_device(&softdog_dev);
143153
if (ret)

0 commit comments

Comments
 (0)