]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
58687acb DZ |
2 | /* |
3 | * Detect hard and soft lockups on a system | |
4 | * | |
5 | * started by Don Zickus, Copyright (C) 2010 Red Hat, Inc. | |
6 | * | |
86f5e6a7 FLVC |
7 | * Note: Most of this code is borrowed heavily from the original softlockup |
8 | * detector, so thanks to Ingo for the initial implementation. | |
9 | * Some chunks also taken from the old x86-specific nmi watchdog code, thanks | |
58687acb DZ |
10 | * to those contributors as well. |
11 | */ | |
12 | ||
5f92a7b0 | 13 | #define pr_fmt(fmt) "watchdog: " fmt |
4501980a | 14 | |
58687acb DZ |
15 | #include <linux/mm.h> |
16 | #include <linux/cpu.h> | |
17 | #include <linux/nmi.h> | |
18 | #include <linux/init.h> | |
58687acb DZ |
19 | #include <linux/module.h> |
20 | #include <linux/sysctl.h> | |
fe4ba3c3 | 21 | #include <linux/tick.h> |
e6017571 | 22 | #include <linux/sched/clock.h> |
b17b0153 | 23 | #include <linux/sched/debug.h> |
78634061 | 24 | #include <linux/sched/isolation.h> |
9cf57731 | 25 | #include <linux/stop_machine.h> |
58687acb DZ |
26 | |
27 | #include <asm/irq_regs.h> | |
5d1c0f4a | 28 | #include <linux/kvm_para.h> |
58687acb | 29 | |
946d1977 | 30 | static DEFINE_MUTEX(watchdog_mutex); |
ab992dc3 | 31 | |
47f4cb43 | 32 | #if defined(CONFIG_HARDLOCKUP_DETECTOR) || defined(CONFIG_HARDLOCKUP_DETECTOR_SPARC64) |
df95d308 | 33 | # define WATCHDOG_HARDLOCKUP_DEFAULT 1 |
84d56e66 | 34 | #else |
df95d308 | 35 | # define WATCHDOG_HARDLOCKUP_DEFAULT 0 |
84d56e66 | 36 | #endif |
05a4a952 | 37 | |
09154985 TG |
38 | unsigned long __read_mostly watchdog_enabled; |
39 | int __read_mostly watchdog_user_enabled = 1; | |
df95d308 DA |
40 | static int __read_mostly watchdog_hardlockup_user_enabled = WATCHDOG_HARDLOCKUP_DEFAULT; |
41 | static int __read_mostly watchdog_softlockup_user_enabled = 1; | |
7feeb9cd | 42 | int __read_mostly watchdog_thresh = 10; |
df95d308 | 43 | static int __read_mostly watchdog_hardlockup_available; |
7feeb9cd | 44 | |
7feeb9cd TG |
45 | struct cpumask watchdog_cpumask __read_mostly; |
46 | unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask); | |
47 | ||
05a4a952 | 48 | #ifdef CONFIG_HARDLOCKUP_DETECTOR |
f117955a GP |
49 | |
50 | # ifdef CONFIG_SMP | |
51 | int __read_mostly sysctl_hardlockup_all_cpu_backtrace; | |
52 | # endif /* CONFIG_SMP */ | |
53 | ||
05a4a952 NP |
54 | /* |
55 | * Should we panic when a soft-lockup or hard-lockup occurs: | |
56 | */ | |
57 | unsigned int __read_mostly hardlockup_panic = | |
67fca000 | 58 | IS_ENABLED(CONFIG_BOOTPARAM_HARDLOCKUP_PANIC); |
05a4a952 NP |
59 | /* |
60 | * We may not want to enable hard lockup detection by default in all cases, | |
61 | * for example when running the kernel as a guest on a hypervisor. In these | |
62 | * cases this function can be called to disable hard lockup detection. This | |
63 | * function should only be executed once by the boot processor before the | |
64 | * kernel command line parameters are parsed, because otherwise it is not | |
65 | * possible to override this in hardlockup_panic_setup(). | |
66 | */ | |
7a355820 | 67 | void __init hardlockup_detector_disable(void) |
05a4a952 | 68 | { |
df95d308 | 69 | watchdog_hardlockup_user_enabled = 0; |
05a4a952 NP |
70 | } |
71 | ||
72 | static int __init hardlockup_panic_setup(char *str) | |
73 | { | |
74 | if (!strncmp(str, "panic", 5)) | |
75 | hardlockup_panic = 1; | |
76 | else if (!strncmp(str, "nopanic", 7)) | |
77 | hardlockup_panic = 0; | |
78 | else if (!strncmp(str, "0", 1)) | |
df95d308 | 79 | watchdog_hardlockup_user_enabled = 0; |
05a4a952 | 80 | else if (!strncmp(str, "1", 1)) |
df95d308 | 81 | watchdog_hardlockup_user_enabled = 1; |
05a4a952 NP |
82 | return 1; |
83 | } | |
84 | __setup("nmi_watchdog=", hardlockup_panic_setup); | |
85 | ||
368a7e2c | 86 | #endif /* CONFIG_HARDLOCKUP_DETECTOR */ |
05a4a952 | 87 | |
1f423c90 | 88 | #if defined(CONFIG_HARDLOCKUP_DETECTOR_COUNTS_HRTIMER) |
81972551 | 89 | |
77c12fc9 DA |
90 | static DEFINE_PER_CPU(atomic_t, hrtimer_interrupts); |
91 | static DEFINE_PER_CPU(int, hrtimer_interrupts_saved); | |
1610611a | 92 | static DEFINE_PER_CPU(bool, watchdog_hardlockup_warned); |
ed92e1ef | 93 | static DEFINE_PER_CPU(bool, watchdog_hardlockup_touched); |
1610611a | 94 | static unsigned long watchdog_hardlockup_all_cpu_dumped; |
81972551 | 95 | |
ed92e1ef DA |
96 | notrace void arch_touch_nmi_watchdog(void) |
97 | { | |
98 | /* | |
99 | * Using __raw here because some code paths have | |
100 | * preemption enabled. If preemption is enabled | |
101 | * then interrupts should be enabled too, in which | |
102 | * case we shouldn't have to worry about the watchdog | |
103 | * going off. | |
104 | */ | |
105 | raw_cpu_write(watchdog_hardlockup_touched, true); | |
106 | } | |
107 | EXPORT_SYMBOL(arch_touch_nmi_watchdog); | |
108 | ||
1f423c90 DA |
109 | void watchdog_hardlockup_touch_cpu(unsigned int cpu) |
110 | { | |
111 | per_cpu(watchdog_hardlockup_touched, cpu) = true; | |
1f423c90 DA |
112 | } |
113 | ||
77c12fc9 | 114 | static bool is_hardlockup(unsigned int cpu) |
81972551 | 115 | { |
77c12fc9 | 116 | int hrint = atomic_read(&per_cpu(hrtimer_interrupts, cpu)); |
81972551 | 117 | |
77c12fc9 | 118 | if (per_cpu(hrtimer_interrupts_saved, cpu) == hrint) |
81972551 DA |
119 | return true; |
120 | ||
77c12fc9 DA |
121 | /* |
122 | * NOTE: we don't need any fancy atomic_t or READ_ONCE/WRITE_ONCE | |
123 | * for hrtimer_interrupts_saved. hrtimer_interrupts_saved is | |
124 | * written/read by a single CPU. | |
125 | */ | |
126 | per_cpu(hrtimer_interrupts_saved, cpu) = hrint; | |
1610611a | 127 | |
81972551 DA |
128 | return false; |
129 | } | |
130 | ||
d3b62ace | 131 | static void watchdog_hardlockup_kick(void) |
81972551 | 132 | { |
d3b62ace DA |
133 | int new_interrupts; |
134 | ||
135 | new_interrupts = atomic_inc_return(this_cpu_ptr(&hrtimer_interrupts)); | |
136 | watchdog_buddy_check_hardlockup(new_interrupts); | |
81972551 DA |
137 | } |
138 | ||
77c12fc9 | 139 | void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs) |
81972551 | 140 | { |
ed92e1ef DA |
141 | if (per_cpu(watchdog_hardlockup_touched, cpu)) { |
142 | per_cpu(watchdog_hardlockup_touched, cpu) = false; | |
143 | return; | |
144 | } | |
145 | ||
1610611a DA |
146 | /* |
147 | * Check for a hardlockup by making sure the CPU's timer | |
148 | * interrupt is incrementing. The timer interrupt should have | |
149 | * fired multiple times before we overflow'd. If it hasn't | |
81972551 DA |
150 | * then this is a good indication the cpu is stuck |
151 | */ | |
77c12fc9 | 152 | if (is_hardlockup(cpu)) { |
1610611a | 153 | unsigned int this_cpu = smp_processor_id(); |
81972551 | 154 | |
1610611a | 155 | /* Only print hardlockups once. */ |
77c12fc9 | 156 | if (per_cpu(watchdog_hardlockup_warned, cpu)) |
81972551 DA |
157 | return; |
158 | ||
77c12fc9 | 159 | pr_emerg("Watchdog detected hard LOCKUP on cpu %d\n", cpu); |
81972551 DA |
160 | print_modules(); |
161 | print_irqtrace_events(current); | |
77c12fc9 DA |
162 | if (cpu == this_cpu) { |
163 | if (regs) | |
164 | show_regs(regs); | |
165 | else | |
166 | dump_stack(); | |
77c12fc9 | 167 | } else { |
1f38c86b | 168 | trigger_single_cpu_backtrace(cpu); |
77c12fc9 | 169 | } |
81972551 DA |
170 | |
171 | /* | |
77c12fc9 DA |
172 | * Perform multi-CPU dump only once to avoid multiple |
173 | * hardlockups generating interleaving traces | |
81972551 DA |
174 | */ |
175 | if (sysctl_hardlockup_all_cpu_backtrace && | |
1610611a | 176 | !test_and_set_bit(0, &watchdog_hardlockup_all_cpu_dumped)) |
1f38c86b | 177 | trigger_allbutcpu_cpu_backtrace(cpu); |
81972551 DA |
178 | |
179 | if (hardlockup_panic) | |
180 | nmi_panic(regs, "Hard LOCKUP"); | |
181 | ||
77c12fc9 | 182 | per_cpu(watchdog_hardlockup_warned, cpu) = true; |
1610611a | 183 | } else { |
77c12fc9 | 184 | per_cpu(watchdog_hardlockup_warned, cpu) = false; |
81972551 | 185 | } |
81972551 DA |
186 | } |
187 | ||
1f423c90 | 188 | #else /* CONFIG_HARDLOCKUP_DETECTOR_COUNTS_HRTIMER */ |
81972551 | 189 | |
d3b62ace | 190 | static inline void watchdog_hardlockup_kick(void) { } |
81972551 | 191 | |
1f423c90 | 192 | #endif /* !CONFIG_HARDLOCKUP_DETECTOR_COUNTS_HRTIMER */ |
81972551 | 193 | |
05a4a952 | 194 | /* |
d9b3629a | 195 | * These functions can be overridden based on the configured hardlockdup detector. |
a10a842f | 196 | * |
df95d308 | 197 | * watchdog_hardlockup_enable/disable can be implemented to start and stop when |
d9b3629a | 198 | * softlockup watchdog start and stop. The detector must select the |
a10a842f | 199 | * SOFTLOCKUP_DETECTOR Kconfig. |
05a4a952 | 200 | */ |
d9b3629a | 201 | void __weak watchdog_hardlockup_enable(unsigned int cpu) { } |
941154bd | 202 | |
d9b3629a | 203 | void __weak watchdog_hardlockup_disable(unsigned int cpu) { } |
05a4a952 | 204 | |
930d8f8d LC |
205 | /* |
206 | * Watchdog-detector specific API. | |
207 | * | |
208 | * Return 0 when hardlockup watchdog is available, negative value otherwise. | |
209 | * Note that the negative value means that a delayed probe might | |
210 | * succeed later. | |
211 | */ | |
df95d308 | 212 | int __weak __init watchdog_hardlockup_probe(void) |
a994a314 | 213 | { |
d9b3629a | 214 | return -ENODEV; |
a994a314 TG |
215 | } |
216 | ||
6592ad2f | 217 | /** |
df95d308 | 218 | * watchdog_hardlockup_stop - Stop the watchdog for reconfiguration |
6592ad2f | 219 | * |
6b9dc480 | 220 | * The reconfiguration steps are: |
df95d308 | 221 | * watchdog_hardlockup_stop(); |
6592ad2f | 222 | * update_variables(); |
df95d308 | 223 | * watchdog_hardlockup_start(); |
6b9dc480 | 224 | */ |
df95d308 | 225 | void __weak watchdog_hardlockup_stop(void) { } |
6b9dc480 TG |
226 | |
227 | /** | |
df95d308 | 228 | * watchdog_hardlockup_start - Start the watchdog after reconfiguration |
6592ad2f | 229 | * |
df95d308 | 230 | * Counterpart to watchdog_hardlockup_stop(). |
6b9dc480 TG |
231 | * |
232 | * The following variables have been updated in update_variables() and | |
233 | * contain the currently valid configuration: | |
7feeb9cd | 234 | * - watchdog_enabled |
a10a842f NP |
235 | * - watchdog_thresh |
236 | * - watchdog_cpumask | |
a10a842f | 237 | */ |
df95d308 | 238 | void __weak watchdog_hardlockup_start(void) { } |
a10a842f | 239 | |
09154985 TG |
240 | /** |
241 | * lockup_detector_update_enable - Update the sysctl enable bit | |
242 | * | |
df95d308 DA |
243 | * Caller needs to make sure that the hard watchdogs are off, so this |
244 | * can't race with watchdog_hardlockup_disable(). | |
09154985 TG |
245 | */ |
246 | static void lockup_detector_update_enable(void) | |
247 | { | |
248 | watchdog_enabled = 0; | |
249 | if (!watchdog_user_enabled) | |
250 | return; | |
df95d308 DA |
251 | if (watchdog_hardlockup_available && watchdog_hardlockup_user_enabled) |
252 | watchdog_enabled |= WATCHDOG_HARDLOCKUP_ENABLED; | |
253 | if (watchdog_softlockup_user_enabled) | |
254 | watchdog_enabled |= WATCHDOG_SOFTOCKUP_ENABLED; | |
09154985 TG |
255 | } |
256 | ||
05a4a952 NP |
257 | #ifdef CONFIG_SOFTLOCKUP_DETECTOR |
258 | ||
fef06efc PM |
259 | /* |
260 | * Delay the soflockup report when running a known slow code. | |
261 | * It does _not_ affect the timestamp of the last successdul reschedule. | |
262 | */ | |
263 | #define SOFTLOCKUP_DELAY_REPORT ULONG_MAX | |
11e31f60 | 264 | |
f117955a GP |
265 | #ifdef CONFIG_SMP |
266 | int __read_mostly sysctl_softlockup_all_cpu_backtrace; | |
267 | #endif | |
268 | ||
e7e04615 SS |
269 | static struct cpumask watchdog_allowed_mask __read_mostly; |
270 | ||
2b9d7f23 TG |
271 | /* Global variables, exported for sysctl */ |
272 | unsigned int __read_mostly softlockup_panic = | |
67fca000 | 273 | IS_ENABLED(CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC); |
2eb2527f | 274 | |
9cf57731 | 275 | static bool softlockup_initialized __read_mostly; |
0f34c400 | 276 | static u64 __read_mostly sample_period; |
58687acb | 277 | |
fef06efc | 278 | /* Timestamp taken after the last successful reschedule. */ |
58687acb | 279 | static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts); |
fef06efc PM |
280 | /* Timestamp of the last softlockup report. */ |
281 | static DEFINE_PER_CPU(unsigned long, watchdog_report_ts); | |
58687acb DZ |
282 | static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer); |
283 | static DEFINE_PER_CPU(bool, softlockup_touch_sync); | |
ed235875 | 284 | static unsigned long soft_lockup_nmi_warn; |
58687acb | 285 | |
8b793bcd KJ |
286 | static int __init softlockup_panic_setup(char *str) |
287 | { | |
288 | softlockup_panic = simple_strtoul(str, NULL, 0); | |
289 | return 1; | |
290 | } | |
291 | __setup("softlockup_panic=", softlockup_panic_setup); | |
292 | ||
58687acb DZ |
293 | static int __init nowatchdog_setup(char *str) |
294 | { | |
09154985 | 295 | watchdog_user_enabled = 0; |
58687acb DZ |
296 | return 1; |
297 | } | |
298 | __setup("nowatchdog", nowatchdog_setup); | |
299 | ||
58687acb DZ |
300 | static int __init nosoftlockup_setup(char *str) |
301 | { | |
df95d308 | 302 | watchdog_softlockup_user_enabled = 0; |
58687acb DZ |
303 | return 1; |
304 | } | |
305 | __setup("nosoftlockup", nosoftlockup_setup); | |
195daf66 | 306 | |
11295055 LO |
307 | static int __init watchdog_thresh_setup(char *str) |
308 | { | |
309 | get_option(&str, &watchdog_thresh); | |
310 | return 1; | |
311 | } | |
312 | __setup("watchdog_thresh=", watchdog_thresh_setup); | |
313 | ||
941154bd TG |
314 | static void __lockup_detector_cleanup(void); |
315 | ||
4eec42f3 MSB |
316 | /* |
317 | * Hard-lockup warnings should be triggered after just a few seconds. Soft- | |
318 | * lockups can have false positives under extreme conditions. So we generally | |
319 | * want a higher threshold for soft lockups than for hard lockups. So we couple | |
320 | * the thresholds with a factor: we make the soft threshold twice the amount of | |
321 | * time the hard threshold is. | |
322 | */ | |
6e9101ae | 323 | static int get_softlockup_thresh(void) |
4eec42f3 MSB |
324 | { |
325 | return watchdog_thresh * 2; | |
326 | } | |
58687acb DZ |
327 | |
328 | /* | |
329 | * Returns seconds, approximately. We don't need nanosecond | |
330 | * resolution, and we don't need to waste time with a big divide when | |
331 | * 2^30ns == 1.074s. | |
332 | */ | |
c06b4f19 | 333 | static unsigned long get_timestamp(void) |
58687acb | 334 | { |
545a2bf7 | 335 | return running_clock() >> 30LL; /* 2^30 ~= 10^9 */ |
58687acb DZ |
336 | } |
337 | ||
0f34c400 | 338 | static void set_sample_period(void) |
58687acb DZ |
339 | { |
340 | /* | |
586692a5 | 341 | * convert watchdog_thresh from seconds to ns |
86f5e6a7 FLVC |
342 | * the divide by 5 is to give hrtimer several chances (two |
343 | * or three with the current relation between the soft | |
344 | * and hard thresholds) to increment before the | |
345 | * hardlockup detector generates a warning | |
58687acb | 346 | */ |
0f34c400 | 347 | sample_period = get_softlockup_thresh() * ((u64)NSEC_PER_SEC / 5); |
7edaeb68 | 348 | watchdog_update_hrtimer_threshold(sample_period); |
58687acb DZ |
349 | } |
350 | ||
fef06efc PM |
351 | static void update_report_ts(void) |
352 | { | |
353 | __this_cpu_write(watchdog_report_ts, get_timestamp()); | |
354 | } | |
355 | ||
58687acb | 356 | /* Commands for resetting the watchdog */ |
7c0012f5 | 357 | static void update_touch_ts(void) |
58687acb | 358 | { |
c06b4f19 | 359 | __this_cpu_write(watchdog_touch_ts, get_timestamp()); |
fef06efc | 360 | update_report_ts(); |
58687acb DZ |
361 | } |
362 | ||
03e0d461 TH |
363 | /** |
364 | * touch_softlockup_watchdog_sched - touch watchdog on scheduler stalls | |
365 | * | |
366 | * Call when the scheduler may have stalled for legitimate reasons | |
367 | * preventing the watchdog task from executing - e.g. the scheduler | |
368 | * entering idle state. This should only be used for scheduler events. | |
369 | * Use touch_softlockup_watchdog() for everything else. | |
370 | */ | |
cb9d7fd5 | 371 | notrace void touch_softlockup_watchdog_sched(void) |
58687acb | 372 | { |
7861144b | 373 | /* |
fef06efc PM |
374 | * Preemption can be enabled. It doesn't matter which CPU's watchdog |
375 | * report period gets restarted here, so use the raw_ operation. | |
7861144b | 376 | */ |
fef06efc | 377 | raw_cpu_write(watchdog_report_ts, SOFTLOCKUP_DELAY_REPORT); |
58687acb | 378 | } |
03e0d461 | 379 | |
cb9d7fd5 | 380 | notrace void touch_softlockup_watchdog(void) |
03e0d461 TH |
381 | { |
382 | touch_softlockup_watchdog_sched(); | |
82607adc | 383 | wq_watchdog_touch(raw_smp_processor_id()); |
03e0d461 | 384 | } |
0167c781 | 385 | EXPORT_SYMBOL(touch_softlockup_watchdog); |
58687acb | 386 | |
332fbdbc | 387 | void touch_all_softlockup_watchdogs(void) |
58687acb DZ |
388 | { |
389 | int cpu; | |
390 | ||
391 | /* | |
d57108d4 TG |
392 | * watchdog_mutex cannpt be taken here, as this might be called |
393 | * from (soft)interrupt context, so the access to | |
394 | * watchdog_allowed_cpumask might race with a concurrent update. | |
395 | * | |
396 | * The watchdog time stamp can race against a concurrent real | |
397 | * update as well, the only side effect might be a cycle delay for | |
398 | * the softlockup check. | |
58687acb | 399 | */ |
89e28ce6 | 400 | for_each_cpu(cpu, &watchdog_allowed_mask) { |
fef06efc | 401 | per_cpu(watchdog_report_ts, cpu) = SOFTLOCKUP_DELAY_REPORT; |
89e28ce6 WQ |
402 | wq_watchdog_touch(cpu); |
403 | } | |
58687acb DZ |
404 | } |
405 | ||
58687acb DZ |
406 | void touch_softlockup_watchdog_sync(void) |
407 | { | |
f7f66b05 | 408 | __this_cpu_write(softlockup_touch_sync, true); |
fef06efc | 409 | __this_cpu_write(watchdog_report_ts, SOFTLOCKUP_DELAY_REPORT); |
58687acb DZ |
410 | } |
411 | ||
0f90b88d PM |
412 | static int is_softlockup(unsigned long touch_ts, |
413 | unsigned long period_ts, | |
414 | unsigned long now) | |
58687acb | 415 | { |
df95d308 | 416 | if ((watchdog_enabled & WATCHDOG_SOFTOCKUP_ENABLED) && watchdog_thresh) { |
195daf66 | 417 | /* Warn about unreasonable delays. */ |
fef06efc | 418 | if (time_after(now, period_ts + get_softlockup_thresh())) |
195daf66 UO |
419 | return now - touch_ts; |
420 | } | |
58687acb DZ |
421 | return 0; |
422 | } | |
423 | ||
05a4a952 | 424 | /* watchdog detector functions */ |
be45bf53 PZ |
425 | static DEFINE_PER_CPU(struct completion, softlockup_completion); |
426 | static DEFINE_PER_CPU(struct cpu_stop_work, softlockup_stop_work); | |
427 | ||
9cf57731 | 428 | /* |
b124ac45 | 429 | * The watchdog feed function - touches the timestamp. |
9cf57731 PZ |
430 | * |
431 | * It only runs once every sample_period seconds (4 seconds by | |
432 | * default) to reset the softlockup timestamp. If this gets delayed | |
433 | * for more than 2*watchdog_thresh seconds then the debug-printout | |
434 | * triggers in watchdog_timer_fn(). | |
435 | */ | |
436 | static int softlockup_fn(void *data) | |
437 | { | |
7c0012f5 | 438 | update_touch_ts(); |
be45bf53 | 439 | complete(this_cpu_ptr(&softlockup_completion)); |
9cf57731 PZ |
440 | |
441 | return 0; | |
442 | } | |
443 | ||
58687acb DZ |
444 | /* watchdog kicker functions */ |
445 | static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) | |
446 | { | |
0f90b88d | 447 | unsigned long touch_ts, period_ts, now; |
58687acb DZ |
448 | struct pt_regs *regs = get_irq_regs(); |
449 | int duration; | |
ed235875 | 450 | int softlockup_all_cpu_backtrace = sysctl_softlockup_all_cpu_backtrace; |
58687acb | 451 | |
01f0a027 | 452 | if (!watchdog_enabled) |
b94f5118 DZ |
453 | return HRTIMER_NORESTART; |
454 | ||
d3b62ace | 455 | watchdog_hardlockup_kick(); |
58687acb DZ |
456 | |
457 | /* kick the softlockup detector */ | |
be45bf53 PZ |
458 | if (completion_done(this_cpu_ptr(&softlockup_completion))) { |
459 | reinit_completion(this_cpu_ptr(&softlockup_completion)); | |
460 | stop_one_cpu_nowait(smp_processor_id(), | |
461 | softlockup_fn, NULL, | |
462 | this_cpu_ptr(&softlockup_stop_work)); | |
463 | } | |
58687acb DZ |
464 | |
465 | /* .. and repeat */ | |
0f34c400 | 466 | hrtimer_forward_now(hrtimer, ns_to_ktime(sample_period)); |
58687acb | 467 | |
0f90b88d PM |
468 | /* |
469 | * Read the current timestamp first. It might become invalid anytime | |
470 | * when a virtual machine is stopped by the host or when the watchog | |
471 | * is touched from NMI. | |
472 | */ | |
473 | now = get_timestamp(); | |
9bf3bc94 PM |
474 | /* |
475 | * If a virtual machine is stopped by the host it can look to | |
0f90b88d | 476 | * the watchdog like a soft lockup. This function touches the watchdog. |
9bf3bc94 PM |
477 | */ |
478 | kvm_check_and_clear_guest_paused(); | |
0f90b88d PM |
479 | /* |
480 | * The stored timestamp is comparable with @now only when not touched. | |
481 | * It might get touched anytime from NMI. Make sure that is_softlockup() | |
482 | * uses the same (valid) value. | |
483 | */ | |
484 | period_ts = READ_ONCE(*this_cpu_ptr(&watchdog_report_ts)); | |
9bf3bc94 PM |
485 | |
486 | /* Reset the interval when touched by known problematic code. */ | |
fef06efc | 487 | if (period_ts == SOFTLOCKUP_DELAY_REPORT) { |
909ea964 | 488 | if (unlikely(__this_cpu_read(softlockup_touch_sync))) { |
58687acb DZ |
489 | /* |
490 | * If the time stamp was touched atomically | |
491 | * make sure the scheduler tick is up to date. | |
492 | */ | |
909ea964 | 493 | __this_cpu_write(softlockup_touch_sync, false); |
58687acb DZ |
494 | sched_clock_tick(); |
495 | } | |
5d1c0f4a | 496 | |
fef06efc | 497 | update_report_ts(); |
58687acb DZ |
498 | return HRTIMER_RESTART; |
499 | } | |
500 | ||
0f90b88d PM |
501 | /* Check for a softlockup. */ |
502 | touch_ts = __this_cpu_read(watchdog_touch_ts); | |
503 | duration = is_softlockup(touch_ts, period_ts, now); | |
58687acb | 504 | if (unlikely(duration)) { |
9f113bf7 PM |
505 | /* |
506 | * Prevent multiple soft-lockup reports if one cpu is already | |
507 | * engaged in dumping all cpu back traces. | |
508 | */ | |
ed235875 | 509 | if (softlockup_all_cpu_backtrace) { |
9f113bf7 | 510 | if (test_and_set_bit_lock(0, &soft_lockup_nmi_warn)) |
ed235875 | 511 | return HRTIMER_RESTART; |
ed235875 AT |
512 | } |
513 | ||
c9ad17c9 | 514 | /* Start period for the next softlockup warning. */ |
fef06efc | 515 | update_report_ts(); |
c9ad17c9 | 516 | |
656c3b79 | 517 | pr_emerg("BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n", |
26e09c6e | 518 | smp_processor_id(), duration, |
58687acb DZ |
519 | current->comm, task_pid_nr(current)); |
520 | print_modules(); | |
521 | print_irqtrace_events(current); | |
522 | if (regs) | |
523 | show_regs(regs); | |
524 | else | |
525 | dump_stack(); | |
526 | ||
ed235875 | 527 | if (softlockup_all_cpu_backtrace) { |
8d539b84 | 528 | trigger_allbutcpu_cpu_backtrace(smp_processor_id()); |
9f113bf7 | 529 | clear_bit_unlock(0, &soft_lockup_nmi_warn); |
ed235875 AT |
530 | } |
531 | ||
69361eef | 532 | add_taint(TAINT_SOFTLOCKUP, LOCKDEP_STILL_OK); |
58687acb DZ |
533 | if (softlockup_panic) |
534 | panic("softlockup: hung tasks"); | |
1bc503cb | 535 | } |
58687acb DZ |
536 | |
537 | return HRTIMER_RESTART; | |
538 | } | |
539 | ||
bcd951cf | 540 | static void watchdog_enable(unsigned int cpu) |
58687acb | 541 | { |
01f0a027 | 542 | struct hrtimer *hrtimer = this_cpu_ptr(&watchdog_hrtimer); |
be45bf53 | 543 | struct completion *done = this_cpu_ptr(&softlockup_completion); |
58687acb | 544 | |
9cf57731 PZ |
545 | WARN_ON_ONCE(cpu != smp_processor_id()); |
546 | ||
be45bf53 PZ |
547 | init_completion(done); |
548 | complete(done); | |
549 | ||
01f0a027 | 550 | /* |
df95d308 | 551 | * Start the timer first to prevent the hardlockup watchdog triggering |
01f0a027 TG |
552 | * before the timer has a chance to fire. |
553 | */ | |
d2ab4cf4 | 554 | hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD); |
3935e895 | 555 | hrtimer->function = watchdog_timer_fn; |
01f0a027 | 556 | hrtimer_start(hrtimer, ns_to_ktime(sample_period), |
d2ab4cf4 | 557 | HRTIMER_MODE_REL_PINNED_HARD); |
3935e895 | 558 | |
01f0a027 | 559 | /* Initialize timestamp */ |
7c0012f5 | 560 | update_touch_ts(); |
df95d308 DA |
561 | /* Enable the hardlockup detector */ |
562 | if (watchdog_enabled & WATCHDOG_HARDLOCKUP_ENABLED) | |
563 | watchdog_hardlockup_enable(cpu); | |
bcd951cf | 564 | } |
58687acb | 565 | |
bcd951cf TG |
566 | static void watchdog_disable(unsigned int cpu) |
567 | { | |
01f0a027 | 568 | struct hrtimer *hrtimer = this_cpu_ptr(&watchdog_hrtimer); |
58687acb | 569 | |
9cf57731 PZ |
570 | WARN_ON_ONCE(cpu != smp_processor_id()); |
571 | ||
01f0a027 | 572 | /* |
df95d308 DA |
573 | * Disable the hardlockup detector first. That prevents that a large |
574 | * delay between disabling the timer and disabling the hardlockup | |
575 | * detector causes a false positive. | |
01f0a027 | 576 | */ |
df95d308 | 577 | watchdog_hardlockup_disable(cpu); |
01f0a027 | 578 | hrtimer_cancel(hrtimer); |
be45bf53 | 579 | wait_for_completion(this_cpu_ptr(&softlockup_completion)); |
58687acb DZ |
580 | } |
581 | ||
9cf57731 | 582 | static int softlockup_stop_fn(void *data) |
b8900bc0 | 583 | { |
9cf57731 PZ |
584 | watchdog_disable(smp_processor_id()); |
585 | return 0; | |
b8900bc0 FW |
586 | } |
587 | ||
9cf57731 | 588 | static void softlockup_stop_all(void) |
bcd951cf | 589 | { |
9cf57731 PZ |
590 | int cpu; |
591 | ||
592 | if (!softlockup_initialized) | |
593 | return; | |
594 | ||
595 | for_each_cpu(cpu, &watchdog_allowed_mask) | |
596 | smp_call_on_cpu(cpu, softlockup_stop_fn, NULL, false); | |
597 | ||
598 | cpumask_clear(&watchdog_allowed_mask); | |
bcd951cf TG |
599 | } |
600 | ||
9cf57731 | 601 | static int softlockup_start_fn(void *data) |
bcd951cf | 602 | { |
9cf57731 PZ |
603 | watchdog_enable(smp_processor_id()); |
604 | return 0; | |
bcd951cf | 605 | } |
58687acb | 606 | |
9cf57731 | 607 | static void softlockup_start_all(void) |
2eb2527f | 608 | { |
9cf57731 | 609 | int cpu; |
2eb2527f | 610 | |
9cf57731 PZ |
611 | cpumask_copy(&watchdog_allowed_mask, &watchdog_cpumask); |
612 | for_each_cpu(cpu, &watchdog_allowed_mask) | |
613 | smp_call_on_cpu(cpu, softlockup_start_fn, NULL, false); | |
2eb2527f TG |
614 | } |
615 | ||
9cf57731 | 616 | int lockup_detector_online_cpu(unsigned int cpu) |
2eb2527f | 617 | { |
7dd47617 TG |
618 | if (cpumask_test_cpu(cpu, &watchdog_allowed_mask)) |
619 | watchdog_enable(cpu); | |
9cf57731 | 620 | return 0; |
2eb2527f TG |
621 | } |
622 | ||
9cf57731 | 623 | int lockup_detector_offline_cpu(unsigned int cpu) |
2eb2527f | 624 | { |
7dd47617 TG |
625 | if (cpumask_test_cpu(cpu, &watchdog_allowed_mask)) |
626 | watchdog_disable(cpu); | |
9cf57731 | 627 | return 0; |
2eb2527f TG |
628 | } |
629 | ||
7c56a873 | 630 | static void __lockup_detector_reconfigure(void) |
2eb2527f | 631 | { |
e31d6883 | 632 | cpus_read_lock(); |
df95d308 | 633 | watchdog_hardlockup_stop(); |
9cf57731 PZ |
634 | |
635 | softlockup_stop_all(); | |
2eb2527f | 636 | set_sample_period(); |
09154985 TG |
637 | lockup_detector_update_enable(); |
638 | if (watchdog_enabled && watchdog_thresh) | |
9cf57731 PZ |
639 | softlockup_start_all(); |
640 | ||
df95d308 | 641 | watchdog_hardlockup_start(); |
e31d6883 TG |
642 | cpus_read_unlock(); |
643 | /* | |
644 | * Must be called outside the cpus locked section to prevent | |
645 | * recursive locking in the perf code. | |
646 | */ | |
647 | __lockup_detector_cleanup(); | |
2eb2527f TG |
648 | } |
649 | ||
7c56a873 LD |
650 | void lockup_detector_reconfigure(void) |
651 | { | |
652 | mutex_lock(&watchdog_mutex); | |
653 | __lockup_detector_reconfigure(); | |
654 | mutex_unlock(&watchdog_mutex); | |
655 | } | |
656 | ||
2eb2527f | 657 | /* |
b124ac45 | 658 | * Create the watchdog infrastructure and configure the detector(s). |
2eb2527f | 659 | */ |
5587185d | 660 | static __init void lockup_detector_setup(void) |
2eb2527f | 661 | { |
2eb2527f TG |
662 | /* |
663 | * If sysctl is off and watchdog got disabled on the command line, | |
664 | * nothing to do here. | |
665 | */ | |
09154985 TG |
666 | lockup_detector_update_enable(); |
667 | ||
2eb2527f TG |
668 | if (!IS_ENABLED(CONFIG_SYSCTL) && |
669 | !(watchdog_enabled && watchdog_thresh)) | |
670 | return; | |
671 | ||
2eb2527f | 672 | mutex_lock(&watchdog_mutex); |
7c56a873 | 673 | __lockup_detector_reconfigure(); |
9cf57731 | 674 | softlockup_initialized = true; |
2eb2527f TG |
675 | mutex_unlock(&watchdog_mutex); |
676 | } | |
677 | ||
2b9d7f23 | 678 | #else /* CONFIG_SOFTLOCKUP_DETECTOR */ |
7c56a873 | 679 | static void __lockup_detector_reconfigure(void) |
6592ad2f | 680 | { |
e31d6883 | 681 | cpus_read_lock(); |
df95d308 | 682 | watchdog_hardlockup_stop(); |
09154985 | 683 | lockup_detector_update_enable(); |
df95d308 | 684 | watchdog_hardlockup_start(); |
e31d6883 | 685 | cpus_read_unlock(); |
6592ad2f | 686 | } |
7c56a873 LD |
687 | void lockup_detector_reconfigure(void) |
688 | { | |
689 | __lockup_detector_reconfigure(); | |
690 | } | |
5587185d | 691 | static inline void lockup_detector_setup(void) |
34ddaa3e | 692 | { |
7c56a873 | 693 | __lockup_detector_reconfigure(); |
34ddaa3e | 694 | } |
2b9d7f23 | 695 | #endif /* !CONFIG_SOFTLOCKUP_DETECTOR */ |
05a4a952 | 696 | |
941154bd TG |
697 | static void __lockup_detector_cleanup(void) |
698 | { | |
699 | lockdep_assert_held(&watchdog_mutex); | |
700 | hardlockup_detector_perf_cleanup(); | |
701 | } | |
702 | ||
703 | /** | |
704 | * lockup_detector_cleanup - Cleanup after cpu hotplug or sysctl changes | |
705 | * | |
706 | * Caller must not hold the cpu hotplug rwsem. | |
707 | */ | |
708 | void lockup_detector_cleanup(void) | |
709 | { | |
710 | mutex_lock(&watchdog_mutex); | |
711 | __lockup_detector_cleanup(); | |
712 | mutex_unlock(&watchdog_mutex); | |
713 | } | |
714 | ||
6554fd8c TG |
715 | /** |
716 | * lockup_detector_soft_poweroff - Interface to stop lockup detector(s) | |
717 | * | |
718 | * Special interface for parisc. It prevents lockup detector warnings from | |
719 | * the default pm_poweroff() function which busy loops forever. | |
720 | */ | |
721 | void lockup_detector_soft_poweroff(void) | |
722 | { | |
723 | watchdog_enabled = 0; | |
724 | } | |
725 | ||
58cf690a UO |
726 | #ifdef CONFIG_SYSCTL |
727 | ||
b124ac45 | 728 | /* Propagate any changes to the watchdog infrastructure */ |
d57108d4 | 729 | static void proc_watchdog_update(void) |
a0c9cbb9 | 730 | { |
e8b62b2d TG |
731 | /* Remove impossible cpus to keep sysctl output clean. */ |
732 | cpumask_and(&watchdog_cpumask, &watchdog_cpumask, cpu_possible_mask); | |
7c56a873 | 733 | __lockup_detector_reconfigure(); |
a0c9cbb9 UO |
734 | } |
735 | ||
ef246a21 UO |
736 | /* |
737 | * common function for watchdog, nmi_watchdog and soft_watchdog parameter | |
738 | * | |
df95d308 DA |
739 | * caller | table->data points to | 'which' |
740 | * -------------------|----------------------------------|------------------------------- | |
741 | * proc_watchdog | watchdog_user_enabled | WATCHDOG_HARDLOCKUP_ENABLED | | |
742 | * | | WATCHDOG_SOFTOCKUP_ENABLED | |
743 | * -------------------|----------------------------------|------------------------------- | |
744 | * proc_nmi_watchdog | watchdog_hardlockup_user_enabled | WATCHDOG_HARDLOCKUP_ENABLED | |
745 | * -------------------|----------------------------------|------------------------------- | |
746 | * proc_soft_watchdog | watchdog_softlockup_user_enabled | WATCHDOG_SOFTOCKUP_ENABLED | |
ef246a21 UO |
747 | */ |
748 | static int proc_watchdog_common(int which, struct ctl_table *table, int write, | |
32927393 | 749 | void *buffer, size_t *lenp, loff_t *ppos) |
ef246a21 | 750 | { |
09154985 | 751 | int err, old, *param = table->data; |
ef246a21 | 752 | |
946d1977 | 753 | mutex_lock(&watchdog_mutex); |
ef246a21 | 754 | |
ef246a21 | 755 | if (!write) { |
09154985 TG |
756 | /* |
757 | * On read synchronize the userspace interface. This is a | |
758 | * racy snapshot. | |
759 | */ | |
760 | *param = (watchdog_enabled & which) != 0; | |
ef246a21 UO |
761 | err = proc_dointvec_minmax(table, write, buffer, lenp, ppos); |
762 | } else { | |
09154985 | 763 | old = READ_ONCE(*param); |
ef246a21 | 764 | err = proc_dointvec_minmax(table, write, buffer, lenp, ppos); |
09154985 | 765 | if (!err && old != READ_ONCE(*param)) |
d57108d4 | 766 | proc_watchdog_update(); |
ef246a21 | 767 | } |
946d1977 | 768 | mutex_unlock(&watchdog_mutex); |
ef246a21 UO |
769 | return err; |
770 | } | |
771 | ||
83a80a39 UO |
772 | /* |
773 | * /proc/sys/kernel/watchdog | |
774 | */ | |
775 | int proc_watchdog(struct ctl_table *table, int write, | |
32927393 | 776 | void *buffer, size_t *lenp, loff_t *ppos) |
83a80a39 | 777 | { |
df95d308 DA |
778 | return proc_watchdog_common(WATCHDOG_HARDLOCKUP_ENABLED | |
779 | WATCHDOG_SOFTOCKUP_ENABLED, | |
83a80a39 UO |
780 | table, write, buffer, lenp, ppos); |
781 | } | |
782 | ||
783 | /* | |
784 | * /proc/sys/kernel/nmi_watchdog | |
58687acb | 785 | */ |
83a80a39 | 786 | int proc_nmi_watchdog(struct ctl_table *table, int write, |
32927393 | 787 | void *buffer, size_t *lenp, loff_t *ppos) |
83a80a39 | 788 | { |
df95d308 | 789 | if (!watchdog_hardlockup_available && write) |
a994a314 | 790 | return -ENOTSUPP; |
df95d308 | 791 | return proc_watchdog_common(WATCHDOG_HARDLOCKUP_ENABLED, |
83a80a39 UO |
792 | table, write, buffer, lenp, ppos); |
793 | } | |
794 | ||
795 | /* | |
796 | * /proc/sys/kernel/soft_watchdog | |
797 | */ | |
798 | int proc_soft_watchdog(struct ctl_table *table, int write, | |
32927393 | 799 | void *buffer, size_t *lenp, loff_t *ppos) |
83a80a39 | 800 | { |
df95d308 | 801 | return proc_watchdog_common(WATCHDOG_SOFTOCKUP_ENABLED, |
83a80a39 UO |
802 | table, write, buffer, lenp, ppos); |
803 | } | |
58687acb | 804 | |
83a80a39 UO |
805 | /* |
806 | * /proc/sys/kernel/watchdog_thresh | |
807 | */ | |
808 | int proc_watchdog_thresh(struct ctl_table *table, int write, | |
32927393 | 809 | void *buffer, size_t *lenp, loff_t *ppos) |
58687acb | 810 | { |
d57108d4 | 811 | int err, old; |
58687acb | 812 | |
946d1977 | 813 | mutex_lock(&watchdog_mutex); |
bcd951cf | 814 | |
d57108d4 | 815 | old = READ_ONCE(watchdog_thresh); |
b8900bc0 | 816 | err = proc_dointvec_minmax(table, write, buffer, lenp, ppos); |
83a80a39 | 817 | |
d57108d4 TG |
818 | if (!err && write && old != READ_ONCE(watchdog_thresh)) |
819 | proc_watchdog_update(); | |
e04ab2bc | 820 | |
946d1977 | 821 | mutex_unlock(&watchdog_mutex); |
b8900bc0 | 822 | return err; |
58687acb | 823 | } |
fe4ba3c3 CM |
824 | |
825 | /* | |
826 | * The cpumask is the mask of possible cpus that the watchdog can run | |
827 | * on, not the mask of cpus it is actually running on. This allows the | |
828 | * user to specify a mask that will include cpus that have not yet | |
829 | * been brought online, if desired. | |
830 | */ | |
831 | int proc_watchdog_cpumask(struct ctl_table *table, int write, | |
32927393 | 832 | void *buffer, size_t *lenp, loff_t *ppos) |
fe4ba3c3 CM |
833 | { |
834 | int err; | |
835 | ||
946d1977 | 836 | mutex_lock(&watchdog_mutex); |
8c073d27 | 837 | |
fe4ba3c3 | 838 | err = proc_do_large_bitmap(table, write, buffer, lenp, ppos); |
05ba3de7 | 839 | if (!err && write) |
e8b62b2d | 840 | proc_watchdog_update(); |
5490125d | 841 | |
946d1977 | 842 | mutex_unlock(&watchdog_mutex); |
fe4ba3c3 CM |
843 | return err; |
844 | } | |
dd0693fd XN |
845 | |
846 | static const int sixty = 60; | |
847 | ||
848 | static struct ctl_table watchdog_sysctls[] = { | |
849 | { | |
850 | .procname = "watchdog", | |
851 | .data = &watchdog_user_enabled, | |
852 | .maxlen = sizeof(int), | |
853 | .mode = 0644, | |
854 | .proc_handler = proc_watchdog, | |
855 | .extra1 = SYSCTL_ZERO, | |
856 | .extra2 = SYSCTL_ONE, | |
857 | }, | |
858 | { | |
859 | .procname = "watchdog_thresh", | |
860 | .data = &watchdog_thresh, | |
861 | .maxlen = sizeof(int), | |
862 | .mode = 0644, | |
863 | .proc_handler = proc_watchdog_thresh, | |
864 | .extra1 = SYSCTL_ZERO, | |
865 | .extra2 = (void *)&sixty, | |
866 | }, | |
dd0693fd XN |
867 | { |
868 | .procname = "watchdog_cpumask", | |
869 | .data = &watchdog_cpumask_bits, | |
870 | .maxlen = NR_CPUS, | |
871 | .mode = 0644, | |
872 | .proc_handler = proc_watchdog_cpumask, | |
873 | }, | |
874 | #ifdef CONFIG_SOFTLOCKUP_DETECTOR | |
875 | { | |
876 | .procname = "soft_watchdog", | |
df95d308 | 877 | .data = &watchdog_softlockup_user_enabled, |
dd0693fd XN |
878 | .maxlen = sizeof(int), |
879 | .mode = 0644, | |
880 | .proc_handler = proc_soft_watchdog, | |
881 | .extra1 = SYSCTL_ZERO, | |
882 | .extra2 = SYSCTL_ONE, | |
883 | }, | |
884 | { | |
885 | .procname = "softlockup_panic", | |
886 | .data = &softlockup_panic, | |
887 | .maxlen = sizeof(int), | |
888 | .mode = 0644, | |
889 | .proc_handler = proc_dointvec_minmax, | |
890 | .extra1 = SYSCTL_ZERO, | |
891 | .extra2 = SYSCTL_ONE, | |
892 | }, | |
893 | #ifdef CONFIG_SMP | |
894 | { | |
895 | .procname = "softlockup_all_cpu_backtrace", | |
896 | .data = &sysctl_softlockup_all_cpu_backtrace, | |
897 | .maxlen = sizeof(int), | |
898 | .mode = 0644, | |
899 | .proc_handler = proc_dointvec_minmax, | |
900 | .extra1 = SYSCTL_ZERO, | |
901 | .extra2 = SYSCTL_ONE, | |
902 | }, | |
903 | #endif /* CONFIG_SMP */ | |
904 | #endif | |
905 | #ifdef CONFIG_HARDLOCKUP_DETECTOR | |
906 | { | |
907 | .procname = "hardlockup_panic", | |
908 | .data = &hardlockup_panic, | |
909 | .maxlen = sizeof(int), | |
910 | .mode = 0644, | |
911 | .proc_handler = proc_dointvec_minmax, | |
912 | .extra1 = SYSCTL_ZERO, | |
913 | .extra2 = SYSCTL_ONE, | |
914 | }, | |
915 | #ifdef CONFIG_SMP | |
916 | { | |
917 | .procname = "hardlockup_all_cpu_backtrace", | |
918 | .data = &sysctl_hardlockup_all_cpu_backtrace, | |
919 | .maxlen = sizeof(int), | |
920 | .mode = 0644, | |
921 | .proc_handler = proc_dointvec_minmax, | |
922 | .extra1 = SYSCTL_ZERO, | |
923 | .extra2 = SYSCTL_ONE, | |
924 | }, | |
925 | #endif /* CONFIG_SMP */ | |
926 | #endif | |
927 | {} | |
928 | }; | |
929 | ||
9ec272c5 DA |
930 | static struct ctl_table watchdog_hardlockup_sysctl[] = { |
931 | { | |
932 | .procname = "nmi_watchdog", | |
933 | .data = &watchdog_hardlockup_user_enabled, | |
934 | .maxlen = sizeof(int), | |
935 | .mode = 0444, | |
936 | .proc_handler = proc_nmi_watchdog, | |
937 | .extra1 = SYSCTL_ZERO, | |
938 | .extra2 = SYSCTL_ONE, | |
939 | }, | |
940 | {} | |
941 | }; | |
942 | ||
dd0693fd XN |
943 | static void __init watchdog_sysctl_init(void) |
944 | { | |
945 | register_sysctl_init("kernel", watchdog_sysctls); | |
9ec272c5 DA |
946 | |
947 | if (watchdog_hardlockup_available) | |
948 | watchdog_hardlockup_sysctl[0].mode = 0644; | |
949 | register_sysctl_init("kernel", watchdog_hardlockup_sysctl); | |
dd0693fd | 950 | } |
9ec272c5 | 951 | |
dd0693fd XN |
952 | #else |
953 | #define watchdog_sysctl_init() do { } while (0) | |
58687acb DZ |
954 | #endif /* CONFIG_SYSCTL */ |
955 | ||
930d8f8d LC |
956 | static void __init lockup_detector_delay_init(struct work_struct *work); |
957 | static bool allow_lockup_detector_init_retry __initdata; | |
958 | ||
959 | static struct work_struct detector_work __initdata = | |
960 | __WORK_INITIALIZER(detector_work, lockup_detector_delay_init); | |
961 | ||
962 | static void __init lockup_detector_delay_init(struct work_struct *work) | |
963 | { | |
964 | int ret; | |
965 | ||
966 | ret = watchdog_hardlockup_probe(); | |
967 | if (ret) { | |
968 | pr_info("Delayed init of the lockup detector failed: %d\n", ret); | |
969 | pr_info("Hard watchdog permanently disabled\n"); | |
970 | return; | |
971 | } | |
972 | ||
973 | allow_lockup_detector_init_retry = false; | |
974 | ||
975 | watchdog_hardlockup_available = true; | |
976 | lockup_detector_setup(); | |
977 | } | |
978 | ||
979 | /* | |
980 | * lockup_detector_retry_init - retry init lockup detector if possible. | |
981 | * | |
982 | * Retry hardlockup detector init. It is useful when it requires some | |
983 | * functionality that has to be initialized later on a particular | |
984 | * platform. | |
985 | */ | |
986 | void __init lockup_detector_retry_init(void) | |
987 | { | |
988 | /* Must be called before late init calls */ | |
989 | if (!allow_lockup_detector_init_retry) | |
990 | return; | |
991 | ||
992 | schedule_work(&detector_work); | |
993 | } | |
994 | ||
995 | /* | |
996 | * Ensure that optional delayed hardlockup init is proceed before | |
997 | * the init code and memory is freed. | |
998 | */ | |
999 | static int __init lockup_detector_check(void) | |
1000 | { | |
1001 | /* Prevent any later retry. */ | |
1002 | allow_lockup_detector_init_retry = false; | |
1003 | ||
1004 | /* Make sure no work is pending. */ | |
1005 | flush_work(&detector_work); | |
1006 | ||
9ec272c5 DA |
1007 | watchdog_sysctl_init(); |
1008 | ||
930d8f8d LC |
1009 | return 0; |
1010 | ||
1011 | } | |
1012 | late_initcall_sync(lockup_detector_check); | |
1013 | ||
004417a6 | 1014 | void __init lockup_detector_init(void) |
58687acb | 1015 | { |
13316b31 | 1016 | if (tick_nohz_full_enabled()) |
314b08ff | 1017 | pr_info("Disabling watchdog on nohz_full cores by default\n"); |
13316b31 | 1018 | |
de201559 | 1019 | cpumask_copy(&watchdog_cpumask, |
04d4e665 | 1020 | housekeeping_cpumask(HK_TYPE_TIMER)); |
fe4ba3c3 | 1021 | |
df95d308 DA |
1022 | if (!watchdog_hardlockup_probe()) |
1023 | watchdog_hardlockup_available = true; | |
930d8f8d LC |
1024 | else |
1025 | allow_lockup_detector_init_retry = true; | |
1026 | ||
5587185d | 1027 | lockup_detector_setup(); |
58687acb | 1028 | } |