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