blackfin: cplb-mpu: fix page mask table overflow
[linux-2.6.git] / arch / x86 / kernel / dumpstack.c
blob4025fe4f928f6f4cb2ddcfc0233197e9e0b3ad44
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/ftrace.h>
14 #include <linux/kexec.h>
15 #include <linux/bug.h>
16 #include <linux/nmi.h>
17 #include <linux/sysfs.h>
19 #include <asm/stacktrace.h>
22 int panic_on_unrecovered_nmi;
23 int panic_on_io_nmi;
24 unsigned int code_bytes = 64;
25 int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE;
26 static int die_counter;
28 void printk_address(unsigned long address, int reliable)
30 printk(" [<%p>] %s%pB\n", (void *) address,
31 reliable ? "" : "? ", (void *) address);
34 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
35 static void
36 print_ftrace_graph_addr(unsigned long addr, void *data,
37 const struct stacktrace_ops *ops,
38 struct thread_info *tinfo, int *graph)
40 struct task_struct *task = tinfo->task;
41 unsigned long ret_addr;
42 int index = task->curr_ret_stack;
44 if (addr != (unsigned long)return_to_handler)
45 return;
47 if (!task->ret_stack || index < *graph)
48 return;
50 index -= *graph;
51 ret_addr = task->ret_stack[index].ret;
53 ops->address(data, ret_addr, 1);
55 (*graph)++;
57 #else
58 static inline void
59 print_ftrace_graph_addr(unsigned long addr, void *data,
60 const struct stacktrace_ops *ops,
61 struct thread_info *tinfo, int *graph)
62 { }
63 #endif
66 * x86-64 can have up to three kernel stacks:
67 * process stack
68 * interrupt stack
69 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
72 static inline int valid_stack_ptr(struct thread_info *tinfo,
73 void *p, unsigned int size, void *end)
75 void *t = tinfo;
76 if (end) {
77 if (p < end && p >= (end-THREAD_SIZE))
78 return 1;
79 else
80 return 0;
82 return p > t && p < t + THREAD_SIZE - size;
85 unsigned long
86 print_context_stack(struct thread_info *tinfo,
87 unsigned long *stack, unsigned long bp,
88 const struct stacktrace_ops *ops, void *data,
89 unsigned long *end, int *graph)
91 struct stack_frame *frame = (struct stack_frame *)bp;
93 while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
94 unsigned long addr;
96 addr = *stack;
97 if (__kernel_text_address(addr)) {
98 if ((unsigned long) stack == bp + sizeof(long)) {
99 ops->address(data, addr, 1);
100 frame = frame->next_frame;
101 bp = (unsigned long) frame;
102 } else {
103 ops->address(data, addr, 0);
105 print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
107 stack++;
109 return bp;
111 EXPORT_SYMBOL_GPL(print_context_stack);
113 unsigned long
114 print_context_stack_bp(struct thread_info *tinfo,
115 unsigned long *stack, unsigned long bp,
116 const struct stacktrace_ops *ops, void *data,
117 unsigned long *end, int *graph)
119 struct stack_frame *frame = (struct stack_frame *)bp;
120 unsigned long *ret_addr = &frame->return_address;
122 while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
123 unsigned long addr = *ret_addr;
125 if (!__kernel_text_address(addr))
126 break;
128 ops->address(data, addr, 1);
129 frame = frame->next_frame;
130 ret_addr = &frame->return_address;
131 print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
134 return (unsigned long)frame;
136 EXPORT_SYMBOL_GPL(print_context_stack_bp);
138 static int print_trace_stack(void *data, char *name)
140 printk("%s <%s> ", (char *)data, name);
141 return 0;
145 * Print one address/symbol entries per line.
147 static void print_trace_address(void *data, unsigned long addr, int reliable)
149 touch_nmi_watchdog();
150 printk(data);
151 printk_address(addr, reliable);
154 static const struct stacktrace_ops print_trace_ops = {
155 .stack = print_trace_stack,
156 .address = print_trace_address,
157 .walk_stack = print_context_stack,
160 void
161 show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
162 unsigned long *stack, unsigned long bp, char *log_lvl)
164 printk("%sCall Trace:\n", log_lvl);
165 dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl);
168 void show_trace(struct task_struct *task, struct pt_regs *regs,
169 unsigned long *stack, unsigned long bp)
171 show_trace_log_lvl(task, regs, stack, bp, "");
174 void show_stack(struct task_struct *task, unsigned long *sp)
176 show_stack_log_lvl(task, NULL, sp, 0, "");
180 * The architecture-independent dump_stack generator
182 void dump_stack(void)
184 unsigned long bp;
185 unsigned long stack;
187 bp = stack_frame(current, NULL);
188 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
189 current->pid, current->comm, print_tainted(),
190 init_utsname()->release,
191 (int)strcspn(init_utsname()->version, " "),
192 init_utsname()->version);
193 show_trace(NULL, NULL, &stack, bp);
195 EXPORT_SYMBOL(dump_stack);
197 static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
198 static int die_owner = -1;
199 static unsigned int die_nest_count;
201 unsigned __kprobes long oops_begin(void)
203 int cpu;
204 unsigned long flags;
206 oops_enter();
208 /* racy, but better than risking deadlock. */
209 raw_local_irq_save(flags);
210 cpu = smp_processor_id();
211 if (!arch_spin_trylock(&die_lock)) {
212 if (cpu == die_owner)
213 /* nested oops. should stop eventually */;
214 else
215 arch_spin_lock(&die_lock);
217 die_nest_count++;
218 die_owner = cpu;
219 console_verbose();
220 bust_spinlocks(1);
221 return flags;
223 EXPORT_SYMBOL_GPL(oops_begin);
225 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
227 if (regs && kexec_should_crash(current))
228 crash_kexec(regs);
230 bust_spinlocks(0);
231 die_owner = -1;
232 add_taint(TAINT_DIE);
233 die_nest_count--;
234 if (!die_nest_count)
235 /* Nest count reaches zero, release the lock. */
236 arch_spin_unlock(&die_lock);
237 raw_local_irq_restore(flags);
238 oops_exit();
240 if (!signr)
241 return;
242 if (in_interrupt())
243 panic("Fatal exception in interrupt");
244 if (panic_on_oops)
245 panic("Fatal exception");
246 do_exit(signr);
249 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
251 #ifdef CONFIG_X86_32
252 unsigned short ss;
253 unsigned long sp;
254 #endif
255 printk(KERN_DEFAULT
256 "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter);
257 #ifdef CONFIG_PREEMPT
258 printk("PREEMPT ");
259 #endif
260 #ifdef CONFIG_SMP
261 printk("SMP ");
262 #endif
263 #ifdef CONFIG_DEBUG_PAGEALLOC
264 printk("DEBUG_PAGEALLOC");
265 #endif
266 printk("\n");
267 if (notify_die(DIE_OOPS, str, regs, err,
268 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
269 return 1;
271 show_registers(regs);
272 #ifdef CONFIG_X86_32
273 if (user_mode_vm(regs)) {
274 sp = regs->sp;
275 ss = regs->ss & 0xffff;
276 } else {
277 sp = kernel_stack_pointer(regs);
278 savesegment(ss, ss);
280 printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip);
281 print_symbol("%s", regs->ip);
282 printk(" SS:ESP %04x:%08lx\n", ss, sp);
283 #else
284 /* Executive summary in case the oops scrolled away */
285 printk(KERN_ALERT "RIP ");
286 printk_address(regs->ip, 1);
287 printk(" RSP <%016lx>\n", regs->sp);
288 #endif
289 return 0;
293 * This is gone through when something in the kernel has done something bad
294 * and is about to be terminated:
296 void die(const char *str, struct pt_regs *regs, long err)
298 unsigned long flags = oops_begin();
299 int sig = SIGSEGV;
301 if (!user_mode_vm(regs))
302 report_bug(regs->ip, regs);
304 if (__die(str, regs, err))
305 sig = 0;
306 oops_end(flags, regs, sig);
309 static int __init kstack_setup(char *s)
311 if (!s)
312 return -EINVAL;
313 kstack_depth_to_print = simple_strtoul(s, NULL, 0);
314 return 0;
316 early_param("kstack", kstack_setup);
318 static int __init code_bytes_setup(char *s)
320 code_bytes = simple_strtoul(s, NULL, 0);
321 if (code_bytes > 8192)
322 code_bytes = 8192;
324 return 1;
326 __setup("code_bytes=", code_bytes_setup);