Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/x86-64/traps.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs |
| 6 | * |
| 7 | * Pentium III FXSR, SSE support |
| 8 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * 'Traps.c' handles hardware traps and faults after we have saved some |
| 13 | * state in 'entry.S'. |
| 14 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/sched.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/ptrace.h> |
| 20 | #include <linux/timer.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/interrupt.h> |
Randy Dunlap | 4b0ff1a | 2006-10-05 19:07:26 +0200 | [diff] [blame] | 26 | #include <linux/kallsyms.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/moduleparam.h> |
akpm@osdl.org | 35faa71 | 2005-04-16 15:24:54 -0700 | [diff] [blame] | 29 | #include <linux/nmi.h> |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 30 | #include <linux/kprobes.h> |
Vivek Goyal | 8bcc528 | 2006-04-18 12:35:13 +0200 | [diff] [blame] | 31 | #include <linux/kexec.h> |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 32 | #include <linux/unwind.h> |
Andi Kleen | ab2bf0c | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 33 | #include <linux/uaccess.h> |
Jeremy Fitzhardinge | c31a0bf | 2006-12-08 02:36:22 -0800 | [diff] [blame^] | 34 | #include <linux/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/io.h> |
| 38 | #include <asm/atomic.h> |
| 39 | #include <asm/debugreg.h> |
| 40 | #include <asm/desc.h> |
| 41 | #include <asm/i387.h> |
| 42 | #include <asm/kdebug.h> |
| 43 | #include <asm/processor.h> |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 44 | #include <asm/unwind.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/smp.h> |
| 46 | #include <asm/pgalloc.h> |
| 47 | #include <asm/pda.h> |
| 48 | #include <asm/proto.h> |
| 49 | #include <asm/nmi.h> |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 50 | #include <asm/stacktrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | asmlinkage void divide_error(void); |
| 53 | asmlinkage void debug(void); |
| 54 | asmlinkage void nmi(void); |
| 55 | asmlinkage void int3(void); |
| 56 | asmlinkage void overflow(void); |
| 57 | asmlinkage void bounds(void); |
| 58 | asmlinkage void invalid_op(void); |
| 59 | asmlinkage void device_not_available(void); |
| 60 | asmlinkage void double_fault(void); |
| 61 | asmlinkage void coprocessor_segment_overrun(void); |
| 62 | asmlinkage void invalid_TSS(void); |
| 63 | asmlinkage void segment_not_present(void); |
| 64 | asmlinkage void stack_segment(void); |
| 65 | asmlinkage void general_protection(void); |
| 66 | asmlinkage void page_fault(void); |
| 67 | asmlinkage void coprocessor_error(void); |
| 68 | asmlinkage void simd_coprocessor_error(void); |
| 69 | asmlinkage void reserved(void); |
| 70 | asmlinkage void alignment_check(void); |
| 71 | asmlinkage void machine_check(void); |
| 72 | asmlinkage void spurious_interrupt_bug(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 74 | ATOMIC_NOTIFIER_HEAD(die_chain); |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 75 | EXPORT_SYMBOL(die_chain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | int register_die_notifier(struct notifier_block *nb) |
| 78 | { |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 79 | vmalloc_sync_all(); |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 80 | return atomic_notifier_chain_register(&die_chain, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
Arjan van de Ven | 1454aed | 2006-07-10 04:44:05 -0700 | [diff] [blame] | 82 | EXPORT_SYMBOL(register_die_notifier); /* used modular by kdb */ |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 83 | |
| 84 | int unregister_die_notifier(struct notifier_block *nb) |
| 85 | { |
| 86 | return atomic_notifier_chain_unregister(&die_chain, nb); |
| 87 | } |
Arjan van de Ven | 1454aed | 2006-07-10 04:44:05 -0700 | [diff] [blame] | 88 | EXPORT_SYMBOL(unregister_die_notifier); /* used modular by kdb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | static inline void conditional_sti(struct pt_regs *regs) |
| 91 | { |
| 92 | if (regs->eflags & X86_EFLAGS_IF) |
| 93 | local_irq_enable(); |
| 94 | } |
| 95 | |
John Blackwood | a65d17c | 2006-02-12 14:34:58 -0800 | [diff] [blame] | 96 | static inline void preempt_conditional_sti(struct pt_regs *regs) |
| 97 | { |
| 98 | preempt_disable(); |
| 99 | if (regs->eflags & X86_EFLAGS_IF) |
| 100 | local_irq_enable(); |
| 101 | } |
| 102 | |
| 103 | static inline void preempt_conditional_cli(struct pt_regs *regs) |
| 104 | { |
| 105 | if (regs->eflags & X86_EFLAGS_IF) |
| 106 | local_irq_disable(); |
Andi Kleen | 40e59a6 | 2006-05-15 18:19:47 +0200 | [diff] [blame] | 107 | /* Make sure to not schedule here because we could be running |
| 108 | on an exception stack. */ |
John Blackwood | a65d17c | 2006-02-12 14:34:58 -0800 | [diff] [blame] | 109 | preempt_enable_no_resched(); |
| 110 | } |
| 111 | |
Chuck Ebbert | 0741f4d | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 112 | int kstack_depth_to_print = 12; |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 113 | #ifdef CONFIG_STACK_UNWIND |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 114 | static int call_trace = 1; |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 115 | #else |
| 116 | #define call_trace (-1) |
| 117 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | #ifdef CONFIG_KALLSYMS |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 120 | void printk_address(unsigned long address) |
| 121 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | unsigned long offset = 0, symsize; |
| 123 | const char *symname; |
| 124 | char *modname; |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 125 | char *delim = ":"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | char namebuf[128]; |
| 127 | |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 128 | symname = kallsyms_lookup(address, &symsize, &offset, |
| 129 | &modname, namebuf); |
| 130 | if (!symname) { |
| 131 | printk(" [<%016lx>]\n", address); |
| 132 | return; |
| 133 | } |
| 134 | if (!modname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | modname = delim = ""; |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 136 | printk(" [<%016lx>] %s%s%s%s+0x%lx/0x%lx\n", |
| 137 | address, delim, modname, delim, symname, offset, symsize); |
| 138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | #else |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 140 | void printk_address(unsigned long address) |
| 141 | { |
| 142 | printk(" [<%016lx>]\n", address); |
| 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #endif |
| 145 | |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 146 | static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 147 | unsigned *usedp, char **idp) |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 148 | { |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 149 | static char ids[][8] = { |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 150 | [DEBUG_STACK - 1] = "#DB", |
| 151 | [NMI_STACK - 1] = "NMI", |
| 152 | [DOUBLEFAULT_STACK - 1] = "#DF", |
| 153 | [STACKFAULT_STACK - 1] = "#SS", |
| 154 | [MCE_STACK - 1] = "#MC", |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 155 | #if DEBUG_STKSZ > EXCEPTION_STKSZ |
| 156 | [N_EXCEPTION_STACKS ... N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]" |
| 157 | #endif |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 158 | }; |
| 159 | unsigned k; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 161 | /* |
| 162 | * Iterate over all exception stacks, and figure out whether |
| 163 | * 'stack' is in one of them: |
| 164 | */ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 165 | for (k = 0; k < N_EXCEPTION_STACKS; k++) { |
Keith Owens | f574164 | 2006-09-26 10:52:38 +0200 | [diff] [blame] | 166 | unsigned long end = per_cpu(orig_ist, cpu).ist[k]; |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 167 | /* |
| 168 | * Is 'stack' above this exception frame's end? |
| 169 | * If yes then skip to the next frame. |
| 170 | */ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 171 | if (stack >= end) |
| 172 | continue; |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 173 | /* |
| 174 | * Is 'stack' above this exception frame's start address? |
| 175 | * If yes then we found the right frame. |
| 176 | */ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 177 | if (stack >= end - EXCEPTION_STKSZ) { |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 178 | /* |
| 179 | * Make sure we only iterate through an exception |
| 180 | * stack once. If it comes up for the second time |
| 181 | * then there's something wrong going on - just |
| 182 | * break out and return NULL: |
| 183 | */ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 184 | if (*usedp & (1U << k)) |
| 185 | break; |
| 186 | *usedp |= 1U << k; |
| 187 | *idp = ids[k]; |
| 188 | return (unsigned long *)end; |
| 189 | } |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 190 | /* |
| 191 | * If this is a debug stack, and if it has a larger size than |
| 192 | * the usual exception stacks, then 'stack' might still |
| 193 | * be within the lower portion of the debug stack: |
| 194 | */ |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 195 | #if DEBUG_STKSZ > EXCEPTION_STKSZ |
| 196 | if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) { |
| 197 | unsigned j = N_EXCEPTION_STACKS - 1; |
| 198 | |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 199 | /* |
| 200 | * Black magic. A large debug stack is composed of |
| 201 | * multiple exception stack entries, which we |
| 202 | * iterate through now. Dont look: |
| 203 | */ |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 204 | do { |
| 205 | ++j; |
| 206 | end -= EXCEPTION_STKSZ; |
| 207 | ids[j][4] = '1' + (j - N_EXCEPTION_STACKS); |
| 208 | } while (stack < end - EXCEPTION_STKSZ); |
| 209 | if (*usedp & (1U << j)) |
| 210 | break; |
| 211 | *usedp |= 1U << j; |
| 212 | *idp = ids[j]; |
| 213 | return (unsigned long *)end; |
| 214 | } |
| 215 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | return NULL; |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 220 | struct ops_and_data { |
| 221 | struct stacktrace_ops *ops; |
| 222 | void *data; |
| 223 | }; |
| 224 | |
| 225 | static int dump_trace_unwind(struct unwind_frame_info *info, void *context) |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 226 | { |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 227 | struct ops_and_data *oad = (struct ops_and_data *)context; |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 228 | int n = 0; |
Jan Beulich | 359ad0d | 2006-12-07 02:14:13 +0100 | [diff] [blame] | 229 | unsigned long sp = UNW_SP(info); |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 230 | |
Jan Beulich | 359ad0d | 2006-12-07 02:14:13 +0100 | [diff] [blame] | 231 | if (arch_unw_user_mode(info)) |
| 232 | return -1; |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 233 | while (unwind(info) == 0 && UNW_PC(info)) { |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 234 | n++; |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 235 | oad->ops->address(oad->data, UNW_PC(info)); |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 236 | if (arch_unw_user_mode(info)) |
| 237 | break; |
Jan Beulich | 359ad0d | 2006-12-07 02:14:13 +0100 | [diff] [blame] | 238 | if ((sp & ~(PAGE_SIZE - 1)) == (UNW_SP(info) & ~(PAGE_SIZE - 1)) |
| 239 | && sp > UNW_SP(info)) |
| 240 | break; |
| 241 | sp = UNW_SP(info); |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 242 | } |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 243 | return n; |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 246 | #define MSG(txt) ops->warning(data, txt) |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | /* |
| 249 | * x86-64 can have upto three kernel stacks: |
| 250 | * process stack |
| 251 | * interrupt stack |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 252 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | */ |
| 254 | |
Andi Kleen | c547c77 | 2006-11-28 20:12:59 +0100 | [diff] [blame] | 255 | static inline int valid_stack_ptr(struct thread_info *tinfo, void *p) |
| 256 | { |
| 257 | void *t = (void *)tinfo; |
| 258 | return p > t && p < t + THREAD_SIZE - 3; |
| 259 | } |
| 260 | |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 261 | void dump_trace(struct task_struct *tsk, struct pt_regs *regs, |
| 262 | unsigned long *stack, |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 263 | struct stacktrace_ops *ops, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Andrew Morton | da68933 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 265 | const unsigned cpu = get_cpu(); |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 266 | unsigned long *irqstack_end = (unsigned long*)cpu_pda(cpu)->irqstackptr; |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 267 | unsigned used = 0; |
Andi Kleen | c547c77 | 2006-11-28 20:12:59 +0100 | [diff] [blame] | 268 | struct thread_info *tinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 270 | if (!tsk) |
| 271 | tsk = current; |
| 272 | |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 273 | if (call_trace >= 0) { |
| 274 | int unw_ret = 0; |
| 275 | struct unwind_frame_info info; |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 276 | struct ops_and_data oad = { .ops = ops, .data = data }; |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 277 | |
| 278 | if (regs) { |
| 279 | if (unwind_init_frame_info(&info, tsk, regs) == 0) |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 280 | unw_ret = dump_trace_unwind(&info, &oad); |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 281 | } else if (tsk == current) |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 282 | unw_ret = unwind_init_running(&info, dump_trace_unwind, |
| 283 | &oad); |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 284 | else { |
| 285 | if (unwind_init_blocked(&info, tsk) == 0) |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 286 | unw_ret = dump_trace_unwind(&info, &oad); |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 287 | } |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 288 | if (unw_ret > 0) { |
| 289 | if (call_trace == 1 && !arch_unw_user_mode(&info)) { |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 290 | ops->warning_symbol(data, |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 291 | "DWARF2 unwinder stuck at %s", |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 292 | UNW_PC(&info)); |
| 293 | if ((long)UNW_SP(&info) < 0) { |
Andi Kleen | b615ebd | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 294 | MSG("Leftover inexact backtrace:"); |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 295 | stack = (unsigned long *)UNW_SP(&info); |
Andi Kleen | be7a917 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 296 | if (!stack) |
Andrew Morton | da68933 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 297 | goto out; |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 298 | } else |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 299 | MSG("Full inexact backtrace again:"); |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 300 | } else if (call_trace >= 1) |
Andrew Morton | da68933 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 301 | goto out; |
Andi Kleen | b13761e | 2006-07-28 14:44:51 +0200 | [diff] [blame] | 302 | else |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 303 | MSG("Full inexact backtrace again:"); |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 304 | } else |
Andi Kleen | dd315df | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 305 | MSG("Inexact backtrace:"); |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 306 | } |
| 307 | if (!stack) { |
| 308 | unsigned long dummy; |
| 309 | stack = &dummy; |
| 310 | if (tsk && tsk != current) |
| 311 | stack = (unsigned long *)tsk->thread.rsp; |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 314 | /* |
| 315 | * Print function call entries within a stack. 'cond' is the |
| 316 | * "end of stackframe" condition, that the 'stack++' |
| 317 | * iteration will eventually trigger. |
| 318 | */ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 319 | #define HANDLE_STACK(cond) \ |
| 320 | do while (cond) { \ |
Jan Beulich | 1b2f630 | 2006-01-11 22:46:45 +0100 | [diff] [blame] | 321 | unsigned long addr = *stack++; \ |
Andi Kleen | 446f713 | 2006-12-07 02:14:12 +0100 | [diff] [blame] | 322 | /* Use unlocked access here because except for NMIs \ |
| 323 | we should be already protected against module unloads */ \ |
| 324 | if (__kernel_text_address(addr)) { \ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 325 | /* \ |
| 326 | * If the address is either in the text segment of the \ |
| 327 | * kernel, or in the region which contains vmalloc'ed \ |
| 328 | * memory, it *may* be the address of a calling \ |
| 329 | * routine; if so, print it so that someone tracing \ |
| 330 | * down the cause of the crash will be able to figure \ |
| 331 | * out the call path that was taken. \ |
| 332 | */ \ |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 333 | ops->address(data, addr); \ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 334 | } \ |
| 335 | } while (0) |
| 336 | |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 337 | /* |
| 338 | * Print function call entries in all stacks, starting at the |
| 339 | * current stack address. If the stacks consist of nested |
| 340 | * exceptions |
| 341 | */ |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 342 | for (;;) { |
| 343 | char *id; |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 344 | unsigned long *estack_end; |
| 345 | estack_end = in_exception_stack(cpu, (unsigned long)stack, |
| 346 | &used, &id); |
| 347 | |
| 348 | if (estack_end) { |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 349 | if (ops->stack(data, id) < 0) |
| 350 | break; |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 351 | HANDLE_STACK (stack < estack_end); |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 352 | ops->stack(data, "<EOE>"); |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 353 | /* |
| 354 | * We link to the next stack via the |
| 355 | * second-to-last pointer (index -2 to end) in the |
| 356 | * exception stack: |
| 357 | */ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 358 | stack = (unsigned long *) estack_end[-2]; |
| 359 | continue; |
| 360 | } |
| 361 | if (irqstack_end) { |
| 362 | unsigned long *irqstack; |
| 363 | irqstack = irqstack_end - |
| 364 | (IRQSTACKSIZE - 64) / sizeof(*irqstack); |
| 365 | |
| 366 | if (stack >= irqstack && stack < irqstack_end) { |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 367 | if (ops->stack(data, "IRQ") < 0) |
| 368 | break; |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 369 | HANDLE_STACK (stack < irqstack_end); |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 370 | /* |
| 371 | * We link to the next stack (which would be |
| 372 | * the process stack normally) the last |
| 373 | * pointer (index -1 to end) in the IRQ stack: |
| 374 | */ |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 375 | stack = (unsigned long *) (irqstack_end[-1]); |
| 376 | irqstack_end = NULL; |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 377 | ops->stack(data, "EOI"); |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 378 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 381 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 383 | |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 384 | /* |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 385 | * This handles the process stack: |
Ingo Molnar | c9ca1ba | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 386 | */ |
Andi Kleen | c547c77 | 2006-11-28 20:12:59 +0100 | [diff] [blame] | 387 | tinfo = current_thread_info(); |
| 388 | HANDLE_STACK (valid_stack_ptr(tinfo, stack)); |
Andi Kleen | 0a65800 | 2005-04-16 15:25:17 -0700 | [diff] [blame] | 389 | #undef HANDLE_STACK |
Andrew Morton | da68933 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 390 | out: |
| 391 | put_cpu(); |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 392 | } |
| 393 | EXPORT_SYMBOL(dump_trace); |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 394 | |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 395 | static void |
| 396 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) |
| 397 | { |
| 398 | print_symbol(msg, symbol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | printk("\n"); |
| 400 | } |
| 401 | |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 402 | static void print_trace_warning(void *data, char *msg) |
| 403 | { |
| 404 | printk("%s\n", msg); |
| 405 | } |
| 406 | |
| 407 | static int print_trace_stack(void *data, char *name) |
| 408 | { |
| 409 | printk(" <%s> ", name); |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | static void print_trace_address(void *data, unsigned long addr) |
| 414 | { |
| 415 | printk_address(addr); |
| 416 | } |
| 417 | |
| 418 | static struct stacktrace_ops print_trace_ops = { |
| 419 | .warning = print_trace_warning, |
| 420 | .warning_symbol = print_trace_warning_symbol, |
| 421 | .stack = print_trace_stack, |
| 422 | .address = print_trace_address, |
| 423 | }; |
| 424 | |
| 425 | void |
| 426 | show_trace(struct task_struct *tsk, struct pt_regs *regs, unsigned long *stack) |
| 427 | { |
| 428 | printk("\nCall Trace:\n"); |
| 429 | dump_trace(tsk, regs, stack, &print_trace_ops, NULL); |
| 430 | printk("\n"); |
| 431 | } |
| 432 | |
| 433 | static void |
| 434 | _show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
| 436 | unsigned long *stack; |
| 437 | int i; |
Andi Kleen | 151f8cc | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 438 | const int cpu = smp_processor_id(); |
Ravikiran G Thirumalai | df79efd | 2006-01-11 22:45:39 +0100 | [diff] [blame] | 439 | unsigned long *irqstack_end = (unsigned long *) (cpu_pda(cpu)->irqstackptr); |
| 440 | unsigned long *irqstack = (unsigned long *) (cpu_pda(cpu)->irqstackptr - IRQSTACKSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | // debugging aid: "show_stack(NULL, NULL);" prints the |
| 443 | // back trace for this cpu. |
| 444 | |
| 445 | if (rsp == NULL) { |
| 446 | if (tsk) |
| 447 | rsp = (unsigned long *)tsk->thread.rsp; |
| 448 | else |
| 449 | rsp = (unsigned long *)&rsp; |
| 450 | } |
| 451 | |
| 452 | stack = rsp; |
| 453 | for(i=0; i < kstack_depth_to_print; i++) { |
| 454 | if (stack >= irqstack && stack <= irqstack_end) { |
| 455 | if (stack == irqstack_end) { |
| 456 | stack = (unsigned long *) (irqstack_end[-1]); |
| 457 | printk(" <EOI> "); |
| 458 | } |
| 459 | } else { |
| 460 | if (((long) stack & (THREAD_SIZE-1)) == 0) |
| 461 | break; |
| 462 | } |
| 463 | if (i && ((i % 4) == 0)) |
Ingo Molnar | 3ac9493 | 2006-07-03 00:24:36 -0700 | [diff] [blame] | 464 | printk("\n"); |
| 465 | printk(" %016lx", *stack++); |
akpm@osdl.org | 35faa71 | 2005-04-16 15:24:54 -0700 | [diff] [blame] | 466 | touch_nmi_watchdog(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 468 | show_trace(tsk, regs, rsp); |
| 469 | } |
| 470 | |
| 471 | void show_stack(struct task_struct *tsk, unsigned long * rsp) |
| 472 | { |
| 473 | _show_stack(tsk, NULL, rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /* |
| 477 | * The architecture-independent dump_stack generator |
| 478 | */ |
| 479 | void dump_stack(void) |
| 480 | { |
| 481 | unsigned long dummy; |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 482 | show_trace(NULL, NULL, &dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | EXPORT_SYMBOL(dump_stack); |
| 486 | |
| 487 | void show_registers(struct pt_regs *regs) |
| 488 | { |
| 489 | int i; |
Vincent Hanquez | 76381fe | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 490 | int in_kernel = !user_mode(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | unsigned long rsp; |
Andi Kleen | 151f8cc | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 492 | const int cpu = smp_processor_id(); |
Ravikiran G Thirumalai | df79efd | 2006-01-11 22:45:39 +0100 | [diff] [blame] | 493 | struct task_struct *cur = cpu_pda(cpu)->pcurrent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | rsp = regs->rsp; |
| 496 | |
| 497 | printk("CPU %d ", cpu); |
| 498 | __show_regs(regs); |
| 499 | printk("Process %s (pid: %d, threadinfo %p, task %p)\n", |
Al Viro | e4f17c4 | 2006-01-12 01:05:38 -0800 | [diff] [blame] | 500 | cur->comm, cur->pid, task_thread_info(cur), cur); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
| 502 | /* |
| 503 | * When in-kernel, we also print out the stack and code at the |
| 504 | * time of the fault.. |
| 505 | */ |
| 506 | if (in_kernel) { |
| 507 | |
| 508 | printk("Stack: "); |
Jan Beulich | b538ed2 | 2006-06-26 13:57:32 +0200 | [diff] [blame] | 509 | _show_stack(NULL, regs, (unsigned long*)rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | printk("\nCode: "); |
Roberto Nibali | 2b692a8 | 2006-03-25 16:29:55 +0100 | [diff] [blame] | 512 | if (regs->rip < PAGE_OFFSET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | goto bad; |
| 514 | |
Roberto Nibali | 2b692a8 | 2006-03-25 16:29:55 +0100 | [diff] [blame] | 515 | for (i=0; i<20; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | unsigned char c; |
Roberto Nibali | 2b692a8 | 2006-03-25 16:29:55 +0100 | [diff] [blame] | 517 | if (__get_user(c, &((unsigned char*)regs->rip)[i])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | bad: |
| 519 | printk(" Bad RIP value."); |
| 520 | break; |
| 521 | } |
| 522 | printk("%02x ", c); |
| 523 | } |
| 524 | } |
| 525 | printk("\n"); |
| 526 | } |
| 527 | |
Jeremy Fitzhardinge | c31a0bf | 2006-12-08 02:36:22 -0800 | [diff] [blame^] | 528 | int is_valid_bugaddr(unsigned long rip) |
| 529 | { |
| 530 | unsigned short ud2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Jeremy Fitzhardinge | c31a0bf | 2006-12-08 02:36:22 -0800 | [diff] [blame^] | 532 | if (__copy_from_user(&ud2, (const void __user *) rip, sizeof(ud2))) |
| 533 | return 0; |
| 534 | |
| 535 | return ud2 == 0x0b0f; |
| 536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Alexander Nyberg | 4f60fdf | 2005-05-25 12:31:28 -0700 | [diff] [blame] | 538 | #ifdef CONFIG_BUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | void out_of_line_bug(void) |
| 540 | { |
| 541 | BUG(); |
| 542 | } |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 543 | EXPORT_SYMBOL(out_of_line_bug); |
Alexander Nyberg | 4f60fdf | 2005-05-25 12:31:28 -0700 | [diff] [blame] | 544 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
| 546 | static DEFINE_SPINLOCK(die_lock); |
| 547 | static int die_owner = -1; |
Corey Minyard | cdc60a4 | 2006-05-08 15:17:22 +0200 | [diff] [blame] | 548 | static unsigned int die_nest_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 550 | unsigned __kprobes long oops_begin(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
Andi Kleen | 151f8cc | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 552 | int cpu = smp_processor_id(); |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 553 | unsigned long flags; |
| 554 | |
Andrew Morton | abf0f10 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 555 | oops_enter(); |
| 556 | |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 557 | /* racy, but better than risking deadlock. */ |
| 558 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | if (!spin_trylock(&die_lock)) { |
| 560 | if (cpu == die_owner) |
| 561 | /* nested oops. should stop eventually */; |
| 562 | else |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 563 | spin_lock(&die_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
Corey Minyard | cdc60a4 | 2006-05-08 15:17:22 +0200 | [diff] [blame] | 565 | die_nest_count++; |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 566 | die_owner = cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | console_verbose(); |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 568 | bust_spinlocks(1); |
| 569 | return flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 572 | void __kprobes oops_end(unsigned long flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
| 574 | die_owner = -1; |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 575 | bust_spinlocks(0); |
Corey Minyard | cdc60a4 | 2006-05-08 15:17:22 +0200 | [diff] [blame] | 576 | die_nest_count--; |
| 577 | if (die_nest_count) |
| 578 | /* We still own the lock */ |
| 579 | local_irq_restore(flags); |
| 580 | else |
| 581 | /* Nest count reaches zero, release the lock. */ |
| 582 | spin_unlock_irqrestore(&die_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | if (panic_on_oops) |
Horms | 012c437 | 2006-08-13 23:24:22 -0700 | [diff] [blame] | 584 | panic("Fatal exception"); |
Andrew Morton | abf0f10 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 585 | oops_exit(); |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 588 | void __kprobes __die(const char * str, struct pt_regs * regs, long err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
| 590 | static int die_counter; |
| 591 | printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff,++die_counter); |
| 592 | #ifdef CONFIG_PREEMPT |
| 593 | printk("PREEMPT "); |
| 594 | #endif |
| 595 | #ifdef CONFIG_SMP |
| 596 | printk("SMP "); |
| 597 | #endif |
| 598 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 599 | printk("DEBUG_PAGEALLOC"); |
| 600 | #endif |
| 601 | printk("\n"); |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 602 | notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | show_registers(regs); |
| 604 | /* Executive summary in case the oops scrolled away */ |
| 605 | printk(KERN_ALERT "RIP "); |
| 606 | printk_address(regs->rip); |
| 607 | printk(" RSP <%016lx>\n", regs->rsp); |
Vivek Goyal | 8bcc528 | 2006-04-18 12:35:13 +0200 | [diff] [blame] | 608 | if (kexec_should_crash(current)) |
| 609 | crash_kexec(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | void die(const char * str, struct pt_regs * regs, long err) |
| 613 | { |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 614 | unsigned long flags = oops_begin(); |
| 615 | |
Jeremy Fitzhardinge | c31a0bf | 2006-12-08 02:36:22 -0800 | [diff] [blame^] | 616 | if (!user_mode(regs)) |
| 617 | report_bug(regs->rip); |
| 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | __die(str, regs, err); |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 620 | oops_end(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | do_exit(SIGSEGV); |
| 622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Andi Kleen | fac5855 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 624 | void __kprobes die_nmi(char *str, struct pt_regs *regs, int do_panic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | { |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 626 | unsigned long flags = oops_begin(); |
| 627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | /* |
| 629 | * We are in trouble anyway, lets at least try |
| 630 | * to get a message out. |
| 631 | */ |
Andi Kleen | 151f8cc | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 632 | printk(str, smp_processor_id()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | show_registers(regs); |
Vivek Goyal | 8bcc528 | 2006-04-18 12:35:13 +0200 | [diff] [blame] | 634 | if (kexec_should_crash(current)) |
| 635 | crash_kexec(regs); |
Andi Kleen | fac5855 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 636 | if (do_panic || panic_on_oops) |
| 637 | panic("Non maskable interrupt"); |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 638 | oops_end(flags); |
Corey Minyard | 8b1ffe95 | 2006-05-08 15:17:25 +0200 | [diff] [blame] | 639 | nmi_exit(); |
| 640 | local_irq_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | do_exit(SIGSEGV); |
| 642 | } |
| 643 | |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 644 | static void __kprobes do_trap(int trapnr, int signr, char *str, |
| 645 | struct pt_regs * regs, long error_code, |
| 646 | siginfo_t *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 648 | struct task_struct *tsk = current; |
| 649 | |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 650 | tsk->thread.error_code = error_code; |
| 651 | tsk->thread.trap_no = trapnr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 653 | if (user_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | if (exception_trace && unhandled_signal(tsk, signr)) |
| 655 | printk(KERN_INFO |
| 656 | "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n", |
| 657 | tsk->comm, tsk->pid, str, |
Roberto Nibali | 2b692a8 | 2006-03-25 16:29:55 +0100 | [diff] [blame] | 658 | regs->rip, regs->rsp, error_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | if (info) |
| 661 | force_sig_info(signr, info, tsk); |
| 662 | else |
| 663 | force_sig(signr, tsk); |
| 664 | return; |
| 665 | } |
| 666 | |
| 667 | |
| 668 | /* kernel trap */ |
| 669 | { |
| 670 | const struct exception_table_entry *fixup; |
| 671 | fixup = search_exception_tables(regs->rip); |
Roberto Nibali | 2b692a8 | 2006-03-25 16:29:55 +0100 | [diff] [blame] | 672 | if (fixup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | regs->rip = fixup->fixup; |
Roberto Nibali | 2b692a8 | 2006-03-25 16:29:55 +0100 | [diff] [blame] | 674 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | die(str, regs, error_code); |
| 676 | return; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | #define DO_ERROR(trapnr, signr, str, name) \ |
| 681 | asmlinkage void do_##name(struct pt_regs * regs, long error_code) \ |
| 682 | { \ |
| 683 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
| 684 | == NOTIFY_STOP) \ |
| 685 | return; \ |
Andi Kleen | 40e59a6 | 2006-05-15 18:19:47 +0200 | [diff] [blame] | 686 | conditional_sti(regs); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | do_trap(trapnr, signr, str, regs, error_code, NULL); \ |
| 688 | } |
| 689 | |
| 690 | #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ |
| 691 | asmlinkage void do_##name(struct pt_regs * regs, long error_code) \ |
| 692 | { \ |
| 693 | siginfo_t info; \ |
| 694 | info.si_signo = signr; \ |
| 695 | info.si_errno = 0; \ |
| 696 | info.si_code = sicode; \ |
| 697 | info.si_addr = (void __user *)siaddr; \ |
| 698 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
| 699 | == NOTIFY_STOP) \ |
| 700 | return; \ |
Andi Kleen | 40e59a6 | 2006-05-15 18:19:47 +0200 | [diff] [blame] | 701 | conditional_sti(regs); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | do_trap(trapnr, signr, str, regs, error_code, &info); \ |
| 703 | } |
| 704 | |
| 705 | DO_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->rip) |
| 706 | DO_ERROR( 4, SIGSEGV, "overflow", overflow) |
| 707 | DO_ERROR( 5, SIGSEGV, "bounds", bounds) |
Chuck Ebbert | 100c0e3 | 2006-01-11 22:46:00 +0100 | [diff] [blame] | 708 | DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->rip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | DO_ERROR( 7, SIGSEGV, "device not available", device_not_available) |
| 710 | DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun) |
| 711 | DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS) |
| 712 | DO_ERROR(11, SIGBUS, "segment not present", segment_not_present) |
| 713 | DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0) |
| 714 | DO_ERROR(18, SIGSEGV, "reserved", reserved) |
Andi Kleen | 40e59a6 | 2006-05-15 18:19:47 +0200 | [diff] [blame] | 715 | |
| 716 | /* Runs on IST stack */ |
| 717 | asmlinkage void do_stack_segment(struct pt_regs *regs, long error_code) |
| 718 | { |
| 719 | if (notify_die(DIE_TRAP, "stack segment", regs, error_code, |
| 720 | 12, SIGBUS) == NOTIFY_STOP) |
| 721 | return; |
| 722 | preempt_conditional_sti(regs); |
| 723 | do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL); |
| 724 | preempt_conditional_cli(regs); |
| 725 | } |
Jan Beulich | eca37c1 | 2006-01-11 22:42:17 +0100 | [diff] [blame] | 726 | |
| 727 | asmlinkage void do_double_fault(struct pt_regs * regs, long error_code) |
| 728 | { |
| 729 | static const char str[] = "double fault"; |
| 730 | struct task_struct *tsk = current; |
| 731 | |
| 732 | /* Return not checked because double check cannot be ignored */ |
| 733 | notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV); |
| 734 | |
| 735 | tsk->thread.error_code = error_code; |
| 736 | tsk->thread.trap_no = 8; |
| 737 | |
| 738 | /* This is always a kernel trap and never fixable (and thus must |
| 739 | never return). */ |
| 740 | for (;;) |
| 741 | die(str, regs, error_code); |
| 742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 744 | asmlinkage void __kprobes do_general_protection(struct pt_regs * regs, |
| 745 | long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | { |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 747 | struct task_struct *tsk = current; |
| 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | conditional_sti(regs); |
| 750 | |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 751 | tsk->thread.error_code = error_code; |
| 752 | tsk->thread.trap_no = 13; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 754 | if (user_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if (exception_trace && unhandled_signal(tsk, SIGSEGV)) |
| 756 | printk(KERN_INFO |
| 757 | "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n", |
| 758 | tsk->comm, tsk->pid, |
Roberto Nibali | 2b692a8 | 2006-03-25 16:29:55 +0100 | [diff] [blame] | 759 | regs->rip, regs->rsp, error_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | force_sig(SIGSEGV, tsk); |
| 762 | return; |
| 763 | } |
| 764 | |
| 765 | /* kernel gp */ |
| 766 | { |
| 767 | const struct exception_table_entry *fixup; |
| 768 | fixup = search_exception_tables(regs->rip); |
| 769 | if (fixup) { |
| 770 | regs->rip = fixup->fixup; |
| 771 | return; |
| 772 | } |
| 773 | if (notify_die(DIE_GPF, "general protection fault", regs, |
| 774 | error_code, 13, SIGSEGV) == NOTIFY_STOP) |
| 775 | return; |
| 776 | die("general protection fault", regs, error_code); |
| 777 | } |
| 778 | } |
| 779 | |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 780 | static __kprobes void |
| 781 | mem_parity_error(unsigned char reason, struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 783 | printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n", |
| 784 | reason); |
Andi Kleen | 9c5f8be | 2006-12-07 02:14:03 +0100 | [diff] [blame] | 785 | printk(KERN_EMERG "You have some hardware problem, likely on the PCI bus.\n"); |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 786 | |
Don Zickus | 8da5add | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 787 | if (panic_on_unrecovered_nmi) |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 788 | panic("NMI: Not continuing"); |
| 789 | |
| 790 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
| 792 | /* Clear and disable the memory parity error line. */ |
| 793 | reason = (reason & 0xf) | 4; |
| 794 | outb(reason, 0x61); |
| 795 | } |
| 796 | |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 797 | static __kprobes void |
| 798 | io_check_error(unsigned char reason, struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | { |
| 800 | printk("NMI: IOCK error (debug interrupt?)\n"); |
| 801 | show_registers(regs); |
| 802 | |
| 803 | /* Re-enable the IOCK line, wait for a few seconds */ |
| 804 | reason = (reason & 0xf) | 8; |
| 805 | outb(reason, 0x61); |
| 806 | mdelay(2000); |
| 807 | reason &= ~8; |
| 808 | outb(reason, 0x61); |
| 809 | } |
| 810 | |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 811 | static __kprobes void |
| 812 | unknown_nmi_error(unsigned char reason, struct pt_regs * regs) |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 813 | { |
| 814 | printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n", |
| 815 | reason); |
| 816 | printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n"); |
Don Zickus | 8da5add | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 817 | |
| 818 | if (panic_on_unrecovered_nmi) |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 819 | panic("NMI: Not continuing"); |
Don Zickus | 8da5add | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 820 | |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 821 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Andi Kleen | 6fefb0d | 2005-04-16 15:25:03 -0700 | [diff] [blame] | 824 | /* Runs on IST stack. This code must keep interrupts off all the time. |
| 825 | Nested NMIs are prevented by the CPU. */ |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 826 | asmlinkage __kprobes void default_do_nmi(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | { |
| 828 | unsigned char reason = 0; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 829 | int cpu; |
| 830 | |
| 831 | cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
| 833 | /* Only the BSP gets external NMIs from the system. */ |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 834 | if (!cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | reason = get_nmi_reason(); |
| 836 | |
| 837 | if (!(reason & 0xc0)) { |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 838 | if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | == NOTIFY_STOP) |
| 840 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | /* |
| 842 | * Ok, so this is none of the documented NMI sources, |
| 843 | * so it must be the NMI watchdog. |
| 844 | */ |
Don Zickus | 3adbbcce | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 845 | if (nmi_watchdog_tick(regs,reason)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | return; |
Don Zickus | 3adbbcce | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 847 | if (!do_nmi_callback(regs,cpu)) |
Don Zickus | 3adbbcce | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 848 | unknown_nmi_error(reason, regs); |
| 849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | return; |
| 851 | } |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 852 | if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | return; |
| 854 | |
| 855 | /* AK: following checks seem to be broken on modern chipsets. FIXME */ |
| 856 | |
| 857 | if (reason & 0x80) |
| 858 | mem_parity_error(reason, regs); |
| 859 | if (reason & 0x40) |
| 860 | io_check_error(reason, regs); |
| 861 | } |
| 862 | |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 863 | /* runs on IST stack. */ |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 864 | asmlinkage void __kprobes do_int3(struct pt_regs * regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
| 866 | if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) == NOTIFY_STOP) { |
| 867 | return; |
| 868 | } |
Andi Kleen | 40e59a6 | 2006-05-15 18:19:47 +0200 | [diff] [blame] | 869 | preempt_conditional_sti(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | do_trap(3, SIGTRAP, "int3", regs, error_code, NULL); |
Andi Kleen | 40e59a6 | 2006-05-15 18:19:47 +0200 | [diff] [blame] | 871 | preempt_conditional_cli(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Andi Kleen | 6fefb0d | 2005-04-16 15:25:03 -0700 | [diff] [blame] | 874 | /* Help handler running on IST stack to switch back to user stack |
| 875 | for scheduling or signal handling. The actual stack switch is done in |
| 876 | entry.S */ |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 877 | asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { |
Andi Kleen | 6fefb0d | 2005-04-16 15:25:03 -0700 | [diff] [blame] | 879 | struct pt_regs *regs = eregs; |
| 880 | /* Did already sync */ |
| 881 | if (eregs == (struct pt_regs *)eregs->rsp) |
| 882 | ; |
| 883 | /* Exception from user space */ |
Vincent Hanquez | 76381fe | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 884 | else if (user_mode(eregs)) |
Al Viro | bb04923 | 2006-01-12 01:05:38 -0800 | [diff] [blame] | 885 | regs = task_pt_regs(current); |
Andi Kleen | 6fefb0d | 2005-04-16 15:25:03 -0700 | [diff] [blame] | 886 | /* Exception from kernel and interrupts are enabled. Move to |
| 887 | kernel process stack. */ |
| 888 | else if (eregs->eflags & X86_EFLAGS_IF) |
| 889 | regs = (struct pt_regs *)(eregs->rsp -= sizeof(struct pt_regs)); |
| 890 | if (eregs != regs) |
| 891 | *regs = *eregs; |
| 892 | return regs; |
| 893 | } |
| 894 | |
| 895 | /* runs on IST stack. */ |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 896 | asmlinkage void __kprobes do_debug(struct pt_regs * regs, |
| 897 | unsigned long error_code) |
Andi Kleen | 6fefb0d | 2005-04-16 15:25:03 -0700 | [diff] [blame] | 898 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | unsigned long condition; |
| 900 | struct task_struct *tsk = current; |
| 901 | siginfo_t info; |
| 902 | |
Vincent Hanquez | e9129e5 | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 903 | get_debugreg(condition, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code, |
Andi Kleen | daeeafe | 2005-04-16 15:25:13 -0700 | [diff] [blame] | 906 | SIGTRAP) == NOTIFY_STOP) |
Andi Kleen | 6fefb0d | 2005-04-16 15:25:03 -0700 | [diff] [blame] | 907 | return; |
Andi Kleen | daeeafe | 2005-04-16 15:25:13 -0700 | [diff] [blame] | 908 | |
John Blackwood | a65d17c | 2006-02-12 14:34:58 -0800 | [diff] [blame] | 909 | preempt_conditional_sti(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
| 911 | /* Mask out spurious debug traps due to lazy DR7 setting */ |
| 912 | if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) { |
| 913 | if (!tsk->thread.debugreg7) { |
| 914 | goto clear_dr7; |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | tsk->thread.debugreg6 = condition; |
| 919 | |
| 920 | /* Mask out spurious TF errors due to lazy TF clearing */ |
Andi Kleen | daeeafe | 2005-04-16 15:25:13 -0700 | [diff] [blame] | 921 | if (condition & DR_STEP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | /* |
| 923 | * The TF error should be masked out only if the current |
| 924 | * process is not traced and if the TRAP flag has been set |
| 925 | * previously by a tracing process (condition detected by |
| 926 | * the PT_DTRACE flag); remember that the i386 TRAP flag |
| 927 | * can be modified by the process itself in user mode, |
| 928 | * allowing programs to debug themselves without the ptrace() |
| 929 | * interface. |
| 930 | */ |
Vincent Hanquez | 76381fe | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 931 | if (!user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | goto clear_TF_reenable; |
Andi Kleen | be61bff | 2005-04-16 15:24:57 -0700 | [diff] [blame] | 933 | /* |
| 934 | * Was the TF flag set by a debugger? If so, clear it now, |
| 935 | * so that register information is correct. |
| 936 | */ |
| 937 | if (tsk->ptrace & PT_DTRACE) { |
| 938 | regs->eflags &= ~TF_MASK; |
| 939 | tsk->ptrace &= ~PT_DTRACE; |
| 940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /* Ok, finally something we can handle */ |
| 944 | tsk->thread.trap_no = 1; |
| 945 | tsk->thread.error_code = error_code; |
| 946 | info.si_signo = SIGTRAP; |
| 947 | info.si_errno = 0; |
| 948 | info.si_code = TRAP_BRKPT; |
John Blackwood | 01b8faa | 2006-01-11 22:44:15 +0100 | [diff] [blame] | 949 | info.si_addr = user_mode(regs) ? (void __user *)regs->rip : NULL; |
| 950 | force_sig_info(SIGTRAP, &info, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | clear_dr7: |
Vincent Hanquez | e9129e5 | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 953 | set_debugreg(0UL, 7); |
John Blackwood | a65d17c | 2006-02-12 14:34:58 -0800 | [diff] [blame] | 954 | preempt_conditional_cli(regs); |
Andi Kleen | 6fefb0d | 2005-04-16 15:25:03 -0700 | [diff] [blame] | 955 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | clear_TF_reenable: |
| 958 | set_tsk_thread_flag(tsk, TIF_SINGLESTEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | regs->eflags &= ~TF_MASK; |
John Blackwood | a65d17c | 2006-02-12 14:34:58 -0800 | [diff] [blame] | 960 | preempt_conditional_cli(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 963 | static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
| 965 | const struct exception_table_entry *fixup; |
| 966 | fixup = search_exception_tables(regs->rip); |
| 967 | if (fixup) { |
| 968 | regs->rip = fixup->fixup; |
| 969 | return 1; |
| 970 | } |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 971 | notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE); |
Andi Kleen | 3a848f6 | 2005-04-16 15:25:06 -0700 | [diff] [blame] | 972 | /* Illegal floating point operation in the kernel */ |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 973 | current->thread.trap_no = trapnr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | die(str, regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | /* |
| 979 | * Note that we play around with the 'TS' bit in an attempt to get |
| 980 | * the correct behaviour even in the presence of the asynchronous |
| 981 | * IRQ13 behaviour |
| 982 | */ |
| 983 | asmlinkage void do_coprocessor_error(struct pt_regs *regs) |
| 984 | { |
| 985 | void __user *rip = (void __user *)(regs->rip); |
| 986 | struct task_struct * task; |
| 987 | siginfo_t info; |
| 988 | unsigned short cwd, swd; |
| 989 | |
| 990 | conditional_sti(regs); |
Vincent Hanquez | 76381fe | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 991 | if (!user_mode(regs) && |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 992 | kernel_math_error(regs, "kernel x87 math error", 16)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | return; |
| 994 | |
| 995 | /* |
| 996 | * Save the info for the exception handler and clear the error. |
| 997 | */ |
| 998 | task = current; |
| 999 | save_init_fpu(task); |
| 1000 | task->thread.trap_no = 16; |
| 1001 | task->thread.error_code = 0; |
| 1002 | info.si_signo = SIGFPE; |
| 1003 | info.si_errno = 0; |
| 1004 | info.si_code = __SI_FAULT; |
| 1005 | info.si_addr = rip; |
| 1006 | /* |
| 1007 | * (~cwd & swd) will mask out exceptions that are not set to unmasked |
| 1008 | * status. 0x3f is the exception bits in these regs, 0x200 is the |
| 1009 | * C1 reg you need in case of a stack fault, 0x040 is the stack |
| 1010 | * fault bit. We should only be taking one exception at a time, |
| 1011 | * so if this combination doesn't produce any single exception, |
| 1012 | * then we have a bad program that isn't synchronizing its FPU usage |
| 1013 | * and it will suffer the consequences since we won't be able to |
| 1014 | * fully reproduce the context of the exception |
| 1015 | */ |
| 1016 | cwd = get_fpu_cwd(task); |
| 1017 | swd = get_fpu_swd(task); |
Chuck Ebbert | ff347b2 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 1018 | switch (swd & ~cwd & 0x3f) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | case 0x000: |
| 1020 | default: |
| 1021 | break; |
| 1022 | case 0x001: /* Invalid Op */ |
Chuck Ebbert | ff347b2 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 1023 | /* |
| 1024 | * swd & 0x240 == 0x040: Stack Underflow |
| 1025 | * swd & 0x240 == 0x240: Stack Overflow |
| 1026 | * User must clear the SF bit (0x40) if set |
| 1027 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | info.si_code = FPE_FLTINV; |
| 1029 | break; |
| 1030 | case 0x002: /* Denormalize */ |
| 1031 | case 0x010: /* Underflow */ |
| 1032 | info.si_code = FPE_FLTUND; |
| 1033 | break; |
| 1034 | case 0x004: /* Zero Divide */ |
| 1035 | info.si_code = FPE_FLTDIV; |
| 1036 | break; |
| 1037 | case 0x008: /* Overflow */ |
| 1038 | info.si_code = FPE_FLTOVF; |
| 1039 | break; |
| 1040 | case 0x020: /* Precision */ |
| 1041 | info.si_code = FPE_FLTRES; |
| 1042 | break; |
| 1043 | } |
| 1044 | force_sig_info(SIGFPE, &info, task); |
| 1045 | } |
| 1046 | |
| 1047 | asmlinkage void bad_intr(void) |
| 1048 | { |
| 1049 | printk("bad interrupt"); |
| 1050 | } |
| 1051 | |
| 1052 | asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs) |
| 1053 | { |
| 1054 | void __user *rip = (void __user *)(regs->rip); |
| 1055 | struct task_struct * task; |
| 1056 | siginfo_t info; |
| 1057 | unsigned short mxcsr; |
| 1058 | |
| 1059 | conditional_sti(regs); |
Vincent Hanquez | 76381fe | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 1060 | if (!user_mode(regs) && |
Jan Beulich | 6e3f361 | 2006-01-11 22:42:14 +0100 | [diff] [blame] | 1061 | kernel_math_error(regs, "kernel simd math error", 19)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | return; |
| 1063 | |
| 1064 | /* |
| 1065 | * Save the info for the exception handler and clear the error. |
| 1066 | */ |
| 1067 | task = current; |
| 1068 | save_init_fpu(task); |
| 1069 | task->thread.trap_no = 19; |
| 1070 | task->thread.error_code = 0; |
| 1071 | info.si_signo = SIGFPE; |
| 1072 | info.si_errno = 0; |
| 1073 | info.si_code = __SI_FAULT; |
| 1074 | info.si_addr = rip; |
| 1075 | /* |
| 1076 | * The SIMD FPU exceptions are handled a little differently, as there |
| 1077 | * is only a single status/control register. Thus, to determine which |
| 1078 | * unmasked exception was caught we must mask the exception mask bits |
| 1079 | * at 0x1f80, and then use these to mask the exception bits at 0x3f. |
| 1080 | */ |
| 1081 | mxcsr = get_fpu_mxcsr(task); |
| 1082 | switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) { |
| 1083 | case 0x000: |
| 1084 | default: |
| 1085 | break; |
| 1086 | case 0x001: /* Invalid Op */ |
| 1087 | info.si_code = FPE_FLTINV; |
| 1088 | break; |
| 1089 | case 0x002: /* Denormalize */ |
| 1090 | case 0x010: /* Underflow */ |
| 1091 | info.si_code = FPE_FLTUND; |
| 1092 | break; |
| 1093 | case 0x004: /* Zero Divide */ |
| 1094 | info.si_code = FPE_FLTDIV; |
| 1095 | break; |
| 1096 | case 0x008: /* Overflow */ |
| 1097 | info.si_code = FPE_FLTOVF; |
| 1098 | break; |
| 1099 | case 0x020: /* Precision */ |
| 1100 | info.si_code = FPE_FLTRES; |
| 1101 | break; |
| 1102 | } |
| 1103 | force_sig_info(SIGFPE, &info, task); |
| 1104 | } |
| 1105 | |
| 1106 | asmlinkage void do_spurious_interrupt_bug(struct pt_regs * regs) |
| 1107 | { |
| 1108 | } |
| 1109 | |
| 1110 | asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void) |
| 1111 | { |
| 1112 | } |
| 1113 | |
Jacob Shin | 89b831e | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 1114 | asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void) |
| 1115 | { |
| 1116 | } |
| 1117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | /* |
| 1119 | * 'math_state_restore()' saves the current math information in the |
| 1120 | * old math state array, and gets the new ones from the current task |
| 1121 | * |
| 1122 | * Careful.. There are problems with IBM-designed IRQ13 behaviour. |
| 1123 | * Don't touch unless you *really* know how it works. |
| 1124 | */ |
| 1125 | asmlinkage void math_state_restore(void) |
| 1126 | { |
| 1127 | struct task_struct *me = current; |
| 1128 | clts(); /* Allow maths ops (or we recurse) */ |
| 1129 | |
| 1130 | if (!used_math()) |
| 1131 | init_fpu(me); |
| 1132 | restore_fpu_checking(&me->thread.i387.fxsave); |
Al Viro | e4f17c4 | 2006-01-12 01:05:38 -0800 | [diff] [blame] | 1133 | task_thread_info(me)->status |= TS_USEDFPU; |
Arjan van de Ven | e07e23e | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 1134 | me->fpu_counter++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | void __init trap_init(void) |
| 1138 | { |
| 1139 | set_intr_gate(0,÷_error); |
| 1140 | set_intr_gate_ist(1,&debug,DEBUG_STACK); |
| 1141 | set_intr_gate_ist(2,&nmi,NMI_STACK); |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 1142 | set_system_gate_ist(3,&int3,DEBUG_STACK); /* int3 can be called from all */ |
Jan Beulich | 0a52158 | 2006-01-11 22:42:08 +0100 | [diff] [blame] | 1143 | set_system_gate(4,&overflow); /* int4 can be called from all */ |
| 1144 | set_intr_gate(5,&bounds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | set_intr_gate(6,&invalid_op); |
| 1146 | set_intr_gate(7,&device_not_available); |
| 1147 | set_intr_gate_ist(8,&double_fault, DOUBLEFAULT_STACK); |
| 1148 | set_intr_gate(9,&coprocessor_segment_overrun); |
| 1149 | set_intr_gate(10,&invalid_TSS); |
| 1150 | set_intr_gate(11,&segment_not_present); |
| 1151 | set_intr_gate_ist(12,&stack_segment,STACKFAULT_STACK); |
| 1152 | set_intr_gate(13,&general_protection); |
| 1153 | set_intr_gate(14,&page_fault); |
| 1154 | set_intr_gate(15,&spurious_interrupt_bug); |
| 1155 | set_intr_gate(16,&coprocessor_error); |
| 1156 | set_intr_gate(17,&alignment_check); |
| 1157 | #ifdef CONFIG_X86_MCE |
| 1158 | set_intr_gate_ist(18,&machine_check, MCE_STACK); |
| 1159 | #endif |
| 1160 | set_intr_gate(19,&simd_coprocessor_error); |
| 1161 | |
| 1162 | #ifdef CONFIG_IA32_EMULATION |
| 1163 | set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall); |
| 1164 | #endif |
| 1165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | /* |
| 1167 | * Should be a barrier for any external CPU state. |
| 1168 | */ |
| 1169 | cpu_init(); |
| 1170 | } |
| 1171 | |
| 1172 | |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1173 | static int __init oops_setup(char *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | { |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1175 | if (!s) |
| 1176 | return -EINVAL; |
| 1177 | if (!strcmp(s, "panic")) |
| 1178 | panic_on_oops = 1; |
| 1179 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | } |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1181 | early_param("oops", oops_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
| 1183 | static int __init kstack_setup(char *s) |
| 1184 | { |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1185 | if (!s) |
| 1186 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | kstack_depth_to_print = simple_strtoul(s,NULL,0); |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1188 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | } |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1190 | early_param("kstack", kstack_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 1192 | #ifdef CONFIG_STACK_UNWIND |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 1193 | static int __init call_trace_setup(char *s) |
| 1194 | { |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1195 | if (!s) |
| 1196 | return -EINVAL; |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 1197 | if (strcmp(s, "old") == 0) |
| 1198 | call_trace = -1; |
| 1199 | else if (strcmp(s, "both") == 0) |
| 1200 | call_trace = 0; |
Andi Kleen | b13761e | 2006-07-28 14:44:51 +0200 | [diff] [blame] | 1201 | else if (strcmp(s, "newfallback") == 0) |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 1202 | call_trace = 1; |
Andi Kleen | b13761e | 2006-07-28 14:44:51 +0200 | [diff] [blame] | 1203 | else if (strcmp(s, "new") == 0) |
| 1204 | call_trace = 2; |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1205 | return 0; |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 1206 | } |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1207 | early_param("call_trace", call_trace_setup); |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 1208 | #endif |