]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Copyright (C) 1991, 1992 Linus Torvalds |
3 | * | |
4 | * Pentium III FXSR, SSE support | |
5 | * Gareth Hughes <gareth@valinux.com>, May 2000 | |
6 | */ | |
7 | ||
8 | /* | |
9 | * 'Traps.c' handles hardware traps and faults after we have saved some | |
10 | * state in 'asm.s'. | |
11 | */ | |
1da177e4 LT |
12 | #include <linux/sched.h> |
13 | #include <linux/kernel.h> | |
14 | #include <linux/string.h> | |
15 | #include <linux/errno.h> | |
16 | #include <linux/timer.h> | |
17 | #include <linux/mm.h> | |
18 | #include <linux/init.h> | |
19 | #include <linux/delay.h> | |
20 | #include <linux/spinlock.h> | |
21 | #include <linux/interrupt.h> | |
22 | #include <linux/highmem.h> | |
23 | #include <linux/kallsyms.h> | |
24 | #include <linux/ptrace.h> | |
25 | #include <linux/utsname.h> | |
26 | #include <linux/kprobes.h> | |
6e274d14 | 27 | #include <linux/kexec.h> |
176a2718 | 28 | #include <linux/unwind.h> |
1e2af92e | 29 | #include <linux/uaccess.h> |
a36df98a | 30 | #include <linux/nmi.h> |
91768d6c | 31 | #include <linux/bug.h> |
1da177e4 LT |
32 | |
33 | #ifdef CONFIG_EISA | |
34 | #include <linux/ioport.h> | |
35 | #include <linux/eisa.h> | |
36 | #endif | |
37 | ||
38 | #ifdef CONFIG_MCA | |
39 | #include <linux/mca.h> | |
40 | #endif | |
41 | ||
c0d12172 DJ |
42 | #if defined(CONFIG_EDAC) |
43 | #include <linux/edac.h> | |
44 | #endif | |
45 | ||
1da177e4 LT |
46 | #include <asm/processor.h> |
47 | #include <asm/system.h> | |
1da177e4 LT |
48 | #include <asm/io.h> |
49 | #include <asm/atomic.h> | |
50 | #include <asm/debugreg.h> | |
51 | #include <asm/desc.h> | |
52 | #include <asm/i387.h> | |
53 | #include <asm/nmi.h> | |
176a2718 | 54 | #include <asm/unwind.h> |
1da177e4 LT |
55 | #include <asm/smp.h> |
56 | #include <asm/arch_hooks.h> | |
1eeb66a1 | 57 | #include <linux/kdebug.h> |
2b14a78c | 58 | #include <asm/stacktrace.h> |
1da177e4 | 59 | |
1da177e4 LT |
60 | #include <linux/module.h> |
61 | ||
62 | #include "mach_traps.h" | |
63 | ||
29cbc78b AK |
64 | int panic_on_unrecovered_nmi; |
65 | ||
dbeb2be2 RR |
66 | DECLARE_BITMAP(used_vectors, NR_VECTORS); |
67 | EXPORT_SYMBOL_GPL(used_vectors); | |
68 | ||
1da177e4 LT |
69 | asmlinkage int system_call(void); |
70 | ||
1da177e4 LT |
71 | /* Do we ignore FPU interrupts ? */ |
72 | char ignore_fpu_irq = 0; | |
73 | ||
74 | /* | |
75 | * The IDT has to be page-aligned to simplify the Pentium | |
76 | * F0 0F bug workaround.. We have a special link segment | |
77 | * for this. | |
78 | */ | |
79 | struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, }; | |
80 | ||
81 | asmlinkage void divide_error(void); | |
82 | asmlinkage void debug(void); | |
83 | asmlinkage void nmi(void); | |
84 | asmlinkage void int3(void); | |
85 | asmlinkage void overflow(void); | |
86 | asmlinkage void bounds(void); | |
87 | asmlinkage void invalid_op(void); | |
88 | asmlinkage void device_not_available(void); | |
89 | asmlinkage void coprocessor_segment_overrun(void); | |
90 | asmlinkage void invalid_TSS(void); | |
91 | asmlinkage void segment_not_present(void); | |
92 | asmlinkage void stack_segment(void); | |
93 | asmlinkage void general_protection(void); | |
94 | asmlinkage void page_fault(void); | |
95 | asmlinkage void coprocessor_error(void); | |
96 | asmlinkage void simd_coprocessor_error(void); | |
97 | asmlinkage void alignment_check(void); | |
98 | asmlinkage void spurious_interrupt_bug(void); | |
99 | asmlinkage void machine_check(void); | |
100 | ||
0741f4d2 | 101 | int kstack_depth_to_print = 24; |
86c41837 | 102 | static unsigned int code_bytes = 64; |
e041c683 | 103 | |
36ad4885 | 104 | static inline int valid_stack_ptr(struct thread_info *tinfo, void *p, unsigned size) |
1da177e4 LT |
105 | { |
106 | return p > (void *)tinfo && | |
36ad4885 | 107 | p <= (void *)tinfo + THREAD_SIZE - size; |
1da177e4 LT |
108 | } |
109 | ||
36ad4885 LT |
110 | /* The form of the top of the frame on the stack */ |
111 | struct stack_frame { | |
112 | struct stack_frame *next_frame; | |
113 | unsigned long return_address; | |
114 | }; | |
115 | ||
1da177e4 | 116 | static inline unsigned long print_context_stack(struct thread_info *tinfo, |
7aa89746 | 117 | unsigned long *stack, unsigned long ebp, |
9689ba8a | 118 | const struct stacktrace_ops *ops, void *data) |
1da177e4 | 119 | { |
1da177e4 | 120 | #ifdef CONFIG_FRAME_POINTER |
36ad4885 LT |
121 | struct stack_frame *frame = (struct stack_frame *)ebp; |
122 | while (valid_stack_ptr(tinfo, frame, sizeof(*frame))) { | |
123 | struct stack_frame *next; | |
124 | unsigned long addr; | |
125 | ||
126 | addr = frame->return_address; | |
2b14a78c | 127 | ops->address(data, addr); |
b88d4f1d IM |
128 | /* |
129 | * break out of recursive entries (such as | |
808dbbb6 LT |
130 | * end_of_stack_stop_unwind_function). Also, |
131 | * we can never allow a frame pointer to | |
132 | * move downwards! | |
36ad4885 LT |
133 | */ |
134 | next = frame->next_frame; | |
135 | if (next <= frame) | |
b88d4f1d | 136 | break; |
36ad4885 | 137 | frame = next; |
1da177e4 LT |
138 | } |
139 | #else | |
36ad4885 LT |
140 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) { |
141 | unsigned long addr; | |
142 | ||
1da177e4 | 143 | addr = *stack++; |
7aa89746 | 144 | if (__kernel_text_address(addr)) |
2b14a78c | 145 | ops->address(data, addr); |
1da177e4 LT |
146 | } |
147 | #endif | |
148 | return ebp; | |
149 | } | |
150 | ||
b615ebda AK |
151 | #define MSG(msg) ops->warning(data, msg) |
152 | ||
2b14a78c AK |
153 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
154 | unsigned long *stack, | |
9689ba8a | 155 | const struct stacktrace_ops *ops, void *data) |
1da177e4 | 156 | { |
a32cf397 | 157 | unsigned long ebp = 0; |
1da177e4 LT |
158 | |
159 | if (!task) | |
160 | task = current; | |
161 | ||
a32cf397 | 162 | if (!stack) { |
2b14a78c AK |
163 | unsigned long dummy; |
164 | stack = &dummy; | |
028a690a | 165 | if (task != current) |
2b14a78c | 166 | stack = (unsigned long *)task->thread.esp; |
176a2718 JB |
167 | } |
168 | ||
a32cf397 AK |
169 | #ifdef CONFIG_FRAME_POINTER |
170 | if (!ebp) { | |
171 | if (task == current) { | |
172 | /* Grab ebp right from our regs */ | |
173 | asm ("movl %%ebp, %0" : "=r" (ebp) : ); | |
174 | } else { | |
175 | /* ebp is the last reg pushed by switch_to */ | |
176 | ebp = *(unsigned long *) task->thread.esp; | |
177 | } | |
1da177e4 | 178 | } |
a32cf397 | 179 | #endif |
1da177e4 LT |
180 | |
181 | while (1) { | |
182 | struct thread_info *context; | |
183 | context = (struct thread_info *) | |
184 | ((unsigned long)stack & (~(THREAD_SIZE - 1))); | |
2b14a78c AK |
185 | ebp = print_context_stack(context, stack, ebp, ops, data); |
186 | /* Should be after the line below, but somewhere | |
187 | in early boot context comes out corrupted and we | |
188 | can't reference it -AK */ | |
189 | if (ops->stack(data, "IRQ") < 0) | |
190 | break; | |
1da177e4 LT |
191 | stack = (unsigned long*)context->previous_esp; |
192 | if (!stack) | |
193 | break; | |
a36df98a | 194 | touch_nmi_watchdog(); |
1da177e4 LT |
195 | } |
196 | } | |
2b14a78c AK |
197 | EXPORT_SYMBOL(dump_trace); |
198 | ||
199 | static void | |
200 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | |
201 | { | |
202 | printk(data); | |
203 | print_symbol(msg, symbol); | |
204 | printk("\n"); | |
205 | } | |
206 | ||
207 | static void print_trace_warning(void *data, char *msg) | |
208 | { | |
209 | printk("%s%s\n", (char *)data, msg); | |
210 | } | |
211 | ||
212 | static int print_trace_stack(void *data, char *name) | |
213 | { | |
214 | return 0; | |
215 | } | |
216 | ||
217 | /* | |
218 | * Print one address/symbol entries per line. | |
219 | */ | |
220 | static void print_trace_address(void *data, unsigned long addr) | |
221 | { | |
222 | printk("%s [<%08lx>] ", (char *)data, addr); | |
223 | print_symbol("%s\n", addr); | |
601e6255 | 224 | touch_nmi_watchdog(); |
2b14a78c AK |
225 | } |
226 | ||
9689ba8a | 227 | static const struct stacktrace_ops print_trace_ops = { |
2b14a78c AK |
228 | .warning = print_trace_warning, |
229 | .warning_symbol = print_trace_warning_symbol, | |
230 | .stack = print_trace_stack, | |
231 | .address = print_trace_address, | |
232 | }; | |
233 | ||
234 | static void | |
235 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | |
236 | unsigned long * stack, char *log_lvl) | |
237 | { | |
238 | dump_trace(task, regs, stack, &print_trace_ops, log_lvl); | |
239 | printk("%s =======================\n", log_lvl); | |
240 | } | |
1da177e4 | 241 | |
2b14a78c AK |
242 | void show_trace(struct task_struct *task, struct pt_regs *regs, |
243 | unsigned long * stack) | |
7aa89746 | 244 | { |
176a2718 | 245 | show_trace_log_lvl(task, regs, stack, ""); |
7aa89746 CE |
246 | } |
247 | ||
176a2718 JB |
248 | static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
249 | unsigned long *esp, char *log_lvl) | |
1da177e4 LT |
250 | { |
251 | unsigned long *stack; | |
252 | int i; | |
253 | ||
254 | if (esp == NULL) { | |
255 | if (task) | |
256 | esp = (unsigned long*)task->thread.esp; | |
257 | else | |
258 | esp = (unsigned long *)&esp; | |
259 | } | |
260 | ||
261 | stack = esp; | |
262 | for(i = 0; i < kstack_depth_to_print; i++) { | |
263 | if (kstack_end(stack)) | |
264 | break; | |
75874d5c CE |
265 | if (i && ((i % 8) == 0)) |
266 | printk("\n%s ", log_lvl); | |
1da177e4 LT |
267 | printk("%08lx ", *stack++); |
268 | } | |
75874d5c | 269 | printk("\n%sCall Trace:\n", log_lvl); |
176a2718 | 270 | show_trace_log_lvl(task, regs, esp, log_lvl); |
7aa89746 CE |
271 | } |
272 | ||
273 | void show_stack(struct task_struct *task, unsigned long *esp) | |
274 | { | |
75874d5c | 275 | printk(" "); |
176a2718 | 276 | show_stack_log_lvl(task, NULL, esp, ""); |
1da177e4 LT |
277 | } |
278 | ||
279 | /* | |
280 | * The architecture-independent dump_stack generator | |
281 | */ | |
282 | void dump_stack(void) | |
283 | { | |
284 | unsigned long stack; | |
285 | ||
57c351de AV |
286 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", |
287 | current->pid, current->comm, print_tainted(), | |
288 | init_utsname()->release, | |
289 | (int)strcspn(init_utsname()->version, " "), | |
290 | init_utsname()->version); | |
176a2718 | 291 | show_trace(current, NULL, &stack); |
1da177e4 LT |
292 | } |
293 | ||
294 | EXPORT_SYMBOL(dump_stack); | |
295 | ||
296 | void show_registers(struct pt_regs *regs) | |
297 | { | |
298 | int i; | |
9d975ebd | 299 | |
1da177e4 | 300 | print_modules(); |
9d975ebd | 301 | __show_registers(regs, 0); |
7e04a118 | 302 | printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)", |
19c5870c | 303 | TASK_COMM_LEN, current->comm, task_pid_nr(current), |
c9f4f06d | 304 | current_thread_info(), current, task_thread_info(current)); |
1da177e4 LT |
305 | /* |
306 | * When in-kernel, we also print out the stack and code at the | |
307 | * time of the fault.. | |
308 | */ | |
9d975ebd | 309 | if (!user_mode_vm(regs)) { |
11a4180c | 310 | u8 *eip; |
86c41837 CE |
311 | unsigned int code_prologue = code_bytes * 43 / 64; |
312 | unsigned int code_len = code_bytes; | |
99325326 | 313 | unsigned char c; |
1da177e4 | 314 | |
9c107805 | 315 | printk("\n" KERN_EMERG "Stack: "); |
9d975ebd | 316 | show_stack_log_lvl(NULL, regs, ®s->esp, KERN_EMERG); |
1da177e4 | 317 | |
9c107805 | 318 | printk(KERN_EMERG "Code: "); |
1da177e4 | 319 | |
86c41837 | 320 | eip = (u8 *)regs->eip - code_prologue; |
11a4180c AK |
321 | if (eip < (u8 *)PAGE_OFFSET || |
322 | probe_kernel_address(eip, c)) { | |
99325326 | 323 | /* try starting at EIP */ |
11a4180c | 324 | eip = (u8 *)regs->eip; |
86c41837 | 325 | code_len = code_len - code_prologue + 1; |
99325326 | 326 | } |
86c41837 | 327 | for (i = 0; i < code_len; i++, eip++) { |
11a4180c AK |
328 | if (eip < (u8 *)PAGE_OFFSET || |
329 | probe_kernel_address(eip, c)) { | |
1da177e4 LT |
330 | printk(" Bad EIP value."); |
331 | break; | |
332 | } | |
11a4180c | 333 | if (eip == (u8 *)regs->eip) |
1da177e4 LT |
334 | printk("<%02x> ", c); |
335 | else | |
336 | printk("%02x ", c); | |
337 | } | |
338 | } | |
339 | printk("\n"); | |
340 | } | |
341 | ||
91768d6c | 342 | int is_valid_bugaddr(unsigned long eip) |
1da177e4 LT |
343 | { |
344 | unsigned short ud2; | |
1da177e4 LT |
345 | |
346 | if (eip < PAGE_OFFSET) | |
91768d6c | 347 | return 0; |
11a4180c | 348 | if (probe_kernel_address((unsigned short *)eip, ud2)) |
91768d6c | 349 | return 0; |
1da177e4 | 350 | |
91768d6c | 351 | return ud2 == 0x0b0f; |
1da177e4 LT |
352 | } |
353 | ||
91768d6c JF |
354 | /* |
355 | * This is gone through when something in the kernel has done something bad and | |
356 | * is about to be terminated. | |
357 | */ | |
1da177e4 LT |
358 | void die(const char * str, struct pt_regs * regs, long err) |
359 | { | |
360 | static struct { | |
39743c9e | 361 | raw_spinlock_t lock; |
1da177e4 LT |
362 | u32 lock_owner; |
363 | int lock_owner_depth; | |
364 | } die = { | |
39743c9e | 365 | .lock = __RAW_SPIN_LOCK_UNLOCKED, |
1da177e4 LT |
366 | .lock_owner = -1, |
367 | .lock_owner_depth = 0 | |
368 | }; | |
369 | static int die_counter; | |
e43d674f | 370 | unsigned long flags; |
1da177e4 | 371 | |
dd287796 AM |
372 | oops_enter(); |
373 | ||
39c715b7 | 374 | if (die.lock_owner != raw_smp_processor_id()) { |
1da177e4 | 375 | console_verbose(); |
c0a698b7 | 376 | raw_local_irq_save(flags); |
39743c9e | 377 | __raw_spin_lock(&die.lock); |
1da177e4 LT |
378 | die.lock_owner = smp_processor_id(); |
379 | die.lock_owner_depth = 0; | |
380 | bust_spinlocks(1); | |
c0a698b7 IM |
381 | } else |
382 | raw_local_irq_save(flags); | |
1da177e4 LT |
383 | |
384 | if (++die.lock_owner_depth < 3) { | |
7bee5c0f RD |
385 | unsigned long esp; |
386 | unsigned short ss; | |
387 | ||
608e2619 | 388 | report_bug(regs->eip, regs); |
91768d6c | 389 | |
9aa8d719 PE |
390 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, |
391 | ++die_counter); | |
1da177e4 | 392 | #ifdef CONFIG_PREEMPT |
9aa8d719 | 393 | printk("PREEMPT "); |
1da177e4 LT |
394 | #endif |
395 | #ifdef CONFIG_SMP | |
396 | printk("SMP "); | |
1da177e4 LT |
397 | #endif |
398 | #ifdef CONFIG_DEBUG_PAGEALLOC | |
399 | printk("DEBUG_PAGEALLOC"); | |
1da177e4 | 400 | #endif |
9aa8d719 PE |
401 | printk("\n"); |
402 | ||
20c0d2d4 JB |
403 | if (notify_die(DIE_OOPS, str, regs, err, |
404 | current->thread.trap_no, SIGSEGV) != | |
7bee5c0f | 405 | NOTIFY_STOP) { |
20c0d2d4 | 406 | show_registers(regs); |
7bee5c0f RD |
407 | /* Executive summary in case the oops scrolled away */ |
408 | esp = (unsigned long) (®s->esp); | |
409 | savesegment(ss, ss); | |
410 | if (user_mode(regs)) { | |
411 | esp = regs->esp; | |
412 | ss = regs->xss & 0xffff; | |
413 | } | |
414 | printk(KERN_EMERG "EIP: [<%08lx>] ", regs->eip); | |
415 | print_symbol("%s", regs->eip); | |
416 | printk(" SS:ESP %04x:%08lx\n", ss, esp); | |
417 | } | |
20c0d2d4 JB |
418 | else |
419 | regs = NULL; | |
1da177e4 | 420 | } else |
9c107805 | 421 | printk(KERN_EMERG "Recursive die() failure, output suppressed\n"); |
1da177e4 LT |
422 | |
423 | bust_spinlocks(0); | |
424 | die.lock_owner = -1; | |
bcdcd8e7 | 425 | add_taint(TAINT_DIE); |
39743c9e AK |
426 | __raw_spin_unlock(&die.lock); |
427 | raw_local_irq_restore(flags); | |
6e274d14 | 428 | |
20c0d2d4 JB |
429 | if (!regs) |
430 | return; | |
431 | ||
6e274d14 AN |
432 | if (kexec_should_crash(current)) |
433 | crash_kexec(regs); | |
434 | ||
1da177e4 LT |
435 | if (in_interrupt()) |
436 | panic("Fatal exception in interrupt"); | |
437 | ||
cea6a4ba | 438 | if (panic_on_oops) |
012c437d | 439 | panic("Fatal exception"); |
cea6a4ba | 440 | |
dd287796 | 441 | oops_exit(); |
1da177e4 LT |
442 | do_exit(SIGSEGV); |
443 | } | |
444 | ||
445 | static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err) | |
446 | { | |
717b594a | 447 | if (!user_mode_vm(regs)) |
1da177e4 LT |
448 | die(str, regs, err); |
449 | } | |
450 | ||
3d97ae5b PP |
451 | static void __kprobes do_trap(int trapnr, int signr, char *str, int vm86, |
452 | struct pt_regs * regs, long error_code, | |
453 | siginfo_t *info) | |
1da177e4 | 454 | { |
4f339ecb | 455 | struct task_struct *tsk = current; |
4f339ecb | 456 | |
1da177e4 LT |
457 | if (regs->eflags & VM_MASK) { |
458 | if (vm86) | |
459 | goto vm86_trap; | |
460 | goto trap_signal; | |
461 | } | |
462 | ||
717b594a | 463 | if (!user_mode(regs)) |
1da177e4 LT |
464 | goto kernel_trap; |
465 | ||
466 | trap_signal: { | |
d1895183 AK |
467 | /* |
468 | * We want error_code and trap_no set for userspace faults and | |
469 | * kernelspace faults which result in die(), but not | |
470 | * kernelspace faults which are fixed up. die() gives the | |
471 | * process no chance to handle the signal and notice the | |
472 | * kernel fault information, so that won't result in polluting | |
473 | * the information about previously queued, but not yet | |
474 | * delivered, faults. See also do_general_protection below. | |
475 | */ | |
476 | tsk->thread.error_code = error_code; | |
477 | tsk->thread.trap_no = trapnr; | |
478 | ||
1da177e4 LT |
479 | if (info) |
480 | force_sig_info(signr, info, tsk); | |
481 | else | |
482 | force_sig(signr, tsk); | |
483 | return; | |
484 | } | |
485 | ||
486 | kernel_trap: { | |
d1895183 AK |
487 | if (!fixup_exception(regs)) { |
488 | tsk->thread.error_code = error_code; | |
489 | tsk->thread.trap_no = trapnr; | |
1da177e4 | 490 | die(str, regs, error_code); |
d1895183 | 491 | } |
1da177e4 LT |
492 | return; |
493 | } | |
494 | ||
495 | vm86_trap: { | |
496 | int ret = handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, trapnr); | |
497 | if (ret) goto trap_signal; | |
498 | return; | |
499 | } | |
500 | } | |
501 | ||
502 | #define DO_ERROR(trapnr, signr, str, name) \ | |
503 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ | |
504 | { \ | |
505 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | |
506 | == NOTIFY_STOP) \ | |
507 | return; \ | |
508 | do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \ | |
509 | } | |
510 | ||
a10d9a71 | 511 | #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr, irq) \ |
1da177e4 LT |
512 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ |
513 | { \ | |
514 | siginfo_t info; \ | |
a10d9a71 PZ |
515 | if (irq) \ |
516 | local_irq_enable(); \ | |
1da177e4 LT |
517 | info.si_signo = signr; \ |
518 | info.si_errno = 0; \ | |
519 | info.si_code = sicode; \ | |
520 | info.si_addr = (void __user *)siaddr; \ | |
521 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | |
522 | == NOTIFY_STOP) \ | |
523 | return; \ | |
524 | do_trap(trapnr, signr, str, 0, regs, error_code, &info); \ | |
525 | } | |
526 | ||
527 | #define DO_VM86_ERROR(trapnr, signr, str, name) \ | |
528 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ | |
529 | { \ | |
530 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | |
531 | == NOTIFY_STOP) \ | |
532 | return; \ | |
533 | do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \ | |
534 | } | |
535 | ||
536 | #define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ | |
537 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ | |
538 | { \ | |
539 | siginfo_t info; \ | |
540 | info.si_signo = signr; \ | |
541 | info.si_errno = 0; \ | |
542 | info.si_code = sicode; \ | |
543 | info.si_addr = (void __user *)siaddr; \ | |
fb1dac90 | 544 | trace_hardirqs_fixup(); \ |
1da177e4 LT |
545 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
546 | == NOTIFY_STOP) \ | |
547 | return; \ | |
548 | do_trap(trapnr, signr, str, 1, regs, error_code, &info); \ | |
549 | } | |
550 | ||
551 | DO_VM86_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->eip) | |
552 | #ifndef CONFIG_KPROBES | |
553 | DO_VM86_ERROR( 3, SIGTRAP, "int3", int3) | |
554 | #endif | |
555 | DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow) | |
556 | DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds) | |
a10d9a71 | 557 | DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip, 0) |
1da177e4 LT |
558 | DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun) |
559 | DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS) | |
560 | DO_ERROR(11, SIGBUS, "segment not present", segment_not_present) | |
561 | DO_ERROR(12, SIGBUS, "stack segment", stack_segment) | |
a10d9a71 PZ |
562 | DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0) |
563 | DO_ERROR_INFO(32, SIGSEGV, "iret exception", iret_error, ILL_BADSTK, 0, 1) | |
1da177e4 | 564 | |
3d97ae5b PP |
565 | fastcall void __kprobes do_general_protection(struct pt_regs * regs, |
566 | long error_code) | |
1da177e4 LT |
567 | { |
568 | int cpu = get_cpu(); | |
569 | struct tss_struct *tss = &per_cpu(init_tss, cpu); | |
570 | struct thread_struct *thread = ¤t->thread; | |
571 | ||
572 | /* | |
573 | * Perform the lazy TSS's I/O bitmap copy. If the TSS has an | |
574 | * invalid offset set (the LAZY one) and the faulting thread has | |
575 | * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS | |
576 | * and we set the offset field correctly. Then we let the CPU to | |
577 | * restart the faulting instruction. | |
578 | */ | |
a75c54f9 | 579 | if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY && |
1da177e4 LT |
580 | thread->io_bitmap_ptr) { |
581 | memcpy(tss->io_bitmap, thread->io_bitmap_ptr, | |
582 | thread->io_bitmap_max); | |
583 | /* | |
584 | * If the previously set map was extending to higher ports | |
585 | * than the current one, pad extra space with 0xff (no access). | |
586 | */ | |
587 | if (thread->io_bitmap_max < tss->io_bitmap_max) | |
588 | memset((char *) tss->io_bitmap + | |
589 | thread->io_bitmap_max, 0xff, | |
590 | tss->io_bitmap_max - thread->io_bitmap_max); | |
591 | tss->io_bitmap_max = thread->io_bitmap_max; | |
a75c54f9 | 592 | tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET; |
d5cd4aad | 593 | tss->io_bitmap_owner = thread; |
1da177e4 LT |
594 | put_cpu(); |
595 | return; | |
596 | } | |
597 | put_cpu(); | |
598 | ||
599 | if (regs->eflags & VM_MASK) | |
600 | goto gp_in_vm86; | |
601 | ||
717b594a | 602 | if (!user_mode(regs)) |
1da177e4 LT |
603 | goto gp_in_kernel; |
604 | ||
605 | current->thread.error_code = error_code; | |
606 | current->thread.trap_no = 13; | |
abd4f750 MAS |
607 | if (show_unhandled_signals && unhandled_signal(current, SIGSEGV) && |
608 | printk_ratelimit()) | |
609 | printk(KERN_INFO | |
610 | "%s[%d] general protection eip:%lx esp:%lx error:%lx\n", | |
19c5870c | 611 | current->comm, task_pid_nr(current), |
abd4f750 MAS |
612 | regs->eip, regs->esp, error_code); |
613 | ||
1da177e4 LT |
614 | force_sig(SIGSEGV, current); |
615 | return; | |
616 | ||
617 | gp_in_vm86: | |
618 | local_irq_enable(); | |
619 | handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); | |
620 | return; | |
621 | ||
622 | gp_in_kernel: | |
623 | if (!fixup_exception(regs)) { | |
d1895183 AK |
624 | current->thread.error_code = error_code; |
625 | current->thread.trap_no = 13; | |
1da177e4 LT |
626 | if (notify_die(DIE_GPF, "general protection fault", regs, |
627 | error_code, 13, SIGSEGV) == NOTIFY_STOP) | |
628 | return; | |
629 | die("general protection fault", regs, error_code); | |
630 | } | |
631 | } | |
632 | ||