Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/i386/traps.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * |
| 6 | * Pentium III FXSR, SSE support |
| 7 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * 'Traps.c' handles hardware traps and faults after we have saved some |
| 12 | * state in 'asm.s'. |
| 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/sched.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/timer.h> |
| 19 | #include <linux/mm.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/spinlock.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/highmem.h> |
| 25 | #include <linux/kallsyms.h> |
| 26 | #include <linux/ptrace.h> |
| 27 | #include <linux/utsname.h> |
| 28 | #include <linux/kprobes.h> |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 29 | #include <linux/kexec.h> |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 30 | #include <linux/unwind.h> |
Andrew Morton | 1e2af92 | 2006-09-27 01:51:15 -0700 | [diff] [blame] | 31 | #include <linux/uaccess.h> |
Dave Jones | a36df98 | 2006-12-07 02:14:12 +0100 | [diff] [blame^] | 32 | #include <linux/nmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #ifdef CONFIG_EISA |
| 35 | #include <linux/ioport.h> |
| 36 | #include <linux/eisa.h> |
| 37 | #endif |
| 38 | |
| 39 | #ifdef CONFIG_MCA |
| 40 | #include <linux/mca.h> |
| 41 | #endif |
| 42 | |
| 43 | #include <asm/processor.h> |
| 44 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/io.h> |
| 46 | #include <asm/atomic.h> |
| 47 | #include <asm/debugreg.h> |
| 48 | #include <asm/desc.h> |
| 49 | #include <asm/i387.h> |
| 50 | #include <asm/nmi.h> |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 51 | #include <asm/unwind.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/smp.h> |
| 53 | #include <asm/arch_hooks.h> |
| 54 | #include <asm/kdebug.h> |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 55 | #include <asm/stacktrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <linux/module.h> |
| 58 | |
| 59 | #include "mach_traps.h" |
| 60 | |
Andi Kleen | 29cbc78 | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 61 | int panic_on_unrecovered_nmi; |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | asmlinkage int system_call(void); |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* Do we ignore FPU interrupts ? */ |
| 66 | char ignore_fpu_irq = 0; |
| 67 | |
| 68 | /* |
| 69 | * The IDT has to be page-aligned to simplify the Pentium |
| 70 | * F0 0F bug workaround.. We have a special link segment |
| 71 | * for this. |
| 72 | */ |
| 73 | struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, }; |
| 74 | |
| 75 | asmlinkage void divide_error(void); |
| 76 | asmlinkage void debug(void); |
| 77 | asmlinkage void nmi(void); |
| 78 | asmlinkage void int3(void); |
| 79 | asmlinkage void overflow(void); |
| 80 | asmlinkage void bounds(void); |
| 81 | asmlinkage void invalid_op(void); |
| 82 | asmlinkage void device_not_available(void); |
| 83 | asmlinkage void coprocessor_segment_overrun(void); |
| 84 | asmlinkage void invalid_TSS(void); |
| 85 | asmlinkage void segment_not_present(void); |
| 86 | asmlinkage void stack_segment(void); |
| 87 | asmlinkage void general_protection(void); |
| 88 | asmlinkage void page_fault(void); |
| 89 | asmlinkage void coprocessor_error(void); |
| 90 | asmlinkage void simd_coprocessor_error(void); |
| 91 | asmlinkage void alignment_check(void); |
| 92 | asmlinkage void spurious_interrupt_bug(void); |
| 93 | asmlinkage void machine_check(void); |
| 94 | |
Chuck Ebbert | 0741f4d | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 95 | int kstack_depth_to_print = 24; |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 96 | #ifdef CONFIG_STACK_UNWIND |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 97 | static int call_trace = 1; |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 98 | #else |
| 99 | #define call_trace (-1) |
| 100 | #endif |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 101 | ATOMIC_NOTIFIER_HEAD(i386die_chain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | int register_die_notifier(struct notifier_block *nb) |
| 104 | { |
Jan Beulich | 101f12a | 2006-03-23 02:59:45 -0800 | [diff] [blame] | 105 | vmalloc_sync_all(); |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 106 | return atomic_notifier_chain_register(&i386die_chain, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
Arjan van de Ven | 1454aed | 2006-07-10 04:44:05 -0700 | [diff] [blame] | 108 | EXPORT_SYMBOL(register_die_notifier); /* used modular by kdb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 110 | int unregister_die_notifier(struct notifier_block *nb) |
| 111 | { |
| 112 | return atomic_notifier_chain_unregister(&i386die_chain, nb); |
| 113 | } |
Arjan van de Ven | 1454aed | 2006-07-10 04:44:05 -0700 | [diff] [blame] | 114 | EXPORT_SYMBOL(unregister_die_notifier); /* used modular by kdb */ |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | static inline int valid_stack_ptr(struct thread_info *tinfo, void *p) |
| 117 | { |
| 118 | return p > (void *)tinfo && |
| 119 | p < (void *)tinfo + THREAD_SIZE - 3; |
| 120 | } |
| 121 | |
| 122 | static inline unsigned long print_context_stack(struct thread_info *tinfo, |
Chuck Ebbert | 7aa8974 | 2006-01-14 13:20:52 -0800 | [diff] [blame] | 123 | unsigned long *stack, unsigned long ebp, |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 124 | struct stacktrace_ops *ops, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
| 126 | unsigned long addr; |
| 127 | |
| 128 | #ifdef CONFIG_FRAME_POINTER |
| 129 | while (valid_stack_ptr(tinfo, (void *)ebp)) { |
Linus Torvalds | 808dbbb | 2006-11-17 11:14:56 -0800 | [diff] [blame] | 130 | unsigned long new_ebp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | addr = *(unsigned long *)(ebp + 4); |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 132 | ops->address(data, addr); |
Ingo Molnar | b88d4f1 | 2006-06-23 02:04:20 -0700 | [diff] [blame] | 133 | /* |
| 134 | * break out of recursive entries (such as |
Linus Torvalds | 808dbbb | 2006-11-17 11:14:56 -0800 | [diff] [blame] | 135 | * end_of_stack_stop_unwind_function). Also, |
| 136 | * we can never allow a frame pointer to |
| 137 | * move downwards! |
Ingo Molnar | b88d4f1 | 2006-06-23 02:04:20 -0700 | [diff] [blame] | 138 | */ |
Linus Torvalds | 808dbbb | 2006-11-17 11:14:56 -0800 | [diff] [blame] | 139 | new_ebp = *(unsigned long *)ebp; |
| 140 | if (new_ebp <= ebp) |
Ingo Molnar | b88d4f1 | 2006-06-23 02:04:20 -0700 | [diff] [blame] | 141 | break; |
Linus Torvalds | 808dbbb | 2006-11-17 11:14:56 -0800 | [diff] [blame] | 142 | ebp = new_ebp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | #else |
| 145 | while (valid_stack_ptr(tinfo, stack)) { |
| 146 | addr = *stack++; |
Chuck Ebbert | 7aa8974 | 2006-01-14 13:20:52 -0800 | [diff] [blame] | 147 | if (__kernel_text_address(addr)) |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 148 | ops->address(data, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | #endif |
| 151 | return ebp; |
| 152 | } |
| 153 | |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 154 | struct ops_and_data { |
| 155 | struct stacktrace_ops *ops; |
| 156 | void *data; |
| 157 | }; |
| 158 | |
Ingo Molnar | f0a5c31 | 2006-07-03 00:24:37 -0700 | [diff] [blame] | 159 | static asmlinkage int |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 160 | dump_trace_unwind(struct unwind_frame_info *info, void *data) |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 161 | { |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 162 | struct ops_and_data *oad = (struct ops_and_data *)data; |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 163 | int n = 0; |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 164 | |
| 165 | while (unwind(info) == 0 && UNW_PC(info)) { |
Ingo Molnar | f0a5c31 | 2006-07-03 00:24:37 -0700 | [diff] [blame] | 166 | n++; |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 167 | oad->ops->address(oad->data, UNW_PC(info)); |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 168 | if (arch_unw_user_mode(info)) |
| 169 | break; |
| 170 | } |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 171 | return n; |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 174 | #define MSG(msg) ops->warning(data, msg) |
| 175 | |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 176 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
| 177 | unsigned long *stack, |
| 178 | struct stacktrace_ops *ops, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { |
Andi Kleen | a32cf39 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 180 | unsigned long ebp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | if (!task) |
| 183 | task = current; |
| 184 | |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 185 | if (call_trace >= 0) { |
| 186 | int unw_ret = 0; |
| 187 | struct unwind_frame_info info; |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 188 | struct ops_and_data oad = { .ops = ops, .data = data }; |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 189 | |
| 190 | if (regs) { |
| 191 | if (unwind_init_frame_info(&info, task, regs) == 0) |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 192 | unw_ret = dump_trace_unwind(&info, &oad); |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 193 | } else if (task == current) |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 194 | unw_ret = unwind_init_running(&info, dump_trace_unwind, |
| 195 | &oad); |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 196 | else { |
| 197 | if (unwind_init_blocked(&info, task) == 0) |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 198 | unw_ret = dump_trace_unwind(&info, &oad); |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 199 | } |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 200 | if (unw_ret > 0) { |
| 201 | if (call_trace == 1 && !arch_unw_user_mode(&info)) { |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 202 | ops->warning_symbol(data, |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 203 | "DWARF2 unwinder stuck at %s", |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 204 | UNW_PC(&info)); |
| 205 | if (UNW_SP(&info) >= PAGE_OFFSET) { |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 206 | MSG("Leftover inexact backtrace:"); |
Andi Kleen | 7058316 | 2006-07-29 21:42:52 +0200 | [diff] [blame] | 207 | stack = (void *)UNW_SP(&info); |
Andi Kleen | 950fee8 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 208 | if (!stack) |
| 209 | return; |
Andi Kleen | a32cf39 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 210 | ebp = UNW_FP(&info); |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 211 | } else |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 212 | MSG("Full inexact backtrace again:"); |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 213 | } else if (call_trace >= 1) |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 214 | return; |
Andi Kleen | c97d20a | 2006-07-28 14:44:57 +0200 | [diff] [blame] | 215 | else |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 216 | MSG("Full inexact backtrace again:"); |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 217 | } else |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 218 | MSG("Inexact backtrace:"); |
Andi Kleen | a32cf39 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 219 | } |
| 220 | if (!stack) { |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 221 | unsigned long dummy; |
| 222 | stack = &dummy; |
| 223 | if (task && task != current) |
| 224 | stack = (unsigned long *)task->thread.esp; |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Andi Kleen | a32cf39 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 227 | #ifdef CONFIG_FRAME_POINTER |
| 228 | if (!ebp) { |
| 229 | if (task == current) { |
| 230 | /* Grab ebp right from our regs */ |
| 231 | asm ("movl %%ebp, %0" : "=r" (ebp) : ); |
| 232 | } else { |
| 233 | /* ebp is the last reg pushed by switch_to */ |
| 234 | ebp = *(unsigned long *) task->thread.esp; |
| 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
Andi Kleen | a32cf39 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 237 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | while (1) { |
| 240 | struct thread_info *context; |
| 241 | context = (struct thread_info *) |
| 242 | ((unsigned long)stack & (~(THREAD_SIZE - 1))); |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 243 | ebp = print_context_stack(context, stack, ebp, ops, data); |
| 244 | /* Should be after the line below, but somewhere |
| 245 | in early boot context comes out corrupted and we |
| 246 | can't reference it -AK */ |
| 247 | if (ops->stack(data, "IRQ") < 0) |
| 248 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | stack = (unsigned long*)context->previous_esp; |
| 250 | if (!stack) |
| 251 | break; |
Dave Jones | a36df98 | 2006-12-07 02:14:12 +0100 | [diff] [blame^] | 252 | touch_nmi_watchdog(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | } |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 255 | EXPORT_SYMBOL(dump_trace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Andi Kleen | 2b14a78 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 257 | static void |
| 258 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) |
| 259 | { |
| 260 | printk(data); |
| 261 | print_symbol(msg, symbol); |
| 262 | printk("\n"); |
| 263 | } |
| 264 | |
| 265 | static void print_trace_warning(void *data, char *msg) |
| 266 | { |
| 267 | printk("%s%s\n", (char *)data, msg); |
| 268 | } |
| 269 | |
| 270 | static int print_trace_stack(void *data, char *name) |
| 271 | { |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * Print one address/symbol entries per line. |
| 277 | */ |
| 278 | static void print_trace_address(void *data, unsigned long addr) |
| 279 | { |
| 280 | printk("%s [<%08lx>] ", (char *)data, addr); |
| 281 | print_symbol("%s\n", addr); |
| 282 | } |
| 283 | |
| 284 | static struct stacktrace_ops print_trace_ops = { |
| 285 | .warning = print_trace_warning, |
| 286 | .warning_symbol = print_trace_warning_symbol, |
| 287 | .stack = print_trace_stack, |
| 288 | .address = print_trace_address, |
| 289 | }; |
| 290 | |
| 291 | static void |
| 292 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, |
| 293 | unsigned long * stack, char *log_lvl) |
| 294 | { |
| 295 | dump_trace(task, regs, stack, &print_trace_ops, log_lvl); |
| 296 | printk("%s =======================\n", log_lvl); |
| 297 | } |
| 298 | |
| 299 | void show_trace(struct task_struct *task, struct pt_regs *regs, |
| 300 | unsigned long * stack) |
Chuck Ebbert | 7aa8974 | 2006-01-14 13:20:52 -0800 | [diff] [blame] | 301 | { |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 302 | show_trace_log_lvl(task, regs, stack, ""); |
Chuck Ebbert | 7aa8974 | 2006-01-14 13:20:52 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 305 | static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
| 306 | unsigned long *esp, char *log_lvl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
| 308 | unsigned long *stack; |
| 309 | int i; |
| 310 | |
| 311 | if (esp == NULL) { |
| 312 | if (task) |
| 313 | esp = (unsigned long*)task->thread.esp; |
| 314 | else |
| 315 | esp = (unsigned long *)&esp; |
| 316 | } |
| 317 | |
| 318 | stack = esp; |
| 319 | for(i = 0; i < kstack_depth_to_print; i++) { |
| 320 | if (kstack_end(stack)) |
| 321 | break; |
Chuck Ebbert | 75874d5 | 2006-03-23 02:59:52 -0800 | [diff] [blame] | 322 | if (i && ((i % 8) == 0)) |
| 323 | printk("\n%s ", log_lvl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | printk("%08lx ", *stack++); |
| 325 | } |
Chuck Ebbert | 75874d5 | 2006-03-23 02:59:52 -0800 | [diff] [blame] | 326 | printk("\n%sCall Trace:\n", log_lvl); |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 327 | show_trace_log_lvl(task, regs, esp, log_lvl); |
Chuck Ebbert | 7aa8974 | 2006-01-14 13:20:52 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void show_stack(struct task_struct *task, unsigned long *esp) |
| 331 | { |
Chuck Ebbert | 75874d5 | 2006-03-23 02:59:52 -0800 | [diff] [blame] | 332 | printk(" "); |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 333 | show_stack_log_lvl(task, NULL, esp, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /* |
| 337 | * The architecture-independent dump_stack generator |
| 338 | */ |
| 339 | void dump_stack(void) |
| 340 | { |
| 341 | unsigned long stack; |
| 342 | |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 343 | show_trace(current, NULL, &stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | EXPORT_SYMBOL(dump_stack); |
| 347 | |
| 348 | void show_registers(struct pt_regs *regs) |
| 349 | { |
| 350 | int i; |
| 351 | int in_kernel = 1; |
| 352 | unsigned long esp; |
| 353 | unsigned short ss; |
| 354 | |
| 355 | esp = (unsigned long) (®s->esp); |
Zachary Amsden | 0998e42 | 2005-09-03 15:56:43 -0700 | [diff] [blame] | 356 | savesegment(ss, ss); |
Jan Beulich | db753bd | 2006-03-23 02:59:46 -0800 | [diff] [blame] | 357 | if (user_mode_vm(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | in_kernel = 0; |
| 359 | esp = regs->esp; |
| 360 | ss = regs->xss & 0xffff; |
| 361 | } |
| 362 | print_modules(); |
Dave Jones | f354b3a | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 363 | printk(KERN_EMERG "CPU: %d\n" |
| 364 | KERN_EMERG "EIP: %04x:[<%08lx>] %s VLI\n" |
| 365 | KERN_EMERG "EFLAGS: %08lx (%s %.*s)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | smp_processor_id(), 0xffff & regs->xcs, regs->eip, |
Serge E. Hallyn | 96b644b | 2006-10-02 02:18:13 -0700 | [diff] [blame] | 367 | print_tainted(), regs->eflags, init_utsname()->release, |
| 368 | (int)strcspn(init_utsname()->version, " "), |
| 369 | init_utsname()->version); |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 370 | print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip); |
| 371 | printk(KERN_EMERG "eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | regs->eax, regs->ebx, regs->ecx, regs->edx); |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 373 | printk(KERN_EMERG "esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | regs->esi, regs->edi, regs->ebp, esp); |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 375 | printk(KERN_EMERG "ds: %04x es: %04x ss: %04x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | regs->xds & 0xffff, regs->xes & 0xffff, ss); |
Chuck Ebbert | 7e04a11 | 2006-06-23 02:04:31 -0700 | [diff] [blame] | 377 | printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)", |
| 378 | TASK_COMM_LEN, current->comm, current->pid, |
| 379 | current_thread_info(), current, current->thread_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | /* |
| 381 | * When in-kernel, we also print out the stack and code at the |
| 382 | * time of the fault.. |
| 383 | */ |
| 384 | if (in_kernel) { |
Andi Kleen | 11a4180 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 385 | u8 *eip; |
Chuck Ebbert | 9932532 | 2006-09-25 23:32:19 -0700 | [diff] [blame] | 386 | int code_bytes = 64; |
| 387 | unsigned char c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 389 | printk("\n" KERN_EMERG "Stack: "); |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 390 | show_stack_log_lvl(NULL, regs, (unsigned long *)esp, KERN_EMERG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 392 | printk(KERN_EMERG "Code: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Andi Kleen | 11a4180 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 394 | eip = (u8 *)regs->eip - 43; |
| 395 | if (eip < (u8 *)PAGE_OFFSET || |
| 396 | probe_kernel_address(eip, c)) { |
Chuck Ebbert | 9932532 | 2006-09-25 23:32:19 -0700 | [diff] [blame] | 397 | /* try starting at EIP */ |
Andi Kleen | 11a4180 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 398 | eip = (u8 *)regs->eip; |
Chuck Ebbert | 9932532 | 2006-09-25 23:32:19 -0700 | [diff] [blame] | 399 | code_bytes = 32; |
| 400 | } |
| 401 | for (i = 0; i < code_bytes; i++, eip++) { |
Andi Kleen | 11a4180 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 402 | if (eip < (u8 *)PAGE_OFFSET || |
| 403 | probe_kernel_address(eip, c)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | printk(" Bad EIP value."); |
| 405 | break; |
| 406 | } |
Andi Kleen | 11a4180 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 407 | if (eip == (u8 *)regs->eip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | printk("<%02x> ", c); |
| 409 | else |
| 410 | printk("%02x ", c); |
| 411 | } |
| 412 | } |
| 413 | printk("\n"); |
| 414 | } |
| 415 | |
| 416 | static void handle_BUG(struct pt_regs *regs) |
| 417 | { |
Chuck Ebbert | b701533 | 2006-07-14 00:23:58 -0700 | [diff] [blame] | 418 | unsigned long eip = regs->eip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | unsigned short ud2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | if (eip < PAGE_OFFSET) |
Chuck Ebbert | b701533 | 2006-07-14 00:23:58 -0700 | [diff] [blame] | 422 | return; |
Andi Kleen | 11a4180 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 423 | if (probe_kernel_address((unsigned short *)eip, ud2)) |
Chuck Ebbert | b701533 | 2006-07-14 00:23:58 -0700 | [diff] [blame] | 424 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | if (ud2 != 0x0b0f) |
Chuck Ebbert | b701533 | 2006-07-14 00:23:58 -0700 | [diff] [blame] | 426 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 428 | printk(KERN_EMERG "------------[ cut here ]------------\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Chuck Ebbert | b701533 | 2006-07-14 00:23:58 -0700 | [diff] [blame] | 430 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 431 | do { |
| 432 | unsigned short line; |
| 433 | char *file; |
| 434 | char c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Andi Kleen | 11a4180 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 436 | if (probe_kernel_address((unsigned short *)(eip + 2), line)) |
Chuck Ebbert | b701533 | 2006-07-14 00:23:58 -0700 | [diff] [blame] | 437 | break; |
Andi Kleen | 11a4180 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 438 | if (probe_kernel_address((char **)(eip + 4), file) || |
| 439 | (unsigned long)file < PAGE_OFFSET || |
| 440 | probe_kernel_address(file, c)) |
Chuck Ebbert | b701533 | 2006-07-14 00:23:58 -0700 | [diff] [blame] | 441 | file = "<bad filename>"; |
| 442 | |
| 443 | printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line); |
| 444 | return; |
| 445 | } while (0); |
| 446 | #endif |
| 447 | printk(KERN_EMERG "Kernel BUG at [verbose debug info unavailable]\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 450 | /* This is gone through when something in the kernel |
| 451 | * has done something bad and is about to be terminated. |
| 452 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | void die(const char * str, struct pt_regs * regs, long err) |
| 454 | { |
| 455 | static struct { |
| 456 | spinlock_t lock; |
| 457 | u32 lock_owner; |
| 458 | int lock_owner_depth; |
| 459 | } die = { |
| 460 | .lock = SPIN_LOCK_UNLOCKED, |
| 461 | .lock_owner = -1, |
| 462 | .lock_owner_depth = 0 |
| 463 | }; |
| 464 | static int die_counter; |
Jan Beulich | e43d674 | 2006-01-06 00:11:48 -0800 | [diff] [blame] | 465 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Andrew Morton | dd28779 | 2006-03-23 03:00:57 -0800 | [diff] [blame] | 467 | oops_enter(); |
| 468 | |
Ingo Molnar | 39c715b | 2005-06-21 17:14:34 -0700 | [diff] [blame] | 469 | if (die.lock_owner != raw_smp_processor_id()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | console_verbose(); |
Jan Beulich | e43d674 | 2006-01-06 00:11:48 -0800 | [diff] [blame] | 471 | spin_lock_irqsave(&die.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | die.lock_owner = smp_processor_id(); |
| 473 | die.lock_owner_depth = 0; |
| 474 | bust_spinlocks(1); |
| 475 | } |
Jan Beulich | e43d674 | 2006-01-06 00:11:48 -0800 | [diff] [blame] | 476 | else |
| 477 | local_save_flags(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | if (++die.lock_owner_depth < 3) { |
| 480 | int nl = 0; |
Randy Dunlap | 7bee5c0 | 2006-04-10 22:53:11 -0700 | [diff] [blame] | 481 | unsigned long esp; |
| 482 | unsigned short ss; |
| 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | handle_BUG(regs); |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 485 | printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | #ifdef CONFIG_PREEMPT |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 487 | printk(KERN_EMERG "PREEMPT "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | nl = 1; |
| 489 | #endif |
| 490 | #ifdef CONFIG_SMP |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 491 | if (!nl) |
| 492 | printk(KERN_EMERG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | printk("SMP "); |
| 494 | nl = 1; |
| 495 | #endif |
| 496 | #ifdef CONFIG_DEBUG_PAGEALLOC |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 497 | if (!nl) |
| 498 | printk(KERN_EMERG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | printk("DEBUG_PAGEALLOC"); |
| 500 | nl = 1; |
| 501 | #endif |
| 502 | if (nl) |
| 503 | printk("\n"); |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 504 | if (notify_die(DIE_OOPS, str, regs, err, |
| 505 | current->thread.trap_no, SIGSEGV) != |
Randy Dunlap | 7bee5c0 | 2006-04-10 22:53:11 -0700 | [diff] [blame] | 506 | NOTIFY_STOP) { |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 507 | show_registers(regs); |
Randy Dunlap | 7bee5c0 | 2006-04-10 22:53:11 -0700 | [diff] [blame] | 508 | /* Executive summary in case the oops scrolled away */ |
| 509 | esp = (unsigned long) (®s->esp); |
| 510 | savesegment(ss, ss); |
| 511 | if (user_mode(regs)) { |
| 512 | esp = regs->esp; |
| 513 | ss = regs->xss & 0xffff; |
| 514 | } |
| 515 | printk(KERN_EMERG "EIP: [<%08lx>] ", regs->eip); |
| 516 | print_symbol("%s", regs->eip); |
| 517 | printk(" SS:ESP %04x:%08lx\n", ss, esp); |
| 518 | } |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 519 | else |
| 520 | regs = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } else |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 522 | printk(KERN_EMERG "Recursive die() failure, output suppressed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
| 524 | bust_spinlocks(0); |
| 525 | die.lock_owner = -1; |
Jan Beulich | e43d674 | 2006-01-06 00:11:48 -0800 | [diff] [blame] | 526 | spin_unlock_irqrestore(&die.lock, flags); |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 527 | |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 528 | if (!regs) |
| 529 | return; |
| 530 | |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 531 | if (kexec_should_crash(current)) |
| 532 | crash_kexec(regs); |
| 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | if (in_interrupt()) |
| 535 | panic("Fatal exception in interrupt"); |
| 536 | |
Horms | cea6a4b | 2006-07-30 03:03:34 -0700 | [diff] [blame] | 537 | if (panic_on_oops) |
Horms | 012c437 | 2006-08-13 23:24:22 -0700 | [diff] [blame] | 538 | panic("Fatal exception"); |
Horms | cea6a4b | 2006-07-30 03:03:34 -0700 | [diff] [blame] | 539 | |
Andrew Morton | dd28779 | 2006-03-23 03:00:57 -0800 | [diff] [blame] | 540 | oops_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | do_exit(SIGSEGV); |
| 542 | } |
| 543 | |
| 544 | static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err) |
| 545 | { |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 546 | if (!user_mode_vm(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | die(str, regs, err); |
| 548 | } |
| 549 | |
Prasanna S Panchamukhi | 3d97ae5 | 2005-09-06 15:19:27 -0700 | [diff] [blame] | 550 | static void __kprobes do_trap(int trapnr, int signr, char *str, int vm86, |
| 551 | struct pt_regs * regs, long error_code, |
| 552 | siginfo_t *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
Alexander Nyberg | 4f339ec | 2005-06-25 14:58:27 -0700 | [diff] [blame] | 554 | struct task_struct *tsk = current; |
| 555 | tsk->thread.error_code = error_code; |
| 556 | tsk->thread.trap_no = trapnr; |
| 557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | if (regs->eflags & VM_MASK) { |
| 559 | if (vm86) |
| 560 | goto vm86_trap; |
| 561 | goto trap_signal; |
| 562 | } |
| 563 | |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 564 | if (!user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | goto kernel_trap; |
| 566 | |
| 567 | trap_signal: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | if (info) |
| 569 | force_sig_info(signr, info, tsk); |
| 570 | else |
| 571 | force_sig(signr, tsk); |
| 572 | return; |
| 573 | } |
| 574 | |
| 575 | kernel_trap: { |
| 576 | if (!fixup_exception(regs)) |
| 577 | die(str, regs, error_code); |
| 578 | return; |
| 579 | } |
| 580 | |
| 581 | vm86_trap: { |
| 582 | int ret = handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, trapnr); |
| 583 | if (ret) goto trap_signal; |
| 584 | return; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | #define DO_ERROR(trapnr, signr, str, name) \ |
| 589 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ |
| 590 | { \ |
| 591 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
| 592 | == NOTIFY_STOP) \ |
| 593 | return; \ |
| 594 | do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \ |
| 595 | } |
| 596 | |
| 597 | #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ |
| 598 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ |
| 599 | { \ |
| 600 | siginfo_t info; \ |
| 601 | info.si_signo = signr; \ |
| 602 | info.si_errno = 0; \ |
| 603 | info.si_code = sicode; \ |
| 604 | info.si_addr = (void __user *)siaddr; \ |
| 605 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
| 606 | == NOTIFY_STOP) \ |
| 607 | return; \ |
| 608 | do_trap(trapnr, signr, str, 0, regs, error_code, &info); \ |
| 609 | } |
| 610 | |
| 611 | #define DO_VM86_ERROR(trapnr, signr, str, name) \ |
| 612 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ |
| 613 | { \ |
| 614 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
| 615 | == NOTIFY_STOP) \ |
| 616 | return; \ |
| 617 | do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \ |
| 618 | } |
| 619 | |
| 620 | #define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ |
| 621 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ |
| 622 | { \ |
| 623 | siginfo_t info; \ |
| 624 | info.si_signo = signr; \ |
| 625 | info.si_errno = 0; \ |
| 626 | info.si_code = sicode; \ |
| 627 | info.si_addr = (void __user *)siaddr; \ |
| 628 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
| 629 | == NOTIFY_STOP) \ |
| 630 | return; \ |
| 631 | do_trap(trapnr, signr, str, 1, regs, error_code, &info); \ |
| 632 | } |
| 633 | |
| 634 | DO_VM86_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->eip) |
| 635 | #ifndef CONFIG_KPROBES |
| 636 | DO_VM86_ERROR( 3, SIGTRAP, "int3", int3) |
| 637 | #endif |
| 638 | DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow) |
| 639 | DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds) |
Chuck Ebbert | 631b034 | 2006-01-03 22:36:14 -0500 | [diff] [blame] | 640 | DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun) |
| 642 | DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS) |
| 643 | DO_ERROR(11, SIGBUS, "segment not present", segment_not_present) |
| 644 | DO_ERROR(12, SIGBUS, "stack segment", stack_segment) |
| 645 | DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0) |
Linus Torvalds | a879cbb | 2005-04-29 09:38:44 -0700 | [diff] [blame] | 646 | DO_ERROR_INFO(32, SIGSEGV, "iret exception", iret_error, ILL_BADSTK, 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Prasanna S Panchamukhi | 3d97ae5 | 2005-09-06 15:19:27 -0700 | [diff] [blame] | 648 | fastcall void __kprobes do_general_protection(struct pt_regs * regs, |
| 649 | long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
| 651 | int cpu = get_cpu(); |
| 652 | struct tss_struct *tss = &per_cpu(init_tss, cpu); |
| 653 | struct thread_struct *thread = ¤t->thread; |
| 654 | |
| 655 | /* |
| 656 | * Perform the lazy TSS's I/O bitmap copy. If the TSS has an |
| 657 | * invalid offset set (the LAZY one) and the faulting thread has |
| 658 | * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS |
| 659 | * and we set the offset field correctly. Then we let the CPU to |
| 660 | * restart the faulting instruction. |
| 661 | */ |
| 662 | if (tss->io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY && |
| 663 | thread->io_bitmap_ptr) { |
| 664 | memcpy(tss->io_bitmap, thread->io_bitmap_ptr, |
| 665 | thread->io_bitmap_max); |
| 666 | /* |
| 667 | * If the previously set map was extending to higher ports |
| 668 | * than the current one, pad extra space with 0xff (no access). |
| 669 | */ |
| 670 | if (thread->io_bitmap_max < tss->io_bitmap_max) |
| 671 | memset((char *) tss->io_bitmap + |
| 672 | thread->io_bitmap_max, 0xff, |
| 673 | tss->io_bitmap_max - thread->io_bitmap_max); |
| 674 | tss->io_bitmap_max = thread->io_bitmap_max; |
| 675 | tss->io_bitmap_base = IO_BITMAP_OFFSET; |
Bart Oldeman | d5cd4aa | 2005-10-30 14:59:29 -0800 | [diff] [blame] | 676 | tss->io_bitmap_owner = thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | put_cpu(); |
| 678 | return; |
| 679 | } |
| 680 | put_cpu(); |
| 681 | |
Alexander Nyberg | 4f339ec | 2005-06-25 14:58:27 -0700 | [diff] [blame] | 682 | current->thread.error_code = error_code; |
| 683 | current->thread.trap_no = 13; |
| 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | if (regs->eflags & VM_MASK) |
| 686 | goto gp_in_vm86; |
| 687 | |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 688 | if (!user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | goto gp_in_kernel; |
| 690 | |
| 691 | current->thread.error_code = error_code; |
| 692 | current->thread.trap_no = 13; |
| 693 | force_sig(SIGSEGV, current); |
| 694 | return; |
| 695 | |
| 696 | gp_in_vm86: |
| 697 | local_irq_enable(); |
| 698 | handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); |
| 699 | return; |
| 700 | |
| 701 | gp_in_kernel: |
| 702 | if (!fixup_exception(regs)) { |
| 703 | if (notify_die(DIE_GPF, "general protection fault", regs, |
| 704 | error_code, 13, SIGSEGV) == NOTIFY_STOP) |
| 705 | return; |
| 706 | die("general protection fault", regs, error_code); |
| 707 | } |
| 708 | } |
| 709 | |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 710 | static __kprobes void |
| 711 | mem_parity_error(unsigned char reason, struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | { |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 713 | printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x on " |
| 714 | "CPU %d.\n", reason, smp_processor_id()); |
Andi Kleen | 9c5f8be | 2006-12-07 02:14:03 +0100 | [diff] [blame] | 715 | printk(KERN_EMERG "You have some hardware problem, likely on the PCI bus.\n"); |
Don Zickus | 8da5adda | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 716 | if (panic_on_unrecovered_nmi) |
| 717 | panic("NMI: Not continuing"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 719 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
| 721 | /* Clear and disable the memory parity error line. */ |
| 722 | clear_mem_error(reason); |
| 723 | } |
| 724 | |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 725 | static __kprobes void |
| 726 | io_check_error(unsigned char reason, struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
| 728 | unsigned long i; |
| 729 | |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 730 | printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | show_registers(regs); |
| 732 | |
| 733 | /* Re-enable the IOCK line, wait for a few seconds */ |
| 734 | reason = (reason & 0xf) | 8; |
| 735 | outb(reason, 0x61); |
| 736 | i = 2000; |
| 737 | while (--i) udelay(1000); |
| 738 | reason &= ~8; |
| 739 | outb(reason, 0x61); |
| 740 | } |
| 741 | |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 742 | static __kprobes void |
| 743 | unknown_nmi_error(unsigned char reason, struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
| 745 | #ifdef CONFIG_MCA |
| 746 | /* Might actually be able to figure out what the guilty party |
| 747 | * is. */ |
| 748 | if( MCA_bus ) { |
| 749 | mca_handle_nmi(); |
| 750 | return; |
| 751 | } |
| 752 | #endif |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 753 | printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x on " |
| 754 | "CPU %d.\n", reason, smp_processor_id()); |
| 755 | printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n"); |
Don Zickus | 8da5adda | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 756 | if (panic_on_unrecovered_nmi) |
| 757 | panic("NMI: Not continuing"); |
| 758 | |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 759 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static DEFINE_SPINLOCK(nmi_print_lock); |
| 763 | |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 764 | void __kprobes die_nmi(struct pt_regs *regs, const char *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | { |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 766 | if (notify_die(DIE_NMIWATCHDOG, msg, regs, 0, 2, SIGINT) == |
George Anzinger | 748f2ed | 2005-09-03 15:56:48 -0700 | [diff] [blame] | 767 | NOTIFY_STOP) |
| 768 | return; |
| 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | spin_lock(&nmi_print_lock); |
| 771 | /* |
| 772 | * We are in trouble anyway, lets at least try |
| 773 | * to get a message out. |
| 774 | */ |
| 775 | bust_spinlocks(1); |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 776 | printk(KERN_EMERG "%s", msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | printk(" on CPU%d, eip %08lx, registers:\n", |
| 778 | smp_processor_id(), regs->eip); |
| 779 | show_registers(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | console_silent(); |
| 781 | spin_unlock(&nmi_print_lock); |
| 782 | bust_spinlocks(0); |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 783 | |
| 784 | /* If we are in kernel we are probably nested up pretty bad |
| 785 | * and might aswell get out now while we still can. |
| 786 | */ |
Jan Beulich | db753bd | 2006-03-23 02:59:46 -0800 | [diff] [blame] | 787 | if (!user_mode_vm(regs)) { |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 788 | current->thread.trap_no = 2; |
| 789 | crash_kexec(regs); |
| 790 | } |
| 791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | do_exit(SIGSEGV); |
| 793 | } |
| 794 | |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 795 | static __kprobes void default_do_nmi(struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | { |
| 797 | unsigned char reason = 0; |
| 798 | |
| 799 | /* Only the BSP gets external NMIs from the system. */ |
| 800 | if (!smp_processor_id()) |
| 801 | reason = get_nmi_reason(); |
| 802 | |
| 803 | if (!(reason & 0xc0)) { |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 804 | if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | == NOTIFY_STOP) |
| 806 | return; |
| 807 | #ifdef CONFIG_X86_LOCAL_APIC |
| 808 | /* |
| 809 | * Ok, so this is none of the documented NMI sources, |
| 810 | * so it must be the NMI watchdog. |
| 811 | */ |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 812 | if (nmi_watchdog_tick(regs, reason)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | return; |
Don Zickus | 2fbe7b2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 814 | if (!do_nmi_callback(regs, smp_processor_id())) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | #endif |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 816 | unknown_nmi_error(reason, regs); |
Don Zickus | 2fbe7b2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | return; |
| 819 | } |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 820 | if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | return; |
| 822 | if (reason & 0x80) |
| 823 | mem_parity_error(reason, regs); |
| 824 | if (reason & 0x40) |
| 825 | io_check_error(reason, regs); |
| 826 | /* |
| 827 | * Reassert NMI in case it became active meanwhile |
| 828 | * as it's edge-triggered. |
| 829 | */ |
| 830 | reassert_nmi(); |
| 831 | } |
| 832 | |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 833 | fastcall __kprobes void do_nmi(struct pt_regs * regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | { |
| 835 | int cpu; |
| 836 | |
| 837 | nmi_enter(); |
| 838 | |
| 839 | cpu = smp_processor_id(); |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | ++nmi_count(cpu); |
| 842 | |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 843 | default_do_nmi(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
| 845 | nmi_exit(); |
| 846 | } |
| 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | #ifdef CONFIG_KPROBES |
Prasanna S Panchamukhi | 3d97ae5 | 2005-09-06 15:19:27 -0700 | [diff] [blame] | 849 | fastcall void __kprobes do_int3(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
| 851 | if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) |
| 852 | == NOTIFY_STOP) |
Stas Sergeev | 48c88211 | 2005-05-01 08:58:49 -0700 | [diff] [blame] | 853 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | /* This is an interrupt gate, because kprobes wants interrupts |
| 855 | disabled. Normal trap handlers don't. */ |
| 856 | restore_interrupts(regs); |
| 857 | do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } |
| 859 | #endif |
| 860 | |
| 861 | /* |
| 862 | * Our handling of the processor debug registers is non-trivial. |
| 863 | * We do not clear them on entry and exit from the kernel. Therefore |
| 864 | * it is possible to get a watchpoint trap here from inside the kernel. |
| 865 | * However, the code in ./ptrace.c has ensured that the user can |
| 866 | * only set watchpoints on userspace addresses. Therefore the in-kernel |
| 867 | * watchpoint trap can only occur in code which is reading/writing |
| 868 | * from user space. Such code must not hold kernel locks (since it |
| 869 | * can equally take a page fault), therefore it is safe to call |
| 870 | * force_sig_info even though that claims and releases locks. |
| 871 | * |
| 872 | * Code in ./signal.c ensures that the debug control register |
| 873 | * is restored before we deliver any signal, and therefore that |
| 874 | * user code runs with the correct debug control register even though |
| 875 | * we clear it here. |
| 876 | * |
| 877 | * Being careful here means that we don't have to be as careful in a |
| 878 | * lot of more complicated places (task switching can be a bit lazy |
| 879 | * about restoring all the debug state, and ptrace doesn't have to |
| 880 | * find every occurrence of the TF bit that could be saved away even |
| 881 | * by user code) |
| 882 | */ |
Prasanna S Panchamukhi | 3d97ae5 | 2005-09-06 15:19:27 -0700 | [diff] [blame] | 883 | fastcall void __kprobes do_debug(struct pt_regs * regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
| 885 | unsigned int condition; |
| 886 | struct task_struct *tsk = current; |
| 887 | |
Vincent Hanquez | 1cc6f12 | 2005-06-23 00:08:43 -0700 | [diff] [blame] | 888 | get_debugreg(condition, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
| 890 | if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code, |
| 891 | SIGTRAP) == NOTIFY_STOP) |
| 892 | return; |
| 893 | /* It's safe to allow irq's after DR6 has been saved */ |
| 894 | if (regs->eflags & X86_EFLAGS_IF) |
| 895 | local_irq_enable(); |
| 896 | |
| 897 | /* Mask out spurious debug traps due to lazy DR7 setting */ |
| 898 | if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) { |
| 899 | if (!tsk->thread.debugreg[7]) |
| 900 | goto clear_dr7; |
| 901 | } |
| 902 | |
| 903 | if (regs->eflags & VM_MASK) |
| 904 | goto debug_vm86; |
| 905 | |
| 906 | /* Save debug status register where ptrace can see it */ |
| 907 | tsk->thread.debugreg[6] = condition; |
| 908 | |
| 909 | /* |
| 910 | * Single-stepping through TF: make sure we ignore any events in |
| 911 | * kernel space (but re-enable TF when returning to user mode). |
| 912 | */ |
| 913 | if (condition & DR_STEP) { |
| 914 | /* |
| 915 | * We already checked v86 mode above, so we can |
| 916 | * check for kernel mode by just checking the CPL |
| 917 | * of CS. |
| 918 | */ |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 919 | if (!user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | goto clear_TF_reenable; |
| 921 | } |
| 922 | |
| 923 | /* Ok, finally something we can handle */ |
| 924 | send_sigtrap(tsk, regs, error_code); |
| 925 | |
| 926 | /* Disable additional traps. They'll be re-enabled when |
| 927 | * the signal is delivered. |
| 928 | */ |
| 929 | clear_dr7: |
Vincent Hanquez | 1cc6f12 | 2005-06-23 00:08:43 -0700 | [diff] [blame] | 930 | set_debugreg(0, 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | return; |
| 932 | |
| 933 | debug_vm86: |
| 934 | handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1); |
| 935 | return; |
| 936 | |
| 937 | clear_TF_reenable: |
| 938 | set_tsk_thread_flag(tsk, TIF_SINGLESTEP); |
| 939 | regs->eflags &= ~TF_MASK; |
| 940 | return; |
| 941 | } |
| 942 | |
| 943 | /* |
| 944 | * Note that we play around with the 'TS' bit in an attempt to get |
| 945 | * the correct behaviour even in the presence of the asynchronous |
| 946 | * IRQ13 behaviour |
| 947 | */ |
| 948 | void math_error(void __user *eip) |
| 949 | { |
| 950 | struct task_struct * task; |
| 951 | siginfo_t info; |
| 952 | unsigned short cwd, swd; |
| 953 | |
| 954 | /* |
| 955 | * Save the info for the exception handler and clear the error. |
| 956 | */ |
| 957 | task = current; |
| 958 | save_init_fpu(task); |
| 959 | task->thread.trap_no = 16; |
| 960 | task->thread.error_code = 0; |
| 961 | info.si_signo = SIGFPE; |
| 962 | info.si_errno = 0; |
| 963 | info.si_code = __SI_FAULT; |
| 964 | info.si_addr = eip; |
| 965 | /* |
| 966 | * (~cwd & swd) will mask out exceptions that are not set to unmasked |
| 967 | * status. 0x3f is the exception bits in these regs, 0x200 is the |
| 968 | * C1 reg you need in case of a stack fault, 0x040 is the stack |
| 969 | * fault bit. We should only be taking one exception at a time, |
| 970 | * so if this combination doesn't produce any single exception, |
| 971 | * then we have a bad program that isn't syncronizing its FPU usage |
| 972 | * and it will suffer the consequences since we won't be able to |
| 973 | * fully reproduce the context of the exception |
| 974 | */ |
| 975 | cwd = get_fpu_cwd(task); |
| 976 | swd = get_fpu_swd(task); |
Chuck Ebbert | b1daec3 | 2005-08-23 21:36:40 -0400 | [diff] [blame] | 977 | switch (swd & ~cwd & 0x3f) { |
Chuck Ebbert | 3333337 | 2005-09-13 04:55:41 -0400 | [diff] [blame] | 978 | case 0x000: /* No unmasked exception */ |
| 979 | return; |
| 980 | default: /* Multiple exceptions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | break; |
| 982 | case 0x001: /* Invalid Op */ |
Chuck Ebbert | b1daec3 | 2005-08-23 21:36:40 -0400 | [diff] [blame] | 983 | /* |
| 984 | * swd & 0x240 == 0x040: Stack Underflow |
| 985 | * swd & 0x240 == 0x240: Stack Overflow |
| 986 | * User must clear the SF bit (0x40) if set |
| 987 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | info.si_code = FPE_FLTINV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | break; |
| 990 | case 0x002: /* Denormalize */ |
| 991 | case 0x010: /* Underflow */ |
| 992 | info.si_code = FPE_FLTUND; |
| 993 | break; |
| 994 | case 0x004: /* Zero Divide */ |
| 995 | info.si_code = FPE_FLTDIV; |
| 996 | break; |
| 997 | case 0x008: /* Overflow */ |
| 998 | info.si_code = FPE_FLTOVF; |
| 999 | break; |
| 1000 | case 0x020: /* Precision */ |
| 1001 | info.si_code = FPE_FLTRES; |
| 1002 | break; |
| 1003 | } |
| 1004 | force_sig_info(SIGFPE, &info, task); |
| 1005 | } |
| 1006 | |
| 1007 | fastcall void do_coprocessor_error(struct pt_regs * regs, long error_code) |
| 1008 | { |
| 1009 | ignore_fpu_irq = 1; |
| 1010 | math_error((void __user *)regs->eip); |
| 1011 | } |
| 1012 | |
| 1013 | static void simd_math_error(void __user *eip) |
| 1014 | { |
| 1015 | struct task_struct * task; |
| 1016 | siginfo_t info; |
| 1017 | unsigned short mxcsr; |
| 1018 | |
| 1019 | /* |
| 1020 | * Save the info for the exception handler and clear the error. |
| 1021 | */ |
| 1022 | task = current; |
| 1023 | save_init_fpu(task); |
| 1024 | task->thread.trap_no = 19; |
| 1025 | task->thread.error_code = 0; |
| 1026 | info.si_signo = SIGFPE; |
| 1027 | info.si_errno = 0; |
| 1028 | info.si_code = __SI_FAULT; |
| 1029 | info.si_addr = eip; |
| 1030 | /* |
| 1031 | * The SIMD FPU exceptions are handled a little differently, as there |
| 1032 | * is only a single status/control register. Thus, to determine which |
| 1033 | * unmasked exception was caught we must mask the exception mask bits |
| 1034 | * at 0x1f80, and then use these to mask the exception bits at 0x3f. |
| 1035 | */ |
| 1036 | mxcsr = get_fpu_mxcsr(task); |
| 1037 | switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) { |
| 1038 | case 0x000: |
| 1039 | default: |
| 1040 | break; |
| 1041 | case 0x001: /* Invalid Op */ |
| 1042 | info.si_code = FPE_FLTINV; |
| 1043 | break; |
| 1044 | case 0x002: /* Denormalize */ |
| 1045 | case 0x010: /* Underflow */ |
| 1046 | info.si_code = FPE_FLTUND; |
| 1047 | break; |
| 1048 | case 0x004: /* Zero Divide */ |
| 1049 | info.si_code = FPE_FLTDIV; |
| 1050 | break; |
| 1051 | case 0x008: /* Overflow */ |
| 1052 | info.si_code = FPE_FLTOVF; |
| 1053 | break; |
| 1054 | case 0x020: /* Precision */ |
| 1055 | info.si_code = FPE_FLTRES; |
| 1056 | break; |
| 1057 | } |
| 1058 | force_sig_info(SIGFPE, &info, task); |
| 1059 | } |
| 1060 | |
| 1061 | fastcall void do_simd_coprocessor_error(struct pt_regs * regs, |
| 1062 | long error_code) |
| 1063 | { |
| 1064 | if (cpu_has_xmm) { |
| 1065 | /* Handle SIMD FPU exceptions on PIII+ processors. */ |
| 1066 | ignore_fpu_irq = 1; |
| 1067 | simd_math_error((void __user *)regs->eip); |
| 1068 | } else { |
| 1069 | /* |
| 1070 | * Handle strange cache flush from user space exception |
| 1071 | * in all other cases. This is undocumented behaviour. |
| 1072 | */ |
| 1073 | if (regs->eflags & VM_MASK) { |
| 1074 | handle_vm86_fault((struct kernel_vm86_regs *)regs, |
| 1075 | error_code); |
| 1076 | return; |
| 1077 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | current->thread.trap_no = 19; |
| 1079 | current->thread.error_code = error_code; |
Alexander Nyberg | 4f339ec | 2005-06-25 14:58:27 -0700 | [diff] [blame] | 1080 | die_if_kernel("cache flush denied", regs, error_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | force_sig(SIGSEGV, current); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | fastcall void do_spurious_interrupt_bug(struct pt_regs * regs, |
| 1086 | long error_code) |
| 1087 | { |
| 1088 | #if 0 |
| 1089 | /* No need to warn about this any longer. */ |
| 1090 | printk("Ignoring P6 Local APIC Spurious Interrupt Bug...\n"); |
| 1091 | #endif |
| 1092 | } |
| 1093 | |
Stas Sergeev | be44d2a | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 1094 | fastcall unsigned long patch_espfix_desc(unsigned long uesp, |
| 1095 | unsigned long kesp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | int cpu = smp_processor_id(); |
Stas Sergeev | be44d2a | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 1098 | struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, cpu); |
| 1099 | struct desc_struct *gdt = (struct desc_struct *)cpu_gdt_descr->address; |
| 1100 | unsigned long base = (kesp - uesp) & -THREAD_SIZE; |
| 1101 | unsigned long new_kesp = kesp - base; |
| 1102 | unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT; |
| 1103 | __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS]; |
| 1104 | /* Set up base for espfix segment */ |
| 1105 | desc &= 0x00f0ff0000000000ULL; |
| 1106 | desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) | |
| 1107 | ((((__u64)base) << 32) & 0xff00000000000000ULL) | |
| 1108 | ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) | |
| 1109 | (lim_pages & 0xffff); |
| 1110 | *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc; |
| 1111 | return new_kesp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | /* |
| 1115 | * 'math_state_restore()' saves the current math information in the |
| 1116 | * old math state array, and gets the new ones from the current task |
| 1117 | * |
| 1118 | * Careful.. There are problems with IBM-designed IRQ13 behaviour. |
| 1119 | * Don't touch unless you *really* know how it works. |
| 1120 | * |
| 1121 | * Must be called with kernel preemption disabled (in this case, |
| 1122 | * local interrupts are disabled at the call-site in entry.S). |
| 1123 | */ |
Chuck Ebbert | acc2076 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 1124 | asmlinkage void math_state_restore(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | { |
| 1126 | struct thread_info *thread = current_thread_info(); |
| 1127 | struct task_struct *tsk = thread->task; |
| 1128 | |
| 1129 | clts(); /* Allow maths ops (or we recurse) */ |
| 1130 | if (!tsk_used_math(tsk)) |
| 1131 | init_fpu(tsk); |
| 1132 | restore_fpu(tsk); |
| 1133 | thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */ |
Chuck Ebbert | acc2076 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 1134 | tsk->fpu_counter++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | #ifndef CONFIG_MATH_EMULATION |
| 1138 | |
| 1139 | asmlinkage void math_emulate(long arg) |
| 1140 | { |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 1141 | printk(KERN_EMERG "math-emulation not enabled and no coprocessor found.\n"); |
| 1142 | printk(KERN_EMERG "killing %s.\n",current->comm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | force_sig(SIGFPE,current); |
| 1144 | schedule(); |
| 1145 | } |
| 1146 | |
| 1147 | #endif /* CONFIG_MATH_EMULATION */ |
| 1148 | |
| 1149 | #ifdef CONFIG_X86_F00F_BUG |
| 1150 | void __init trap_init_f00f_bug(void) |
| 1151 | { |
| 1152 | __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO); |
| 1153 | |
| 1154 | /* |
| 1155 | * Update the IDT descriptor and reload the IDT so that |
| 1156 | * it uses the read-only mapped virtual address. |
| 1157 | */ |
| 1158 | idt_descr.address = fix_to_virt(FIX_F00F_IDT); |
Zachary Amsden | 4d37e7e | 2005-09-03 15:56:38 -0700 | [diff] [blame] | 1159 | load_idt(&idt_descr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | } |
| 1161 | #endif |
| 1162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | /* |
| 1164 | * This needs to use 'idt_table' rather than 'idt', and |
| 1165 | * thus use the _nonmapped_ version of the IDT, as the |
| 1166 | * Pentium F0 0F bugfix can have resulted in the mapped |
| 1167 | * IDT being write-protected. |
| 1168 | */ |
| 1169 | void set_intr_gate(unsigned int n, void *addr) |
| 1170 | { |
Rusty Russell | 522e93e | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 1171 | _set_gate(n, DESCTYPE_INT, addr, __KERNEL_CS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /* |
| 1175 | * This routine sets up an interrupt gate at directory privilege level 3. |
| 1176 | */ |
| 1177 | static inline void set_system_intr_gate(unsigned int n, void *addr) |
| 1178 | { |
Rusty Russell | 522e93e | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 1179 | _set_gate(n, DESCTYPE_INT | DESCTYPE_DPL3, addr, __KERNEL_CS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | static void __init set_trap_gate(unsigned int n, void *addr) |
| 1183 | { |
Rusty Russell | 522e93e | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 1184 | _set_gate(n, DESCTYPE_TRAP, addr, __KERNEL_CS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | static void __init set_system_gate(unsigned int n, void *addr) |
| 1188 | { |
Rusty Russell | 522e93e | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 1189 | _set_gate(n, DESCTYPE_TRAP | DESCTYPE_DPL3, addr, __KERNEL_CS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | static void __init set_task_gate(unsigned int n, unsigned int gdt_entry) |
| 1193 | { |
Rusty Russell | 522e93e | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 1194 | _set_gate(n, DESCTYPE_TASK, (void *)0, (gdt_entry<<3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | void __init trap_init(void) |
| 1199 | { |
| 1200 | #ifdef CONFIG_EISA |
| 1201 | void __iomem *p = ioremap(0x0FFFD9, 4); |
| 1202 | if (readl(p) == 'E'+('I'<<8)+('S'<<16)+('A'<<24)) { |
| 1203 | EISA_bus = 1; |
| 1204 | } |
| 1205 | iounmap(p); |
| 1206 | #endif |
| 1207 | |
| 1208 | #ifdef CONFIG_X86_LOCAL_APIC |
| 1209 | init_apic_mappings(); |
| 1210 | #endif |
| 1211 | |
| 1212 | set_trap_gate(0,÷_error); |
| 1213 | set_intr_gate(1,&debug); |
| 1214 | set_intr_gate(2,&nmi); |
Jan Beulich | eb05c32 | 2006-01-06 00:11:49 -0800 | [diff] [blame] | 1215 | set_system_intr_gate(3, &int3); /* int3/4 can be called from all */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | set_system_gate(4,&overflow); |
Jan Beulich | eb05c32 | 2006-01-06 00:11:49 -0800 | [diff] [blame] | 1217 | set_trap_gate(5,&bounds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | set_trap_gate(6,&invalid_op); |
| 1219 | set_trap_gate(7,&device_not_available); |
| 1220 | set_task_gate(8,GDT_ENTRY_DOUBLEFAULT_TSS); |
| 1221 | set_trap_gate(9,&coprocessor_segment_overrun); |
| 1222 | set_trap_gate(10,&invalid_TSS); |
| 1223 | set_trap_gate(11,&segment_not_present); |
| 1224 | set_trap_gate(12,&stack_segment); |
| 1225 | set_trap_gate(13,&general_protection); |
| 1226 | set_intr_gate(14,&page_fault); |
| 1227 | set_trap_gate(15,&spurious_interrupt_bug); |
| 1228 | set_trap_gate(16,&coprocessor_error); |
| 1229 | set_trap_gate(17,&alignment_check); |
| 1230 | #ifdef CONFIG_X86_MCE |
| 1231 | set_trap_gate(18,&machine_check); |
| 1232 | #endif |
| 1233 | set_trap_gate(19,&simd_coprocessor_error); |
| 1234 | |
Jan Beulich | d43c6e8 | 2006-01-06 00:11:49 -0800 | [diff] [blame] | 1235 | if (cpu_has_fxsr) { |
| 1236 | /* |
| 1237 | * Verify that the FXSAVE/FXRSTOR data will be 16-byte aligned. |
| 1238 | * Generates a compile-time "error: zero width for bit-field" if |
| 1239 | * the alignment is wrong. |
| 1240 | */ |
| 1241 | struct fxsrAlignAssert { |
| 1242 | int _:!(offsetof(struct task_struct, |
| 1243 | thread.i387.fxsave) & 15); |
| 1244 | }; |
| 1245 | |
| 1246 | printk(KERN_INFO "Enabling fast FPU save and restore... "); |
| 1247 | set_in_cr4(X86_CR4_OSFXSR); |
| 1248 | printk("done.\n"); |
| 1249 | } |
| 1250 | if (cpu_has_xmm) { |
| 1251 | printk(KERN_INFO "Enabling unmasked SIMD FPU exception " |
| 1252 | "support... "); |
| 1253 | set_in_cr4(X86_CR4_OSXMMEXCPT); |
| 1254 | printk("done.\n"); |
| 1255 | } |
| 1256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | set_system_gate(SYSCALL_VECTOR,&system_call); |
| 1258 | |
| 1259 | /* |
| 1260 | * Should be a barrier for any external CPU state. |
| 1261 | */ |
| 1262 | cpu_init(); |
| 1263 | |
| 1264 | trap_init_hook(); |
| 1265 | } |
| 1266 | |
| 1267 | static int __init kstack_setup(char *s) |
| 1268 | { |
| 1269 | kstack_depth_to_print = simple_strtoul(s, NULL, 0); |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1270 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | } |
| 1272 | __setup("kstack=", kstack_setup); |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 1273 | |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 1274 | #ifdef CONFIG_STACK_UNWIND |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 1275 | static int __init call_trace_setup(char *s) |
| 1276 | { |
| 1277 | if (strcmp(s, "old") == 0) |
| 1278 | call_trace = -1; |
| 1279 | else if (strcmp(s, "both") == 0) |
| 1280 | call_trace = 0; |
Andi Kleen | 7058316 | 2006-07-29 21:42:52 +0200 | [diff] [blame] | 1281 | else if (strcmp(s, "newfallback") == 0) |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 1282 | call_trace = 1; |
Andi Kleen | 7058316 | 2006-07-29 21:42:52 +0200 | [diff] [blame] | 1283 | else if (strcmp(s, "new") == 2) |
| 1284 | call_trace = 2; |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 1285 | return 1; |
| 1286 | } |
| 1287 | __setup("call_trace=", call_trace_setup); |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 1288 | #endif |