summaryrefslogtreecommitdiffstats
path: root/drivers/watchdog
diff options
context:
space:
mode:
authorNiklas Cassel <niklas.cassel@axis.com>2017-02-27 07:49:09 -0500
committerGuenter Roeck <linux@roeck-us.net>2017-03-01 09:15:10 -0500
commit8d5755b3f77b57447ce5de253ef704ad028474d3 (patch)
tree0646924cdfd71e4e00a59924061c52e79b8560f1 /drivers/watchdog
parented4a9eca66720366d117d9b39f2335ca9b0a7aae (diff)
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 4cd13c21b207 ("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>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r--drivers/watchdog/softdog.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/drivers/watchdog/softdog.c b/drivers/watchdog/softdog.c
index 7983029852ab..060740625485 100644
--- a/drivers/watchdog/softdog.c
+++ b/drivers/watchdog/softdog.c
@@ -21,13 +21,12 @@
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 23
24#include <linux/hrtimer.h>
24#include <linux/init.h> 25#include <linux/init.h>
25#include <linux/jiffies.h>
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
29#include <linux/reboot.h> 29#include <linux/reboot.h>
30#include <linux/timer.h>
31#include <linux/types.h> 30#include <linux/types.h>
32#include <linux/watchdog.h> 31#include <linux/watchdog.h>
33 32
@@ -54,7 +53,10 @@ module_param(soft_panic, int, 0);
54MODULE_PARM_DESC(soft_panic, 53MODULE_PARM_DESC(soft_panic,
55 "Softdog action, set to 1 to panic, 0 to reboot (default=0)"); 54 "Softdog action, set to 1 to panic, 0 to reboot (default=0)");
56 55
57static void softdog_fire(unsigned long data) 56static struct hrtimer softdog_ticktock;
57static struct hrtimer softdog_preticktock;
58
59static enum hrtimer_restart softdog_fire(struct hrtimer *timer)
58{ 60{
59 module_put(THIS_MODULE); 61 module_put(THIS_MODULE);
60 if (soft_noboot) { 62 if (soft_noboot) {
@@ -67,32 +69,33 @@ static void softdog_fire(unsigned long data)
67 emergency_restart(); 69 emergency_restart();
68 pr_crit("Reboot didn't ?????\n"); 70 pr_crit("Reboot didn't ?????\n");
69 } 71 }
70}
71 72
72static struct timer_list softdog_ticktock = 73 return HRTIMER_NORESTART;
73 TIMER_INITIALIZER(softdog_fire, 0, 0); 74}
74 75
75static struct watchdog_device softdog_dev; 76static struct watchdog_device softdog_dev;
76 77
77static void softdog_pretimeout(unsigned long data) 78static enum hrtimer_restart softdog_pretimeout(struct hrtimer *timer)
78{ 79{
79 watchdog_notify_pretimeout(&softdog_dev); 80 watchdog_notify_pretimeout(&softdog_dev);
80}
81 81
82static struct timer_list softdog_preticktock = 82 return HRTIMER_NORESTART;
83 TIMER_INITIALIZER(softdog_pretimeout, 0, 0); 83}
84 84
85static int softdog_ping(struct watchdog_device *w) 85static int softdog_ping(struct watchdog_device *w)
86{ 86{
87 if (!mod_timer(&softdog_ticktock, jiffies + (w->timeout * HZ))) 87 if (!hrtimer_active(&softdog_ticktock))
88 __module_get(THIS_MODULE); 88 __module_get(THIS_MODULE);
89 hrtimer_start(&softdog_ticktock, ktime_set(w->timeout, 0),
90 HRTIMER_MODE_REL);
89 91
90 if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT)) { 92 if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT)) {
91 if (w->pretimeout) 93 if (w->pretimeout)
92 mod_timer(&softdog_preticktock, jiffies + 94 hrtimer_start(&softdog_preticktock,
93 (w->timeout - w->pretimeout) * HZ); 95 ktime_set(w->timeout - w->pretimeout, 0),
96 HRTIMER_MODE_REL);
94 else 97 else
95 del_timer(&softdog_preticktock); 98 hrtimer_cancel(&softdog_preticktock);
96 } 99 }
97 100
98 return 0; 101 return 0;
@@ -100,11 +103,11 @@ static int softdog_ping(struct watchdog_device *w)
100 103
101static int softdog_stop(struct watchdog_device *w) 104static int softdog_stop(struct watchdog_device *w)
102{ 105{
103 if (del_timer(&softdog_ticktock)) 106 if (hrtimer_cancel(&softdog_ticktock))
104 module_put(THIS_MODULE); 107 module_put(THIS_MODULE);
105 108
106 if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT)) 109 if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT))
107 del_timer(&softdog_preticktock); 110 hrtimer_cancel(&softdog_preticktock);
108 111
109 return 0; 112 return 0;
110} 113}
@@ -136,8 +139,15 @@ static int __init softdog_init(void)
136 watchdog_set_nowayout(&softdog_dev, nowayout); 139 watchdog_set_nowayout(&softdog_dev, nowayout);
137 watchdog_stop_on_reboot(&softdog_dev); 140 watchdog_stop_on_reboot(&softdog_dev);
138 141
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)) {
140 softdog_info.options |= WDIOF_PRETIMEOUT; 146 softdog_info.options |= WDIOF_PRETIMEOUT;
147 hrtimer_init(&softdog_preticktock, CLOCK_MONOTONIC,
148 HRTIMER_MODE_REL);
149 softdog_preticktock.function = softdog_pretimeout;
150 }
141 151
142 ret = watchdog_register_device(&softdog_dev); 152 ret = watchdog_register_device(&softdog_dev);
143 if (ret) 153 if (ret)