blob: 8b5b3b81d437e72f76a2a90cc6fd43089457a97e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
4 *
5 * Pentium III FXSR, SSE support
6 * Gareth Hughes <gareth@valinux.com>, May 2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9/*
10 * 'Traps.c' handles hardware traps and faults after we have saved some
11 * state in 'entry.S'.
12 */
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020013#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/interrupt.h>
Randy Dunlap4b0ff1a2006-10-05 19:07:26 +020015#include <linux/kallsyms.h>
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020016#include <linux/spinlock.h>
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -070017#include <linux/kprobes.h>
Andi Kleenab2bf0c2006-12-07 02:14:06 +010018#include <linux/uaccess.h>
Arjan van de Ven57c351d2007-11-26 20:42:19 +010019#include <linux/utsname.h>
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020020#include <linux/kdebug.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/ptrace.h>
24#include <linux/string.h>
25#include <linux/unwind.h>
26#include <linux/delay.h>
27#include <linux/errno.h>
28#include <linux/kexec.h>
29#include <linux/sched.h>
30#include <linux/timer.h>
31#include <linux/init.h>
32#include <linux/bug.h>
33#include <linux/nmi.h>
34#include <linux/mm.h>
Glauber de Oliveira Costae32ede12008-03-19 14:25:35 -030035
Dave Jiangc0d12172007-07-19 01:49:46 -070036#if defined(CONFIG_EDAC)
37#include <linux/edac.h>
38#endif
39
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020040#include <asm/stacktrace.h>
41#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/debugreg.h>
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020043#include <asm/atomic.h>
44#include <asm/system.h>
45#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/desc.h>
47#include <asm/i387.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <asm/nmi.h>
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020049#include <asm/smp.h>
50#include <asm/io.h>
51#include <asm/pgalloc.h>
52#include <asm/proto.h>
53#include <asm/pda.h>
Jaswinder Singh6ac8d512008-07-15 21:09:13 +053054#include <asm/traps.h>
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020055
56#include <mach_traps.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +040058int panic_on_unrecovered_nmi;
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020059int kstack_depth_to_print = 12;
Arjan van de Vena25bd942008-01-30 13:33:08 +010060static unsigned int code_bytes = 64;
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020061static int ignore_nmis;
62static int die_counter;
Arjan van de Vena25bd942008-01-30 13:33:08 +010063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static inline void conditional_sti(struct pt_regs *regs)
65{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010066 if (regs->flags & X86_EFLAGS_IF)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 local_irq_enable();
68}
69
John Blackwooda65d17c2006-02-12 14:34:58 -080070static inline void preempt_conditional_sti(struct pt_regs *regs)
71{
Ingo Molnare8bff742008-02-13 20:21:06 +010072 inc_preempt_count();
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010073 if (regs->flags & X86_EFLAGS_IF)
John Blackwooda65d17c2006-02-12 14:34:58 -080074 local_irq_enable();
75}
76
77static inline void preempt_conditional_cli(struct pt_regs *regs)
78{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010079 if (regs->flags & X86_EFLAGS_IF)
John Blackwooda65d17c2006-02-12 14:34:58 -080080 local_irq_disable();
Andi Kleen40e59a62006-05-15 18:19:47 +020081 /* Make sure to not schedule here because we could be running
82 on an exception stack. */
Ingo Molnare8bff742008-02-13 20:21:06 +010083 dec_preempt_count();
John Blackwooda65d17c2006-02-12 14:34:58 -080084}
85
Arjan van de Venbc850d62008-01-30 13:33:07 +010086void printk_address(unsigned long address, int reliable)
Ingo Molnar3ac94932006-07-03 00:24:36 -070087{
Linus Torvalds7daf7052008-07-14 12:12:53 -070088 printk(" [<%016lx>] %s%pS\n", address, reliable ? "": "? ", (void *) address);
Harvey Harrisona5ff6772008-01-30 13:33:25 +010089}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Andi Kleen0a658002005-04-16 15:25:17 -070091static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
Andi Kleenc0b766f2006-09-26 10:52:34 +020092 unsigned *usedp, char **idp)
Andi Kleen0a658002005-04-16 15:25:17 -070093{
Jan Beulichb556b352006-01-11 22:43:00 +010094 static char ids[][8] = {
Andi Kleen0a658002005-04-16 15:25:17 -070095 [DEBUG_STACK - 1] = "#DB",
96 [NMI_STACK - 1] = "NMI",
97 [DOUBLEFAULT_STACK - 1] = "#DF",
98 [STACKFAULT_STACK - 1] = "#SS",
99 [MCE_STACK - 1] = "#MC",
Jan Beulichb556b352006-01-11 22:43:00 +0100100#if DEBUG_STKSZ > EXCEPTION_STKSZ
101 [N_EXCEPTION_STACKS ... N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]"
102#endif
Andi Kleen0a658002005-04-16 15:25:17 -0700103 };
104 unsigned k;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700106 /*
107 * Iterate over all exception stacks, and figure out whether
108 * 'stack' is in one of them:
109 */
Andi Kleen0a658002005-04-16 15:25:17 -0700110 for (k = 0; k < N_EXCEPTION_STACKS; k++) {
Keith Owensf5741642006-09-26 10:52:38 +0200111 unsigned long end = per_cpu(orig_ist, cpu).ist[k];
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700112 /*
113 * Is 'stack' above this exception frame's end?
114 * If yes then skip to the next frame.
115 */
Andi Kleen0a658002005-04-16 15:25:17 -0700116 if (stack >= end)
117 continue;
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700118 /*
119 * Is 'stack' above this exception frame's start address?
120 * If yes then we found the right frame.
121 */
Andi Kleen0a658002005-04-16 15:25:17 -0700122 if (stack >= end - EXCEPTION_STKSZ) {
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700123 /*
124 * Make sure we only iterate through an exception
125 * stack once. If it comes up for the second time
126 * then there's something wrong going on - just
127 * break out and return NULL:
128 */
Andi Kleen0a658002005-04-16 15:25:17 -0700129 if (*usedp & (1U << k))
130 break;
131 *usedp |= 1U << k;
132 *idp = ids[k];
133 return (unsigned long *)end;
134 }
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700135 /*
136 * If this is a debug stack, and if it has a larger size than
137 * the usual exception stacks, then 'stack' might still
138 * be within the lower portion of the debug stack:
139 */
Jan Beulichb556b352006-01-11 22:43:00 +0100140#if DEBUG_STKSZ > EXCEPTION_STKSZ
141 if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
142 unsigned j = N_EXCEPTION_STACKS - 1;
143
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700144 /*
145 * Black magic. A large debug stack is composed of
146 * multiple exception stack entries, which we
147 * iterate through now. Dont look:
148 */
Jan Beulichb556b352006-01-11 22:43:00 +0100149 do {
150 ++j;
151 end -= EXCEPTION_STKSZ;
152 ids[j][4] = '1' + (j - N_EXCEPTION_STACKS);
153 } while (stack < end - EXCEPTION_STKSZ);
154 if (*usedp & (1U << j))
155 break;
156 *usedp |= 1U << j;
157 *idp = ids[j];
158 return (unsigned long *)end;
159 }
160#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162 return NULL;
Andi Kleen0a658002005-04-16 15:25:17 -0700163}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165/*
Simon Arlott676b1852007-10-20 01:25:36 +0200166 * x86-64 can have up to three kernel stacks:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 * process stack
168 * interrupt stack
Andi Kleen0a658002005-04-16 15:25:17 -0700169 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 */
171
Arjan van de Vene4a94562008-01-30 13:33:07 +0100172static inline int valid_stack_ptr(struct thread_info *tinfo,
173 void *p, unsigned int size, void *end)
Andi Kleenc547c772006-11-28 20:12:59 +0100174{
Jan Engelhardtade1af72008-01-30 13:33:23 +0100175 void *t = tinfo;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100176 if (end) {
177 if (p < end && p >= (end-THREAD_SIZE))
178 return 1;
179 else
180 return 0;
181 }
182 return p > t && p < t + THREAD_SIZE - size;
183}
184
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100185/* The form of the top of the frame on the stack */
186struct stack_frame {
187 struct stack_frame *next_frame;
188 unsigned long return_address;
189};
190
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200191static inline unsigned long
192print_context_stack(struct thread_info *tinfo,
193 unsigned long *stack, unsigned long bp,
194 const struct stacktrace_ops *ops, void *data,
195 unsigned long *end)
Arjan van de Vene4a94562008-01-30 13:33:07 +0100196{
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100197 struct stack_frame *frame = (struct stack_frame *)bp;
198
199 while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
200 unsigned long addr;
201
202 addr = *stack;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100203 if (__kernel_text_address(addr)) {
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100204 if ((unsigned long) stack == bp + 8) {
205 ops->address(data, addr, 1);
206 frame = frame->next_frame;
207 bp = (unsigned long) frame;
208 } else {
209 ops->address(data, addr, bp == 0);
210 }
Arjan van de Vene4a94562008-01-30 13:33:07 +0100211 }
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100212 stack++;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100213 }
214 return bp;
Andi Kleenc547c772006-11-28 20:12:59 +0100215}
216
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200217void dump_trace(struct task_struct *task, struct pt_regs *regs,
Arjan van de Venbc850d62008-01-30 13:33:07 +0100218 unsigned long *stack, unsigned long bp,
Jan Beulich9689ba82007-10-17 18:04:37 +0200219 const struct stacktrace_ops *ops, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Andrew Mortonda689332006-12-07 02:14:02 +0100221 const unsigned cpu = get_cpu();
Andi Kleenb615ebd2006-12-07 02:14:00 +0100222 unsigned long *irqstack_end = (unsigned long*)cpu_pda(cpu)->irqstackptr;
Andi Kleen0a658002005-04-16 15:25:17 -0700223 unsigned used = 0;
Andi Kleenc547c772006-11-28 20:12:59 +0100224 struct thread_info *tinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200226 if (!task)
227 task = current;
Jan Beulichb538ed22006-06-26 13:57:32 +0200228
Andi Kleenc0b766f2006-09-26 10:52:34 +0200229 if (!stack) {
230 unsigned long dummy;
231 stack = &dummy;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200232 if (task && task != current)
233 stack = (unsigned long *)task->thread.sp;
Jan Beulichb538ed22006-06-26 13:57:32 +0200234 }
235
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100236#ifdef CONFIG_FRAME_POINTER
237 if (!bp) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200238 if (task == current) {
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100239 /* Grab bp right from our regs */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200240 asm("movq %%rbp, %0" : "=r" (bp) :);
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100241 } else {
242 /* bp is the last reg pushed by switch_to */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200243 bp = *(unsigned long *) task->thread.sp;
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100244 }
245 }
246#endif
247
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700248 /*
249 * Print function call entries in all stacks, starting at the
250 * current stack address. If the stacks consist of nested
251 * exceptions
252 */
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200253 tinfo = task_thread_info(task);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200254 for (;;) {
255 char *id;
Andi Kleen0a658002005-04-16 15:25:17 -0700256 unsigned long *estack_end;
257 estack_end = in_exception_stack(cpu, (unsigned long)stack,
258 &used, &id);
259
260 if (estack_end) {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200261 if (ops->stack(data, id) < 0)
262 break;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100263
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100264 bp = print_context_stack(tinfo, stack, bp, ops,
265 data, estack_end);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200266 ops->stack(data, "<EOE>");
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700267 /*
268 * We link to the next stack via the
269 * second-to-last pointer (index -2 to end) in the
270 * exception stack:
271 */
Andi Kleen0a658002005-04-16 15:25:17 -0700272 stack = (unsigned long *) estack_end[-2];
273 continue;
274 }
275 if (irqstack_end) {
276 unsigned long *irqstack;
277 irqstack = irqstack_end -
278 (IRQSTACKSIZE - 64) / sizeof(*irqstack);
279
280 if (stack >= irqstack && stack < irqstack_end) {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200281 if (ops->stack(data, "IRQ") < 0)
282 break;
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100283 bp = print_context_stack(tinfo, stack, bp,
284 ops, data, irqstack_end);
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700285 /*
286 * We link to the next stack (which would be
287 * the process stack normally) the last
288 * pointer (index -1 to end) in the IRQ stack:
289 */
Andi Kleen0a658002005-04-16 15:25:17 -0700290 stack = (unsigned long *) (irqstack_end[-1]);
291 irqstack_end = NULL;
Andi Kleenc0b766f2006-09-26 10:52:34 +0200292 ops->stack(data, "EOI");
Andi Kleen0a658002005-04-16 15:25:17 -0700293 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295 }
Andi Kleen0a658002005-04-16 15:25:17 -0700296 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
Andi Kleen0a658002005-04-16 15:25:17 -0700298
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700299 /*
Andi Kleenc0b766f2006-09-26 10:52:34 +0200300 * This handles the process stack:
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700301 */
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100302 bp = print_context_stack(tinfo, stack, bp, ops, data, NULL);
Andrew Mortonda689332006-12-07 02:14:02 +0100303 put_cpu();
Andi Kleenc0b766f2006-09-26 10:52:34 +0200304}
305EXPORT_SYMBOL(dump_trace);
Ingo Molnar3ac94932006-07-03 00:24:36 -0700306
Andi Kleenc0b766f2006-09-26 10:52:34 +0200307static void
308print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
309{
310 print_symbol(msg, symbol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 printk("\n");
312}
313
Andi Kleenc0b766f2006-09-26 10:52:34 +0200314static void print_trace_warning(void *data, char *msg)
315{
316 printk("%s\n", msg);
317}
318
319static int print_trace_stack(void *data, char *name)
320{
321 printk(" <%s> ", name);
322 return 0;
323}
324
Arjan van de Venbc850d62008-01-30 13:33:07 +0100325static void print_trace_address(void *data, unsigned long addr, int reliable)
Andi Kleenc0b766f2006-09-26 10:52:34 +0200326{
Konrad Rzeszutek1c978b92007-07-17 04:03:56 -0700327 touch_nmi_watchdog();
Arjan van de Venbc850d62008-01-30 13:33:07 +0100328 printk_address(addr, reliable);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200329}
330
Jan Beulich9689ba82007-10-17 18:04:37 +0200331static const struct stacktrace_ops print_trace_ops = {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200332 .warning = print_trace_warning,
333 .warning_symbol = print_trace_warning_symbol,
334 .stack = print_trace_stack,
335 .address = print_trace_address,
336};
337
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200338static void
339show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
340 unsigned long *stack, unsigned long bp, char *log_lvl)
Andi Kleenc0b766f2006-09-26 10:52:34 +0200341{
Alexey Dobriyanc9c3ddd2008-08-01 03:51:38 +0400342 printk("Call Trace:\n");
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200343 dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200344}
345
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200346void show_trace(struct task_struct *task, struct pt_regs *regs,
347 unsigned long *stack, unsigned long bp)
348{
349 show_trace_log_lvl(task, regs, stack, bp, "");
350}
351
Andi Kleenc0b766f2006-09-26 10:52:34 +0200352static void
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200353show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
354 unsigned long *sp, unsigned long bp, char *log_lvl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 unsigned long *stack;
357 int i;
Andi Kleen151f8cc2006-09-26 10:52:37 +0200358 const int cpu = smp_processor_id();
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100359 unsigned long *irqstack_end = (unsigned long *) (cpu_pda(cpu)->irqstackptr);
360 unsigned long *irqstack = (unsigned long *) (cpu_pda(cpu)->irqstackptr - IRQSTACKSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 // debugging aid: "show_stack(NULL, NULL);" prints the
363 // back trace for this cpu.
364
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100365 if (sp == NULL) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200366 if (task)
367 sp = (unsigned long *)task->thread.sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 else
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100369 sp = (unsigned long *)&sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
371
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100372 stack = sp;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200373 for (i = 0; i < kstack_depth_to_print; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 if (stack >= irqstack && stack <= irqstack_end) {
375 if (stack == irqstack_end) {
376 stack = (unsigned long *) (irqstack_end[-1]);
377 printk(" <EOI> ");
378 }
379 } else {
380 if (((long) stack & (THREAD_SIZE-1)) == 0)
381 break;
382 }
383 if (i && ((i % 4) == 0))
Ingo Molnar3ac94932006-07-03 00:24:36 -0700384 printk("\n");
385 printk(" %016lx", *stack++);
akpm@osdl.org35faa712005-04-16 15:24:54 -0700386 touch_nmi_watchdog();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
Alexey Dobriyanc9c3ddd2008-08-01 03:51:38 +0400388 printk("\n");
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200389 show_trace_log_lvl(task, regs, sp, bp, log_lvl);
Jan Beulichb538ed22006-06-26 13:57:32 +0200390}
391
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200392void show_stack(struct task_struct *task, unsigned long *sp)
Jan Beulichb538ed22006-06-26 13:57:32 +0200393{
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200394 show_stack_log_lvl(task, NULL, sp, 0, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
396
397/*
398 * The architecture-independent dump_stack generator
399 */
400void dump_stack(void)
401{
Arjan van de Venbc850d62008-01-30 13:33:07 +0100402 unsigned long bp = 0;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200403 unsigned long stack;
Arjan van de Ven57c351d2007-11-26 20:42:19 +0100404
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100405#ifdef CONFIG_FRAME_POINTER
406 if (!bp)
407 asm("movq %%rbp, %0" : "=r" (bp):);
408#endif
409
Arjan van de Ven57c351d2007-11-26 20:42:19 +0100410 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
411 current->pid, current->comm, print_tainted(),
412 init_utsname()->release,
413 (int)strcspn(init_utsname()->version, " "),
414 init_utsname()->version);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200415 show_trace(NULL, NULL, &stack, bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
418EXPORT_SYMBOL(dump_stack);
419
420void show_registers(struct pt_regs *regs)
421{
422 int i;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100423 unsigned long sp;
Andi Kleen151f8cc2006-09-26 10:52:37 +0200424 const int cpu = smp_processor_id();
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100425 struct task_struct *cur = cpu_pda(cpu)->pcurrent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100427 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 printk("CPU %d ", cpu);
429 __show_regs(regs);
430 printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
Al Viroe4f17c42006-01-12 01:05:38 -0800431 cur->comm, cur->pid, task_thread_info(cur), cur);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 /*
434 * When in-kernel, we also print out the stack and code at the
435 * time of the fault..
436 */
Arjan van de Vena25bd942008-01-30 13:33:08 +0100437 if (!user_mode(regs)) {
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200438 unsigned int code_prologue = code_bytes * 43 / 64;
439 unsigned int code_len = code_bytes;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100440 unsigned char c;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200441 u8 *ip;
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 printk("Stack: ");
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200444 show_stack_log_lvl(NULL, regs, (unsigned long *)sp,
445 regs->bp, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Arjan van de Vena25bd942008-01-30 13:33:08 +0100447 printk(KERN_EMERG "Code: ");
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200448
449 ip = (u8 *)regs->ip - code_prologue;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100450 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
451 /* try starting at RIP */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200452 ip = (u8 *)regs->ip;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100453 code_len = code_len - code_prologue + 1;
454 }
455 for (i = 0; i < code_len; i++, ip++) {
456 if (ip < (u8 *)PAGE_OFFSET ||
457 probe_kernel_address(ip, c)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 printk(" Bad RIP value.");
459 break;
460 }
Arjan van de Vena25bd942008-01-30 13:33:08 +0100461 if (ip == (u8 *)regs->ip)
462 printk("<%02x> ", c);
463 else
464 printk("%02x ", c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
466 }
467 printk("\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200468}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100470int is_valid_bugaddr(unsigned long ip)
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800471{
472 unsigned short ud2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100474 if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2)))
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800475 return 0;
476
477 return ud2 == 0x0b0f;
478}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Andi Kleen39743c92007-10-19 20:35:03 +0200480static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481static int die_owner = -1;
Corey Minyardcdc60a42006-05-08 15:17:22 +0200482static unsigned int die_nest_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100484unsigned __kprobes long oops_begin(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Andrew Mortonb39b7032007-06-08 13:47:01 -0700486 int cpu;
Jan Beulich12091402005-09-12 18:49:24 +0200487 unsigned long flags;
488
Andrew Mortonabf0f102006-09-26 10:52:36 +0200489 oops_enter();
490
Jan Beulich12091402005-09-12 18:49:24 +0200491 /* racy, but better than risking deadlock. */
Andi Kleen39743c92007-10-19 20:35:03 +0200492 raw_local_irq_save(flags);
Andrew Mortonb39b7032007-06-08 13:47:01 -0700493 cpu = smp_processor_id();
Andi Kleen39743c92007-10-19 20:35:03 +0200494 if (!__raw_spin_trylock(&die_lock)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (cpu == die_owner)
496 /* nested oops. should stop eventually */;
497 else
Andi Kleen39743c92007-10-19 20:35:03 +0200498 __raw_spin_lock(&die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
Corey Minyardcdc60a42006-05-08 15:17:22 +0200500 die_nest_count++;
Jan Beulich12091402005-09-12 18:49:24 +0200501 die_owner = cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 console_verbose();
Jan Beulich12091402005-09-12 18:49:24 +0200503 bust_spinlocks(1);
504 return flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
Jan Beulich22f59912008-01-30 13:31:23 +0100507void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
Alexander van Heukelum78cbac62008-07-10 21:14:52 +0200508{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 die_owner = -1;
Jan Beulich12091402005-09-12 18:49:24 +0200510 bust_spinlocks(0);
Corey Minyardcdc60a42006-05-08 15:17:22 +0200511 die_nest_count--;
Andi Kleen39743c92007-10-19 20:35:03 +0200512 if (!die_nest_count)
Corey Minyardcdc60a42006-05-08 15:17:22 +0200513 /* Nest count reaches zero, release the lock. */
Andi Kleen39743c92007-10-19 20:35:03 +0200514 __raw_spin_unlock(&die_lock);
515 raw_local_irq_restore(flags);
Jan Beulich22f59912008-01-30 13:31:23 +0100516 if (!regs) {
517 oops_exit();
518 return;
519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (panic_on_oops)
Horms012c4372006-08-13 23:24:22 -0700521 panic("Fatal exception");
Andrew Mortonabf0f102006-09-26 10:52:36 +0200522 oops_exit();
Jan Beulich22f59912008-01-30 13:31:23 +0100523 do_exit(signr);
Jan Beulich12091402005-09-12 18:49:24 +0200524}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Alexander van Heukelume423f492008-07-02 01:31:03 +0200526int __kprobes __die(const char *str, struct pt_regs *regs, long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Alexander van Heukelume423f492008-07-02 01:31:03 +0200528 printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#ifdef CONFIG_PREEMPT
530 printk("PREEMPT ");
531#endif
532#ifdef CONFIG_SMP
533 printk("SMP ");
534#endif
535#ifdef CONFIG_DEBUG_PAGEALLOC
536 printk("DEBUG_PAGEALLOC");
537#endif
538 printk("\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200539 if (notify_die(DIE_OOPS, str, regs, err,
540 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
Jan Beulich22f59912008-01-30 13:31:23 +0100541 return 1;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 show_registers(regs);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700544 add_taint(TAINT_DIE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 /* Executive summary in case the oops scrolled away */
546 printk(KERN_ALERT "RIP ");
Arjan van de Venaafbd7e2008-01-30 13:33:08 +0100547 printk_address(regs->ip, 1);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100548 printk(" RSP <%016lx>\n", regs->sp);
Vivek Goyal8bcc5282006-04-18 12:35:13 +0200549 if (kexec_should_crash(current))
550 crash_kexec(regs);
Jan Beulich22f59912008-01-30 13:31:23 +0100551 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552}
553
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200554void die(const char *str, struct pt_regs *regs, long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Jan Beulich12091402005-09-12 18:49:24 +0200556 unsigned long flags = oops_begin();
557
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800558 if (!user_mode(regs))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100559 report_bug(regs->ip, regs);
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800560
Jan Beulich22f59912008-01-30 13:31:23 +0100561 if (__die(str, regs, err))
562 regs = NULL;
563 oops_end(flags, regs, SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200566notrace __kprobes void
567die_nmi(char *str, struct pt_regs *regs, int do_panic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Jason Wessel737a4602008-03-07 16:34:16 -0600569 unsigned long flags;
Jan Beulich12091402005-09-12 18:49:24 +0200570
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200571 if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP)
Jason Wessel737a4602008-03-07 16:34:16 -0600572 return;
573
574 flags = oops_begin();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 /*
576 * We are in trouble anyway, lets at least try
577 * to get a message out.
578 */
Cyrill Gorcunove56b3a12008-05-24 19:36:32 +0400579 printk(KERN_EMERG "%s", str);
580 printk(" on CPU%d, ip %08lx, registers:\n",
581 smp_processor_id(), regs->ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 show_registers(regs);
Vivek Goyal8bcc5282006-04-18 12:35:13 +0200583 if (kexec_should_crash(current))
584 crash_kexec(regs);
Andi Kleenfac58552006-09-26 10:52:27 +0200585 if (do_panic || panic_on_oops)
586 panic("Non maskable interrupt");
Jan Beulich22f59912008-01-30 13:31:23 +0100587 oops_end(flags, NULL, SIGBUS);
Corey Minyard8b1ffe952006-05-08 15:17:25 +0200588 nmi_exit();
589 local_irq_enable();
Jan Beulich22f59912008-01-30 13:31:23 +0100590 do_exit(SIGBUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200593static void __kprobes
594do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
595 long error_code, siginfo_t *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Jan Beulich6e3f3612006-01-11 22:42:14 +0100597 struct task_struct *tsk = current;
598
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200599 if (!user_mode(regs))
600 goto kernel_trap;
Andi Kleend1895182007-05-02 19:27:05 +0200601
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200602 /*
603 * We want error_code and trap_no set for userspace faults and
604 * kernelspace faults which result in die(), but not
605 * kernelspace faults which are fixed up. die() gives the
606 * process no chance to handle the signal and notice the
607 * kernel fault information, so that won't result in polluting
608 * the information about previously queued, but not yet
609 * delivered, faults. See also do_general_protection below.
610 */
611 tsk->thread.error_code = error_code;
612 tsk->thread.trap_no = trapnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200614 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
615 printk_ratelimit()) {
616 printk(KERN_INFO
617 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
618 tsk->comm, tsk->pid, str,
619 regs->ip, regs->sp, error_code);
620 print_vma_addr(" in ", regs->ip);
621 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
623
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200624 if (info)
625 force_sig_info(signr, info, tsk);
626 else
627 force_sig(signr, tsk);
628 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200630kernel_trap:
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100631 if (!fixup_exception(regs)) {
632 tsk->thread.error_code = error_code;
633 tsk->thread.trap_no = trapnr;
634 die(str, regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100636 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637}
638
639#define DO_ERROR(trapnr, signr, str, name) \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200640asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
641{ \
642 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
643 == NOTIFY_STOP) \
644 return; \
Andi Kleen40e59a62006-05-15 18:19:47 +0200645 conditional_sti(regs); \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200646 do_trap(trapnr, signr, str, regs, error_code, NULL); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200649#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
650asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
651{ \
652 siginfo_t info; \
653 info.si_signo = signr; \
654 info.si_errno = 0; \
655 info.si_code = sicode; \
656 info.si_addr = (void __user *)siaddr; \
657 trace_hardirqs_fixup(); \
658 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
659 == NOTIFY_STOP) \
660 return; \
Andi Kleen40e59a62006-05-15 18:19:47 +0200661 conditional_sti(regs); \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200662 do_trap(trapnr, signr, str, regs, error_code, &info); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200665DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
666DO_ERROR(4, SIGSEGV, "overflow", overflow)
667DO_ERROR(5, SIGSEGV, "bounds", bounds)
668DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
669DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200671DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
Andi Kleen40e59a62006-05-15 18:19:47 +0200673
674/* Runs on IST stack */
675asmlinkage void do_stack_segment(struct pt_regs *regs, long error_code)
676{
677 if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
678 12, SIGBUS) == NOTIFY_STOP)
679 return;
680 preempt_conditional_sti(regs);
681 do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL);
682 preempt_conditional_cli(regs);
683}
Jan Beulicheca37c12006-01-11 22:42:17 +0100684
685asmlinkage void do_double_fault(struct pt_regs * regs, long error_code)
686{
687 static const char str[] = "double fault";
688 struct task_struct *tsk = current;
689
690 /* Return not checked because double check cannot be ignored */
691 notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV);
692
693 tsk->thread.error_code = error_code;
694 tsk->thread.trap_no = 8;
695
696 /* This is always a kernel trap and never fixable (and thus must
697 never return). */
698 for (;;)
699 die(str, regs, error_code);
700}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200702asmlinkage void __kprobes
703do_general_protection(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200705 struct task_struct *tsk;
Jan Beulich6e3f3612006-01-11 22:42:14 +0100706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 conditional_sti(regs);
708
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200709 tsk = current;
710 if (!user_mode(regs))
711 goto gp_in_kernel;
Andi Kleend1895182007-05-02 19:27:05 +0200712
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200713 tsk->thread.error_code = error_code;
714 tsk->thread.trap_no = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200716 if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
717 printk_ratelimit()) {
718 printk(KERN_INFO
719 "%s[%d] general protection ip:%lx sp:%lx error:%lx",
720 tsk->comm, tsk->pid,
721 regs->ip, regs->sp, error_code);
722 print_vma_addr(" in ", regs->ip);
723 printk("\n");
724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200726 force_sig(SIGSEGV, tsk);
727 return;
728
729gp_in_kernel:
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100730 if (fixup_exception(regs))
731 return;
Andi Kleend1895182007-05-02 19:27:05 +0200732
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100733 tsk->thread.error_code = error_code;
734 tsk->thread.trap_no = 13;
735 if (notify_die(DIE_GPF, "general protection fault", regs,
736 error_code, 13, SIGSEGV) == NOTIFY_STOP)
737 return;
738 die("general protection fault", regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
740
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200741static notrace __kprobes void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200742mem_parity_error(unsigned char reason, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
Don Zickusc41c5cd2006-09-26 10:52:27 +0200744 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
745 reason);
Andi Kleen9c5f8be2006-12-07 02:14:03 +0100746 printk(KERN_EMERG "You have some hardware problem, likely on the PCI bus.\n");
Don Zickusc41c5cd2006-09-26 10:52:27 +0200747
Dave Jiangc0d12172007-07-19 01:49:46 -0700748#if defined(CONFIG_EDAC)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200749 if (edac_handler_set()) {
Dave Jiangc0d12172007-07-19 01:49:46 -0700750 edac_atomic_assert_error();
751 return;
752 }
753#endif
754
Don Zickus8da5add2006-09-26 10:52:27 +0200755 if (panic_on_unrecovered_nmi)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200756 panic("NMI: Not continuing");
757
758 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760 /* Clear and disable the memory parity error line. */
761 reason = (reason & 0xf) | 4;
762 outb(reason, 0x61);
763}
764
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200765static notrace __kprobes void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200766io_check_error(unsigned char reason, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
768 printk("NMI: IOCK error (debug interrupt?)\n");
769 show_registers(regs);
770
771 /* Re-enable the IOCK line, wait for a few seconds */
772 reason = (reason & 0xf) | 8;
773 outb(reason, 0x61);
774 mdelay(2000);
775 reason &= ~8;
776 outb(reason, 0x61);
777}
778
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200779static notrace __kprobes void
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100780unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200781{
Jason Wesseld3597522008-02-15 14:55:53 -0600782 if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
783 return;
Don Zickusc41c5cd2006-09-26 10:52:27 +0200784 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
785 reason);
786 printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n");
Don Zickus8da5add2006-09-26 10:52:27 +0200787
788 if (panic_on_unrecovered_nmi)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200789 panic("NMI: Not continuing");
Don Zickus8da5add2006-09-26 10:52:27 +0200790
Don Zickusc41c5cd2006-09-26 10:52:27 +0200791 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700794/* Runs on IST stack. This code must keep interrupts off all the time.
795 Nested NMIs are prevented by the CPU. */
Alexander van Heukelumabd34802008-07-02 18:39:01 +0200796asmlinkage notrace __kprobes void default_do_nmi(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
798 unsigned char reason = 0;
Ashok Raj76e4f662005-06-25 14:55:00 -0700799 int cpu;
800
801 cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200803 /* Only the BSP gets external NMIs from the system. */
Ashok Raj76e4f662005-06-25 14:55:00 -0700804 if (!cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 reason = get_nmi_reason();
806
807 if (!(reason & 0xc0)) {
Jan Beulich6e3f3612006-01-11 22:42:14 +0100808 if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 == NOTIFY_STOP)
810 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 /*
812 * Ok, so this is none of the documented NMI sources,
813 * so it must be the NMI watchdog.
814 */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200815 if (nmi_watchdog_tick(regs, reason))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 return;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200817 if (!do_nmi_callback(regs, cpu))
Don Zickus3adbbcce2006-09-26 10:52:26 +0200818 unknown_nmi_error(reason, regs);
819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 return;
821 }
Jan Beulich6e3f3612006-01-11 22:42:14 +0100822 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200823 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 /* AK: following checks seem to be broken on modern chipsets. FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 if (reason & 0x80)
827 mem_parity_error(reason, regs);
828 if (reason & 0x40)
829 io_check_error(reason, regs);
830}
831
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400832asmlinkage notrace __kprobes void
833do_nmi(struct pt_regs *regs, long error_code)
834{
835 nmi_enter();
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200836
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400837 add_pda(__nmi_count, 1);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200838
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400839 if (!ignore_nmis)
840 default_do_nmi(regs);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200841
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400842 nmi_exit();
843}
844
845void stop_nmi(void)
846{
847 acpi_nmi_disable();
848 ignore_nmis++;
849}
850
851void restart_nmi(void)
852{
853 ignore_nmis--;
854 acpi_nmi_enable();
855}
856
Jan Beulichb556b352006-01-11 22:43:00 +0100857/* runs on IST stack. */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200858asmlinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Peter Zijlstra143a5d32007-10-25 14:01:10 +0200860 trace_hardirqs_fixup();
861
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200862 if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
863 == NOTIFY_STOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 return;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200865
Andi Kleen40e59a62006-05-15 18:19:47 +0200866 preempt_conditional_sti(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
Andi Kleen40e59a62006-05-15 18:19:47 +0200868 preempt_conditional_cli(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869}
870
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700871/* Help handler running on IST stack to switch back to user stack
872 for scheduling or signal handling. The actual stack switch is done in
873 entry.S */
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100874asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700876 struct pt_regs *regs = eregs;
877 /* Did already sync */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100878 if (eregs == (struct pt_regs *)eregs->sp)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700879 ;
880 /* Exception from user space */
Vincent Hanquez76381fe2005-06-23 00:08:46 -0700881 else if (user_mode(eregs))
Al Virobb049232006-01-12 01:05:38 -0800882 regs = task_pt_regs(current);
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700883 /* Exception from kernel and interrupts are enabled. Move to
884 kernel process stack. */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100885 else if (eregs->flags & X86_EFLAGS_IF)
886 regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs));
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700887 if (eregs != regs)
888 *regs = *eregs;
889 return regs;
890}
891
892/* runs on IST stack. */
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -0700893asmlinkage void __kprobes do_debug(struct pt_regs * regs,
894 unsigned long error_code)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700895{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 struct task_struct *tsk = current;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200897 unsigned long condition;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 siginfo_t info;
899
Peter Zijlstra000f4a92007-11-26 20:42:19 +0100900 trace_hardirqs_fixup();
901
Vincent Hanqueze9129e52005-06-23 00:08:46 -0700902 get_debugreg(condition, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Roland McGrath10faa812008-01-30 13:30:54 +0100904 /*
905 * The processor cleared BTF, so don't mark that we need it set.
906 */
907 clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
908 tsk->thread.debugctlmsr = 0;
909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
Andi Kleendaeeafe2005-04-16 15:25:13 -0700911 SIGTRAP) == NOTIFY_STOP)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700912 return;
Andi Kleendaeeafe2005-04-16 15:25:13 -0700913
John Blackwooda65d17c2006-02-12 14:34:58 -0800914 preempt_conditional_sti(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* Mask out spurious debug traps due to lazy DR7 setting */
917 if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200918 if (!tsk->thread.debugreg7)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 goto clear_dr7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921
922 tsk->thread.debugreg6 = condition;
923
Roland McGrathe1f28772008-01-30 13:30:50 +0100924 /*
925 * Single-stepping through TF: make sure we ignore any events in
926 * kernel space (but re-enable TF when returning to user mode).
927 */
Andi Kleendaeeafe2005-04-16 15:25:13 -0700928 if (condition & DR_STEP) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200929 if (!user_mode(regs))
930 goto clear_TF_reenable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
932
933 /* Ok, finally something we can handle */
934 tsk->thread.trap_no = 1;
935 tsk->thread.error_code = error_code;
936 info.si_signo = SIGTRAP;
937 info.si_errno = 0;
938 info.si_code = TRAP_BRKPT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100939 info.si_addr = user_mode(regs) ? (void __user *)regs->ip : NULL;
John Blackwood01b8faa2006-01-11 22:44:15 +0100940 force_sig_info(SIGTRAP, &info, tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942clear_dr7:
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200943 set_debugreg(0, 7);
John Blackwooda65d17c2006-02-12 14:34:58 -0800944 preempt_conditional_cli(regs);
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700945 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947clear_TF_reenable:
948 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
Glauber de Oliveira Costa053de042008-01-30 13:31:27 +0100949 regs->flags &= ~X86_EFLAGS_TF;
John Blackwooda65d17c2006-02-12 14:34:58 -0800950 preempt_conditional_cli(regs);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200951 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
Jan Beulich6e3f3612006-01-11 22:42:14 +0100954static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100956 if (fixup_exception(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 return 1;
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100958
Jan Beulich6e3f3612006-01-11 22:42:14 +0100959 notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
Andi Kleen3a848f62005-04-16 15:25:06 -0700960 /* Illegal floating point operation in the kernel */
Jan Beulich6e3f3612006-01-11 22:42:14 +0100961 current->thread.trap_no = trapnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 die(str, regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return 0;
964}
965
966/*
967 * Note that we play around with the 'TS' bit in an attempt to get
968 * the correct behaviour even in the presence of the asynchronous
969 * IRQ13 behaviour
970 */
971asmlinkage void do_coprocessor_error(struct pt_regs *regs)
972{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100973 void __user *ip = (void __user *)(regs->ip);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200974 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 siginfo_t info;
976 unsigned short cwd, swd;
977
978 conditional_sti(regs);
Vincent Hanquez76381fe2005-06-23 00:08:46 -0700979 if (!user_mode(regs) &&
Jan Beulich6e3f3612006-01-11 22:42:14 +0100980 kernel_math_error(regs, "kernel x87 math error", 16))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 return;
982
983 /*
984 * Save the info for the exception handler and clear the error.
985 */
986 task = current;
987 save_init_fpu(task);
988 task->thread.trap_no = 16;
989 task->thread.error_code = 0;
990 info.si_signo = SIGFPE;
991 info.si_errno = 0;
992 info.si_code = __SI_FAULT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100993 info.si_addr = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 /*
995 * (~cwd & swd) will mask out exceptions that are not set to unmasked
996 * status. 0x3f is the exception bits in these regs, 0x200 is the
997 * C1 reg you need in case of a stack fault, 0x040 is the stack
998 * fault bit. We should only be taking one exception at a time,
999 * so if this combination doesn't produce any single exception,
1000 * then we have a bad program that isn't synchronizing its FPU usage
1001 * and it will suffer the consequences since we won't be able to
1002 * fully reproduce the context of the exception
1003 */
1004 cwd = get_fpu_cwd(task);
1005 swd = get_fpu_swd(task);
Chuck Ebbertff347b22005-09-12 18:49:25 +02001006 switch (swd & ~cwd & 0x3f) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001007 case 0x000: /* No unmasked exception */
1008 default: /* Multiple exceptions */
1009 break;
1010 case 0x001: /* Invalid Op */
1011 /*
1012 * swd & 0x240 == 0x040: Stack Underflow
1013 * swd & 0x240 == 0x240: Stack Overflow
1014 * User must clear the SF bit (0x40) if set
1015 */
1016 info.si_code = FPE_FLTINV;
1017 break;
1018 case 0x002: /* Denormalize */
1019 case 0x010: /* Underflow */
1020 info.si_code = FPE_FLTUND;
1021 break;
1022 case 0x004: /* Zero Divide */
1023 info.si_code = FPE_FLTDIV;
1024 break;
1025 case 0x008: /* Overflow */
1026 info.si_code = FPE_FLTOVF;
1027 break;
1028 case 0x020: /* Precision */
1029 info.si_code = FPE_FLTRES;
1030 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 }
1032 force_sig_info(SIGFPE, &info, task);
1033}
1034
1035asmlinkage void bad_intr(void)
1036{
1037 printk("bad interrupt");
1038}
1039
1040asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs)
1041{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001042 void __user *ip = (void __user *)(regs->ip);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001043 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 siginfo_t info;
1045 unsigned short mxcsr;
1046
1047 conditional_sti(regs);
Vincent Hanquez76381fe2005-06-23 00:08:46 -07001048 if (!user_mode(regs) &&
Jan Beulich6e3f3612006-01-11 22:42:14 +01001049 kernel_math_error(regs, "kernel simd math error", 19))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 return;
1051
1052 /*
1053 * Save the info for the exception handler and clear the error.
1054 */
1055 task = current;
1056 save_init_fpu(task);
1057 task->thread.trap_no = 19;
1058 task->thread.error_code = 0;
1059 info.si_signo = SIGFPE;
1060 info.si_errno = 0;
1061 info.si_code = __SI_FAULT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001062 info.si_addr = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 /*
1064 * The SIMD FPU exceptions are handled a little differently, as there
1065 * is only a single status/control register. Thus, to determine which
1066 * unmasked exception was caught we must mask the exception mask bits
1067 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
1068 */
1069 mxcsr = get_fpu_mxcsr(task);
1070 switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001071 case 0x000:
1072 default:
1073 break;
1074 case 0x001: /* Invalid Op */
1075 info.si_code = FPE_FLTINV;
1076 break;
1077 case 0x002: /* Denormalize */
1078 case 0x010: /* Underflow */
1079 info.si_code = FPE_FLTUND;
1080 break;
1081 case 0x004: /* Zero Divide */
1082 info.si_code = FPE_FLTDIV;
1083 break;
1084 case 0x008: /* Overflow */
1085 info.si_code = FPE_FLTOVF;
1086 break;
1087 case 0x020: /* Precision */
1088 info.si_code = FPE_FLTRES;
1089 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091 force_sig_info(SIGFPE, &info, task);
1092}
1093
1094asmlinkage void do_spurious_interrupt_bug(struct pt_regs * regs)
1095{
1096}
1097
1098asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void)
1099{
1100}
1101
Jacob Shin89b831e2005-11-05 17:25:53 +01001102asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void)
1103{
1104}
1105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106/*
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001107 * 'math_state_restore()' saves the current math information in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 * old math state array, and gets the new ones from the current task
1109 *
1110 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
1111 * Don't touch unless you *really* know how it works.
1112 */
1113asmlinkage void math_state_restore(void)
1114{
1115 struct task_struct *me = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Suresh Siddhaaa283f42008-03-10 15:28:05 -07001117 if (!used_math()) {
1118 local_irq_enable();
1119 /*
1120 * does a slab alloc which can sleep
1121 */
1122 if (init_fpu(me)) {
1123 /*
1124 * ran out of memory!
1125 */
1126 do_group_exit(SIGKILL);
1127 return;
1128 }
1129 local_irq_disable();
1130 }
1131
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001132 clts(); /* Allow maths ops (or we recurse) */
Suresh Siddha61c46282008-03-10 15:28:04 -07001133 restore_fpu_checking(&me->thread.xstate->fxsave);
Al Viroe4f17c42006-01-12 01:05:38 -08001134 task_thread_info(me)->status |= TS_USEDFPU;
Arjan van de Vene07e23e2006-09-26 10:52:36 +02001135 me->fpu_counter++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136}
Glauber de Oliveira Costa21db5582008-01-30 13:31:10 +01001137EXPORT_SYMBOL_GPL(math_state_restore);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139void __init trap_init(void)
1140{
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001141 set_intr_gate(0, &divide_error);
1142 set_intr_gate_ist(1, &debug, DEBUG_STACK);
1143 set_intr_gate_ist(2, &nmi, NMI_STACK);
1144 set_system_gate_ist(3, &int3, DEBUG_STACK); /* int3 can be called from all */
1145 set_system_gate(4, &overflow); /* int4 can be called from all */
1146 set_intr_gate(5, &bounds);
1147 set_intr_gate(6, &invalid_op);
1148 set_intr_gate(7, &device_not_available);
1149 set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK);
1150 set_intr_gate(9, &coprocessor_segment_overrun);
1151 set_intr_gate(10, &invalid_TSS);
1152 set_intr_gate(11, &segment_not_present);
1153 set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK);
1154 set_intr_gate(13, &general_protection);
1155 set_intr_gate(14, &page_fault);
1156 set_intr_gate(15, &spurious_interrupt_bug);
1157 set_intr_gate(16, &coprocessor_error);
1158 set_intr_gate(17, &alignment_check);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159#ifdef CONFIG_X86_MCE
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001160 set_intr_gate_ist(18, &machine_check, MCE_STACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161#endif
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001162 set_intr_gate(19, &simd_coprocessor_error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164#ifdef CONFIG_IA32_EMULATION
1165 set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
1166#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 /*
Suresh Siddha61c46282008-03-10 15:28:04 -07001168 * initialize the per thread extended state:
1169 */
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +02001170 init_thread_xstate();
Suresh Siddha61c46282008-03-10 15:28:04 -07001171 /*
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001172 * Should be a barrier for any external CPU state:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 */
1174 cpu_init();
1175}
1176
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001177static int __init oops_setup(char *s)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001178{
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001179 if (!s)
1180 return -EINVAL;
1181 if (!strcmp(s, "panic"))
1182 panic_on_oops = 1;
1183 return 0;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001184}
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001185early_param("oops", oops_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187static int __init kstack_setup(char *s)
1188{
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001189 if (!s)
1190 return -EINVAL;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001191 kstack_depth_to_print = simple_strtoul(s, NULL, 0);
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001192 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001194early_param("kstack", kstack_setup);
Arjan van de Vena25bd942008-01-30 13:33:08 +01001195
Arjan van de Vena25bd942008-01-30 13:33:08 +01001196static int __init code_bytes_setup(char *s)
1197{
1198 code_bytes = simple_strtoul(s, NULL, 0);
1199 if (code_bytes > 8192)
1200 code_bytes = 8192;
1201
1202 return 1;
1203}
1204__setup("code_bytes=", code_bytes_setup);