blob: 5df5d2e97eceeccef74fb6c8e451d19e9846a406 [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>
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -030035#include <linux/smp.h>
36#include <linux/io.h>
Glauber de Oliveira Costae32ede12008-03-19 14:25:35 -030037
Dave Jiangc0d12172007-07-19 01:49:46 -070038#if defined(CONFIG_EDAC)
39#include <linux/edac.h>
40#endif
41
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020042#include <asm/stacktrace.h>
43#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/debugreg.h>
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020045#include <asm/atomic.h>
46#include <asm/system.h>
47#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <asm/desc.h>
49#include <asm/i387.h>
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020050#include <asm/pgalloc.h>
51#include <asm/proto.h>
52#include <asm/pda.h>
Jaswinder Singh6ac8d512008-07-15 21:09:13 +053053#include <asm/traps.h>
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020054
55#include <mach_traps.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +040057int panic_on_unrecovered_nmi;
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020058int kstack_depth_to_print = 12;
Arjan van de Vena25bd942008-01-30 13:33:08 +010059static unsigned int code_bytes = 64;
Alexander van Heukelumbadc7652008-07-02 01:30:30 +020060static int ignore_nmis;
61static int die_counter;
Arjan van de Vena25bd942008-01-30 13:33:08 +010062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static inline void conditional_sti(struct pt_regs *regs)
64{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010065 if (regs->flags & X86_EFLAGS_IF)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 local_irq_enable();
67}
68
John Blackwooda65d17c2006-02-12 14:34:58 -080069static inline void preempt_conditional_sti(struct pt_regs *regs)
70{
Ingo Molnare8bff742008-02-13 20:21:06 +010071 inc_preempt_count();
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010072 if (regs->flags & X86_EFLAGS_IF)
John Blackwooda65d17c2006-02-12 14:34:58 -080073 local_irq_enable();
74}
75
76static inline void preempt_conditional_cli(struct pt_regs *regs)
77{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010078 if (regs->flags & X86_EFLAGS_IF)
John Blackwooda65d17c2006-02-12 14:34:58 -080079 local_irq_disable();
Andi Kleen40e59a62006-05-15 18:19:47 +020080 /* Make sure to not schedule here because we could be running
81 on an exception stack. */
Ingo Molnare8bff742008-02-13 20:21:06 +010082 dec_preempt_count();
John Blackwooda65d17c2006-02-12 14:34:58 -080083}
84
Arjan van de Venbc850d62008-01-30 13:33:07 +010085void printk_address(unsigned long address, int reliable)
Ingo Molnar3ac94932006-07-03 00:24:36 -070086{
Gustavo F. Padovan48e2bd52008-08-02 12:50:37 -030087 printk(" [<%016lx>] %s%pS\n",
88 address, reliable ? "" : "? ", (void *) address);
Harvey Harrisona5ff6772008-01-30 13:33:25 +010089}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Andi Kleen0a658002005-04-16 15:25:17 -070091static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
Andi Kleenc0b766f2006-09-26 10:52:34 +020092 unsigned *usedp, char **idp)
Andi Kleen0a658002005-04-16 15:25:17 -070093{
Jan Beulichb556b352006-01-11 22:43:00 +010094 static char ids[][8] = {
Andi Kleen0a658002005-04-16 15:25:17 -070095 [DEBUG_STACK - 1] = "#DB",
96 [NMI_STACK - 1] = "NMI",
97 [DOUBLEFAULT_STACK - 1] = "#DF",
98 [STACKFAULT_STACK - 1] = "#SS",
99 [MCE_STACK - 1] = "#MC",
Jan Beulichb556b352006-01-11 22:43:00 +0100100#if DEBUG_STKSZ > EXCEPTION_STKSZ
Gustavo F. Padovan48e2bd52008-08-02 12:50:37 -0300101 [N_EXCEPTION_STACKS ...
102 N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]"
Jan Beulichb556b352006-01-11 22:43:00 +0100103#endif
Andi Kleen0a658002005-04-16 15:25:17 -0700104 };
105 unsigned k;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700107 /*
108 * Iterate over all exception stacks, and figure out whether
109 * 'stack' is in one of them:
110 */
Andi Kleen0a658002005-04-16 15:25:17 -0700111 for (k = 0; k < N_EXCEPTION_STACKS; k++) {
Keith Owensf5741642006-09-26 10:52:38 +0200112 unsigned long end = per_cpu(orig_ist, cpu).ist[k];
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700113 /*
114 * Is 'stack' above this exception frame's end?
115 * If yes then skip to the next frame.
116 */
Andi Kleen0a658002005-04-16 15:25:17 -0700117 if (stack >= end)
118 continue;
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700119 /*
120 * Is 'stack' above this exception frame's start address?
121 * If yes then we found the right frame.
122 */
Andi Kleen0a658002005-04-16 15:25:17 -0700123 if (stack >= end - EXCEPTION_STKSZ) {
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700124 /*
125 * Make sure we only iterate through an exception
126 * stack once. If it comes up for the second time
127 * then there's something wrong going on - just
128 * break out and return NULL:
129 */
Andi Kleen0a658002005-04-16 15:25:17 -0700130 if (*usedp & (1U << k))
131 break;
132 *usedp |= 1U << k;
133 *idp = ids[k];
134 return (unsigned long *)end;
135 }
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700136 /*
137 * If this is a debug stack, and if it has a larger size than
138 * the usual exception stacks, then 'stack' might still
139 * be within the lower portion of the debug stack:
140 */
Jan Beulichb556b352006-01-11 22:43:00 +0100141#if DEBUG_STKSZ > EXCEPTION_STKSZ
142 if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
143 unsigned j = N_EXCEPTION_STACKS - 1;
144
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700145 /*
146 * Black magic. A large debug stack is composed of
147 * multiple exception stack entries, which we
148 * iterate through now. Dont look:
149 */
Jan Beulichb556b352006-01-11 22:43:00 +0100150 do {
151 ++j;
152 end -= EXCEPTION_STKSZ;
153 ids[j][4] = '1' + (j - N_EXCEPTION_STACKS);
154 } while (stack < end - EXCEPTION_STKSZ);
155 if (*usedp & (1U << j))
156 break;
157 *usedp |= 1U << j;
158 *idp = ids[j];
159 return (unsigned long *)end;
160 }
161#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163 return NULL;
Andi Kleen0a658002005-04-16 15:25:17 -0700164}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166/*
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300167 * x86-64 can have up to three kernel stacks:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 * process stack
169 * interrupt stack
Andi Kleen0a658002005-04-16 15:25:17 -0700170 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 */
172
Arjan van de Vene4a94562008-01-30 13:33:07 +0100173static inline int valid_stack_ptr(struct thread_info *tinfo,
174 void *p, unsigned int size, void *end)
Andi Kleenc547c772006-11-28 20:12:59 +0100175{
Jan Engelhardtade1af72008-01-30 13:33:23 +0100176 void *t = tinfo;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100177 if (end) {
178 if (p < end && p >= (end-THREAD_SIZE))
179 return 1;
180 else
181 return 0;
182 }
183 return p > t && p < t + THREAD_SIZE - size;
184}
185
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100186/* The form of the top of the frame on the stack */
187struct stack_frame {
188 struct stack_frame *next_frame;
189 unsigned long return_address;
190};
191
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200192static inline unsigned long
193print_context_stack(struct thread_info *tinfo,
194 unsigned long *stack, unsigned long bp,
195 const struct stacktrace_ops *ops, void *data,
196 unsigned long *end)
Arjan van de Vene4a94562008-01-30 13:33:07 +0100197{
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100198 struct stack_frame *frame = (struct stack_frame *)bp;
199
200 while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
201 unsigned long addr;
202
203 addr = *stack;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100204 if (__kernel_text_address(addr)) {
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100205 if ((unsigned long) stack == bp + 8) {
206 ops->address(data, addr, 1);
207 frame = frame->next_frame;
208 bp = (unsigned long) frame;
209 } else {
210 ops->address(data, addr, bp == 0);
211 }
Arjan van de Vene4a94562008-01-30 13:33:07 +0100212 }
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100213 stack++;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100214 }
215 return bp;
Andi Kleenc547c772006-11-28 20:12:59 +0100216}
217
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200218void dump_trace(struct task_struct *task, struct pt_regs *regs,
Arjan van de Venbc850d62008-01-30 13:33:07 +0100219 unsigned long *stack, unsigned long bp,
Jan Beulich9689ba82007-10-17 18:04:37 +0200220 const struct stacktrace_ops *ops, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Andrew Mortonda689332006-12-07 02:14:02 +0100222 const unsigned cpu = get_cpu();
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300223 unsigned long *irqstack_end = (unsigned long *)cpu_pda(cpu)->irqstackptr;
Andi Kleen0a658002005-04-16 15:25:17 -0700224 unsigned used = 0;
Andi Kleenc547c772006-11-28 20:12:59 +0100225 struct thread_info *tinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200227 if (!task)
228 task = current;
Jan Beulichb538ed22006-06-26 13:57:32 +0200229
Andi Kleenc0b766f2006-09-26 10:52:34 +0200230 if (!stack) {
231 unsigned long dummy;
232 stack = &dummy;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200233 if (task && task != current)
234 stack = (unsigned long *)task->thread.sp;
Jan Beulichb538ed22006-06-26 13:57:32 +0200235 }
236
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100237#ifdef CONFIG_FRAME_POINTER
238 if (!bp) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200239 if (task == current) {
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100240 /* Grab bp right from our regs */
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300241 asm("movq %%rbp, %0" : "=r" (bp) : );
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100242 } else {
243 /* bp is the last reg pushed by switch_to */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200244 bp = *(unsigned long *) task->thread.sp;
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100245 }
246 }
247#endif
248
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700249 /*
250 * Print function call entries in all stacks, starting at the
251 * current stack address. If the stacks consist of nested
252 * exceptions
253 */
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200254 tinfo = task_thread_info(task);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200255 for (;;) {
256 char *id;
Andi Kleen0a658002005-04-16 15:25:17 -0700257 unsigned long *estack_end;
258 estack_end = in_exception_stack(cpu, (unsigned long)stack,
259 &used, &id);
260
261 if (estack_end) {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200262 if (ops->stack(data, id) < 0)
263 break;
Arjan van de Vene4a94562008-01-30 13:33:07 +0100264
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100265 bp = print_context_stack(tinfo, stack, bp, ops,
266 data, estack_end);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200267 ops->stack(data, "<EOE>");
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700268 /*
269 * We link to the next stack via the
270 * second-to-last pointer (index -2 to end) in the
271 * exception stack:
272 */
Andi Kleen0a658002005-04-16 15:25:17 -0700273 stack = (unsigned long *) estack_end[-2];
274 continue;
275 }
276 if (irqstack_end) {
277 unsigned long *irqstack;
278 irqstack = irqstack_end -
279 (IRQSTACKSIZE - 64) / sizeof(*irqstack);
280
281 if (stack >= irqstack && stack < irqstack_end) {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200282 if (ops->stack(data, "IRQ") < 0)
283 break;
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100284 bp = print_context_stack(tinfo, stack, bp,
285 ops, data, irqstack_end);
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700286 /*
287 * We link to the next stack (which would be
288 * the process stack normally) the last
289 * pointer (index -1 to end) in the IRQ stack:
290 */
Andi Kleen0a658002005-04-16 15:25:17 -0700291 stack = (unsigned long *) (irqstack_end[-1]);
292 irqstack_end = NULL;
Andi Kleenc0b766f2006-09-26 10:52:34 +0200293 ops->stack(data, "EOI");
Andi Kleen0a658002005-04-16 15:25:17 -0700294 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296 }
Andi Kleen0a658002005-04-16 15:25:17 -0700297 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
Andi Kleen0a658002005-04-16 15:25:17 -0700299
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700300 /*
Andi Kleenc0b766f2006-09-26 10:52:34 +0200301 * This handles the process stack:
Ingo Molnarc9ca1ba2006-07-03 00:24:36 -0700302 */
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100303 bp = print_context_stack(tinfo, stack, bp, ops, data, NULL);
Andrew Mortonda689332006-12-07 02:14:02 +0100304 put_cpu();
Andi Kleenc0b766f2006-09-26 10:52:34 +0200305}
306EXPORT_SYMBOL(dump_trace);
Ingo Molnar3ac94932006-07-03 00:24:36 -0700307
Andi Kleenc0b766f2006-09-26 10:52:34 +0200308static void
309print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
310{
311 print_symbol(msg, symbol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 printk("\n");
313}
314
Andi Kleenc0b766f2006-09-26 10:52:34 +0200315static void print_trace_warning(void *data, char *msg)
316{
317 printk("%s\n", msg);
318}
319
320static int print_trace_stack(void *data, char *name)
321{
322 printk(" <%s> ", name);
323 return 0;
324}
325
Arjan van de Venbc850d62008-01-30 13:33:07 +0100326static void print_trace_address(void *data, unsigned long addr, int reliable)
Andi Kleenc0b766f2006-09-26 10:52:34 +0200327{
Konrad Rzeszutek1c978b92007-07-17 04:03:56 -0700328 touch_nmi_watchdog();
Arjan van de Venbc850d62008-01-30 13:33:07 +0100329 printk_address(addr, reliable);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200330}
331
Jan Beulich9689ba82007-10-17 18:04:37 +0200332static const struct stacktrace_ops print_trace_ops = {
Andi Kleenc0b766f2006-09-26 10:52:34 +0200333 .warning = print_trace_warning,
334 .warning_symbol = print_trace_warning_symbol,
335 .stack = print_trace_stack,
336 .address = print_trace_address,
337};
338
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200339static void
340show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
341 unsigned long *stack, unsigned long bp, char *log_lvl)
Andi Kleenc0b766f2006-09-26 10:52:34 +0200342{
343 printk("\nCall Trace:\n");
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200344 dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl);
Andi Kleenc0b766f2006-09-26 10:52:34 +0200345 printk("\n");
346}
347
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200348void show_trace(struct task_struct *task, struct pt_regs *regs,
349 unsigned long *stack, unsigned long bp)
350{
351 show_trace_log_lvl(task, regs, stack, bp, "");
352}
353
Andi Kleenc0b766f2006-09-26 10:52:34 +0200354static void
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200355show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
356 unsigned long *sp, unsigned long bp, char *log_lvl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
358 unsigned long *stack;
359 int i;
Andi Kleen151f8cc2006-09-26 10:52:37 +0200360 const int cpu = smp_processor_id();
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300361 unsigned long *irqstack_end =
362 (unsigned long *) (cpu_pda(cpu)->irqstackptr);
363 unsigned long *irqstack =
364 (unsigned long *) (cpu_pda(cpu)->irqstackptr - IRQSTACKSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Gustavo F. Padovan48e2bd52008-08-02 12:50:37 -0300366 /*
367 * debugging aid: "show_stack(NULL, NULL);" prints the
368 * back trace for this cpu.
369 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100371 if (sp == NULL) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200372 if (task)
373 sp = (unsigned long *)task->thread.sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 else
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100375 sp = (unsigned long *)&sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100378 stack = sp;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200379 for (i = 0; i < kstack_depth_to_print; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 if (stack >= irqstack && stack <= irqstack_end) {
381 if (stack == irqstack_end) {
382 stack = (unsigned long *) (irqstack_end[-1]);
383 printk(" <EOI> ");
384 }
385 } else {
386 if (((long) stack & (THREAD_SIZE-1)) == 0)
387 break;
388 }
389 if (i && ((i % 4) == 0))
Ingo Molnar3ac94932006-07-03 00:24:36 -0700390 printk("\n");
391 printk(" %016lx", *stack++);
akpm@osdl.org35faa712005-04-16 15:24:54 -0700392 touch_nmi_watchdog();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200394 show_trace_log_lvl(task, regs, sp, bp, log_lvl);
Jan Beulichb538ed22006-06-26 13:57:32 +0200395}
396
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200397void show_stack(struct task_struct *task, unsigned long *sp)
Jan Beulichb538ed22006-06-26 13:57:32 +0200398{
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200399 show_stack_log_lvl(task, NULL, sp, 0, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
402/*
403 * The architecture-independent dump_stack generator
404 */
405void dump_stack(void)
406{
Arjan van de Venbc850d62008-01-30 13:33:07 +0100407 unsigned long bp = 0;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200408 unsigned long stack;
Arjan van de Ven57c351d2007-11-26 20:42:19 +0100409
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100410#ifdef CONFIG_FRAME_POINTER
411 if (!bp)
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300412 asm("movq %%rbp, %0" : "=r" (bp) : );
Arjan van de Ven80b51f32008-01-30 13:33:07 +0100413#endif
414
Arjan van de Ven57c351d2007-11-26 20:42:19 +0100415 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
416 current->pid, current->comm, print_tainted(),
417 init_utsname()->release,
418 (int)strcspn(init_utsname()->version, " "),
419 init_utsname()->version);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200420 show_trace(NULL, NULL, &stack, bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422EXPORT_SYMBOL(dump_stack);
423
424void show_registers(struct pt_regs *regs)
425{
426 int i;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100427 unsigned long sp;
Andi Kleen151f8cc2006-09-26 10:52:37 +0200428 const int cpu = smp_processor_id();
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100429 struct task_struct *cur = cpu_pda(cpu)->pcurrent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100431 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 printk("CPU %d ", cpu);
433 __show_regs(regs);
434 printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
Al Viroe4f17c42006-01-12 01:05:38 -0800435 cur->comm, cur->pid, task_thread_info(cur), cur);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 /*
438 * When in-kernel, we also print out the stack and code at the
439 * time of the fault..
440 */
Arjan van de Vena25bd942008-01-30 13:33:08 +0100441 if (!user_mode(regs)) {
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200442 unsigned int code_prologue = code_bytes * 43 / 64;
443 unsigned int code_len = code_bytes;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100444 unsigned char c;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200445 u8 *ip;
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 printk("Stack: ");
Alexander van Heukelum7dedcee2008-07-10 21:16:39 +0200448 show_stack_log_lvl(NULL, regs, (unsigned long *)sp,
449 regs->bp, "");
Arjan van de Vena25bd942008-01-30 13:33:08 +0100450 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Arjan van de Vena25bd942008-01-30 13:33:08 +0100452 printk(KERN_EMERG "Code: ");
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200453
454 ip = (u8 *)regs->ip - code_prologue;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100455 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
456 /* try starting at RIP */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200457 ip = (u8 *)regs->ip;
Arjan van de Vena25bd942008-01-30 13:33:08 +0100458 code_len = code_len - code_prologue + 1;
459 }
460 for (i = 0; i < code_len; i++, ip++) {
461 if (ip < (u8 *)PAGE_OFFSET ||
462 probe_kernel_address(ip, c)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 printk(" Bad RIP value.");
464 break;
465 }
Arjan van de Vena25bd942008-01-30 13:33:08 +0100466 if (ip == (u8 *)regs->ip)
467 printk("<%02x> ", c);
468 else
469 printk("%02x ", c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 }
471 }
472 printk("\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200473}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100475int is_valid_bugaddr(unsigned long ip)
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800476{
477 unsigned short ud2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100479 if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2)))
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800480 return 0;
481
482 return ud2 == 0x0b0f;
483}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Andi Kleen39743c92007-10-19 20:35:03 +0200485static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486static int die_owner = -1;
Corey Minyardcdc60a42006-05-08 15:17:22 +0200487static unsigned int die_nest_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100489unsigned __kprobes long oops_begin(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Andrew Mortonb39b7032007-06-08 13:47:01 -0700491 int cpu;
Jan Beulich12091402005-09-12 18:49:24 +0200492 unsigned long flags;
493
Andrew Mortonabf0f102006-09-26 10:52:36 +0200494 oops_enter();
495
Jan Beulich12091402005-09-12 18:49:24 +0200496 /* racy, but better than risking deadlock. */
Andi Kleen39743c92007-10-19 20:35:03 +0200497 raw_local_irq_save(flags);
Andrew Mortonb39b7032007-06-08 13:47:01 -0700498 cpu = smp_processor_id();
Andi Kleen39743c92007-10-19 20:35:03 +0200499 if (!__raw_spin_trylock(&die_lock)) {
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300500 if (cpu == die_owner)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 /* nested oops. should stop eventually */;
502 else
Andi Kleen39743c92007-10-19 20:35:03 +0200503 __raw_spin_lock(&die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
Corey Minyardcdc60a42006-05-08 15:17:22 +0200505 die_nest_count++;
Jan Beulich12091402005-09-12 18:49:24 +0200506 die_owner = cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 console_verbose();
Jan Beulich12091402005-09-12 18:49:24 +0200508 bust_spinlocks(1);
509 return flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}
511
Jan Beulich22f59912008-01-30 13:31:23 +0100512void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
Alexander van Heukelum78cbac62008-07-10 21:14:52 +0200513{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 die_owner = -1;
Jan Beulich12091402005-09-12 18:49:24 +0200515 bust_spinlocks(0);
Corey Minyardcdc60a42006-05-08 15:17:22 +0200516 die_nest_count--;
Andi Kleen39743c92007-10-19 20:35:03 +0200517 if (!die_nest_count)
Corey Minyardcdc60a42006-05-08 15:17:22 +0200518 /* Nest count reaches zero, release the lock. */
Andi Kleen39743c92007-10-19 20:35:03 +0200519 __raw_spin_unlock(&die_lock);
520 raw_local_irq_restore(flags);
Jan Beulich22f59912008-01-30 13:31:23 +0100521 if (!regs) {
522 oops_exit();
523 return;
524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 if (panic_on_oops)
Horms012c4372006-08-13 23:24:22 -0700526 panic("Fatal exception");
Andrew Mortonabf0f102006-09-26 10:52:36 +0200527 oops_exit();
Jan Beulich22f59912008-01-30 13:31:23 +0100528 do_exit(signr);
Jan Beulich12091402005-09-12 18:49:24 +0200529}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Alexander van Heukelume423f492008-07-02 01:31:03 +0200531int __kprobes __die(const char *str, struct pt_regs *regs, long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Alexander van Heukelume423f492008-07-02 01:31:03 +0200533 printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534#ifdef CONFIG_PREEMPT
535 printk("PREEMPT ");
536#endif
537#ifdef CONFIG_SMP
538 printk("SMP ");
539#endif
540#ifdef CONFIG_DEBUG_PAGEALLOC
541 printk("DEBUG_PAGEALLOC");
542#endif
543 printk("\n");
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200544 if (notify_die(DIE_OOPS, str, regs, err,
545 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
Jan Beulich22f59912008-01-30 13:31:23 +0100546 return 1;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 show_registers(regs);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700549 add_taint(TAINT_DIE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 /* Executive summary in case the oops scrolled away */
551 printk(KERN_ALERT "RIP ");
Arjan van de Venaafbd7e2008-01-30 13:33:08 +0100552 printk_address(regs->ip, 1);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100553 printk(" RSP <%016lx>\n", regs->sp);
Vivek Goyal8bcc5282006-04-18 12:35:13 +0200554 if (kexec_should_crash(current))
555 crash_kexec(regs);
Jan Beulich22f59912008-01-30 13:31:23 +0100556 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200559void die(const char *str, struct pt_regs *regs, long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Jan Beulich12091402005-09-12 18:49:24 +0200561 unsigned long flags = oops_begin();
562
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800563 if (!user_mode(regs))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100564 report_bug(regs->ip, regs);
Jeremy Fitzhardingec31a0bf2006-12-08 02:36:22 -0800565
Jan Beulich22f59912008-01-30 13:31:23 +0100566 if (__die(str, regs, err))
567 regs = NULL;
568 oops_end(flags, regs, SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200571notrace __kprobes void
572die_nmi(char *str, struct pt_regs *regs, int do_panic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
Jason Wessel737a4602008-03-07 16:34:16 -0600574 unsigned long flags;
Jan Beulich12091402005-09-12 18:49:24 +0200575
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200576 if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP)
Jason Wessel737a4602008-03-07 16:34:16 -0600577 return;
578
579 flags = oops_begin();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 /*
581 * We are in trouble anyway, lets at least try
582 * to get a message out.
583 */
Cyrill Gorcunove56b3a12008-05-24 19:36:32 +0400584 printk(KERN_EMERG "%s", str);
585 printk(" on CPU%d, ip %08lx, registers:\n",
586 smp_processor_id(), regs->ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 show_registers(regs);
Vivek Goyal8bcc5282006-04-18 12:35:13 +0200588 if (kexec_should_crash(current))
589 crash_kexec(regs);
Andi Kleenfac58552006-09-26 10:52:27 +0200590 if (do_panic || panic_on_oops)
591 panic("Non maskable interrupt");
Jan Beulich22f59912008-01-30 13:31:23 +0100592 oops_end(flags, NULL, SIGBUS);
Corey Minyard8b1ffe952006-05-08 15:17:25 +0200593 nmi_exit();
594 local_irq_enable();
Jan Beulich22f59912008-01-30 13:31:23 +0100595 do_exit(SIGBUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200598static void __kprobes
599do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
600 long error_code, siginfo_t *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Jan Beulich6e3f3612006-01-11 22:42:14 +0100602 struct task_struct *tsk = current;
603
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200604 if (!user_mode(regs))
605 goto kernel_trap;
Andi Kleend1895182007-05-02 19:27:05 +0200606
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200607 /*
608 * We want error_code and trap_no set for userspace faults and
609 * kernelspace faults which result in die(), but not
610 * kernelspace faults which are fixed up. die() gives the
611 * process no chance to handle the signal and notice the
612 * kernel fault information, so that won't result in polluting
613 * the information about previously queued, but not yet
614 * delivered, faults. See also do_general_protection below.
615 */
616 tsk->thread.error_code = error_code;
617 tsk->thread.trap_no = trapnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200619 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
620 printk_ratelimit()) {
621 printk(KERN_INFO
622 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
623 tsk->comm, tsk->pid, str,
624 regs->ip, regs->sp, error_code);
625 print_vma_addr(" in ", regs->ip);
626 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 }
628
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200629 if (info)
630 force_sig_info(signr, info, tsk);
631 else
632 force_sig(signr, tsk);
633 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Alexander van Heukeluma7bbb0c2008-07-02 01:31:34 +0200635kernel_trap:
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100636 if (!fixup_exception(regs)) {
637 tsk->thread.error_code = error_code;
638 tsk->thread.trap_no = trapnr;
639 die(str, regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100641 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642}
643
644#define DO_ERROR(trapnr, signr, str, name) \
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300645asmlinkage void do_##name(struct pt_regs *regs, long error_code) \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200646{ \
647 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
648 == NOTIFY_STOP) \
649 return; \
Andi Kleen40e59a62006-05-15 18:19:47 +0200650 conditional_sti(regs); \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200651 do_trap(trapnr, signr, str, regs, error_code, NULL); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200654#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300655asmlinkage void do_##name(struct pt_regs *regs, long error_code) \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200656{ \
657 siginfo_t info; \
658 info.si_signo = signr; \
659 info.si_errno = 0; \
660 info.si_code = sicode; \
661 info.si_addr = (void __user *)siaddr; \
662 trace_hardirqs_fixup(); \
663 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
664 == NOTIFY_STOP) \
665 return; \
Andi Kleen40e59a62006-05-15 18:19:47 +0200666 conditional_sti(regs); \
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200667 do_trap(trapnr, signr, str, regs, error_code, &info); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200670DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
671DO_ERROR(4, SIGSEGV, "overflow", overflow)
672DO_ERROR(5, SIGSEGV, "bounds", bounds)
673DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
674DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200676DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
Andi Kleen40e59a62006-05-15 18:19:47 +0200678
679/* Runs on IST stack */
680asmlinkage void do_stack_segment(struct pt_regs *regs, long error_code)
681{
682 if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
683 12, SIGBUS) == NOTIFY_STOP)
684 return;
685 preempt_conditional_sti(regs);
686 do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL);
687 preempt_conditional_cli(regs);
688}
Jan Beulicheca37c12006-01-11 22:42:17 +0100689
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300690asmlinkage void do_double_fault(struct pt_regs *regs, long error_code)
Jan Beulicheca37c12006-01-11 22:42:17 +0100691{
692 static const char str[] = "double fault";
693 struct task_struct *tsk = current;
694
695 /* Return not checked because double check cannot be ignored */
696 notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV);
697
698 tsk->thread.error_code = error_code;
699 tsk->thread.trap_no = 8;
700
701 /* This is always a kernel trap and never fixable (and thus must
702 never return). */
703 for (;;)
704 die(str, regs, error_code);
705}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200707asmlinkage void __kprobes
708do_general_protection(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709{
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200710 struct task_struct *tsk;
Jan Beulich6e3f3612006-01-11 22:42:14 +0100711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 conditional_sti(regs);
713
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200714 tsk = current;
715 if (!user_mode(regs))
716 goto gp_in_kernel;
Andi Kleend1895182007-05-02 19:27:05 +0200717
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200718 tsk->thread.error_code = error_code;
719 tsk->thread.trap_no = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200721 if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
722 printk_ratelimit()) {
723 printk(KERN_INFO
724 "%s[%d] general protection ip:%lx sp:%lx error:%lx",
725 tsk->comm, tsk->pid,
726 regs->ip, regs->sp, error_code);
727 print_vma_addr(" in ", regs->ip);
728 printk("\n");
729 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Alexander van Heukelum13485ab2008-07-02 01:32:04 +0200731 force_sig(SIGSEGV, tsk);
732 return;
733
734gp_in_kernel:
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100735 if (fixup_exception(regs))
736 return;
Andi Kleend1895182007-05-02 19:27:05 +0200737
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100738 tsk->thread.error_code = error_code;
739 tsk->thread.trap_no = 13;
740 if (notify_die(DIE_GPF, "general protection fault", regs,
741 error_code, 13, SIGSEGV) == NOTIFY_STOP)
742 return;
743 die("general protection fault", regs, error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744}
745
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200746static notrace __kprobes void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200747mem_parity_error(unsigned char reason, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
Don Zickusc41c5cd2006-09-26 10:52:27 +0200749 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
750 reason);
Andi Kleen9c5f8be2006-12-07 02:14:03 +0100751 printk(KERN_EMERG "You have some hardware problem, likely on the PCI bus.\n");
Don Zickusc41c5cd2006-09-26 10:52:27 +0200752
Dave Jiangc0d12172007-07-19 01:49:46 -0700753#if defined(CONFIG_EDAC)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200754 if (edac_handler_set()) {
Dave Jiangc0d12172007-07-19 01:49:46 -0700755 edac_atomic_assert_error();
756 return;
757 }
758#endif
759
Don Zickus8da5add2006-09-26 10:52:27 +0200760 if (panic_on_unrecovered_nmi)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200761 panic("NMI: Not continuing");
762
763 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 /* Clear and disable the memory parity error line. */
766 reason = (reason & 0xf) | 4;
767 outb(reason, 0x61);
768}
769
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200770static notrace __kprobes void
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200771io_check_error(unsigned char reason, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
773 printk("NMI: IOCK error (debug interrupt?)\n");
774 show_registers(regs);
775
776 /* Re-enable the IOCK line, wait for a few seconds */
777 reason = (reason & 0xf) | 8;
778 outb(reason, 0x61);
779 mdelay(2000);
780 reason &= ~8;
781 outb(reason, 0x61);
782}
783
Steven Rostedt5deb45e2008-04-19 19:19:55 +0200784static notrace __kprobes void
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300785unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200786{
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300787 if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) ==
788 NOTIFY_STOP)
Jason Wesseld3597522008-02-15 14:55:53 -0600789 return;
Don Zickusc41c5cd2006-09-26 10:52:27 +0200790 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
791 reason);
792 printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n");
Don Zickus8da5add2006-09-26 10:52:27 +0200793
794 if (panic_on_unrecovered_nmi)
Don Zickusc41c5cd2006-09-26 10:52:27 +0200795 panic("NMI: Not continuing");
Don Zickus8da5add2006-09-26 10:52:27 +0200796
Don Zickusc41c5cd2006-09-26 10:52:27 +0200797 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700800/* Runs on IST stack. This code must keep interrupts off all the time.
801 Nested NMIs are prevented by the CPU. */
Alexander van Heukelumabd34802008-07-02 18:39:01 +0200802asmlinkage notrace __kprobes void default_do_nmi(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
804 unsigned char reason = 0;
Ashok Raj76e4f662005-06-25 14:55:00 -0700805 int cpu;
806
807 cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200809 /* Only the BSP gets external NMIs from the system. */
Ashok Raj76e4f662005-06-25 14:55:00 -0700810 if (!cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 reason = get_nmi_reason();
812
813 if (!(reason & 0xc0)) {
Jan Beulich6e3f3612006-01-11 22:42:14 +0100814 if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 == NOTIFY_STOP)
816 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 /*
818 * Ok, so this is none of the documented NMI sources,
819 * so it must be the NMI watchdog.
820 */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200821 if (nmi_watchdog_tick(regs, reason))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 return;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200823 if (!do_nmi_callback(regs, cpu))
Don Zickus3adbbcce2006-09-26 10:52:26 +0200824 unknown_nmi_error(reason, regs);
825
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 return;
827 }
Jan Beulich6e3f3612006-01-11 22:42:14 +0100828 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200829 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 /* AK: following checks seem to be broken on modern chipsets. FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 if (reason & 0x80)
833 mem_parity_error(reason, regs);
834 if (reason & 0x40)
835 io_check_error(reason, regs);
836}
837
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400838asmlinkage notrace __kprobes void
839do_nmi(struct pt_regs *regs, long error_code)
840{
841 nmi_enter();
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200842
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400843 add_pda(__nmi_count, 1);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200844
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400845 if (!ignore_nmis)
846 default_do_nmi(regs);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200847
Cyrill Gorcunovc6425b92008-05-24 19:36:33 +0400848 nmi_exit();
849}
850
851void stop_nmi(void)
852{
853 acpi_nmi_disable();
854 ignore_nmis++;
855}
856
857void restart_nmi(void)
858{
859 ignore_nmis--;
860 acpi_nmi_enable();
861}
862
Jan Beulichb556b352006-01-11 22:43:00 +0100863/* runs on IST stack. */
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200864asmlinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
Peter Zijlstra143a5d32007-10-25 14:01:10 +0200866 trace_hardirqs_fixup();
867
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200868 if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
869 == NOTIFY_STOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 return;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200871
Andi Kleen40e59a62006-05-15 18:19:47 +0200872 preempt_conditional_sti(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
Andi Kleen40e59a62006-05-15 18:19:47 +0200874 preempt_conditional_cli(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
876
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700877/* Help handler running on IST stack to switch back to user stack
878 for scheduling or signal handling. The actual stack switch is done in
879 entry.S */
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100880asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700882 struct pt_regs *regs = eregs;
883 /* Did already sync */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100884 if (eregs == (struct pt_regs *)eregs->sp)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700885 ;
886 /* Exception from user space */
Vincent Hanquez76381fe2005-06-23 00:08:46 -0700887 else if (user_mode(eregs))
Al Virobb049232006-01-12 01:05:38 -0800888 regs = task_pt_regs(current);
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700889 /* Exception from kernel and interrupts are enabled. Move to
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300890 kernel process stack. */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100891 else if (eregs->flags & X86_EFLAGS_IF)
892 regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs));
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700893 if (eregs != regs)
894 *regs = *eregs;
895 return regs;
896}
897
898/* runs on IST stack. */
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -0300899asmlinkage void __kprobes do_debug(struct pt_regs *regs,
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -0700900 unsigned long error_code)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700901{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 struct task_struct *tsk = current;
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +0200903 unsigned long condition;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 siginfo_t info;
905
Peter Zijlstra000f4a92007-11-26 20:42:19 +0100906 trace_hardirqs_fixup();
907
Vincent Hanqueze9129e52005-06-23 00:08:46 -0700908 get_debugreg(condition, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Roland McGrath10faa812008-01-30 13:30:54 +0100910 /*
911 * The processor cleared BTF, so don't mark that we need it set.
912 */
913 clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
914 tsk->thread.debugctlmsr = 0;
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
Andi Kleendaeeafe2005-04-16 15:25:13 -0700917 SIGTRAP) == NOTIFY_STOP)
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700918 return;
Andi Kleendaeeafe2005-04-16 15:25:13 -0700919
John Blackwooda65d17c2006-02-12 14:34:58 -0800920 preempt_conditional_sti(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 /* Mask out spurious debug traps due to lazy DR7 setting */
923 if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200924 if (!tsk->thread.debugreg7)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 goto clear_dr7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 }
927
928 tsk->thread.debugreg6 = condition;
929
Roland McGrathe1f28772008-01-30 13:30:50 +0100930 /*
931 * Single-stepping through TF: make sure we ignore any events in
932 * kernel space (but re-enable TF when returning to user mode).
933 */
Andi Kleendaeeafe2005-04-16 15:25:13 -0700934 if (condition & DR_STEP) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200935 if (!user_mode(regs))
936 goto clear_TF_reenable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 }
938
939 /* Ok, finally something we can handle */
940 tsk->thread.trap_no = 1;
941 tsk->thread.error_code = error_code;
942 info.si_signo = SIGTRAP;
943 info.si_errno = 0;
944 info.si_code = TRAP_BRKPT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100945 info.si_addr = user_mode(regs) ? (void __user *)regs->ip : NULL;
John Blackwood01b8faa2006-01-11 22:44:15 +0100946 force_sig_info(SIGTRAP, &info, tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948clear_dr7:
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200949 set_debugreg(0, 7);
John Blackwooda65d17c2006-02-12 14:34:58 -0800950 preempt_conditional_cli(regs);
Andi Kleen6fefb0d2005-04-16 15:25:03 -0700951 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953clear_TF_reenable:
954 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
Glauber de Oliveira Costa053de042008-01-30 13:31:27 +0100955 regs->flags &= ~X86_EFLAGS_TF;
John Blackwooda65d17c2006-02-12 14:34:58 -0800956 preempt_conditional_cli(regs);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200957 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
Jan Beulich6e3f3612006-01-11 22:42:14 +0100960static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961{
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100962 if (fixup_exception(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return 1;
Harvey Harrisonb3a5acc2008-01-30 13:32:59 +0100964
Jan Beulich6e3f3612006-01-11 22:42:14 +0100965 notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
Andi Kleen3a848f62005-04-16 15:25:06 -0700966 /* Illegal floating point operation in the kernel */
Jan Beulich6e3f3612006-01-11 22:42:14 +0100967 current->thread.trap_no = trapnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 die(str, regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 return 0;
970}
971
972/*
973 * Note that we play around with the 'TS' bit in an attempt to get
974 * the correct behaviour even in the presence of the asynchronous
975 * IRQ13 behaviour
976 */
977asmlinkage void do_coprocessor_error(struct pt_regs *regs)
978{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100979 void __user *ip = (void __user *)(regs->ip);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +0200980 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 siginfo_t info;
982 unsigned short cwd, swd;
983
984 conditional_sti(regs);
Vincent Hanquez76381fe2005-06-23 00:08:46 -0700985 if (!user_mode(regs) &&
Jan Beulich6e3f3612006-01-11 22:42:14 +0100986 kernel_math_error(regs, "kernel x87 math error", 16))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 return;
988
989 /*
990 * Save the info for the exception handler and clear the error.
991 */
992 task = current;
993 save_init_fpu(task);
994 task->thread.trap_no = 16;
995 task->thread.error_code = 0;
996 info.si_signo = SIGFPE;
997 info.si_errno = 0;
998 info.si_code = __SI_FAULT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100999 info.si_addr = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 /*
1001 * (~cwd & swd) will mask out exceptions that are not set to unmasked
1002 * status. 0x3f is the exception bits in these regs, 0x200 is the
1003 * C1 reg you need in case of a stack fault, 0x040 is the stack
1004 * fault bit. We should only be taking one exception at a time,
1005 * so if this combination doesn't produce any single exception,
1006 * then we have a bad program that isn't synchronizing its FPU usage
1007 * and it will suffer the consequences since we won't be able to
1008 * fully reproduce the context of the exception
1009 */
1010 cwd = get_fpu_cwd(task);
1011 swd = get_fpu_swd(task);
Chuck Ebbertff347b22005-09-12 18:49:25 +02001012 switch (swd & ~cwd & 0x3f) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001013 case 0x000: /* No unmasked exception */
1014 default: /* Multiple exceptions */
1015 break;
1016 case 0x001: /* Invalid Op */
1017 /*
1018 * swd & 0x240 == 0x040: Stack Underflow
1019 * swd & 0x240 == 0x240: Stack Overflow
1020 * User must clear the SF bit (0x40) if set
1021 */
1022 info.si_code = FPE_FLTINV;
1023 break;
1024 case 0x002: /* Denormalize */
1025 case 0x010: /* Underflow */
1026 info.si_code = FPE_FLTUND;
1027 break;
1028 case 0x004: /* Zero Divide */
1029 info.si_code = FPE_FLTDIV;
1030 break;
1031 case 0x008: /* Overflow */
1032 info.si_code = FPE_FLTOVF;
1033 break;
1034 case 0x020: /* Precision */
1035 info.si_code = FPE_FLTRES;
1036 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038 force_sig_info(SIGFPE, &info, task);
1039}
1040
1041asmlinkage void bad_intr(void)
1042{
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -03001043 printk("bad interrupt");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044}
1045
1046asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs)
1047{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001048 void __user *ip = (void __user *)(regs->ip);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001049 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 siginfo_t info;
1051 unsigned short mxcsr;
1052
1053 conditional_sti(regs);
Vincent Hanquez76381fe2005-06-23 00:08:46 -07001054 if (!user_mode(regs) &&
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -03001055 kernel_math_error(regs, "kernel simd math error", 19))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 return;
1057
1058 /*
1059 * Save the info for the exception handler and clear the error.
1060 */
1061 task = current;
1062 save_init_fpu(task);
1063 task->thread.trap_no = 19;
1064 task->thread.error_code = 0;
1065 info.si_signo = SIGFPE;
1066 info.si_errno = 0;
1067 info.si_code = __SI_FAULT;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +01001068 info.si_addr = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 /*
1070 * The SIMD FPU exceptions are handled a little differently, as there
1071 * is only a single status/control register. Thus, to determine which
1072 * unmasked exception was caught we must mask the exception mask bits
1073 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
1074 */
1075 mxcsr = get_fpu_mxcsr(task);
1076 switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001077 case 0x000:
1078 default:
1079 break;
1080 case 0x001: /* Invalid Op */
1081 info.si_code = FPE_FLTINV;
1082 break;
1083 case 0x002: /* Denormalize */
1084 case 0x010: /* Underflow */
1085 info.si_code = FPE_FLTUND;
1086 break;
1087 case 0x004: /* Zero Divide */
1088 info.si_code = FPE_FLTDIV;
1089 break;
1090 case 0x008: /* Overflow */
1091 info.si_code = FPE_FLTOVF;
1092 break;
1093 case 0x020: /* Precision */
1094 info.si_code = FPE_FLTRES;
1095 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
1097 force_sig_info(SIGFPE, &info, task);
1098}
1099
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -03001100asmlinkage void do_spurious_interrupt_bug(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
1102}
1103
1104asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void)
1105{
1106}
1107
Jacob Shin89b831e2005-11-05 17:25:53 +01001108asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void)
1109{
1110}
1111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112/*
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001113 * 'math_state_restore()' saves the current math information in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 * old math state array, and gets the new ones from the current task
1115 *
1116 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
1117 * Don't touch unless you *really* know how it works.
1118 */
1119asmlinkage void math_state_restore(void)
1120{
1121 struct task_struct *me = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Suresh Siddhaaa283f42008-03-10 15:28:05 -07001123 if (!used_math()) {
1124 local_irq_enable();
1125 /*
1126 * does a slab alloc which can sleep
1127 */
1128 if (init_fpu(me)) {
1129 /*
1130 * ran out of memory!
1131 */
1132 do_group_exit(SIGKILL);
1133 return;
1134 }
1135 local_irq_disable();
1136 }
1137
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001138 clts(); /* Allow maths ops (or we recurse) */
Suresh Siddha61c46282008-03-10 15:28:04 -07001139 restore_fpu_checking(&me->thread.xstate->fxsave);
Al Viroe4f17c42006-01-12 01:05:38 -08001140 task_thread_info(me)->status |= TS_USEDFPU;
Arjan van de Vene07e23e2006-09-26 10:52:36 +02001141 me->fpu_counter++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
Glauber de Oliveira Costa21db5582008-01-30 13:31:10 +01001143EXPORT_SYMBOL_GPL(math_state_restore);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145void __init trap_init(void)
1146{
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001147 set_intr_gate(0, &divide_error);
1148 set_intr_gate_ist(1, &debug, DEBUG_STACK);
1149 set_intr_gate_ist(2, &nmi, NMI_STACK);
Gustavo F. Padovan4df9e512008-07-29 02:48:55 -03001150 /* int3 can be called from all */
1151 set_system_gate_ist(3, &int3, DEBUG_STACK);
1152 /* int4 can be called from all */
1153 set_system_gate(4, &overflow);
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001154 set_intr_gate(5, &bounds);
1155 set_intr_gate(6, &invalid_op);
1156 set_intr_gate(7, &device_not_available);
1157 set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK);
1158 set_intr_gate(9, &coprocessor_segment_overrun);
1159 set_intr_gate(10, &invalid_TSS);
1160 set_intr_gate(11, &segment_not_present);
1161 set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK);
1162 set_intr_gate(13, &general_protection);
1163 set_intr_gate(14, &page_fault);
1164 set_intr_gate(15, &spurious_interrupt_bug);
1165 set_intr_gate(16, &coprocessor_error);
1166 set_intr_gate(17, &alignment_check);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167#ifdef CONFIG_X86_MCE
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001168 set_intr_gate_ist(18, &machine_check, MCE_STACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169#endif
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001170 set_intr_gate(19, &simd_coprocessor_error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172#ifdef CONFIG_IA32_EMULATION
1173 set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
1174#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 /*
Suresh Siddha61c46282008-03-10 15:28:04 -07001176 * initialize the per thread extended state:
1177 */
Alexander van Heukelum7b4fd4b2008-07-02 01:33:14 +02001178 init_thread_xstate();
Suresh Siddha61c46282008-03-10 15:28:04 -07001179 /*
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001180 * Should be a barrier for any external CPU state:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 */
1182 cpu_init();
1183}
1184
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001185static int __init oops_setup(char *s)
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001186{
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001187 if (!s)
1188 return -EINVAL;
1189 if (!strcmp(s, "panic"))
1190 panic_on_oops = 1;
1191 return 0;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001192}
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001193early_param("oops", oops_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195static int __init kstack_setup(char *s)
1196{
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001197 if (!s)
1198 return -EINVAL;
Alexander van Heukeluma8c1be92008-07-02 01:29:44 +02001199 kstack_depth_to_print = simple_strtoul(s, NULL, 0);
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001200 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
Andi Kleen2c8c0e62006-09-26 10:52:32 +02001202early_param("kstack", kstack_setup);
Arjan van de Vena25bd942008-01-30 13:33:08 +01001203
Arjan van de Vena25bd942008-01-30 13:33:08 +01001204static int __init code_bytes_setup(char *s)
1205{
1206 code_bytes = simple_strtoul(s, NULL, 0);
1207 if (code_bytes > 8192)
1208 code_bytes = 8192;
1209
1210 return 1;
1211}
1212__setup("code_bytes=", code_bytes_setup);