blob: 74e992957ff684a5991c59a2ad7073403a207a1a [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{
Harvey Harrisona5ff6772008-01-30 13:33:25 +0100108#ifdef CONFIG_KALLSYMS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 unsigned long offset = 0, symsize;
110 const char *symname;
111 char *modname;
Ingo Molnar3ac94932006-07-03 00:24:36 -0700112 char *delim = ":";
Cyrill Gorcunov85e2aee2008-01-30 13:33:33 +0100113 char namebuf[KSYM_NAME_LEN];
Harvey Harrisona5ff6772008-01-30 13:33:25 +0100114 char reliab[4] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ingo Molnar3ac94932006-07-03 00:24:36 -0700116 symname = kallsyms_lookup(address, &symsize, &offset,
117 &modname, namebuf);
118 if (!symname) {
119 printk(" [<%016lx>]\n", address);
120 return;
121 }
Arjan van de Venbc850d62008-01-30 13:33:07 +0100122 if (!reliable)
123 strcpy(reliab, "? ");
124
Ingo Molnar3ac94932006-07-03 00:24:36 -0700125 if (!modname)
Harvey Harrisona5ff6772008-01-30 13:33:25 +0100126 modname = delim = "";
Arjan van de Venbc850d62008-01-30 13:33:07 +0100127 printk(" [<%016lx>] %s%s%s%s%s+0x%lx/0x%lx\n",
128 address, reliab, delim, modname, delim, symname, offset, symsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#else
Ingo Molnar3ac94932006-07-03 00:24:36 -0700130 printk(" [<%016lx>]\n", address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#endif
Harvey Harrisona5ff6772008-01-30 13:33:25 +0100132}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Andi Kleen0a658002005-04-16 15:25:17 -0700134static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
Andi Kleenc0b766f2006-09-26 10:52:34 +0200135 unsigned *usedp, char **idp)
Andi Kleen0a658002005-04-16 15:25:17 -0700136{
Jan Beulichb556b352006-01-11 22:43:00 +0100137 static char ids[][8] = {
Andi Kleen0a658002005-04-16 15:25:17 -0700138 [DEBUG_STACK - 1] = "#DB",
139 [NMI_STACK - 1] = "NMI",
140 [DOUBLEFAULT_STACK - 1] = "#DF",
141 [STACKFAULT_STACK - 1] = "#SS",
142 [MCE_STACK - 1] = "#MC",
Jan Beulichb556b352006-01-11 22:43:00 +0100143#if DEBUG_STKSZ > EXCEPTION_STKSZ
144 [N_EXCEPTION_STACKS ... N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]"
145#endif
Andi Kleen0a658002005-04-16 15:25:17 -0700146 };
147 unsigned k;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700149 /*
150 * Iterate over all exception stacks, and figure out whether
151 * 'stack' is in one of them:
152 */
Andi Kleen0a658002005-04-16 15:25:17 -0700153 for (k = 0; k < N_EXCEPTION_STACKS; k++) {
Keith Owensf5741642006-09-26 10:52:38 +0200154 unsigned long end = per_cpu(orig_ist, cpu).ist[k];
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700155 /*
156 * Is 'stack' above this exception frame's end?
157 * If yes then skip to the next frame.
158 */
Andi Kleen0a658002005-04-16 15:25:17 -0700159 if (stack >= end)
160 continue;
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700161 /*
162 * Is 'stack' above this exception frame's start address?
163 * If yes then we found the right frame.
164 */
Andi Kleen0a658002005-04-16 15:25:17 -0700165 if (stack >= end - EXCEPTION_STKSZ) {
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700166 /*
167 * Make sure we only iterate through an exception
168 * stack once. If it comes up for the second time
169 * then there's something wrong going on - just
170 * break out and return NULL:
171 */
Andi Kleen0a658002005-04-16 15:25:17 -0700172 if (*usedp & (1U << k))
173 break;
174 *usedp |= 1U << k;
175 *idp = ids[k];
176 return (unsigned long *)end;
177 }
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700178 /*
179 * If this is a debug stack, and if it has a larger size than
180 * the usual exception stacks, then 'stack' might still
181 * be within the lower portion of the debug stack:
182 */
Jan Beulichb556b352006-01-11 22:43:00 +0100183#if DEBUG_STKSZ > EXCEPTION_STKSZ
184 if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
185 unsigned j = N_EXCEPTION_STACKS - 1;
186
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700187 /*
188 * Black magic. A large debug stack is composed of
189 * multiple exception stack entries, which we
190 * iterate through now. Dont look:
191 */
Jan Beulichb556b352006-01-11 22:43:00 +0100192 do {
193 ++j;
194 end -= EXCEPTION_STKSZ;
195 ids[j][4] = '1' + (j - N_EXCEPTION_STACKS);
196 } while (stack < end - EXCEPTION_STKSZ);
197 if (*usedp & (1U << j))
198 break;
199 *usedp |= 1U << j;
200 *idp = ids[j];
201 return (unsigned long *)end;
202 }
203#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
205 return NULL;
Andi Kleen0a658002005-04-16 15:25:17 -0700206}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208/*
Simon Arlott676b1852007-10-20 01:25:36 +0200209 * x86-64 can have up to three kernel stacks:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 * process stack
211 * interrupt stack
Andi Kleen0a658002005-04-16 15:25:17 -0700212 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 */
214
Arjan van de Vene4a94562008-01-30 13:33:07 +0100215static inline int valid_stack_ptr(struct thread_info *tinfo,
216 void *p, unsigned int size, void *end)
Andi Kleenc547c772006-11-28 20:12:59 +0100217{
Jan Engelhardtade1af72008-01-30 13:33:23 +0100218 void *t = tinfo;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100219 if (end) {
220 if (p < end && p >= (end-THREAD_SIZE))
221 return 1;
222 else
223 return 0;
224 }
225 return p > t && p < t + THREAD_SIZE - size;
226}
227
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100228/* The form of the top of the frame on the stack */
229struct stack_frame {
230 struct stack_frame *next_frame;
231 unsigned long return_address;
232};
233
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200234static inline unsigned long
235print_context_stack(struct thread_info *tinfo,
236 unsigned long *stack, unsigned long bp,
237 const struct stacktrace_ops *ops, void *data,
238 unsigned long *end)
Arjan van de Vene4a94562008-01-30 13:33:07 +0100239{
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100240 struct stack_frame *frame = (struct stack_frame *)bp;
241
242 while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
243 unsigned long addr;
244
245 addr = *stack;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100246 if (__kernel_text_address(addr)) {
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100247 if ((unsigned long) stack == bp + 8) {
248 ops->address(data, addr, 1);
249 frame = frame->next_frame;
250 bp = (unsigned long) frame;
251 } else {
252 ops->address(data, addr, bp == 0);
253 }
Arjan van de Vene4a94562008-01-30 13:33:07 +0100254 }
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100255 stack++;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100256 }
257 return bp;
Andi Kleenc547c772006-11-28 20:12:59 +0100258}
259
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200260void dump_trace(struct task_struct *task, struct pt_regs *regs,
Arjan van de Venbc850d62008-01-30 13:33:07 +0100261 unsigned long *stack, unsigned long bp,
Jan Beulich9689ba82007-10-17 18:04:37 +0200262 const struct stacktrace_ops *ops, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Andrew Mortonda689332006-12-07 02:14:02 +0100264 const unsigned cpu = get_cpu();
Andi Kleenb615ebd2006-12-07 02:14:00 +0100265 unsigned long *irqstack_end = (unsigned long*)cpu_pda(cpu)->irqstackptr;
Andi Kleen0a658002005-04-16 15:25:17 -0700266 unsigned used = 0;
Andi Kleenc547c772006-11-28 20:12:59 +0100267 struct thread_info *tinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200269 if (!task)
270 task = current;
Jan Beulichb538ed22006-06-26 13:57:32 +0200271
Andi Kleenc0b766f2006-09-26 10:52:34 +0200272 if (!stack) {
273 unsigned long dummy;
274 stack = &dummy;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200275 if (task && task != current)
276 stack = (unsigned long *)task->thread.sp;
Jan Beulichb538ed22006-06-26 13:57:32 +0200277 }
278
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100279#ifdef CONFIG_FRAME_POINTER
280 if (!bp) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200281 if (task == current) {
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100282 /* Grab bp right from our regs */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200283 asm("movq %%rbp, %0" : "=r" (bp) :);
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100284 } else {
285 /* bp is the last reg pushed by switch_to */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200286 bp = *(unsigned long *) task->thread.sp;
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100287 }
288 }
289#endif
290
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700291 /*
292 * Print function call entries in all stacks, starting at the
293 * current stack address. If the stacks consist of nested
294 * exceptions
295 */
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200296 tinfo = task_thread_info(task);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200297 for (;;) {
298 char *id;
Andi Kleen0a658002005-04-16 15:25:17 -0700299 unsigned long *estack_end;
300 estack_end = in_exception_stack(cpu, (unsigned long)stack,
301 &used, &id);
302
303 if (estack_end) {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200304 if (ops->stack(data, id) < 0)
305 break;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100306
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100307 bp = print_context_stack(tinfo, stack, bp, ops,
308 data, estack_end);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200309 ops->stack(data, "<EOE>");
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700310 /*
311 * We link to the next stack via the
312 * second-to-last pointer (index -2 to end) in the
313 * exception stack:
314 */
Andi Kleen0a658002005-04-16 15:25:17 -0700315 stack = (unsigned long *) estack_end[-2];
316 continue;
317 }
318 if (irqstack_end) {
319 unsigned long *irqstack;
320 irqstack = irqstack_end -
321 (IRQSTACKSIZE - 64) / sizeof(*irqstack);
322
323 if (stack >= irqstack && stack < irqstack_end) {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200324 if (ops->stack(data, "IRQ") < 0)
325 break;
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100326 bp = print_context_stack(tinfo, stack, bp,
327 ops, data, irqstack_end);
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700328 /*
329 * We link to the next stack (which would be
330 * the process stack normally) the last
331 * pointer (index -1 to end) in the IRQ stack:
332 */
Andi Kleen0a658002005-04-16 15:25:17 -0700333 stack = (unsigned long *) (irqstack_end[-1]);
334 irqstack_end = NULL;
Andi Kleenc0b766f2006-09-26 10:52:34 +0200335 ops->stack(data, "EOI");
Andi Kleen0a658002005-04-16 15:25:17 -0700336 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338 }
Andi Kleen0a658002005-04-16 15:25:17 -0700339 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
Andi Kleen0a658002005-04-16 15:25:17 -0700341
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700342 /*
Andi Kleenc0b766f2006-09-26 10:52:34 +0200343 * This handles the process stack:
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700344 */
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100345 bp = print_context_stack(tinfo, stack, bp, ops, data, NULL);
Andrew Mortonda689332006-12-07 02:14:02 +0100346 put_cpu();
Andi Kleenc0b766f2006-09-26 10:52:34 +0200347}
348EXPORT_SYMBOL(dump_trace);
Ingo Molnar3ac94932006-07-03 00:24:36 -0700349
Andi Kleenc0b766f2006-09-26 10:52:34 +0200350static void
351print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
352{
353 print_symbol(msg, symbol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 printk("\n");
355}
356
Andi Kleenc0b766f2006-09-26 10:52:34 +0200357static void print_trace_warning(void *data, char *msg)
358{
359 printk("%s\n", msg);
360}
361
362static int print_trace_stack(void *data, char *name)
363{
364 printk(" <%s> ", name);
365 return 0;
366}
367
Arjan van de Venbc850d62008-01-30 13:33:07 +0100368static void print_trace_address(void *data, unsigned long addr, int reliable)
Andi Kleenc0b766f2006-09-26 10:52:34 +0200369{
Konrad Rzeszutek1c978b92007-07-17 04:03:56 -0700370 touch_nmi_watchdog();
Arjan van de Venbc850d62008-01-30 13:33:07 +0100371 printk_address(addr, reliable);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200372}
373
Jan Beulich9689ba82007-10-17 18:04:37 +0200374static const struct stacktrace_ops print_trace_ops = {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200375 .warning = print_trace_warning,
376 .warning_symbol = print_trace_warning_symbol,
377 .stack = print_trace_stack,
378 .address = print_trace_address,
379};
380
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200381void show_trace(struct task_struct *task, struct pt_regs *regs,
382 unsigned long *stack, unsigned long bp)
Andi Kleenc0b766f2006-09-26 10:52:34 +0200383{
384 printk("\nCall Trace:\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200385 dump_trace(task, regs, stack, bp, &print_trace_ops, NULL);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200386 printk("\n");
387}
388
389static void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200390_show_stack(struct task_struct *task, struct pt_regs *regs,
391 unsigned long *sp, unsigned long bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
393 unsigned long *stack;
394 int i;
Andi Kleen151f8cc2006-09-26 10:52:37 +0200395 const int cpu = smp_processor_id();
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100396 unsigned long *irqstack_end = (unsigned long *) (cpu_pda(cpu)->irqstackptr);
397 unsigned long *irqstack = (unsigned long *) (cpu_pda(cpu)->irqstackptr - IRQSTACKSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 // debugging aid: "show_stack(NULL, NULL);" prints the
400 // back trace for this cpu.
401
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100402 if (sp == NULL) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200403 if (task)
404 sp = (unsigned long *)task->thread.sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 else
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100406 sp = (unsigned long *)&sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
408
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100409 stack = sp;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200410 for (i = 0; i < kstack_depth_to_print; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (stack >= irqstack && stack <= irqstack_end) {
412 if (stack == irqstack_end) {
413 stack = (unsigned long *) (irqstack_end[-1]);
414 printk(" <EOI> ");
415 }
416 } else {
417 if (((long) stack & (THREAD_SIZE-1)) == 0)
418 break;
419 }
420 if (i && ((i % 4) == 0))
Ingo Molnar3ac94932006-07-03 00:24:36 -0700421 printk("\n");
422 printk(" %016lx", *stack++);
akpm@osdl.org35faa712005-04-16 15:24:54 -0700423 touch_nmi_watchdog();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200425 show_trace(task, regs, sp, bp);
Jan Beulichb538ed22006-06-26 13:57:32 +0200426}
427
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200428void show_stack(struct task_struct *task, unsigned long *sp)
Jan Beulichb538ed22006-06-26 13:57:32 +0200429{
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200430 _show_stack(task, NULL, sp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
433/*
434 * The architecture-independent dump_stack generator
435 */
436void dump_stack(void)
437{
Arjan van de Venbc850d62008-01-30 13:33:07 +0100438 unsigned long bp = 0;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200439 unsigned long stack;
Arjan van de Ven57c351d2007-11-26 20:42:19 +0100440
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100441#ifdef CONFIG_FRAME_POINTER
442 if (!bp)
443 asm("movq %%rbp, %0" : "=r" (bp):);
444#endif
445
Arjan van de Ven57c351d2007-11-26 20:42:19 +0100446 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
447 current->pid, current->comm, print_tainted(),
448 init_utsname()->release,
449 (int)strcspn(init_utsname()->version, " "),
450 init_utsname()->version);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200451 show_trace(NULL, NULL, &stack, bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
454EXPORT_SYMBOL(dump_stack);
455
456void show_registers(struct pt_regs *regs)
457{
458 int i;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100459 unsigned long sp;
Andi Kleen151f8cc2006-09-26 10:52:37 +0200460 const int cpu = smp_processor_id();
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100461 struct task_struct *cur = cpu_pda(cpu)->pcurrent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100463 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 printk("CPU %d ", cpu);
465 __show_regs(regs);
466 printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
Al Viroe4f17c42006-01-12 01:05:38 -0800467 cur->comm, cur->pid, task_thread_info(cur), cur);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 /*
470 * When in-kernel, we also print out the stack and code at the
471 * time of the fault..
472 */
Arjan van de Vena25bd942008-01-30 13:33:08 +0100473 if (!user_mode(regs)) {
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200474 unsigned int code_prologue = code_bytes * 43 / 64;
475 unsigned int code_len = code_bytes;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100476 unsigned char c;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200477 u8 *ip;
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 printk("Stack: ");
Arjan van de Venbc850d62008-01-30 13:33:07 +0100480 _show_stack(NULL, regs, (unsigned long *)sp, regs->bp);
Arjan van de Vena25bd942008-01-30 13:33:08 +0100481 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Arjan van de Vena25bd942008-01-30 13:33:08 +0100483 printk(KERN_EMERG "Code: ");
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200484
485 ip = (u8 *)regs->ip - code_prologue;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100486 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
487 /* try starting at RIP */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200488 ip = (u8 *)regs->ip;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100489 code_len = code_len - code_prologue + 1;
490 }
491 for (i = 0; i < code_len; i++, ip++) {
492 if (ip < (u8 *)PAGE_OFFSET ||
493 probe_kernel_address(ip, c)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 printk(" Bad RIP value.");
495 break;
496 }
Arjan van de Vena25bd942008-01-30 13:33:08 +0100497 if (ip == (u8 *)regs->ip)
498 printk("<%02x> ", c);
499 else
500 printk("%02x ", c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502 }
503 printk("\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200504}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100506int is_valid_bugaddr(unsigned long ip)
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800507{
508 unsigned short ud2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100510 if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2)))
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800511 return 0;
512
513 return ud2 == 0x0b0f;
514}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Andi Kleen39743c92007-10-19 20:35:03 +0200516static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517static int die_owner = -1;
Corey Minyardcdc60a42006-05-08 15:17:22 +0200518static unsigned int die_nest_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100520unsigned __kprobes long oops_begin(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
Andrew Mortonb39b7032007-06-08 13:47:01 -0700522 int cpu;
Jan Beulich12091402005-09-12 18:49:24 +0200523 unsigned long flags;
524
Andrew Mortonabf0f102006-09-26 10:52:36 +0200525 oops_enter();
526
Jan Beulich12091402005-09-12 18:49:24 +0200527 /* racy, but better than risking deadlock. */
Andi Kleen39743c92007-10-19 20:35:03 +0200528 raw_local_irq_save(flags);
Andrew Mortonb39b7032007-06-08 13:47:01 -0700529 cpu = smp_processor_id();
Andi Kleen39743c92007-10-19 20:35:03 +0200530 if (!__raw_spin_trylock(&die_lock)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 if (cpu == die_owner)
532 /* nested oops. should stop eventually */;
533 else
Andi Kleen39743c92007-10-19 20:35:03 +0200534 __raw_spin_lock(&die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
Corey Minyardcdc60a42006-05-08 15:17:22 +0200536 die_nest_count++;
Jan Beulich12091402005-09-12 18:49:24 +0200537 die_owner = cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 console_verbose();
Jan Beulich12091402005-09-12 18:49:24 +0200539 bust_spinlocks(1);
540 return flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541}
542
Jan Beulich22f59912008-01-30 13:31:23 +0100543void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
545 die_owner = -1;
Jan Beulich12091402005-09-12 18:49:24 +0200546 bust_spinlocks(0);
Corey Minyardcdc60a42006-05-08 15:17:22 +0200547 die_nest_count--;
Andi Kleen39743c92007-10-19 20:35:03 +0200548 if (!die_nest_count)
Corey Minyardcdc60a42006-05-08 15:17:22 +0200549 /* Nest count reaches zero, release the lock. */
Andi Kleen39743c92007-10-19 20:35:03 +0200550 __raw_spin_unlock(&die_lock);
551 raw_local_irq_restore(flags);
Jan Beulich22f59912008-01-30 13:31:23 +0100552 if (!regs) {
553 oops_exit();
554 return;
555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 if (panic_on_oops)
Horms012c4372006-08-13 23:24:22 -0700557 panic("Fatal exception");
Andrew Mortonabf0f102006-09-26 10:52:36 +0200558 oops_exit();
Jan Beulich22f59912008-01-30 13:31:23 +0100559 do_exit(signr);
Jan Beulich12091402005-09-12 18:49:24 +0200560}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
Alexander van Heukelume423f492008-07-02 01:31:03 +0200562int __kprobes __die(const char *str, struct pt_regs *regs, long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
Alexander van Heukelume423f492008-07-02 01:31:03 +0200564 printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#ifdef CONFIG_PREEMPT
566 printk("PREEMPT ");
567#endif
568#ifdef CONFIG_SMP
569 printk("SMP ");
570#endif
571#ifdef CONFIG_DEBUG_PAGEALLOC
572 printk("DEBUG_PAGEALLOC");
573#endif
574 printk("\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200575 if (notify_die(DIE_OOPS, str, regs, err,
576 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
Jan Beulich22f59912008-01-30 13:31:23 +0100577 return 1;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 show_registers(regs);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700580 add_taint(TAINT_DIE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 /* Executive summary in case the oops scrolled away */
582 printk(KERN_ALERT "RIP ");
Arjan van de Venaafbd7e2008-01-30 13:33:08 +0100583 printk_address(regs->ip, 1);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100584 printk(" RSP <%016lx>\n", regs->sp);
Vivek Goyal8bcc5282006-04-18 12:35:13 +0200585 if (kexec_should_crash(current))
586 crash_kexec(regs);
Jan Beulich22f59912008-01-30 13:31:23 +0100587 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200590void die(const char *str, struct pt_regs *regs, long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Jan Beulich12091402005-09-12 18:49:24 +0200592 unsigned long flags = oops_begin();
593
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800594 if (!user_mode(regs))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100595 report_bug(regs->ip, regs);
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800596
Jan Beulich22f59912008-01-30 13:31:23 +0100597 if (__die(str, regs, err))
598 regs = NULL;
599 oops_end(flags, regs, SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200602notrace __kprobes void
603die_nmi(char *str, struct pt_regs *regs, int do_panic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Jason Wessel737a4602008-03-07 16:34:16 -0600605 unsigned long flags;
Jan Beulich12091402005-09-12 18:49:24 +0200606
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200607 if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP)
Jason Wessel737a4602008-03-07 16:34:16 -0600608 return;
609
610 flags = oops_begin();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 /*
612 * We are in trouble anyway, lets at least try
613 * to get a message out.
614 */
Cyrill Gorcunove56b3a12008-05-24 19:36:32 +0400615 printk(KERN_EMERG "%s", str);
616 printk(" on CPU%d, ip %08lx, registers:\n",
617 smp_processor_id(), regs->ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 show_registers(regs);
Vivek Goyal8bcc5282006-04-18 12:35:13 +0200619 if (kexec_should_crash(current))
620 crash_kexec(regs);
Andi Kleenfac58552006-09-26 10:52:27 +0200621 if (do_panic || panic_on_oops)
622 panic("Non maskable interrupt");
Jan Beulich22f59912008-01-30 13:31:23 +0100623 oops_end(flags, NULL, SIGBUS);
Corey Minyard8b1ffe952006-05-08 15:17:25 +0200624 nmi_exit();
625 local_irq_enable();
Jan Beulich22f59912008-01-30 13:31:23 +0100626 do_exit(SIGBUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200629static void __kprobes
630do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
631 long error_code, siginfo_t *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
Jan Beulich6e3f3612006-01-11 22:42:14 +0100633 struct task_struct *tsk = current;
634
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200635 if (!user_mode(regs))
636 goto kernel_trap;
Andi Kleend1895182007-05-02 19:27:05 +0200637
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200638 /*
639 * We want error_code and trap_no set for userspace faults and
640 * kernelspace faults which result in die(), but not
641 * kernelspace faults which are fixed up. die() gives the
642 * process no chance to handle the signal and notice the
643 * kernel fault information, so that won't result in polluting
644 * the information about previously queued, but not yet
645 * delivered, faults. See also do_general_protection below.
646 */
647 tsk->thread.error_code = error_code;
648 tsk->thread.trap_no = trapnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200650 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
651 printk_ratelimit()) {
652 printk(KERN_INFO
653 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
654 tsk->comm, tsk->pid, str,
655 regs->ip, regs->sp, error_code);
656 print_vma_addr(" in ", regs->ip);
657 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200660 if (info)
661 force_sig_info(signr, info, tsk);
662 else
663 force_sig(signr, tsk);
664 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200666kernel_trap:
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100667 if (!fixup_exception(regs)) {
668 tsk->thread.error_code = error_code;
669 tsk->thread.trap_no = trapnr;
670 die(str, regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100672 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
675#define DO_ERROR(trapnr, signr, str, name) \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200676asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
677{ \
678 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
679 == NOTIFY_STOP) \
680 return; \
Andi Kleen40e59a62006-05-15 18:19:47 +0200681 conditional_sti(regs); \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200682 do_trap(trapnr, signr, str, regs, error_code, NULL); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200685#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
686asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
687{ \
688 siginfo_t info; \
689 info.si_signo = signr; \
690 info.si_errno = 0; \
691 info.si_code = sicode; \
692 info.si_addr = (void __user *)siaddr; \
693 trace_hardirqs_fixup(); \
694 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
695 == NOTIFY_STOP) \
696 return; \
Andi Kleen40e59a62006-05-15 18:19:47 +0200697 conditional_sti(regs); \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200698 do_trap(trapnr, signr, str, regs, error_code, &info); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200701DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
702DO_ERROR(4, SIGSEGV, "overflow", overflow)
703DO_ERROR(5, SIGSEGV, "bounds", bounds)
704DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
705DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200707DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
Andi Kleen40e59a62006-05-15 18:19:47 +0200709
710/* Runs on IST stack */
711asmlinkage void do_stack_segment(struct pt_regs *regs, long error_code)
712{
713 if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
714 12, SIGBUS) == NOTIFY_STOP)
715 return;
716 preempt_conditional_sti(regs);
717 do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL);
718 preempt_conditional_cli(regs);
719}
Jan Beulicheca37c12006-01-11 22:42:17 +0100720
721asmlinkage void do_double_fault(struct pt_regs * regs, long error_code)
722{
723 static const char str[] = "double fault";
724 struct task_struct *tsk = current;
725
726 /* Return not checked because double check cannot be ignored */
727 notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV);
728
729 tsk->thread.error_code = error_code;
730 tsk->thread.trap_no = 8;
731
732 /* This is always a kernel trap and never fixable (and thus must
733 never return). */
734 for (;;)
735 die(str, regs, error_code);
736}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200738asmlinkage void __kprobes
739do_general_protection(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740{
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200741 struct task_struct *tsk;
Jan Beulich6e3f3612006-01-11 22:42:14 +0100742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 conditional_sti(regs);
744
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200745 tsk = current;
746 if (!user_mode(regs))
747 goto gp_in_kernel;
Andi Kleend1895182007-05-02 19:27:05 +0200748
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200749 tsk->thread.error_code = error_code;
750 tsk->thread.trap_no = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200752 if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
753 printk_ratelimit()) {
754 printk(KERN_INFO
755 "%s[%d] general protection ip:%lx sp:%lx error:%lx",
756 tsk->comm, tsk->pid,
757 regs->ip, regs->sp, error_code);
758 print_vma_addr(" in ", regs->ip);
759 printk("\n");
760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200762 force_sig(SIGSEGV, tsk);
763 return;
764
765gp_in_kernel:
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100766 if (fixup_exception(regs))
767 return;
Andi Kleend1895182007-05-02 19:27:05 +0200768
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100769 tsk->thread.error_code = error_code;
770 tsk->thread.trap_no = 13;
771 if (notify_die(DIE_GPF, "general protection fault", regs,
772 error_code, 13, SIGSEGV) == NOTIFY_STOP)
773 return;
774 die("general protection fault", regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200777static notrace __kprobes void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200778mem_parity_error(unsigned char reason, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
Don Zickusc41c5cd2006-09-26 10:52:27 +0200780 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
781 reason);
Andi Kleen9c5f8be2006-12-07 02:14:03 +0100782 printk(KERN_EMERG "You have some hardware problem, likely on the PCI bus.\n");
Don Zickusc41c5cd2006-09-26 10:52:27 +0200783
Dave Jiangc0d12172007-07-19 01:49:46 -0700784#if defined(CONFIG_EDAC)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200785 if (edac_handler_set()) {
Dave Jiangc0d12172007-07-19 01:49:46 -0700786 edac_atomic_assert_error();
787 return;
788 }
789#endif
790
Don Zickus8da5add2006-09-26 10:52:27 +0200791 if (panic_on_unrecovered_nmi)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200792 panic("NMI: Not continuing");
793
794 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 /* Clear and disable the memory parity error line. */
797 reason = (reason & 0xf) | 4;
798 outb(reason, 0x61);
799}
800
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200801static notrace __kprobes void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200802io_check_error(unsigned char reason, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
804 printk("NMI: IOCK error (debug interrupt?)\n");
805 show_registers(regs);
806
807 /* Re-enable the IOCK line, wait for a few seconds */
808 reason = (reason & 0xf) | 8;
809 outb(reason, 0x61);
810 mdelay(2000);
811 reason &= ~8;
812 outb(reason, 0x61);
813}
814
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200815static notrace __kprobes void
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100816unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200817{
Jason Wesseld3597522008-02-15 14:55:53 -0600818 if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
819 return;
Don Zickusc41c5cd2006-09-26 10:52:27 +0200820 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
821 reason);
822 printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n");
Don Zickus8da5add2006-09-26 10:52:27 +0200823
824 if (panic_on_unrecovered_nmi)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200825 panic("NMI: Not continuing");
Don Zickus8da5add2006-09-26 10:52:27 +0200826
Don Zickusc41c5cd2006-09-26 10:52:27 +0200827 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828}
829
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700830/* Runs on IST stack. This code must keep interrupts off all the time.
831 Nested NMIs are prevented by the CPU. */
Alexander van Heukelumabd34802008-07-02 18:39:01 +0200832asmlinkage notrace __kprobes void default_do_nmi(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
834 unsigned char reason = 0;
Ashok Raj76e4f662005-06-25 14:55:00 -0700835 int cpu;
836
837 cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200839 /* Only the BSP gets external NMIs from the system. */
Ashok Raj76e4f662005-06-25 14:55:00 -0700840 if (!cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 reason = get_nmi_reason();
842
843 if (!(reason & 0xc0)) {
Jan Beulich6e3f3612006-01-11 22:42:14 +0100844 if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 == NOTIFY_STOP)
846 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 /*
848 * Ok, so this is none of the documented NMI sources,
849 * so it must be the NMI watchdog.
850 */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200851 if (nmi_watchdog_tick(regs, reason))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 return;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200853 if (!do_nmi_callback(regs, cpu))
Don Zickus3adbbcce2006-09-26 10:52:26 +0200854 unknown_nmi_error(reason, regs);
855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 return;
857 }
Jan Beulich6e3f3612006-01-11 22:42:14 +0100858 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200859 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 /* AK: following checks seem to be broken on modern chipsets. FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 if (reason & 0x80)
863 mem_parity_error(reason, regs);
864 if (reason & 0x40)
865 io_check_error(reason, regs);
866}
867
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400868asmlinkage notrace __kprobes void
869do_nmi(struct pt_regs *regs, long error_code)
870{
871 nmi_enter();
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200872
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400873 add_pda(__nmi_count, 1);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200874
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400875 if (!ignore_nmis)
876 default_do_nmi(regs);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200877
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400878 nmi_exit();
879}
880
881void stop_nmi(void)
882{
883 acpi_nmi_disable();
884 ignore_nmis++;
885}
886
887void restart_nmi(void)
888{
889 ignore_nmis--;
890 acpi_nmi_enable();
891}
892
Jan Beulichb556b352006-01-11 22:43:00 +0100893/* runs on IST stack. */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200894asmlinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
Peter Zijlstra143a5d32007-10-25 14:01:10 +0200896 trace_hardirqs_fixup();
897
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200898 if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
899 == NOTIFY_STOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 return;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200901
Andi Kleen40e59a62006-05-15 18:19:47 +0200902 preempt_conditional_sti(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
Andi Kleen40e59a62006-05-15 18:19:47 +0200904 preempt_conditional_cli(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905}
906
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700907/* Help handler running on IST stack to switch back to user stack
908 for scheduling or signal handling. The actual stack switch is done in
909 entry.S */
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100910asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700912 struct pt_regs *regs = eregs;
913 /* Did already sync */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100914 if (eregs == (struct pt_regs *)eregs->sp)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700915 ;
916 /* Exception from user space */
Vincent Hanquez76381fe2005-06-23 00:08:46 -0700917 else if (user_mode(eregs))
Al Virobb049232006-01-12 01:05:38 -0800918 regs = task_pt_regs(current);
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700919 /* Exception from kernel and interrupts are enabled. Move to
920 kernel process stack. */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100921 else if (eregs->flags & X86_EFLAGS_IF)
922 regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs));
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700923 if (eregs != regs)
924 *regs = *eregs;
925 return regs;
926}
927
928/* runs on IST stack. */
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -0700929asmlinkage void __kprobes do_debug(struct pt_regs * regs,
930 unsigned long error_code)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700931{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 struct task_struct *tsk = current;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200933 unsigned long condition;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 siginfo_t info;
935
Peter Zijlstra000f4a92007-11-26 20:42:19 +0100936 trace_hardirqs_fixup();
937
Vincent Hanqueze9129e52005-06-23 00:08:46 -0700938 get_debugreg(condition, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Roland McGrath10faa812008-01-30 13:30:54 +0100940 /*
941 * The processor cleared BTF, so don't mark that we need it set.
942 */
943 clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
944 tsk->thread.debugctlmsr = 0;
945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
Andi Kleendaeeafe2005-04-16 15:25:13 -0700947 SIGTRAP) == NOTIFY_STOP)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700948 return;
Andi Kleendaeeafe2005-04-16 15:25:13 -0700949
John Blackwooda65d17c2006-02-12 14:34:58 -0800950 preempt_conditional_sti(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 /* Mask out spurious debug traps due to lazy DR7 setting */
953 if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200954 if (!tsk->thread.debugreg7)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 goto clear_dr7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
957
958 tsk->thread.debugreg6 = condition;
959
Roland McGrathe1f28772008-01-30 13:30:50 +0100960 /*
961 * Single-stepping through TF: make sure we ignore any events in
962 * kernel space (but re-enable TF when returning to user mode).
963 */
Andi Kleendaeeafe2005-04-16 15:25:13 -0700964 if (condition & DR_STEP) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200965 if (!user_mode(regs))
966 goto clear_TF_reenable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 }
968
969 /* Ok, finally something we can handle */
970 tsk->thread.trap_no = 1;
971 tsk->thread.error_code = error_code;
972 info.si_signo = SIGTRAP;
973 info.si_errno = 0;
974 info.si_code = TRAP_BRKPT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100975 info.si_addr = user_mode(regs) ? (void __user *)regs->ip : NULL;
John Blackwood01b8faa2006-01-11 22:44:15 +0100976 force_sig_info(SIGTRAP, &info, tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978clear_dr7:
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200979 set_debugreg(0, 7);
John Blackwooda65d17c2006-02-12 14:34:58 -0800980 preempt_conditional_cli(regs);
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700981 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983clear_TF_reenable:
984 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
Glauber de Oliveira Costa053de042008-01-30 13:31:27 +0100985 regs->flags &= ~X86_EFLAGS_TF;
John Blackwooda65d17c2006-02-12 14:34:58 -0800986 preempt_conditional_cli(regs);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200987 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988}
989
Jan Beulich6e3f3612006-01-11 22:42:14 +0100990static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991{
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100992 if (fixup_exception(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 return 1;
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100994
Jan Beulich6e3f3612006-01-11 22:42:14 +0100995 notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
Andi Kleen3a848f62005-04-16 15:25:06 -0700996 /* Illegal floating point operation in the kernel */
Jan Beulich6e3f3612006-01-11 22:42:14 +0100997 current->thread.trap_no = trapnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 die(str, regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 return 0;
1000}
1001
1002/*
1003 * Note that we play around with the 'TS' bit in an attempt to get
1004 * the correct behaviour even in the presence of the asynchronous
1005 * IRQ13 behaviour
1006 */
1007asmlinkage void do_coprocessor_error(struct pt_regs *regs)
1008{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001009 void __user *ip = (void __user *)(regs->ip);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001010 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 siginfo_t info;
1012 unsigned short cwd, swd;
1013
1014 conditional_sti(regs);
Vincent Hanquez76381fe2005-06-23 00:08:46 -07001015 if (!user_mode(regs) &&
Jan Beulich6e3f3612006-01-11 22:42:14 +01001016 kernel_math_error(regs, "kernel x87 math error", 16))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 return;
1018
1019 /*
1020 * Save the info for the exception handler and clear the error.
1021 */
1022 task = current;
1023 save_init_fpu(task);
1024 task->thread.trap_no = 16;
1025 task->thread.error_code = 0;
1026 info.si_signo = SIGFPE;
1027 info.si_errno = 0;
1028 info.si_code = __SI_FAULT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001029 info.si_addr = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 /*
1031 * (~cwd & swd) will mask out exceptions that are not set to unmasked
1032 * status. 0x3f is the exception bits in these regs, 0x200 is the
1033 * C1 reg you need in case of a stack fault, 0x040 is the stack
1034 * fault bit. We should only be taking one exception at a time,
1035 * so if this combination doesn't produce any single exception,
1036 * then we have a bad program that isn't synchronizing its FPU usage
1037 * and it will suffer the consequences since we won't be able to
1038 * fully reproduce the context of the exception
1039 */
1040 cwd = get_fpu_cwd(task);
1041 swd = get_fpu_swd(task);
Chuck Ebbertff347b22005-09-12 18:49:25 +02001042 switch (swd & ~cwd & 0x3f) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001043 case 0x000: /* No unmasked exception */
1044 default: /* Multiple exceptions */
1045 break;
1046 case 0x001: /* Invalid Op */
1047 /*
1048 * swd & 0x240 == 0x040: Stack Underflow
1049 * swd & 0x240 == 0x240: Stack Overflow
1050 * User must clear the SF bit (0x40) if set
1051 */
1052 info.si_code = FPE_FLTINV;
1053 break;
1054 case 0x002: /* Denormalize */
1055 case 0x010: /* Underflow */
1056 info.si_code = FPE_FLTUND;
1057 break;
1058 case 0x004: /* Zero Divide */
1059 info.si_code = FPE_FLTDIV;
1060 break;
1061 case 0x008: /* Overflow */
1062 info.si_code = FPE_FLTOVF;
1063 break;
1064 case 0x020: /* Precision */
1065 info.si_code = FPE_FLTRES;
1066 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
1068 force_sig_info(SIGFPE, &info, task);
1069}
1070
1071asmlinkage void bad_intr(void)
1072{
1073 printk("bad interrupt");
1074}
1075
1076asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs)
1077{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001078 void __user *ip = (void __user *)(regs->ip);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001079 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 siginfo_t info;
1081 unsigned short mxcsr;
1082
1083 conditional_sti(regs);
Vincent Hanquez76381fe2005-06-23 00:08:46 -07001084 if (!user_mode(regs) &&
Jan Beulich6e3f3612006-01-11 22:42:14 +01001085 kernel_math_error(regs, "kernel simd math error", 19))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 return;
1087
1088 /*
1089 * Save the info for the exception handler and clear the error.
1090 */
1091 task = current;
1092 save_init_fpu(task);
1093 task->thread.trap_no = 19;
1094 task->thread.error_code = 0;
1095 info.si_signo = SIGFPE;
1096 info.si_errno = 0;
1097 info.si_code = __SI_FAULT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001098 info.si_addr = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 /*
1100 * The SIMD FPU exceptions are handled a little differently, as there
1101 * is only a single status/control register. Thus, to determine which
1102 * unmasked exception was caught we must mask the exception mask bits
1103 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
1104 */
1105 mxcsr = get_fpu_mxcsr(task);
1106 switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001107 case 0x000:
1108 default:
1109 break;
1110 case 0x001: /* Invalid Op */
1111 info.si_code = FPE_FLTINV;
1112 break;
1113 case 0x002: /* Denormalize */
1114 case 0x010: /* Underflow */
1115 info.si_code = FPE_FLTUND;
1116 break;
1117 case 0x004: /* Zero Divide */
1118 info.si_code = FPE_FLTDIV;
1119 break;
1120 case 0x008: /* Overflow */
1121 info.si_code = FPE_FLTOVF;
1122 break;
1123 case 0x020: /* Precision */
1124 info.si_code = FPE_FLTRES;
1125 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 }
1127 force_sig_info(SIGFPE, &info, task);
1128}
1129
1130asmlinkage void do_spurious_interrupt_bug(struct pt_regs * regs)
1131{
1132}
1133
1134asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void)
1135{
1136}
1137
Jacob Shin89b831e2005-11-05 17:25:53 +01001138asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void)
1139{
1140}
1141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142/*
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001143 * 'math_state_restore()' saves the current math information in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 * old math state array, and gets the new ones from the current task
1145 *
1146 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
1147 * Don't touch unless you *really* know how it works.
1148 */
1149asmlinkage void math_state_restore(void)
1150{
1151 struct task_struct *me = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Suresh Siddhaaa283f42008-03-10 15:28:05 -07001153 if (!used_math()) {
1154 local_irq_enable();
1155 /*
1156 * does a slab alloc which can sleep
1157 */
1158 if (init_fpu(me)) {
1159 /*
1160 * ran out of memory!
1161 */
1162 do_group_exit(SIGKILL);
1163 return;
1164 }
1165 local_irq_disable();
1166 }
1167
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001168 clts(); /* Allow maths ops (or we recurse) */
Suresh Siddha61c46282008-03-10 15:28:04 -07001169 restore_fpu_checking(&me->thread.xstate->fxsave);
Al Viroe4f17c42006-01-12 01:05:38 -08001170 task_thread_info(me)->status |= TS_USEDFPU;
Arjan van de Vene07e23e2006-09-26 10:52:36 +02001171 me->fpu_counter++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
Glauber de Oliveira Costa21db5582008-01-30 13:31:10 +01001173EXPORT_SYMBOL_GPL(math_state_restore);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175void __init trap_init(void)
1176{
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001177 set_intr_gate(0, &divide_error);
1178 set_intr_gate_ist(1, &debug, DEBUG_STACK);
1179 set_intr_gate_ist(2, &nmi, NMI_STACK);
1180 set_system_gate_ist(3, &int3, DEBUG_STACK); /* int3 can be called from all */
1181 set_system_gate(4, &overflow); /* int4 can be called from all */
1182 set_intr_gate(5, &bounds);
1183 set_intr_gate(6, &invalid_op);
1184 set_intr_gate(7, &device_not_available);
1185 set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK);
1186 set_intr_gate(9, &coprocessor_segment_overrun);
1187 set_intr_gate(10, &invalid_TSS);
1188 set_intr_gate(11, &segment_not_present);
1189 set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK);
1190 set_intr_gate(13, &general_protection);
1191 set_intr_gate(14, &page_fault);
1192 set_intr_gate(15, &spurious_interrupt_bug);
1193 set_intr_gate(16, &coprocessor_error);
1194 set_intr_gate(17, &alignment_check);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195#ifdef CONFIG_X86_MCE
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001196 set_intr_gate_ist(18, &machine_check, MCE_STACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197#endif
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001198 set_intr_gate(19, &simd_coprocessor_error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200#ifdef CONFIG_IA32_EMULATION
1201 set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
1202#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 /*
Suresh Siddha61c46282008-03-10 15:28:04 -07001204 * initialize the per thread extended state:
1205 */
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +02001206 init_thread_xstate();
Suresh Siddha61c46282008-03-10 15:28:04 -07001207 /*
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001208 * Should be a barrier for any external CPU state:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 */
1210 cpu_init();
1211}
1212
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001213static int __init oops_setup(char *s)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001214{
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001215 if (!s)
1216 return -EINVAL;
1217 if (!strcmp(s, "panic"))
1218 panic_on_oops = 1;
1219 return 0;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001220}
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001221early_param("oops", oops_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223static int __init kstack_setup(char *s)
1224{
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001225 if (!s)
1226 return -EINVAL;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001227 kstack_depth_to_print = simple_strtoul(s, NULL, 0);
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001228 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001230early_param("kstack", kstack_setup);
Arjan van de Vena25bd942008-01-30 13:33:08 +01001231
Arjan van de Vena25bd942008-01-30 13:33:08 +01001232static int __init code_bytes_setup(char *s)
1233{
1234 code_bytes = simple_strtoul(s, NULL, 0);
1235 if (code_bytes > 8192)
1236 code_bytes = 8192;
1237
1238 return 1;
1239}
1240__setup("code_bytes=", code_bytes_setup);