diff options
author | Neil Horman <nhorman@tuxdriver.com> | 2008-10-23 10:40:06 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-10-27 14:21:19 -0400 |
commit | 878719e831d9e076961aa15d4049a57a6668c67a (patch) | |
tree | 95d77439dff34824f9aea2479d72abe009d0586d | |
parent | 871d3779cba18b028e34d0d2f6cc6caae76a97b6 (diff) |
x86: unify appropriate bits from dumpstack_32 and dumpstack_64
Impact: cleanup
As promised, now that dumpstack_32 and dumpstack_64 have so many bits
in common, we should merge the in-sync bits into a common file, to
prevent them from diverging again.
This patch removes bits which are common between dumpstack_32.c and
dumpstack_64.c and places them in a common dumpstack.c which is built
for both 32 and 64 bit arches.
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Alexander van Heukelum <heukelum@fastmail.fm>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Makefile | 2
arch/x86/kernel/Makefile | 2
arch/x86/kernel/Makefile | 2
arch/x86/kernel/Makefile | 2
arch/x86/kernel/Makefile | 2
arch/x86/kernel/Makefile | 2
arch/x86/kernel/dumpstack.c | 319 +++++++++++++++++++++++++++++++++++++++++
arch/x86/kernel/dumpstack.h | 39 +++++
arch/x86/kernel/dumpstack_32.c | 294 -------------------------------------
arch/x86/kernel/dumpstack_64.c | 285 ------------------------------------
5 files changed, 363 insertions(+), 576 deletions(-)
-rw-r--r-- | arch/x86/kernel/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/kernel/dumpstack.c | 319 | ||||
-rw-r--r-- | arch/x86/kernel/dumpstack.h | 39 | ||||
-rw-r--r-- | arch/x86/kernel/dumpstack_32.c | 294 | ||||
-rw-r--r-- | arch/x86/kernel/dumpstack_64.c | 285 |
5 files changed, 363 insertions, 576 deletions
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index d7e5a58ee22f..db3216a9d2b9 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile | |||
@@ -24,7 +24,7 @@ CFLAGS_tsc.o := $(nostackp) | |||
24 | 24 | ||
25 | obj-y := process_$(BITS).o signal_$(BITS).o entry_$(BITS).o | 25 | obj-y := process_$(BITS).o signal_$(BITS).o entry_$(BITS).o |
26 | obj-y += traps.o irq.o irq_$(BITS).o dumpstack_$(BITS).o | 26 | obj-y += traps.o irq.o irq_$(BITS).o dumpstack_$(BITS).o |
27 | obj-y += time_$(BITS).o ioport.o ldt.o | 27 | obj-y += time_$(BITS).o ioport.o ldt.o dumpstack.o |
28 | obj-y += setup.o i8259.o irqinit_$(BITS).o setup_percpu.o | 28 | obj-y += setup.o i8259.o irqinit_$(BITS).o setup_percpu.o |
29 | obj-$(CONFIG_X86_VISWS) += visws_quirks.o | 29 | obj-$(CONFIG_X86_VISWS) += visws_quirks.o |
30 | obj-$(CONFIG_X86_32) += probe_roms_32.o | 30 | obj-$(CONFIG_X86_32) += probe_roms_32.o |
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c new file mode 100644 index 000000000000..5962176dfabb --- /dev/null +++ b/arch/x86/kernel/dumpstack.c | |||
@@ -0,0 +1,319 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs | ||
4 | */ | ||
5 | #include <linux/kallsyms.h> | ||
6 | #include <linux/kprobes.h> | ||
7 | #include <linux/uaccess.h> | ||
8 | #include <linux/utsname.h> | ||
9 | #include <linux/hardirq.h> | ||
10 | #include <linux/kdebug.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/ptrace.h> | ||
13 | #include <linux/kexec.h> | ||
14 | #include <linux/bug.h> | ||
15 | #include <linux/nmi.h> | ||
16 | #include <linux/sysfs.h> | ||
17 | |||
18 | #include <asm/stacktrace.h> | ||
19 | |||
20 | #include "dumpstack.h" | ||
21 | |||
22 | int panic_on_unrecovered_nmi; | ||
23 | unsigned int code_bytes = 64; | ||
24 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; | ||
25 | static int die_counter; | ||
26 | |||
27 | void printk_address(unsigned long address, int reliable) | ||
28 | { | ||
29 | printk(" [<%p>] %s%pS\n", (void *) address, | ||
30 | reliable ? "" : "? ", (void *) address); | ||
31 | } | ||
32 | |||
33 | /* | ||
34 | * x86-64 can have up to three kernel stacks: | ||
35 | * process stack | ||
36 | * interrupt stack | ||
37 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack | ||
38 | */ | ||
39 | |||
40 | static inline int valid_stack_ptr(struct thread_info *tinfo, | ||
41 | void *p, unsigned int size, void *end) | ||
42 | { | ||
43 | void *t = tinfo; | ||
44 | if (end) { | ||
45 | if (p < end && p >= (end-THREAD_SIZE)) | ||
46 | return 1; | ||
47 | else | ||
48 | return 0; | ||
49 | } | ||
50 | return p > t && p < t + THREAD_SIZE - size; | ||
51 | } | ||
52 | |||
53 | unsigned long | ||
54 | print_context_stack(struct thread_info *tinfo, | ||
55 | unsigned long *stack, unsigned long bp, | ||
56 | const struct stacktrace_ops *ops, void *data, | ||
57 | unsigned long *end) | ||
58 | { | ||
59 | struct stack_frame *frame = (struct stack_frame *)bp; | ||
60 | |||
61 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) { | ||
62 | unsigned long addr; | ||
63 | |||
64 | addr = *stack; | ||
65 | if (__kernel_text_address(addr)) { | ||
66 | if ((unsigned long) stack == bp + sizeof(long)) { | ||
67 | ops->address(data, addr, 1); | ||
68 | frame = frame->next_frame; | ||
69 | bp = (unsigned long) frame; | ||
70 | } else { | ||
71 | ops->address(data, addr, bp == 0); | ||
72 | } | ||
73 | } | ||
74 | stack++; | ||
75 | } | ||
76 | return bp; | ||
77 | } | ||
78 | |||
79 | |||
80 | static void | ||
81 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | ||
82 | { | ||
83 | printk(data); | ||
84 | print_symbol(msg, symbol); | ||
85 | printk("\n"); | ||
86 | } | ||
87 | |||
88 | static void print_trace_warning(void *data, char *msg) | ||
89 | { | ||
90 | printk("%s%s\n", (char *)data, msg); | ||
91 | } | ||
92 | |||
93 | static int print_trace_stack(void *data, char *name) | ||
94 | { | ||
95 | printk("%s <%s> ", (char *)data, name); | ||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | /* | ||
100 | * Print one address/symbol entries per line. | ||
101 | */ | ||
102 | static void print_trace_address(void *data, unsigned long addr, int reliable) | ||
103 | { | ||
104 | touch_nmi_watchdog(); | ||
105 | printk(data); | ||
106 | printk_address(addr, reliable); | ||
107 | } | ||
108 | |||
109 | static const struct stacktrace_ops print_trace_ops = { | ||
110 | .warning = print_trace_warning, | ||
111 | .warning_symbol = print_trace_warning_symbol, | ||
112 | .stack = print_trace_stack, | ||
113 | .address = print_trace_address, | ||
114 | }; | ||
115 | |||
116 | void | ||
117 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
118 | unsigned long *stack, unsigned long bp, char *log_lvl) | ||
119 | { | ||
120 | printk("%sCall Trace:\n", log_lvl); | ||
121 | dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl); | ||
122 | } | ||
123 | |||
124 | void show_trace(struct task_struct *task, struct pt_regs *regs, | ||
125 | unsigned long *stack, unsigned long bp) | ||
126 | { | ||
127 | show_trace_log_lvl(task, regs, stack, bp, ""); | ||
128 | } | ||
129 | |||
130 | void show_stack(struct task_struct *task, unsigned long *sp) | ||
131 | { | ||
132 | show_stack_log_lvl(task, NULL, sp, 0, ""); | ||
133 | } | ||
134 | |||
135 | /* | ||
136 | * The architecture-independent dump_stack generator | ||
137 | */ | ||
138 | void dump_stack(void) | ||
139 | { | ||
140 | unsigned long bp = 0; | ||
141 | unsigned long stack; | ||
142 | |||
143 | #ifdef CONFIG_FRAME_POINTER | ||
144 | if (!bp) | ||
145 | get_bp(bp); | ||
146 | #endif | ||
147 | |||
148 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | ||
149 | current->pid, current->comm, print_tainted(), | ||
150 | init_utsname()->release, | ||
151 | (int)strcspn(init_utsname()->version, " "), | ||
152 | init_utsname()->version); | ||
153 | show_trace(NULL, NULL, &stack, bp); | ||
154 | } | ||
155 | EXPORT_SYMBOL(dump_stack); | ||
156 | |||
157 | static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED; | ||
158 | static int die_owner = -1; | ||
159 | static unsigned int die_nest_count; | ||
160 | |||
161 | unsigned __kprobes long oops_begin(void) | ||
162 | { | ||
163 | int cpu; | ||
164 | unsigned long flags; | ||
165 | |||
166 | oops_enter(); | ||
167 | |||
168 | /* racy, but better than risking deadlock. */ | ||
169 | raw_local_irq_save(flags); | ||
170 | cpu = smp_processor_id(); | ||
171 | if (!__raw_spin_trylock(&die_lock)) { | ||
172 | if (cpu == die_owner) | ||
173 | /* nested oops. should stop eventually */; | ||
174 | else | ||
175 | __raw_spin_lock(&die_lock); | ||
176 | } | ||
177 | die_nest_count++; | ||
178 | die_owner = cpu; | ||
179 | console_verbose(); | ||
180 | bust_spinlocks(1); | ||
181 | return flags; | ||
182 | } | ||
183 | |||
184 | void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | ||
185 | { | ||
186 | if (regs && kexec_should_crash(current)) | ||
187 | crash_kexec(regs); | ||
188 | |||
189 | bust_spinlocks(0); | ||
190 | die_owner = -1; | ||
191 | add_taint(TAINT_DIE); | ||
192 | die_nest_count--; | ||
193 | if (!die_nest_count) | ||
194 | /* Nest count reaches zero, release the lock. */ | ||
195 | __raw_spin_unlock(&die_lock); | ||
196 | raw_local_irq_restore(flags); | ||
197 | oops_exit(); | ||
198 | |||
199 | if (!signr) | ||
200 | return; | ||
201 | if (in_interrupt()) | ||
202 | panic("Fatal exception in interrupt"); | ||
203 | if (panic_on_oops) | ||
204 | panic("Fatal exception"); | ||
205 | do_exit(signr); | ||
206 | } | ||
207 | |||
208 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) | ||
209 | { | ||
210 | #ifdef CONFIG_X86_32 | ||
211 | unsigned short ss; | ||
212 | unsigned long sp; | ||
213 | #endif | ||
214 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter); | ||
215 | #ifdef CONFIG_PREEMPT | ||
216 | printk("PREEMPT "); | ||
217 | #endif | ||
218 | #ifdef CONFIG_SMP | ||
219 | printk("SMP "); | ||
220 | #endif | ||
221 | #ifdef CONFIG_DEBUG_PAGEALLOC | ||
222 | printk("DEBUG_PAGEALLOC"); | ||
223 | #endif | ||
224 | printk("\n"); | ||
225 | sysfs_printk_last_file(); | ||
226 | if (notify_die(DIE_OOPS, str, regs, err, | ||
227 | current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) | ||
228 | return 1; | ||
229 | |||
230 | show_registers(regs); | ||
231 | #ifdef CONFIG_X86_32 | ||
232 | sp = (unsigned long) (®s->sp); | ||
233 | savesegment(ss, ss); | ||
234 | if (user_mode(regs)) { | ||
235 | sp = regs->sp; | ||
236 | ss = regs->ss & 0xffff; | ||
237 | } | ||
238 | printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip); | ||
239 | print_symbol("%s", regs->ip); | ||
240 | printk(" SS:ESP %04x:%08lx\n", ss, sp); | ||
241 | #else | ||
242 | /* Executive summary in case the oops scrolled away */ | ||
243 | printk(KERN_ALERT "RIP "); | ||
244 | printk_address(regs->ip, 1); | ||
245 | printk(" RSP <%016lx>\n", regs->sp); | ||
246 | #endif | ||
247 | return 0; | ||
248 | } | ||
249 | |||
250 | /* | ||
251 | * This is gone through when something in the kernel has done something bad | ||
252 | * and is about to be terminated: | ||
253 | */ | ||
254 | void die(const char *str, struct pt_regs *regs, long err) | ||
255 | { | ||
256 | unsigned long flags = oops_begin(); | ||
257 | int sig = SIGSEGV; | ||
258 | |||
259 | if (!user_mode_vm(regs)) | ||
260 | report_bug(regs->ip, regs); | ||
261 | |||
262 | if (__die(str, regs, err)) | ||
263 | sig = 0; | ||
264 | oops_end(flags, regs, sig); | ||
265 | } | ||
266 | |||
267 | void notrace __kprobes | ||
268 | die_nmi(char *str, struct pt_regs *regs, int do_panic) | ||
269 | { | ||
270 | unsigned long flags; | ||
271 | |||
272 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP) | ||
273 | return; | ||
274 | |||
275 | /* | ||
276 | * We are in trouble anyway, lets at least try | ||
277 | * to get a message out. | ||
278 | */ | ||
279 | flags = oops_begin(); | ||
280 | printk(KERN_EMERG "%s", str); | ||
281 | printk(" on CPU%d, ip %08lx, registers:\n", | ||
282 | smp_processor_id(), regs->ip); | ||
283 | show_registers(regs); | ||
284 | oops_end(flags, regs, 0); | ||
285 | if (do_panic || panic_on_oops) | ||
286 | panic("Non maskable interrupt"); | ||
287 | nmi_exit(); | ||
288 | local_irq_enable(); | ||
289 | do_exit(SIGBUS); | ||
290 | } | ||
291 | |||
292 | static int __init oops_setup(char *s) | ||
293 | { | ||
294 | if (!s) | ||
295 | return -EINVAL; | ||
296 | if (!strcmp(s, "panic")) | ||
297 | panic_on_oops = 1; | ||
298 | return 0; | ||
299 | } | ||
300 | early_param("oops", oops_setup); | ||
301 | |||
302 | static int __init kstack_setup(char *s) | ||
303 | { | ||
304 | if (!s) | ||
305 | return -EINVAL; | ||
306 | kstack_depth_to_print = simple_strtoul(s, NULL, 0); | ||
307 | return 0; | ||
308 | } | ||
309 | early_param("kstack", kstack_setup); | ||
310 | |||
311 | static int __init code_bytes_setup(char *s) | ||
312 | { | ||
313 | code_bytes = simple_strtoul(s, NULL, 0); | ||
314 | if (code_bytes > 8192) | ||
315 | code_bytes = 8192; | ||
316 | |||
317 | return 1; | ||
318 | } | ||
319 | __setup("code_bytes=", code_bytes_setup); | ||
diff --git a/arch/x86/kernel/dumpstack.h b/arch/x86/kernel/dumpstack.h new file mode 100644 index 000000000000..3119a801c32b --- /dev/null +++ b/arch/x86/kernel/dumpstack.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs | ||
4 | */ | ||
5 | |||
6 | #ifndef DUMPSTACK_H | ||
7 | #define DUMPSTACK_H | ||
8 | |||
9 | #ifdef CONFIG_X86_32 | ||
10 | #define STACKSLOTS_PER_LINE 8 | ||
11 | #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :) | ||
12 | #else | ||
13 | #define STACKSLOTS_PER_LINE 4 | ||
14 | #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :) | ||
15 | #endif | ||
16 | |||
17 | extern unsigned long | ||
18 | print_context_stack(struct thread_info *tinfo, | ||
19 | unsigned long *stack, unsigned long bp, | ||
20 | const struct stacktrace_ops *ops, void *data, | ||
21 | unsigned long *end); | ||
22 | |||
23 | extern void | ||
24 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
25 | unsigned long *stack, unsigned long bp, char *log_lvl); | ||
26 | |||
27 | extern void | ||
28 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
29 | unsigned long *sp, unsigned long bp, char *log_lvl); | ||
30 | |||
31 | extern unsigned int code_bytes; | ||
32 | extern int kstack_depth_to_print; | ||
33 | |||
34 | /* The form of the top of the frame on the stack */ | ||
35 | struct stack_frame { | ||
36 | struct stack_frame *next_frame; | ||
37 | unsigned long return_address; | ||
38 | }; | ||
39 | #endif | ||
diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c index f2046c5752d0..7b031b106ec8 100644 --- a/arch/x86/kernel/dumpstack_32.c +++ b/arch/x86/kernel/dumpstack_32.c | |||
@@ -17,64 +17,7 @@ | |||
17 | 17 | ||
18 | #include <asm/stacktrace.h> | 18 | #include <asm/stacktrace.h> |
19 | 19 | ||
20 | #define STACKSLOTS_PER_LINE 8 | 20 | #include "dumpstack.h" |
21 | #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :) | ||
22 | |||
23 | int panic_on_unrecovered_nmi; | ||
24 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; | ||
25 | static unsigned int code_bytes = 64; | ||
26 | static int die_counter; | ||
27 | |||
28 | void printk_address(unsigned long address, int reliable) | ||
29 | { | ||
30 | printk(" [<%p>] %s%pS\n", (void *) address, | ||
31 | reliable ? "" : "? ", (void *) address); | ||
32 | } | ||
33 | |||
34 | static inline int valid_stack_ptr(struct thread_info *tinfo, | ||
35 | void *p, unsigned int size, void *end) | ||
36 | { | ||
37 | void *t = tinfo; | ||
38 | if (end) { | ||
39 | if (p < end && p >= (end-THREAD_SIZE)) | ||
40 | return 1; | ||
41 | else | ||
42 | return 0; | ||
43 | } | ||
44 | return p > t && p < t + THREAD_SIZE - size; | ||
45 | } | ||
46 | |||
47 | /* The form of the top of the frame on the stack */ | ||
48 | struct stack_frame { | ||
49 | struct stack_frame *next_frame; | ||
50 | unsigned long return_address; | ||
51 | }; | ||
52 | |||
53 | static inline unsigned long | ||
54 | print_context_stack(struct thread_info *tinfo, | ||
55 | unsigned long *stack, unsigned long bp, | ||
56 | const struct stacktrace_ops *ops, void *data, | ||
57 | unsigned long *end) | ||
58 | { | ||
59 | struct stack_frame *frame = (struct stack_frame *)bp; | ||
60 | |||
61 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) { | ||
62 | unsigned long addr; | ||
63 | |||
64 | addr = *stack; | ||
65 | if (__kernel_text_address(addr)) { | ||
66 | if ((unsigned long) stack == bp + sizeof(long)) { | ||
67 | ops->address(data, addr, 1); | ||
68 | frame = frame->next_frame; | ||
69 | bp = (unsigned long) frame; | ||
70 | } else { | ||
71 | ops->address(data, addr, bp == 0); | ||
72 | } | ||
73 | } | ||
74 | stack++; | ||
75 | } | ||
76 | return bp; | ||
77 | } | ||
78 | 21 | ||
79 | void dump_trace(struct task_struct *task, struct pt_regs *regs, | 22 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
80 | unsigned long *stack, unsigned long bp, | 23 | unsigned long *stack, unsigned long bp, |
@@ -119,57 +62,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
119 | } | 62 | } |
120 | EXPORT_SYMBOL(dump_trace); | 63 | EXPORT_SYMBOL(dump_trace); |
121 | 64 | ||
122 | static void | 65 | void |
123 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | ||
124 | { | ||
125 | printk(data); | ||
126 | print_symbol(msg, symbol); | ||
127 | printk("\n"); | ||
128 | } | ||
129 | |||
130 | static void print_trace_warning(void *data, char *msg) | ||
131 | { | ||
132 | printk("%s%s\n", (char *)data, msg); | ||
133 | } | ||
134 | |||
135 | static int print_trace_stack(void *data, char *name) | ||
136 | { | ||
137 | printk("%s <%s> ", (char *)data, name); | ||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | * Print one address/symbol entries per line. | ||
143 | */ | ||
144 | static void print_trace_address(void *data, unsigned long addr, int reliable) | ||
145 | { | ||
146 | touch_nmi_watchdog(); | ||
147 | printk(data); | ||
148 | printk_address(addr, reliable); | ||
149 | } | ||
150 | |||
151 | static const struct stacktrace_ops print_trace_ops = { | ||
152 | .warning = print_trace_warning, | ||
153 | .warning_symbol = print_trace_warning_symbol, | ||
154 | .stack = print_trace_stack, | ||
155 | .address = print_trace_address, | ||
156 | }; | ||
157 | |||
158 | static void | ||
159 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
160 | unsigned long *stack, unsigned long bp, char *log_lvl) | ||
161 | { | ||
162 | printk("%sCall Trace:\n", log_lvl); | ||
163 | dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl); | ||
164 | } | ||
165 | |||
166 | void show_trace(struct task_struct *task, struct pt_regs *regs, | ||
167 | unsigned long *stack, unsigned long bp) | ||
168 | { | ||
169 | show_trace_log_lvl(task, regs, stack, bp, ""); | ||
170 | } | ||
171 | |||
172 | static void | ||
173 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | 66 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
174 | unsigned long *sp, unsigned long bp, char *log_lvl) | 67 | unsigned long *sp, unsigned long bp, char *log_lvl) |
175 | { | 68 | { |
@@ -196,33 +89,6 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | |||
196 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); | 89 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); |
197 | } | 90 | } |
198 | 91 | ||
199 | void show_stack(struct task_struct *task, unsigned long *sp) | ||
200 | { | ||
201 | show_stack_log_lvl(task, NULL, sp, 0, ""); | ||
202 | } | ||
203 | |||
204 | /* | ||
205 | * The architecture-independent dump_stack generator | ||
206 | */ | ||
207 | void dump_stack(void) | ||
208 | { | ||
209 | unsigned long bp = 0; | ||
210 | unsigned long stack; | ||
211 | |||
212 | #ifdef CONFIG_FRAME_POINTER | ||
213 | if (!bp) | ||
214 | get_bp(bp); | ||
215 | #endif | ||
216 | |||
217 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | ||
218 | current->pid, current->comm, print_tainted(), | ||
219 | init_utsname()->release, | ||
220 | (int)strcspn(init_utsname()->version, " "), | ||
221 | init_utsname()->version); | ||
222 | show_trace(NULL, NULL, &stack, bp); | ||
223 | } | ||
224 | |||
225 | EXPORT_SYMBOL(dump_stack); | ||
226 | 92 | ||
227 | void show_registers(struct pt_regs *regs) | 93 | void show_registers(struct pt_regs *regs) |
228 | { | 94 | { |
@@ -283,159 +149,3 @@ int is_valid_bugaddr(unsigned long ip) | |||
283 | return ud2 == 0x0b0f; | 149 | return ud2 == 0x0b0f; |
284 | } | 150 | } |
285 | 151 | ||
286 | static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED; | ||
287 | static int die_owner = -1; | ||
288 | static unsigned int die_nest_count; | ||
289 | |||
290 | unsigned __kprobes long oops_begin(void) | ||
291 | { | ||
292 | int cpu; | ||
293 | unsigned long flags; | ||
294 | |||
295 | oops_enter(); | ||
296 | |||
297 | /* racy, but better than risking deadlock. */ | ||
298 | raw_local_irq_save(flags); | ||
299 | cpu = smp_processor_id(); | ||
300 | if (!__raw_spin_trylock(&die_lock)) { | ||
301 | if (cpu == die_owner) | ||
302 | /* nested oops. should stop eventually */; | ||
303 | else | ||
304 | __raw_spin_lock(&die_lock); | ||
305 | } | ||
306 | die_nest_count++; | ||
307 | die_owner = cpu; | ||
308 | console_verbose(); | ||
309 | bust_spinlocks(1); | ||
310 | return flags; | ||
311 | } | ||
312 | |||
313 | void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | ||
314 | { | ||
315 | if (regs && kexec_should_crash(current)) | ||
316 | crash_kexec(regs); | ||
317 | |||
318 | bust_spinlocks(0); | ||
319 | die_owner = -1; | ||
320 | add_taint(TAINT_DIE); | ||
321 | die_nest_count--; | ||
322 | if (!die_nest_count) | ||
323 | /* Nest count reaches zero, release the lock. */ | ||
324 | __raw_spin_unlock(&die_lock); | ||
325 | raw_local_irq_restore(flags); | ||
326 | oops_exit(); | ||
327 | |||
328 | if (!signr) | ||
329 | return; | ||
330 | if (in_interrupt()) | ||
331 | panic("Fatal exception in interrupt"); | ||
332 | if (panic_on_oops) | ||
333 | panic("Fatal exception"); | ||
334 | do_exit(signr); | ||
335 | } | ||
336 | |||
337 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) | ||
338 | { | ||
339 | unsigned short ss; | ||
340 | unsigned long sp; | ||
341 | |||
342 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter); | ||
343 | #ifdef CONFIG_PREEMPT | ||
344 | printk("PREEMPT "); | ||
345 | #endif | ||
346 | #ifdef CONFIG_SMP | ||
347 | printk("SMP "); | ||
348 | #endif | ||
349 | #ifdef CONFIG_DEBUG_PAGEALLOC | ||
350 | printk("DEBUG_PAGEALLOC"); | ||
351 | #endif | ||
352 | printk("\n"); | ||
353 | sysfs_printk_last_file(); | ||
354 | if (notify_die(DIE_OOPS, str, regs, err, | ||
355 | current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) | ||
356 | return 1; | ||
357 | |||
358 | show_registers(regs); | ||
359 | /* Executive summary in case the oops scrolled away */ | ||
360 | sp = (unsigned long) (®s->sp); | ||
361 | savesegment(ss, ss); | ||
362 | if (user_mode(regs)) { | ||
363 | sp = regs->sp; | ||
364 | ss = regs->ss & 0xffff; | ||
365 | } | ||
366 | printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip); | ||
367 | print_symbol("%s", regs->ip); | ||
368 | printk(" SS:ESP %04x:%08lx\n", ss, sp); | ||
369 | return 0; | ||
370 | } | ||
371 | |||
372 | /* | ||
373 | * This is gone through when something in the kernel has done something bad | ||
374 | * and is about to be terminated: | ||
375 | */ | ||
376 | void die(const char *str, struct pt_regs *regs, long err) | ||
377 | { | ||
378 | unsigned long flags = oops_begin(); | ||
379 | int sig = SIGSEGV; | ||
380 | |||
381 | if (!user_mode_vm(regs)) | ||
382 | report_bug(regs->ip, regs); | ||
383 | |||
384 | if (__die(str, regs, err)) | ||
385 | sig = 0; | ||
386 | oops_end(flags, regs, sig); | ||
387 | } | ||
388 | |||
389 | void notrace __kprobes | ||
390 | die_nmi(char *str, struct pt_regs *regs, int do_panic) | ||
391 | { | ||
392 | unsigned long flags; | ||
393 | |||
394 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP) | ||
395 | return; | ||
396 | |||
397 | /* | ||
398 | * We are in trouble anyway, lets at least try | ||
399 | * to get a message out. | ||
400 | */ | ||
401 | flags = oops_begin(); | ||
402 | printk(KERN_EMERG "%s", str); | ||
403 | printk(" on CPU%d, ip %08lx, registers:\n", | ||
404 | smp_processor_id(), regs->ip); | ||
405 | show_registers(regs); | ||
406 | oops_end(flags, regs, 0); | ||
407 | if (do_panic || panic_on_oops) | ||
408 | panic("Non maskable interrupt"); | ||
409 | nmi_exit(); | ||
410 | local_irq_enable(); | ||
411 | do_exit(SIGBUS); | ||
412 | } | ||
413 | |||
414 | static int __init oops_setup(char *s) | ||
415 | { | ||
416 | if (!s) | ||
417 | return -EINVAL; | ||
418 | if (!strcmp(s, "panic")) | ||
419 | panic_on_oops = 1; | ||
420 | return 0; | ||
421 | } | ||
422 | early_param("oops", oops_setup); | ||
423 | |||
424 | static int __init kstack_setup(char *s) | ||
425 | { | ||
426 | if (!s) | ||
427 | return -EINVAL; | ||
428 | kstack_depth_to_print = simple_strtoul(s, NULL, 0); | ||
429 | return 0; | ||
430 | } | ||
431 | early_param("kstack", kstack_setup); | ||
432 | |||
433 | static int __init code_bytes_setup(char *s) | ||
434 | { | ||
435 | code_bytes = simple_strtoul(s, NULL, 0); | ||
436 | if (code_bytes > 8192) | ||
437 | code_bytes = 8192; | ||
438 | |||
439 | return 1; | ||
440 | } | ||
441 | __setup("code_bytes=", code_bytes_setup); | ||
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c index 28c67aae5562..33ff10287a5d 100644 --- a/arch/x86/kernel/dumpstack_64.c +++ b/arch/x86/kernel/dumpstack_64.c | |||
@@ -17,19 +17,7 @@ | |||
17 | 17 | ||
18 | #include <asm/stacktrace.h> | 18 | #include <asm/stacktrace.h> |
19 | 19 | ||
20 | #define STACKSLOTS_PER_LINE 4 | 20 | #include "dumpstack.h" |
21 | #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :) | ||
22 | |||
23 | int panic_on_unrecovered_nmi; | ||
24 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; | ||
25 | static unsigned int code_bytes = 64; | ||
26 | static int die_counter; | ||
27 | |||
28 | void printk_address(unsigned long address, int reliable) | ||
29 | { | ||
30 | printk(" [<%p>] %s%pS\n", (void *) address, | ||
31 | reliable ? "" : "? ", (void *) address); | ||
32 | } | ||
33 | 21 | ||
34 | static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, | 22 | static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, |
35 | unsigned *usedp, char **idp) | 23 | unsigned *usedp, char **idp) |
@@ -113,51 +101,6 @@ static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, | |||
113 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack | 101 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack |
114 | */ | 102 | */ |
115 | 103 | ||
116 | static inline int valid_stack_ptr(struct thread_info *tinfo, | ||
117 | void *p, unsigned int size, void *end) | ||
118 | { | ||
119 | void *t = tinfo; | ||
120 | if (end) { | ||
121 | if (p < end && p >= (end-THREAD_SIZE)) | ||
122 | return 1; | ||
123 | else | ||
124 | return 0; | ||
125 | } | ||
126 | return p > t && p < t + THREAD_SIZE - size; | ||
127 | } | ||
128 | |||
129 | /* The form of the top of the frame on the stack */ | ||
130 | struct stack_frame { | ||
131 | struct stack_frame *next_frame; | ||
132 | unsigned long return_address; | ||
133 | }; | ||
134 | |||
135 | static inline unsigned long | ||
136 | print_context_stack(struct thread_info *tinfo, | ||
137 | unsigned long *stack, unsigned long bp, | ||
138 | const struct stacktrace_ops *ops, void *data, | ||
139 | unsigned long *end) | ||
140 | { | ||
141 | struct stack_frame *frame = (struct stack_frame *)bp; | ||
142 | |||
143 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) { | ||
144 | unsigned long addr; | ||
145 | |||
146 | addr = *stack; | ||
147 | if (__kernel_text_address(addr)) { | ||
148 | if ((unsigned long) stack == bp + sizeof(long)) { | ||
149 | ops->address(data, addr, 1); | ||
150 | frame = frame->next_frame; | ||
151 | bp = (unsigned long) frame; | ||
152 | } else { | ||
153 | ops->address(data, addr, bp == 0); | ||
154 | } | ||
155 | } | ||
156 | stack++; | ||
157 | } | ||
158 | return bp; | ||
159 | } | ||
160 | |||
161 | void dump_trace(struct task_struct *task, struct pt_regs *regs, | 104 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
162 | unsigned long *stack, unsigned long bp, | 105 | unsigned long *stack, unsigned long bp, |
163 | const struct stacktrace_ops *ops, void *data) | 106 | const struct stacktrace_ops *ops, void *data) |
@@ -248,57 +191,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
248 | } | 191 | } |
249 | EXPORT_SYMBOL(dump_trace); | 192 | EXPORT_SYMBOL(dump_trace); |
250 | 193 | ||
251 | static void | 194 | void |
252 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | ||
253 | { | ||
254 | printk(data); | ||
255 | print_symbol(msg, symbol); | ||
256 | printk("\n"); | ||
257 | } | ||
258 | |||
259 | static void print_trace_warning(void *data, char *msg) | ||
260 | { | ||
261 | printk("%s%s\n", (char *)data, msg); | ||
262 | } | ||
263 | |||
264 | static int print_trace_stack(void *data, char *name) | ||
265 | { | ||
266 | printk("%s <%s> ", (char *)data, name); | ||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | /* | ||
271 | * Print one address/symbol entries per line. | ||
272 | */ | ||
273 | static void print_trace_address(void *data, unsigned long addr, int reliable) | ||
274 | { | ||
275 | touch_nmi_watchdog(); | ||
276 | printk(data); | ||
277 | printk_address(addr, reliable); | ||
278 | } | ||
279 | |||
280 | static const struct stacktrace_ops print_trace_ops = { | ||
281 | .warning = print_trace_warning, | ||
282 | .warning_symbol = print_trace_warning_symbol, | ||
283 | .stack = print_trace_stack, | ||
284 | .address = print_trace_address, | ||
285 | }; | ||
286 | |||
287 | static void | ||
288 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
289 | unsigned long *stack, unsigned long bp, char *log_lvl) | ||
290 | { | ||
291 | printk("%sCall Trace:\n", log_lvl); | ||
292 | dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl); | ||
293 | } | ||
294 | |||
295 | void show_trace(struct task_struct *task, struct pt_regs *regs, | ||
296 | unsigned long *stack, unsigned long bp) | ||
297 | { | ||
298 | show_trace_log_lvl(task, regs, stack, bp, ""); | ||
299 | } | ||
300 | |||
301 | static void | ||
302 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | 195 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
303 | unsigned long *sp, unsigned long bp, char *log_lvl) | 196 | unsigned long *sp, unsigned long bp, char *log_lvl) |
304 | { | 197 | { |
@@ -342,33 +235,6 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | |||
342 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); | 235 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); |
343 | } | 236 | } |
344 | 237 | ||
345 | void show_stack(struct task_struct *task, unsigned long *sp) | ||
346 | { | ||
347 | show_stack_log_lvl(task, NULL, sp, 0, ""); | ||
348 | } | ||
349 | |||
350 | /* | ||
351 | * The architecture-independent dump_stack generator | ||
352 | */ | ||
353 | void dump_stack(void) | ||
354 | { | ||
355 | unsigned long bp = 0; | ||
356 | unsigned long stack; | ||
357 | |||
358 | #ifdef CONFIG_FRAME_POINTER | ||
359 | if (!bp) | ||
360 | get_bp(bp); | ||
361 | #endif | ||
362 | |||
363 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | ||
364 | current->pid, current->comm, print_tainted(), | ||
365 | init_utsname()->release, | ||
366 | (int)strcspn(init_utsname()->version, " "), | ||
367 | init_utsname()->version); | ||
368 | show_trace(NULL, NULL, &stack, bp); | ||
369 | } | ||
370 | EXPORT_SYMBOL(dump_stack); | ||
371 | |||
372 | void show_registers(struct pt_regs *regs) | 238 | void show_registers(struct pt_regs *regs) |
373 | { | 239 | { |
374 | int i; | 240 | int i; |
@@ -429,150 +295,3 @@ int is_valid_bugaddr(unsigned long ip) | |||
429 | return ud2 == 0x0b0f; | 295 | return ud2 == 0x0b0f; |
430 | } | 296 | } |
431 | 297 | ||
432 | static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED; | ||
433 | static int die_owner = -1; | ||
434 | static unsigned int die_nest_count; | ||
435 | |||
436 | unsigned __kprobes long oops_begin(void) | ||
437 | { | ||
438 | int cpu; | ||
439 | unsigned long flags; | ||
440 | |||
441 | oops_enter(); | ||
442 | |||
443 | /* racy, but better than risking deadlock. */ | ||
444 | raw_local_irq_save(flags); | ||
445 | cpu = smp_processor_id(); | ||
446 | if (!__raw_spin_trylock(&die_lock)) { | ||
447 | if (cpu == die_owner) | ||
448 | /* nested oops. should stop eventually */; | ||
449 | else | ||
450 | __raw_spin_lock(&die_lock); | ||
451 | } | ||
452 | die_nest_count++; | ||
453 | die_owner = cpu; | ||
454 | console_verbose(); | ||
455 | bust_spinlocks(1); | ||
456 | return flags; | ||
457 | } | ||
458 | |||
459 | void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | ||
460 | { | ||
461 | if (regs && kexec_should_crash(current)) | ||
462 | crash_kexec(regs); | ||
463 | |||
464 | bust_spinlocks(0); | ||
465 | die_owner = -1; | ||
466 | add_taint(TAINT_DIE); | ||
467 | die_nest_count--; | ||
468 | if (!die_nest_count) | ||
469 | /* Nest count reaches zero, release the lock. */ | ||
470 | __raw_spin_unlock(&die_lock); | ||
471 | raw_local_irq_restore(flags); | ||
472 | oops_exit(); | ||
473 | |||
474 | if (!signr) | ||
475 | return; | ||
476 | if (in_interrupt()) | ||
477 | panic("Fatal exception in interrupt"); | ||
478 | if (panic_on_oops) | ||
479 | panic("Fatal exception"); | ||
480 | do_exit(signr); | ||
481 | } | ||
482 | |||
483 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) | ||
484 | { | ||
485 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter); | ||
486 | #ifdef CONFIG_PREEMPT | ||
487 | printk("PREEMPT "); | ||
488 | #endif | ||
489 | #ifdef CONFIG_SMP | ||
490 | printk("SMP "); | ||
491 | #endif | ||
492 | #ifdef CONFIG_DEBUG_PAGEALLOC | ||
493 | printk("DEBUG_PAGEALLOC"); | ||
494 | #endif | ||
495 | printk("\n"); | ||
496 | sysfs_printk_last_file(); | ||
497 | if (notify_die(DIE_OOPS, str, regs, err, | ||
498 | current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) | ||
499 | return 1; | ||
500 | |||
501 | show_registers(regs); | ||
502 | /* Executive summary in case the oops scrolled away */ | ||
503 | printk(KERN_ALERT "RIP "); | ||
504 | printk_address(regs->ip, 1); | ||
505 | printk(" RSP <%016lx>\n", regs->sp); | ||
506 | return 0; | ||
507 | } | ||
508 | |||
509 | /* | ||
510 | * This is gone through when something in the kernel has done something bad | ||
511 | * and is about to be terminated: | ||
512 | */ | ||
513 | void die(const char *str, struct pt_regs *regs, long err) | ||
514 | { | ||
515 | unsigned long flags = oops_begin(); | ||
516 | int sig = SIGSEGV; | ||
517 | |||
518 | if (!user_mode_vm(regs)) | ||
519 | report_bug(regs->ip, regs); | ||
520 | |||
521 | if (__die(str, regs, err)) | ||
522 | sig = 0; | ||
523 | oops_end(flags, regs, sig); | ||
524 | } | ||
525 | |||
526 | void notrace __kprobes | ||
527 | die_nmi(char *str, struct pt_regs *regs, int do_panic) | ||
528 | { | ||
529 | unsigned long flags; | ||
530 | |||
531 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP) | ||
532 | return; | ||
533 | |||
534 | /* | ||
535 | * We are in trouble anyway, lets at least try | ||
536 | * to get a message out. | ||
537 | */ | ||
538 | flags = oops_begin(); | ||
539 | printk(KERN_EMERG "%s", str); | ||
540 | printk(" on CPU%d, ip %08lx, registers:\n", | ||
541 | smp_processor_id(), regs->ip); | ||
542 | show_registers(regs); | ||
543 | oops_end(flags, regs, 0); | ||
544 | if (do_panic || panic_on_oops) | ||
545 | panic("Non maskable interrupt"); | ||
546 | nmi_exit(); | ||
547 | local_irq_enable(); | ||
548 | do_exit(SIGBUS); | ||
549 | } | ||
550 | |||
551 | static int __init oops_setup(char *s) | ||
552 | { | ||
553 | if (!s) | ||
554 | return -EINVAL; | ||
555 | if (!strcmp(s, "panic")) | ||
556 | panic_on_oops = 1; | ||
557 | return 0; | ||
558 | } | ||
559 | early_param("oops", oops_setup); | ||
560 | |||
561 | static int __init kstack_setup(char *s) | ||
562 | { | ||
563 | if (!s) | ||
564 | return -EINVAL; | ||
565 | kstack_depth_to_print = simple_strtoul(s, NULL, 0); | ||
566 | return 0; | ||
567 | } | ||
568 | early_param("kstack", kstack_setup); | ||
569 | |||
570 | static int __init code_bytes_setup(char *s) | ||
571 | { | ||
572 | code_bytes = simple_strtoul(s, NULL, 0); | ||
573 | if (code_bytes > 8192) | ||
574 | code_bytes = 8192; | ||
575 | |||
576 | return 1; | ||
577 | } | ||
578 | __setup("code_bytes=", code_bytes_setup); | ||