Skip to content

Commit 5553787

Browse files
Jiri Kosinatorvalds
authored andcommitted
kernel/watchdog.c: perform all-CPU backtrace in case of hard lockup
In many cases of hardlockup reports, it's actually not possible to know why it triggered, because the CPU that got stuck is usually waiting on a resource (with IRQs disabled) in posession of some other CPU is holding. IOW, we are often looking at the stacktrace of the victim and not the actual offender. Introduce sysctl / cmdline parameter that makes it possible to have hardlockup detector perform all-CPU backtrace. Signed-off-by: Jiri Kosina <jkosina@suse.cz> Reviewed-by: Aaron Tomlin <atomlin@redhat.com> Cc: Ulrich Obergfell <uobergfe@redhat.com> Acked-by: Don Zickus <dzickus@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ee7fed5 commit 5553787

5 files changed

Lines changed: 55 additions & 5 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
12691269
Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
12701270
Default: 1024
12711271

1272+
hardlockup_all_cpu_backtrace=
1273+
[KNL] Should the hard-lockup detector generate
1274+
backtraces on all cpus.
1275+
Format: <integer>
1276+
12721277
hashdist= [KNL,NUMA] Large hashes allocated during boot
12731278
are distributed across NUMA nodes. Defaults on
12741279
for 64-bit NUMA, off otherwise.

‎Documentation/sysctl/kernel.txt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ show up in /proc/sys/kernel:
3333
- domainname
3434
- hostname
3535
- hotplug
36+
- hardlockup_all_cpu_backtrace
3637
- hung_task_panic
3738
- hung_task_check_count
3839
- hung_task_timeout_secs
@@ -292,6 +293,17 @@ Information Service) or YP (Yellow Pages) domainname. These two
292293
domain names are in general different. For a detailed discussion
293294
see the hostname(1) man page.
294295

296+
==============================================================
297+
hardlockup_all_cpu_backtrace:
298+
299+
This value controls the hard lockup detector behavior when a hard
300+
lockup condition is detected as to whether or not to gather further
301+
debug information. If enabled, arch-specific all-CPU stack dumping
302+
will be initiated.
303+
304+
0: do nothing. This is the default behavior.
305+
306+
1: on detection capture more debug information.
295307
==============================================================
296308

297309
hotplug:

‎include/linux/nmi.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ extern int watchdog_user_enabled;
7373
extern int watchdog_thresh;
7474
extern unsigned long *watchdog_cpumask_bits;
7575
extern int sysctl_softlockup_all_cpu_backtrace;
76+
extern int sysctl_hardlockup_all_cpu_backtrace;
7677
struct ctl_table;
7778
extern int proc_watchdog(struct ctl_table *, int ,
7879
void __user *, size_t *, loff_t *);

‎kernel/sysctl.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,15 @@ static struct ctl_table kern_table[] = {
898898
.extra1 = &zero,
899899
.extra2 = &one,
900900
},
901+
{
902+
.procname = "hardlockup_all_cpu_backtrace",
903+
.data = &sysctl_hardlockup_all_cpu_backtrace,
904+
.maxlen = sizeof(int),
905+
.mode = 0644,
906+
.proc_handler = proc_dointvec_minmax,
907+
.extra1 = &zero,
908+
.extra2 = &one,
909+
},
901910
#endif /* CONFIG_SMP */
902911
#endif
903912
#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)

‎kernel/watchdog.c‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ int __read_mostly watchdog_thresh = 10;
5757

5858
#ifdef CONFIG_SMP
5959
int __read_mostly sysctl_softlockup_all_cpu_backtrace;
60+
int __read_mostly sysctl_hardlockup_all_cpu_backtrace;
6061
#else
6162
#define sysctl_softlockup_all_cpu_backtrace 0
63+
#define sysctl_hardlockup_all_cpu_backtrace 0
6264
#endif
6365
static struct cpumask watchdog_cpumask __read_mostly;
6466
unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask);
@@ -112,6 +114,7 @@ static unsigned long soft_lockup_nmi_warn;
112114
#ifdef CONFIG_HARDLOCKUP_DETECTOR
113115
static int hardlockup_panic =
114116
CONFIG_BOOTPARAM_HARDLOCKUP_PANIC_VALUE;
117+
static unsigned long hardlockup_allcpu_dumped;
115118
/*
116119
* We may not want to enable hard lockup detection by default in all cases,
117120
* for example when running the kernel as a guest on a hypervisor. In these
@@ -173,6 +176,13 @@ static int __init softlockup_all_cpu_backtrace_setup(char *str)
173176
return 1;
174177
}
175178
__setup("softlockup_all_cpu_backtrace=", softlockup_all_cpu_backtrace_setup);
179+
static int __init hardlockup_all_cpu_backtrace_setup(char *str)
180+
{
181+
sysctl_hardlockup_all_cpu_backtrace =
182+
!!simple_strtol(str, NULL, 0);
183+
return 1;
184+
}
185+
__setup("hardlockup_all_cpu_backtrace=", hardlockup_all_cpu_backtrace_setup);
176186
#endif
177187

178188
/*
@@ -318,17 +328,30 @@ static void watchdog_overflow_callback(struct perf_event *event,
318328
*/
319329
if (is_hardlockup()) {
320330
int this_cpu = smp_processor_id();
331+
struct pt_regs *regs = get_irq_regs();
321332

322333
/* only print hardlockups once */
323334
if (__this_cpu_read(hard_watchdog_warn) == true)
324335
return;
325336

326-
if (hardlockup_panic)
327-
panic("Watchdog detected hard LOCKUP on cpu %d",
328-
this_cpu);
337+
pr_emerg("Watchdog detected hard LOCKUP on cpu %d", this_cpu);
338+
print_modules();
339+
print_irqtrace_events(current);
340+
if (regs)
341+
show_regs(regs);
329342
else
330-
WARN(1, "Watchdog detected hard LOCKUP on cpu %d",
331-
this_cpu);
343+
dump_stack();
344+
345+
/*
346+
* Perform all-CPU dump only once to avoid multiple hardlockups
347+
* generating interleaving traces
348+
*/
349+
if (sysctl_hardlockup_all_cpu_backtrace &&
350+
!test_and_set_bit(0, &hardlockup_allcpu_dumped))
351+
trigger_allbutself_cpu_backtrace();
352+
353+
if (hardlockup_panic)
354+
panic("Hard LOCKUP");
332355

333356
__this_cpu_write(hard_watchdog_warn, true);
334357
return;

0 commit comments

Comments
 (0)