]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - lib/nmi_backtrace.c
lib/vsprintf: Do not handle %pO[^F] as %px
[mirror_ubuntu-bionic-kernel.git] / lib / nmi_backtrace.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
b2c0b2cb
RK
2/*
3 * NMI backtrace support
4 *
5 * Gratuitously copied from arch/x86/kernel/apic/hw_nmi.c by Russell King,
6 * with the following header:
7 *
8 * HW NMI watchdog support
9 *
10 * started by Don Zickus, Copyright (C) 2010 Red Hat, Inc.
11 *
12 * Arch specific calls to support NMI watchdog
13 *
14 * Bits copied from original nmi.c file
15 */
16#include <linux/cpumask.h>
17#include <linux/delay.h>
18#include <linux/kprobes.h>
19#include <linux/nmi.h>
6727ad9e 20#include <linux/cpu.h>
b17b0153 21#include <linux/sched/debug.h>
b2c0b2cb 22
9a01c3ed 23#ifdef arch_trigger_cpumask_backtrace
b2c0b2cb
RK
24/* For reliability, we're prepared to waste bits here. */
25static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
b2c0b2cb 26
9a01c3ed 27/* "in progress" flag of arch_trigger_cpumask_backtrace */
b2c0b2cb
RK
28static unsigned long backtrace_flag;
29
0768330d 30/*
9a01c3ed 31 * When raise() is called it will be passed a pointer to the
0768330d
DT
32 * backtrace_mask. Architectures that call nmi_cpu_backtrace()
33 * directly from their raise() functions may rely on the mask
34 * they are passed being updated as a side effect of this call.
35 */
9a01c3ed
CM
36void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
37 bool exclude_self,
b2c0b2cb
RK
38 void (*raise)(cpumask_t *mask))
39{
42a0bb3f 40 int i, this_cpu = get_cpu();
b2c0b2cb
RK
41
42 if (test_and_set_bit(0, &backtrace_flag)) {
43 /*
44 * If there is already a trigger_all_cpu_backtrace() in progress
45 * (backtrace_flag == 1), don't output double cpu dump infos.
46 */
47 put_cpu();
48 return;
49 }
50
9a01c3ed
CM
51 cpumask_copy(to_cpumask(backtrace_mask), mask);
52 if (exclude_self)
b2c0b2cb
RK
53 cpumask_clear_cpu(this_cpu, to_cpumask(backtrace_mask));
54
67766489
CM
55 /*
56 * Don't try to send an NMI to this cpu; it may work on some
57 * architectures, but on others it may not, and we'll get
58 * information at least as useful just by doing a dump_stack() here.
59 * Note that nmi_cpu_backtrace(NULL) will clear the cpu bit.
60 */
61 if (cpumask_test_cpu(this_cpu, to_cpumask(backtrace_mask)))
62 nmi_cpu_backtrace(NULL);
63
b2c0b2cb 64 if (!cpumask_empty(to_cpumask(backtrace_mask))) {
9a01c3ed
CM
65 pr_info("Sending NMI from CPU %d to CPUs %*pbl:\n",
66 this_cpu, nr_cpumask_bits, to_cpumask(backtrace_mask));
b2c0b2cb
RK
67 raise(to_cpumask(backtrace_mask));
68 }
69
70 /* Wait for up to 10 seconds for all CPUs to do the backtrace */
71 for (i = 0; i < 10 * 1000; i++) {
72 if (cpumask_empty(to_cpumask(backtrace_mask)))
73 break;
74 mdelay(1);
75 touch_softlockup_watchdog();
76 }
77
78 /*
42a0bb3f
PM
79 * Force flush any remote buffers that might be stuck in IRQ context
80 * and therefore could not run their irq_work.
b2c0b2cb 81 */
f92bac3b 82 printk_safe_flush();
b2c0b2cb 83
42a0bb3f 84 clear_bit_unlock(0, &backtrace_flag);
b2c0b2cb
RK
85 put_cpu();
86}
87
b2c0b2cb
RK
88bool nmi_cpu_backtrace(struct pt_regs *regs)
89{
90 int cpu = smp_processor_id();
91
92 if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
6727ad9e 93 if (regs && cpu_in_idle(instruction_pointer(regs))) {
2f9b7e08
LC
94 pr_warn("NMI backtrace for cpu %d skipped: idling at %pS\n",
95 cpu, (void *)instruction_pointer(regs));
6727ad9e
CM
96 } else {
97 pr_warn("NMI backtrace for cpu %d\n", cpu);
98 if (regs)
99 show_regs(regs);
100 else
101 dump_stack();
102 }
b2c0b2cb
RK
103 cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
104 return true;
105 }
106
107 return false;
108}
109NOKPROBE_SYMBOL(nmi_cpu_backtrace);
110#endif