1
2
3
4
5
6
7#include <linux/kernel.h>
8#include <linux/export.h>
9#include <linux/sched.h>
10#include <linux/sched/debug.h>
11#include <linux/smp.h>
12#include <linux/atomic.h>
13#include <linux/kexec.h>
14#include <linux/utsname.h>
15
16static char dump_stack_arch_desc_str[128];
17
18
19
20
21
22
23
24
25
26
27
28void __init dump_stack_set_arch_desc(const char *fmt, ...)
29{
30 va_list args;
31
32 va_start(args, fmt);
33 vsnprintf(dump_stack_arch_desc_str, sizeof(dump_stack_arch_desc_str),
34 fmt, args);
35 va_end(args);
36}
37
38
39
40
41
42
43
44
45void dump_stack_print_info(const char *log_lvl)
46{
47 printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s\n",
48 log_lvl, raw_smp_processor_id(), current->pid, current->comm,
49 kexec_crash_loaded() ? "Kdump: loaded " : "",
50 print_tainted(),
51 init_utsname()->release,
52 (int)strcspn(init_utsname()->version, " "),
53 init_utsname()->version);
54
55 if (dump_stack_arch_desc_str[0] != '\0')
56 printk("%sHardware name: %s\n",
57 log_lvl, dump_stack_arch_desc_str);
58
59 print_worker_info(log_lvl, current);
60}
61
62
63
64
65
66
67
68
69void show_regs_print_info(const char *log_lvl)
70{
71 dump_stack_print_info(log_lvl);
72}
73
74static void __dump_stack(void)
75{
76 dump_stack_print_info(KERN_DEFAULT);
77 show_stack(NULL, NULL);
78}
79
80
81
82
83
84
85#ifdef CONFIG_SMP
86static atomic_t dump_lock = ATOMIC_INIT(-1);
87
88asmlinkage __visible void dump_stack(void)
89{
90 unsigned long flags;
91 int was_locked;
92 int old;
93 int cpu;
94
95
96
97
98
99retry:
100 local_irq_save(flags);
101 cpu = smp_processor_id();
102 old = atomic_cmpxchg(&dump_lock, -1, cpu);
103 if (old == -1) {
104 was_locked = 0;
105 } else if (old == cpu) {
106 was_locked = 1;
107 } else {
108 local_irq_restore(flags);
109 cpu_relax();
110 goto retry;
111 }
112
113 __dump_stack();
114
115 if (!was_locked)
116 atomic_set(&dump_lock, -1);
117
118 local_irq_restore(flags);
119}
120#else
121asmlinkage __visible void dump_stack(void)
122{
123 __dump_stack();
124}
125#endif
126EXPORT_SYMBOL(dump_stack);
127