blob: babdbe673b7f6e26d7df186fe6ae9a2caa9f6c7d [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>
54
55#include <mach_traps.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057asmlinkage void divide_error(void);
58asmlinkage void debug(void);
59asmlinkage void nmi(void);
60asmlinkage void int3(void);
61asmlinkage void overflow(void);
62asmlinkage void bounds(void);
63asmlinkage void invalid_op(void);
64asmlinkage void device_not_available(void);
65asmlinkage void double_fault(void);
66asmlinkage void coprocessor_segment_overrun(void);
67asmlinkage void invalid_TSS(void);
68asmlinkage void segment_not_present(void);
69asmlinkage void stack_segment(void);
70asmlinkage void general_protection(void);
71asmlinkage void page_fault(void);
72asmlinkage void coprocessor_error(void);
73asmlinkage void simd_coprocessor_error(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074asmlinkage void alignment_check(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075asmlinkage void spurious_interrupt_bug(void);
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020076asmlinkage void machine_check(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +040078int panic_on_unrecovered_nmi;
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020079int kstack_depth_to_print = 12;
Arjan van de Vena25bd942008-01-30 13:33:08 +010080static unsigned int code_bytes = 64;
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020081static int ignore_nmis;
82static int die_counter;
Arjan van de Vena25bd942008-01-30 13:33:08 +010083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static inline void conditional_sti(struct pt_regs *regs)
85{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010086 if (regs->flags & X86_EFLAGS_IF)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 local_irq_enable();
88}
89
John Blackwooda65d17c2006-02-12 14:34:58 -080090static inline void preempt_conditional_sti(struct pt_regs *regs)
91{
Ingo Molnare8bff742008-02-13 20:21:06 +010092 inc_preempt_count();
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010093 if (regs->flags & X86_EFLAGS_IF)
John Blackwooda65d17c2006-02-12 14:34:58 -080094 local_irq_enable();
95}
96
97static inline void preempt_conditional_cli(struct pt_regs *regs)
98{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010099 if (regs->flags & X86_EFLAGS_IF)
John Blackwooda65d17c2006-02-12 14:34:58 -0800100 local_irq_disable();
Andi Kleen40e59a62006-05-15 18:19:47 +0200101 /* Make sure to not schedule here because we could be running
102 on an exception stack. */
Ingo Molnare8bff742008-02-13 20:21:06 +0100103 dec_preempt_count();
John Blackwooda65d17c2006-02-12 14:34:58 -0800104}
105
Arjan van de Venbc850d62008-01-30 13:33:07 +0100106void printk_address(unsigned long address, int reliable)
Ingo Molnar3ac94932006-07-03 00:24:36 -0700107{
Linus Torvalds7daf7052008-07-14 12:12:53 -0700108 printk(" [<%016lx>] %s%pS\n", address, reliable ? "": "? ", (void *) address);
Harvey Harrisona5ff6772008-01-30 13:33:25 +0100109}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Andi Kleen0a658002005-04-16 15:25:17 -0700111static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
Andi Kleenc0b766f2006-09-26 10:52:34 +0200112 unsigned *usedp, char **idp)
Andi Kleen0a658002005-04-16 15:25:17 -0700113{
Jan Beulichb556b352006-01-11 22:43:00 +0100114 static char ids[][8] = {
Andi Kleen0a658002005-04-16 15:25:17 -0700115 [DEBUG_STACK - 1] = "#DB",
116 [NMI_STACK - 1] = "NMI",
117 [DOUBLEFAULT_STACK - 1] = "#DF",
118 [STACKFAULT_STACK - 1] = "#SS",
119 [MCE_STACK - 1] = "#MC",
Jan Beulichb556b352006-01-11 22:43:00 +0100120#if DEBUG_STKSZ > EXCEPTION_STKSZ
121 [N_EXCEPTION_STACKS ... N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]"
122#endif
Andi Kleen0a658002005-04-16 15:25:17 -0700123 };
124 unsigned k;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700126 /*
127 * Iterate over all exception stacks, and figure out whether
128 * 'stack' is in one of them:
129 */
Andi Kleen0a658002005-04-16 15:25:17 -0700130 for (k = 0; k < N_EXCEPTION_STACKS; k++) {
Keith Owensf5741642006-09-26 10:52:38 +0200131 unsigned long end = per_cpu(orig_ist, cpu).ist[k];
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700132 /*
133 * Is 'stack' above this exception frame's end?
134 * If yes then skip to the next frame.
135 */
Andi Kleen0a658002005-04-16 15:25:17 -0700136 if (stack >= end)
137 continue;
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700138 /*
139 * Is 'stack' above this exception frame's start address?
140 * If yes then we found the right frame.
141 */
Andi Kleen0a658002005-04-16 15:25:17 -0700142 if (stack >= end - EXCEPTION_STKSZ) {
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700143 /*
144 * Make sure we only iterate through an exception
145 * stack once. If it comes up for the second time
146 * then there's something wrong going on - just
147 * break out and return NULL:
148 */
Andi Kleen0a658002005-04-16 15:25:17 -0700149 if (*usedp & (1U << k))
150 break;
151 *usedp |= 1U << k;
152 *idp = ids[k];
153 return (unsigned long *)end;
154 }
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700155 /*
156 * If this is a debug stack, and if it has a larger size than
157 * the usual exception stacks, then 'stack' might still
158 * be within the lower portion of the debug stack:
159 */
Jan Beulichb556b352006-01-11 22:43:00 +0100160#if DEBUG_STKSZ > EXCEPTION_STKSZ
161 if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
162 unsigned j = N_EXCEPTION_STACKS - 1;
163
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700164 /*
165 * Black magic. A large debug stack is composed of
166 * multiple exception stack entries, which we
167 * iterate through now. Dont look:
168 */
Jan Beulichb556b352006-01-11 22:43:00 +0100169 do {
170 ++j;
171 end -= EXCEPTION_STKSZ;
172 ids[j][4] = '1' + (j - N_EXCEPTION_STACKS);
173 } while (stack < end - EXCEPTION_STKSZ);
174 if (*usedp & (1U << j))
175 break;
176 *usedp |= 1U << j;
177 *idp = ids[j];
178 return (unsigned long *)end;
179 }
180#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
182 return NULL;
Andi Kleen0a658002005-04-16 15:25:17 -0700183}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185/*
Simon Arlott676b1852007-10-20 01:25:36 +0200186 * x86-64 can have up to three kernel stacks:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 * process stack
188 * interrupt stack
Andi Kleen0a658002005-04-16 15:25:17 -0700189 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 */
191
Arjan van de Vene4a94562008-01-30 13:33:07 +0100192static inline int valid_stack_ptr(struct thread_info *tinfo,
193 void *p, unsigned int size, void *end)
Andi Kleenc547c772006-11-28 20:12:59 +0100194{
Jan Engelhardtade1af72008-01-30 13:33:23 +0100195 void *t = tinfo;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100196 if (end) {
197 if (p < end && p >= (end-THREAD_SIZE))
198 return 1;
199 else
200 return 0;
201 }
202 return p > t && p < t + THREAD_SIZE - size;
203}
204
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100205/* The form of the top of the frame on the stack */
206struct stack_frame {
207 struct stack_frame *next_frame;
208 unsigned long return_address;
209};
210
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200211static inline unsigned long
212print_context_stack(struct thread_info *tinfo,
213 unsigned long *stack, unsigned long bp,
214 const struct stacktrace_ops *ops, void *data,
215 unsigned long *end)
Arjan van de Vene4a94562008-01-30 13:33:07 +0100216{
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100217 struct stack_frame *frame = (struct stack_frame *)bp;
218
219 while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
220 unsigned long addr;
221
222 addr = *stack;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100223 if (__kernel_text_address(addr)) {
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100224 if ((unsigned long) stack == bp + 8) {
225 ops->address(data, addr, 1);
226 frame = frame->next_frame;
227 bp = (unsigned long) frame;
228 } else {
229 ops->address(data, addr, bp == 0);
230 }
Arjan van de Vene4a94562008-01-30 13:33:07 +0100231 }
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100232 stack++;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100233 }
234 return bp;
Andi Kleenc547c772006-11-28 20:12:59 +0100235}
236
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200237void dump_trace(struct task_struct *task, struct pt_regs *regs,
Arjan van de Venbc850d62008-01-30 13:33:07 +0100238 unsigned long *stack, unsigned long bp,
Jan Beulich9689ba82007-10-17 18:04:37 +0200239 const struct stacktrace_ops *ops, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Andrew Mortonda689332006-12-07 02:14:02 +0100241 const unsigned cpu = get_cpu();
Andi Kleenb615ebd2006-12-07 02:14:00 +0100242 unsigned long *irqstack_end = (unsigned long*)cpu_pda(cpu)->irqstackptr;
Andi Kleen0a658002005-04-16 15:25:17 -0700243 unsigned used = 0;
Andi Kleenc547c772006-11-28 20:12:59 +0100244 struct thread_info *tinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200246 if (!task)
247 task = current;
Jan Beulichb538ed22006-06-26 13:57:32 +0200248
Andi Kleenc0b766f2006-09-26 10:52:34 +0200249 if (!stack) {
250 unsigned long dummy;
251 stack = &dummy;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200252 if (task && task != current)
253 stack = (unsigned long *)task->thread.sp;
Jan Beulichb538ed22006-06-26 13:57:32 +0200254 }
255
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100256#ifdef CONFIG_FRAME_POINTER
257 if (!bp) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200258 if (task == current) {
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100259 /* Grab bp right from our regs */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200260 asm("movq %%rbp, %0" : "=r" (bp) :);
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100261 } else {
262 /* bp is the last reg pushed by switch_to */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200263 bp = *(unsigned long *) task->thread.sp;
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100264 }
265 }
266#endif
267
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700268 /*
269 * Print function call entries in all stacks, starting at the
270 * current stack address. If the stacks consist of nested
271 * exceptions
272 */
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200273 tinfo = task_thread_info(task);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200274 for (;;) {
275 char *id;
Andi Kleen0a658002005-04-16 15:25:17 -0700276 unsigned long *estack_end;
277 estack_end = in_exception_stack(cpu, (unsigned long)stack,
278 &used, &id);
279
280 if (estack_end) {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200281 if (ops->stack(data, id) < 0)
282 break;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100283
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100284 bp = print_context_stack(tinfo, stack, bp, ops,
285 data, estack_end);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200286 ops->stack(data, "<EOE>");
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700287 /*
288 * We link to the next stack via the
289 * second-to-last pointer (index -2 to end) in the
290 * exception stack:
291 */
Andi Kleen0a658002005-04-16 15:25:17 -0700292 stack = (unsigned long *) estack_end[-2];
293 continue;
294 }
295 if (irqstack_end) {
296 unsigned long *irqstack;
297 irqstack = irqstack_end -
298 (IRQSTACKSIZE - 64) / sizeof(*irqstack);
299
300 if (stack >= irqstack && stack < irqstack_end) {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200301 if (ops->stack(data, "IRQ") < 0)
302 break;
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100303 bp = print_context_stack(tinfo, stack, bp,
304 ops, data, irqstack_end);
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700305 /*
306 * We link to the next stack (which would be
307 * the process stack normally) the last
308 * pointer (index -1 to end) in the IRQ stack:
309 */
Andi Kleen0a658002005-04-16 15:25:17 -0700310 stack = (unsigned long *) (irqstack_end[-1]);
311 irqstack_end = NULL;
Andi Kleenc0b766f2006-09-26 10:52:34 +0200312 ops->stack(data, "EOI");
Andi Kleen0a658002005-04-16 15:25:17 -0700313 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315 }
Andi Kleen0a658002005-04-16 15:25:17 -0700316 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 }
Andi Kleen0a658002005-04-16 15:25:17 -0700318
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700319 /*
Andi Kleenc0b766f2006-09-26 10:52:34 +0200320 * This handles the process stack:
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700321 */
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100322 bp = print_context_stack(tinfo, stack, bp, ops, data, NULL);
Andrew Mortonda689332006-12-07 02:14:02 +0100323 put_cpu();
Andi Kleenc0b766f2006-09-26 10:52:34 +0200324}
325EXPORT_SYMBOL(dump_trace);
Ingo Molnar3ac94932006-07-03 00:24:36 -0700326
Andi Kleenc0b766f2006-09-26 10:52:34 +0200327static void
328print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
329{
330 print_symbol(msg, symbol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 printk("\n");
332}
333
Andi Kleenc0b766f2006-09-26 10:52:34 +0200334static void print_trace_warning(void *data, char *msg)
335{
336 printk("%s\n", msg);
337}
338
339static int print_trace_stack(void *data, char *name)
340{
341 printk(" <%s> ", name);
342 return 0;
343}
344
Arjan van de Venbc850d62008-01-30 13:33:07 +0100345static void print_trace_address(void *data, unsigned long addr, int reliable)
Andi Kleenc0b766f2006-09-26 10:52:34 +0200346{
Konrad Rzeszutek1c978b92007-07-17 04:03:56 -0700347 touch_nmi_watchdog();
Arjan van de Venbc850d62008-01-30 13:33:07 +0100348 printk_address(addr, reliable);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200349}
350
Jan Beulich9689ba82007-10-17 18:04:37 +0200351static const struct stacktrace_ops print_trace_ops = {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200352 .warning = print_trace_warning,
353 .warning_symbol = print_trace_warning_symbol,
354 .stack = print_trace_stack,
355 .address = print_trace_address,
356};
357
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200358void show_trace(struct task_struct *task, struct pt_regs *regs,
359 unsigned long *stack, unsigned long bp)
Andi Kleenc0b766f2006-09-26 10:52:34 +0200360{
361 printk("\nCall Trace:\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200362 dump_trace(task, regs, stack, bp, &print_trace_ops, NULL);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200363 printk("\n");
364}
365
366static void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200367_show_stack(struct task_struct *task, struct pt_regs *regs,
368 unsigned long *sp, unsigned long bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370 unsigned long *stack;
371 int i;
Andi Kleen151f8cc2006-09-26 10:52:37 +0200372 const int cpu = smp_processor_id();
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100373 unsigned long *irqstack_end = (unsigned long *) (cpu_pda(cpu)->irqstackptr);
374 unsigned long *irqstack = (unsigned long *) (cpu_pda(cpu)->irqstackptr - IRQSTACKSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 // debugging aid: "show_stack(NULL, NULL);" prints the
377 // back trace for this cpu.
378
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100379 if (sp == NULL) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200380 if (task)
381 sp = (unsigned long *)task->thread.sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 else
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100383 sp = (unsigned long *)&sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
385
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100386 stack = sp;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200387 for (i = 0; i < kstack_depth_to_print; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 if (stack >= irqstack && stack <= irqstack_end) {
389 if (stack == irqstack_end) {
390 stack = (unsigned long *) (irqstack_end[-1]);
391 printk(" <EOI> ");
392 }
393 } else {
394 if (((long) stack & (THREAD_SIZE-1)) == 0)
395 break;
396 }
397 if (i && ((i % 4) == 0))
Ingo Molnar3ac94932006-07-03 00:24:36 -0700398 printk("\n");
399 printk(" %016lx", *stack++);
akpm@osdl.org35faa712005-04-16 15:24:54 -0700400 touch_nmi_watchdog();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200402 show_trace(task, regs, sp, bp);
Jan Beulichb538ed22006-06-26 13:57:32 +0200403}
404
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200405void show_stack(struct task_struct *task, unsigned long *sp)
Jan Beulichb538ed22006-06-26 13:57:32 +0200406{
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200407 _show_stack(task, NULL, sp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
410/*
411 * The architecture-independent dump_stack generator
412 */
413void dump_stack(void)
414{
Arjan van de Venbc850d62008-01-30 13:33:07 +0100415 unsigned long bp = 0;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200416 unsigned long stack;
Arjan van de Ven57c351d2007-11-26 20:42:19 +0100417
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100418#ifdef CONFIG_FRAME_POINTER
419 if (!bp)
420 asm("movq %%rbp, %0" : "=r" (bp):);
421#endif
422
Arjan van de Ven57c351d2007-11-26 20:42:19 +0100423 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
424 current->pid, current->comm, print_tainted(),
425 init_utsname()->release,
426 (int)strcspn(init_utsname()->version, " "),
427 init_utsname()->version);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200428 show_trace(NULL, NULL, &stack, bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
430
431EXPORT_SYMBOL(dump_stack);
432
433void show_registers(struct pt_regs *regs)
434{
435 int i;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100436 unsigned long sp;
Andi Kleen151f8cc2006-09-26 10:52:37 +0200437 const int cpu = smp_processor_id();
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100438 struct task_struct *cur = cpu_pda(cpu)->pcurrent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100440 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 printk("CPU %d ", cpu);
442 __show_regs(regs);
443 printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
Al Viroe4f17c42006-01-12 01:05:38 -0800444 cur->comm, cur->pid, task_thread_info(cur), cur);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 /*
447 * When in-kernel, we also print out the stack and code at the
448 * time of the fault..
449 */
Arjan van de Vena25bd942008-01-30 13:33:08 +0100450 if (!user_mode(regs)) {
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200451 unsigned int code_prologue = code_bytes * 43 / 64;
452 unsigned int code_len = code_bytes;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100453 unsigned char c;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200454 u8 *ip;
455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 printk("Stack: ");
Arjan van de Venbc850d62008-01-30 13:33:07 +0100457 _show_stack(NULL, regs, (unsigned long *)sp, regs->bp);
Arjan van de Vena25bd942008-01-30 13:33:08 +0100458 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Arjan van de Vena25bd942008-01-30 13:33:08 +0100460 printk(KERN_EMERG "Code: ");
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200461
462 ip = (u8 *)regs->ip - code_prologue;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100463 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
464 /* try starting at RIP */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200465 ip = (u8 *)regs->ip;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100466 code_len = code_len - code_prologue + 1;
467 }
468 for (i = 0; i < code_len; i++, ip++) {
469 if (ip < (u8 *)PAGE_OFFSET ||
470 probe_kernel_address(ip, c)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 printk(" Bad RIP value.");
472 break;
473 }
Arjan van de Vena25bd942008-01-30 13:33:08 +0100474 if (ip == (u8 *)regs->ip)
475 printk("<%02x> ", c);
476 else
477 printk("%02x ", c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 }
479 }
480 printk("\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200481}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100483int is_valid_bugaddr(unsigned long ip)
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800484{
485 unsigned short ud2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100487 if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2)))
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800488 return 0;
489
490 return ud2 == 0x0b0f;
491}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Andi Kleen39743c92007-10-19 20:35:03 +0200493static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494static int die_owner = -1;
Corey Minyardcdc60a42006-05-08 15:17:22 +0200495static unsigned int die_nest_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100497unsigned __kprobes long oops_begin(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
Andrew Mortonb39b7032007-06-08 13:47:01 -0700499 int cpu;
Jan Beulich12091402005-09-12 18:49:24 +0200500 unsigned long flags;
501
Andrew Mortonabf0f102006-09-26 10:52:36 +0200502 oops_enter();
503
Jan Beulich12091402005-09-12 18:49:24 +0200504 /* racy, but better than risking deadlock. */
Andi Kleen39743c92007-10-19 20:35:03 +0200505 raw_local_irq_save(flags);
Andrew Mortonb39b7032007-06-08 13:47:01 -0700506 cpu = smp_processor_id();
Andi Kleen39743c92007-10-19 20:35:03 +0200507 if (!__raw_spin_trylock(&die_lock)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (cpu == die_owner)
509 /* nested oops. should stop eventually */;
510 else
Andi Kleen39743c92007-10-19 20:35:03 +0200511 __raw_spin_lock(&die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
Corey Minyardcdc60a42006-05-08 15:17:22 +0200513 die_nest_count++;
Jan Beulich12091402005-09-12 18:49:24 +0200514 die_owner = cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 console_verbose();
Jan Beulich12091402005-09-12 18:49:24 +0200516 bust_spinlocks(1);
517 return flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518}
519
Jan Beulich22f59912008-01-30 13:31:23 +0100520void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
Alexander van Heukelum78cbac62008-07-10 21:14:52 +0200521{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 die_owner = -1;
Jan Beulich12091402005-09-12 18:49:24 +0200523 bust_spinlocks(0);
Corey Minyardcdc60a42006-05-08 15:17:22 +0200524 die_nest_count--;
Andi Kleen39743c92007-10-19 20:35:03 +0200525 if (!die_nest_count)
Corey Minyardcdc60a42006-05-08 15:17:22 +0200526 /* Nest count reaches zero, release the lock. */
Andi Kleen39743c92007-10-19 20:35:03 +0200527 __raw_spin_unlock(&die_lock);
528 raw_local_irq_restore(flags);
Jan Beulich22f59912008-01-30 13:31:23 +0100529 if (!regs) {
530 oops_exit();
531 return;
532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (panic_on_oops)
Horms012c4372006-08-13 23:24:22 -0700534 panic("Fatal exception");
Andrew Mortonabf0f102006-09-26 10:52:36 +0200535 oops_exit();
Jan Beulich22f59912008-01-30 13:31:23 +0100536 do_exit(signr);
Jan Beulich12091402005-09-12 18:49:24 +0200537}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Alexander van Heukelume423f492008-07-02 01:31:03 +0200539int __kprobes __die(const char *str, struct pt_regs *regs, long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
Alexander van Heukelume423f492008-07-02 01:31:03 +0200541 printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542#ifdef CONFIG_PREEMPT
543 printk("PREEMPT ");
544#endif
545#ifdef CONFIG_SMP
546 printk("SMP ");
547#endif
548#ifdef CONFIG_DEBUG_PAGEALLOC
549 printk("DEBUG_PAGEALLOC");
550#endif
551 printk("\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200552 if (notify_die(DIE_OOPS, str, regs, err,
553 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
Jan Beulich22f59912008-01-30 13:31:23 +0100554 return 1;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 show_registers(regs);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700557 add_taint(TAINT_DIE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 /* Executive summary in case the oops scrolled away */
559 printk(KERN_ALERT "RIP ");
Arjan van de Venaafbd7e2008-01-30 13:33:08 +0100560 printk_address(regs->ip, 1);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100561 printk(" RSP <%016lx>\n", regs->sp);
Vivek Goyal8bcc5282006-04-18 12:35:13 +0200562 if (kexec_should_crash(current))
563 crash_kexec(regs);
Jan Beulich22f59912008-01-30 13:31:23 +0100564 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200567void die(const char *str, struct pt_regs *regs, long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Jan Beulich12091402005-09-12 18:49:24 +0200569 unsigned long flags = oops_begin();
570
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800571 if (!user_mode(regs))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100572 report_bug(regs->ip, regs);
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800573
Jan Beulich22f59912008-01-30 13:31:23 +0100574 if (__die(str, regs, err))
575 regs = NULL;
576 oops_end(flags, regs, SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200579notrace __kprobes void
580die_nmi(char *str, struct pt_regs *regs, int do_panic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Jason Wessel737a4602008-03-07 16:34:16 -0600582 unsigned long flags;
Jan Beulich12091402005-09-12 18:49:24 +0200583
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200584 if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP)
Jason Wessel737a4602008-03-07 16:34:16 -0600585 return;
586
587 flags = oops_begin();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /*
589 * We are in trouble anyway, lets at least try
590 * to get a message out.
591 */
Cyrill Gorcunove56b3a12008-05-24 19:36:32 +0400592 printk(KERN_EMERG "%s", str);
593 printk(" on CPU%d, ip %08lx, registers:\n",
594 smp_processor_id(), regs->ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 show_registers(regs);
Vivek Goyal8bcc5282006-04-18 12:35:13 +0200596 if (kexec_should_crash(current))
597 crash_kexec(regs);
Andi Kleenfac58552006-09-26 10:52:27 +0200598 if (do_panic || panic_on_oops)
599 panic("Non maskable interrupt");
Jan Beulich22f59912008-01-30 13:31:23 +0100600 oops_end(flags, NULL, SIGBUS);
Corey Minyard8b1ffe952006-05-08 15:17:25 +0200601 nmi_exit();
602 local_irq_enable();
Jan Beulich22f59912008-01-30 13:31:23 +0100603 do_exit(SIGBUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200606static void __kprobes
607do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
608 long error_code, siginfo_t *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
Jan Beulich6e3f3612006-01-11 22:42:14 +0100610 struct task_struct *tsk = current;
611
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200612 if (!user_mode(regs))
613 goto kernel_trap;
Andi Kleend1895182007-05-02 19:27:05 +0200614
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200615 /*
616 * We want error_code and trap_no set for userspace faults and
617 * kernelspace faults which result in die(), but not
618 * kernelspace faults which are fixed up. die() gives the
619 * process no chance to handle the signal and notice the
620 * kernel fault information, so that won't result in polluting
621 * the information about previously queued, but not yet
622 * delivered, faults. See also do_general_protection below.
623 */
624 tsk->thread.error_code = error_code;
625 tsk->thread.trap_no = trapnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200627 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
628 printk_ratelimit()) {
629 printk(KERN_INFO
630 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
631 tsk->comm, tsk->pid, str,
632 regs->ip, regs->sp, error_code);
633 print_vma_addr(" in ", regs->ip);
634 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
636
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200637 if (info)
638 force_sig_info(signr, info, tsk);
639 else
640 force_sig(signr, tsk);
641 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200643kernel_trap:
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100644 if (!fixup_exception(regs)) {
645 tsk->thread.error_code = error_code;
646 tsk->thread.trap_no = trapnr;
647 die(str, regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100649 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
652#define DO_ERROR(trapnr, signr, str, name) \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200653asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
654{ \
655 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
656 == NOTIFY_STOP) \
657 return; \
Andi Kleen40e59a62006-05-15 18:19:47 +0200658 conditional_sti(regs); \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200659 do_trap(trapnr, signr, str, regs, error_code, NULL); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200662#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
663asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
664{ \
665 siginfo_t info; \
666 info.si_signo = signr; \
667 info.si_errno = 0; \
668 info.si_code = sicode; \
669 info.si_addr = (void __user *)siaddr; \
670 trace_hardirqs_fixup(); \
671 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
672 == NOTIFY_STOP) \
673 return; \
Andi Kleen40e59a62006-05-15 18:19:47 +0200674 conditional_sti(regs); \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200675 do_trap(trapnr, signr, str, regs, error_code, &info); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200678DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
679DO_ERROR(4, SIGSEGV, "overflow", overflow)
680DO_ERROR(5, SIGSEGV, "bounds", bounds)
681DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
682DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200684DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
Andi Kleen40e59a62006-05-15 18:19:47 +0200686
687/* Runs on IST stack */
688asmlinkage void do_stack_segment(struct pt_regs *regs, long error_code)
689{
690 if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
691 12, SIGBUS) == NOTIFY_STOP)
692 return;
693 preempt_conditional_sti(regs);
694 do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL);
695 preempt_conditional_cli(regs);
696}
Jan Beulicheca37c12006-01-11 22:42:17 +0100697
698asmlinkage void do_double_fault(struct pt_regs * regs, long error_code)
699{
700 static const char str[] = "double fault";
701 struct task_struct *tsk = current;
702
703 /* Return not checked because double check cannot be ignored */
704 notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV);
705
706 tsk->thread.error_code = error_code;
707 tsk->thread.trap_no = 8;
708
709 /* This is always a kernel trap and never fixable (and thus must
710 never return). */
711 for (;;)
712 die(str, regs, error_code);
713}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200715asmlinkage void __kprobes
716do_general_protection(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200718 struct task_struct *tsk;
Jan Beulich6e3f3612006-01-11 22:42:14 +0100719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 conditional_sti(regs);
721
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200722 tsk = current;
723 if (!user_mode(regs))
724 goto gp_in_kernel;
Andi Kleend1895182007-05-02 19:27:05 +0200725
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200726 tsk->thread.error_code = error_code;
727 tsk->thread.trap_no = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200729 if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
730 printk_ratelimit()) {
731 printk(KERN_INFO
732 "%s[%d] general protection ip:%lx sp:%lx error:%lx",
733 tsk->comm, tsk->pid,
734 regs->ip, regs->sp, error_code);
735 print_vma_addr(" in ", regs->ip);
736 printk("\n");
737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200739 force_sig(SIGSEGV, tsk);
740 return;
741
742gp_in_kernel:
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100743 if (fixup_exception(regs))
744 return;
Andi Kleend1895182007-05-02 19:27:05 +0200745
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100746 tsk->thread.error_code = error_code;
747 tsk->thread.trap_no = 13;
748 if (notify_die(DIE_GPF, "general protection fault", regs,
749 error_code, 13, SIGSEGV) == NOTIFY_STOP)
750 return;
751 die("general protection fault", regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752}
753
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200754static notrace __kprobes void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200755mem_parity_error(unsigned char reason, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
Don Zickusc41c5cd2006-09-26 10:52:27 +0200757 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
758 reason);
Andi Kleen9c5f8be2006-12-07 02:14:03 +0100759 printk(KERN_EMERG "You have some hardware problem, likely on the PCI bus.\n");
Don Zickusc41c5cd2006-09-26 10:52:27 +0200760
Dave Jiangc0d12172007-07-19 01:49:46 -0700761#if defined(CONFIG_EDAC)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200762 if (edac_handler_set()) {
Dave Jiangc0d12172007-07-19 01:49:46 -0700763 edac_atomic_assert_error();
764 return;
765 }
766#endif
767
Don Zickus8da5add2006-09-26 10:52:27 +0200768 if (panic_on_unrecovered_nmi)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200769 panic("NMI: Not continuing");
770
771 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 /* Clear and disable the memory parity error line. */
774 reason = (reason & 0xf) | 4;
775 outb(reason, 0x61);
776}
777
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200778static notrace __kprobes void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200779io_check_error(unsigned char reason, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
781 printk("NMI: IOCK error (debug interrupt?)\n");
782 show_registers(regs);
783
784 /* Re-enable the IOCK line, wait for a few seconds */
785 reason = (reason & 0xf) | 8;
786 outb(reason, 0x61);
787 mdelay(2000);
788 reason &= ~8;
789 outb(reason, 0x61);
790}
791
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200792static notrace __kprobes void
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100793unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200794{
Jason Wesseld3597522008-02-15 14:55:53 -0600795 if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
796 return;
Don Zickusc41c5cd2006-09-26 10:52:27 +0200797 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
798 reason);
799 printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n");
Don Zickus8da5add2006-09-26 10:52:27 +0200800
801 if (panic_on_unrecovered_nmi)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200802 panic("NMI: Not continuing");
Don Zickus8da5add2006-09-26 10:52:27 +0200803
Don Zickusc41c5cd2006-09-26 10:52:27 +0200804 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700807/* Runs on IST stack. This code must keep interrupts off all the time.
808 Nested NMIs are prevented by the CPU. */
Alexander van Heukelumabd34802008-07-02 18:39:01 +0200809asmlinkage notrace __kprobes void default_do_nmi(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
811 unsigned char reason = 0;
Ashok Raj76e4f662005-06-25 14:55:00 -0700812 int cpu;
813
814 cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200816 /* Only the BSP gets external NMIs from the system. */
Ashok Raj76e4f662005-06-25 14:55:00 -0700817 if (!cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 reason = get_nmi_reason();
819
820 if (!(reason & 0xc0)) {
Jan Beulich6e3f3612006-01-11 22:42:14 +0100821 if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 == NOTIFY_STOP)
823 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 /*
825 * Ok, so this is none of the documented NMI sources,
826 * so it must be the NMI watchdog.
827 */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200828 if (nmi_watchdog_tick(regs, reason))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 return;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200830 if (!do_nmi_callback(regs, cpu))
Don Zickus3adbbcce2006-09-26 10:52:26 +0200831 unknown_nmi_error(reason, regs);
832
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 return;
834 }
Jan Beulich6e3f3612006-01-11 22:42:14 +0100835 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200836 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 /* AK: following checks seem to be broken on modern chipsets. FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (reason & 0x80)
840 mem_parity_error(reason, regs);
841 if (reason & 0x40)
842 io_check_error(reason, regs);
843}
844
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400845asmlinkage notrace __kprobes void
846do_nmi(struct pt_regs *regs, long error_code)
847{
848 nmi_enter();
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200849
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400850 add_pda(__nmi_count, 1);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200851
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400852 if (!ignore_nmis)
853 default_do_nmi(regs);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200854
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400855 nmi_exit();
856}
857
858void stop_nmi(void)
859{
860 acpi_nmi_disable();
861 ignore_nmis++;
862}
863
864void restart_nmi(void)
865{
866 ignore_nmis--;
867 acpi_nmi_enable();
868}
869
Jan Beulichb556b352006-01-11 22:43:00 +0100870/* runs on IST stack. */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200871asmlinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
Peter Zijlstra143a5d32007-10-25 14:01:10 +0200873 trace_hardirqs_fixup();
874
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200875 if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
876 == NOTIFY_STOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 return;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200878
Andi Kleen40e59a62006-05-15 18:19:47 +0200879 preempt_conditional_sti(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
Andi Kleen40e59a62006-05-15 18:19:47 +0200881 preempt_conditional_cli(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
883
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700884/* Help handler running on IST stack to switch back to user stack
885 for scheduling or signal handling. The actual stack switch is done in
886 entry.S */
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100887asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700889 struct pt_regs *regs = eregs;
890 /* Did already sync */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100891 if (eregs == (struct pt_regs *)eregs->sp)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700892 ;
893 /* Exception from user space */
Vincent Hanquez76381fe2005-06-23 00:08:46 -0700894 else if (user_mode(eregs))
Al Virobb049232006-01-12 01:05:38 -0800895 regs = task_pt_regs(current);
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700896 /* Exception from kernel and interrupts are enabled. Move to
897 kernel process stack. */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100898 else if (eregs->flags & X86_EFLAGS_IF)
899 regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs));
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700900 if (eregs != regs)
901 *regs = *eregs;
902 return regs;
903}
904
905/* runs on IST stack. */
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -0700906asmlinkage void __kprobes do_debug(struct pt_regs * regs,
907 unsigned long error_code)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700908{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 struct task_struct *tsk = current;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200910 unsigned long condition;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 siginfo_t info;
912
Peter Zijlstra000f4a92007-11-26 20:42:19 +0100913 trace_hardirqs_fixup();
914
Vincent Hanqueze9129e52005-06-23 00:08:46 -0700915 get_debugreg(condition, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Roland McGrath10faa812008-01-30 13:30:54 +0100917 /*
918 * The processor cleared BTF, so don't mark that we need it set.
919 */
920 clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
921 tsk->thread.debugctlmsr = 0;
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
Andi Kleendaeeafe2005-04-16 15:25:13 -0700924 SIGTRAP) == NOTIFY_STOP)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700925 return;
Andi Kleendaeeafe2005-04-16 15:25:13 -0700926
John Blackwooda65d17c2006-02-12 14:34:58 -0800927 preempt_conditional_sti(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 /* Mask out spurious debug traps due to lazy DR7 setting */
930 if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200931 if (!tsk->thread.debugreg7)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 goto clear_dr7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
934
935 tsk->thread.debugreg6 = condition;
936
Roland McGrathe1f28772008-01-30 13:30:50 +0100937 /*
938 * Single-stepping through TF: make sure we ignore any events in
939 * kernel space (but re-enable TF when returning to user mode).
940 */
Andi Kleendaeeafe2005-04-16 15:25:13 -0700941 if (condition & DR_STEP) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200942 if (!user_mode(regs))
943 goto clear_TF_reenable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 }
945
946 /* Ok, finally something we can handle */
947 tsk->thread.trap_no = 1;
948 tsk->thread.error_code = error_code;
949 info.si_signo = SIGTRAP;
950 info.si_errno = 0;
951 info.si_code = TRAP_BRKPT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100952 info.si_addr = user_mode(regs) ? (void __user *)regs->ip : NULL;
John Blackwood01b8faa2006-01-11 22:44:15 +0100953 force_sig_info(SIGTRAP, &info, tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955clear_dr7:
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200956 set_debugreg(0, 7);
John Blackwooda65d17c2006-02-12 14:34:58 -0800957 preempt_conditional_cli(regs);
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700958 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960clear_TF_reenable:
961 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
Glauber de Oliveira Costa053de042008-01-30 13:31:27 +0100962 regs->flags &= ~X86_EFLAGS_TF;
John Blackwooda65d17c2006-02-12 14:34:58 -0800963 preempt_conditional_cli(regs);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200964 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
Jan Beulich6e3f3612006-01-11 22:42:14 +0100967static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100969 if (fixup_exception(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 return 1;
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100971
Jan Beulich6e3f3612006-01-11 22:42:14 +0100972 notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
Andi Kleen3a848f62005-04-16 15:25:06 -0700973 /* Illegal floating point operation in the kernel */
Jan Beulich6e3f3612006-01-11 22:42:14 +0100974 current->thread.trap_no = trapnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 die(str, regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 return 0;
977}
978
979/*
980 * Note that we play around with the 'TS' bit in an attempt to get
981 * the correct behaviour even in the presence of the asynchronous
982 * IRQ13 behaviour
983 */
984asmlinkage void do_coprocessor_error(struct pt_regs *regs)
985{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100986 void __user *ip = (void __user *)(regs->ip);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200987 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 siginfo_t info;
989 unsigned short cwd, swd;
990
991 conditional_sti(regs);
Vincent Hanquez76381fe2005-06-23 00:08:46 -0700992 if (!user_mode(regs) &&
Jan Beulich6e3f3612006-01-11 22:42:14 +0100993 kernel_math_error(regs, "kernel x87 math error", 16))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 return;
995
996 /*
997 * Save the info for the exception handler and clear the error.
998 */
999 task = current;
1000 save_init_fpu(task);
1001 task->thread.trap_no = 16;
1002 task->thread.error_code = 0;
1003 info.si_signo = SIGFPE;
1004 info.si_errno = 0;
1005 info.si_code = __SI_FAULT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001006 info.si_addr = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 /*
1008 * (~cwd & swd) will mask out exceptions that are not set to unmasked
1009 * status. 0x3f is the exception bits in these regs, 0x200 is the
1010 * C1 reg you need in case of a stack fault, 0x040 is the stack
1011 * fault bit. We should only be taking one exception at a time,
1012 * so if this combination doesn't produce any single exception,
1013 * then we have a bad program that isn't synchronizing its FPU usage
1014 * and it will suffer the consequences since we won't be able to
1015 * fully reproduce the context of the exception
1016 */
1017 cwd = get_fpu_cwd(task);
1018 swd = get_fpu_swd(task);
Chuck Ebbertff347b22005-09-12 18:49:25 +02001019 switch (swd & ~cwd & 0x3f) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001020 case 0x000: /* No unmasked exception */
1021 default: /* Multiple exceptions */
1022 break;
1023 case 0x001: /* Invalid Op */
1024 /*
1025 * swd & 0x240 == 0x040: Stack Underflow
1026 * swd & 0x240 == 0x240: Stack Overflow
1027 * User must clear the SF bit (0x40) if set
1028 */
1029 info.si_code = FPE_FLTINV;
1030 break;
1031 case 0x002: /* Denormalize */
1032 case 0x010: /* Underflow */
1033 info.si_code = FPE_FLTUND;
1034 break;
1035 case 0x004: /* Zero Divide */
1036 info.si_code = FPE_FLTDIV;
1037 break;
1038 case 0x008: /* Overflow */
1039 info.si_code = FPE_FLTOVF;
1040 break;
1041 case 0x020: /* Precision */
1042 info.si_code = FPE_FLTRES;
1043 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 }
1045 force_sig_info(SIGFPE, &info, task);
1046}
1047
1048asmlinkage void bad_intr(void)
1049{
1050 printk("bad interrupt");
1051}
1052
1053asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs)
1054{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001055 void __user *ip = (void __user *)(regs->ip);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001056 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 siginfo_t info;
1058 unsigned short mxcsr;
1059
1060 conditional_sti(regs);
Vincent Hanquez76381fe2005-06-23 00:08:46 -07001061 if (!user_mode(regs) &&
Jan Beulich6e3f3612006-01-11 22:42:14 +01001062 kernel_math_error(regs, "kernel simd math error", 19))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 return;
1064
1065 /*
1066 * Save the info for the exception handler and clear the error.
1067 */
1068 task = current;
1069 save_init_fpu(task);
1070 task->thread.trap_no = 19;
1071 task->thread.error_code = 0;
1072 info.si_signo = SIGFPE;
1073 info.si_errno = 0;
1074 info.si_code = __SI_FAULT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001075 info.si_addr = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 /*
1077 * The SIMD FPU exceptions are handled a little differently, as there
1078 * is only a single status/control register. Thus, to determine which
1079 * unmasked exception was caught we must mask the exception mask bits
1080 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
1081 */
1082 mxcsr = get_fpu_mxcsr(task);
1083 switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001084 case 0x000:
1085 default:
1086 break;
1087 case 0x001: /* Invalid Op */
1088 info.si_code = FPE_FLTINV;
1089 break;
1090 case 0x002: /* Denormalize */
1091 case 0x010: /* Underflow */
1092 info.si_code = FPE_FLTUND;
1093 break;
1094 case 0x004: /* Zero Divide */
1095 info.si_code = FPE_FLTDIV;
1096 break;
1097 case 0x008: /* Overflow */
1098 info.si_code = FPE_FLTOVF;
1099 break;
1100 case 0x020: /* Precision */
1101 info.si_code = FPE_FLTRES;
1102 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 }
1104 force_sig_info(SIGFPE, &info, task);
1105}
1106
1107asmlinkage void do_spurious_interrupt_bug(struct pt_regs * regs)
1108{
1109}
1110
1111asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void)
1112{
1113}
1114
Jacob Shin89b831e2005-11-05 17:25:53 +01001115asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void)
1116{
1117}
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119/*
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001120 * 'math_state_restore()' saves the current math information in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 * old math state array, and gets the new ones from the current task
1122 *
1123 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
1124 * Don't touch unless you *really* know how it works.
1125 */
1126asmlinkage void math_state_restore(void)
1127{
1128 struct task_struct *me = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Suresh Siddhaaa283f42008-03-10 15:28:05 -07001130 if (!used_math()) {
1131 local_irq_enable();
1132 /*
1133 * does a slab alloc which can sleep
1134 */
1135 if (init_fpu(me)) {
1136 /*
1137 * ran out of memory!
1138 */
1139 do_group_exit(SIGKILL);
1140 return;
1141 }
1142 local_irq_disable();
1143 }
1144
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001145 clts(); /* Allow maths ops (or we recurse) */
Suresh Siddha61c46282008-03-10 15:28:04 -07001146 restore_fpu_checking(&me->thread.xstate->fxsave);
Al Viroe4f17c42006-01-12 01:05:38 -08001147 task_thread_info(me)->status |= TS_USEDFPU;
Arjan van de Vene07e23e2006-09-26 10:52:36 +02001148 me->fpu_counter++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149}
Glauber de Oliveira Costa21db5582008-01-30 13:31:10 +01001150EXPORT_SYMBOL_GPL(math_state_restore);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152void __init trap_init(void)
1153{
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001154 set_intr_gate(0, &divide_error);
1155 set_intr_gate_ist(1, &debug, DEBUG_STACK);
1156 set_intr_gate_ist(2, &nmi, NMI_STACK);
1157 set_system_gate_ist(3, &int3, DEBUG_STACK); /* int3 can be called from all */
1158 set_system_gate(4, &overflow); /* int4 can be called from all */
1159 set_intr_gate(5, &bounds);
1160 set_intr_gate(6, &invalid_op);
1161 set_intr_gate(7, &device_not_available);
1162 set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK);
1163 set_intr_gate(9, &coprocessor_segment_overrun);
1164 set_intr_gate(10, &invalid_TSS);
1165 set_intr_gate(11, &segment_not_present);
1166 set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK);
1167 set_intr_gate(13, &general_protection);
1168 set_intr_gate(14, &page_fault);
1169 set_intr_gate(15, &spurious_interrupt_bug);
1170 set_intr_gate(16, &coprocessor_error);
1171 set_intr_gate(17, &alignment_check);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172#ifdef CONFIG_X86_MCE
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001173 set_intr_gate_ist(18, &machine_check, MCE_STACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174#endif
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001175 set_intr_gate(19, &simd_coprocessor_error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177#ifdef CONFIG_IA32_EMULATION
1178 set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
1179#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 /*
Suresh Siddha61c46282008-03-10 15:28:04 -07001181 * initialize the per thread extended state:
1182 */
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +02001183 init_thread_xstate();
Suresh Siddha61c46282008-03-10 15:28:04 -07001184 /*
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001185 * Should be a barrier for any external CPU state:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 */
1187 cpu_init();
1188}
1189
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001190static int __init oops_setup(char *s)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001191{
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001192 if (!s)
1193 return -EINVAL;
1194 if (!strcmp(s, "panic"))
1195 panic_on_oops = 1;
1196 return 0;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001197}
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001198early_param("oops", oops_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200static int __init kstack_setup(char *s)
1201{
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001202 if (!s)
1203 return -EINVAL;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001204 kstack_depth_to_print = simple_strtoul(s, NULL, 0);
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001205 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206}
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001207early_param("kstack", kstack_setup);
Arjan van de Vena25bd942008-01-30 13:33:08 +01001208
Arjan van de Vena25bd942008-01-30 13:33:08 +01001209static int __init code_bytes_setup(char *s)
1210{
1211 code_bytes = simple_strtoul(s, NULL, 0);
1212 if (code_bytes > 8192)
1213 code_bytes = 8192;
1214
1215 return 1;
1216}
1217__setup("code_bytes=", code_bytes_setup);