Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1991, 1992 Linus Torvalds |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Pentium III FXSR, SSE support |
| 6 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * 'Traps.c' handles hardware traps and faults after we have saved some |
| 11 | * state in 'asm.s'. |
| 12 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kallsyms.h> |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/highmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/kprobes.h> |
Andrew Morton | 1e2af92 | 2006-09-27 01:51:15 -0700 | [diff] [blame] | 18 | #include <linux/uaccess.h> |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 19 | #include <linux/utsname.h> |
| 20 | #include <linux/kdebug.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/ptrace.h> |
| 24 | #include <linux/string.h> |
| 25 | #include <linux/unwind.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/kexec.h> |
| 29 | #include <linux/sched.h> |
| 30 | #include <linux/timer.h> |
| 31 | #include <linux/init.h> |
Jeremy Fitzhardinge | 91768d6 | 2006-12-08 02:36:21 -0800 | [diff] [blame] | 32 | #include <linux/bug.h> |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 33 | #include <linux/nmi.h> |
| 34 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #ifdef CONFIG_EISA |
| 37 | #include <linux/ioport.h> |
| 38 | #include <linux/eisa.h> |
| 39 | #endif |
| 40 | |
| 41 | #ifdef CONFIG_MCA |
| 42 | #include <linux/mca.h> |
| 43 | #endif |
| 44 | |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 45 | #if defined(CONFIG_EDAC) |
| 46 | #include <linux/edac.h> |
| 47 | #endif |
| 48 | |
Alexander van Heukelum | 7643e9b | 2008-09-09 21:56:02 +0200 | [diff] [blame] | 49 | #include <asm/processor-flags.h> |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 50 | #include <asm/arch_hooks.h> |
| 51 | #include <asm/stacktrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/debugreg.h> |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 54 | #include <asm/atomic.h> |
| 55 | #include <asm/system.h> |
| 56 | #include <asm/unwind.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <asm/desc.h> |
| 58 | #include <asm/i387.h> |
| 59 | #include <asm/nmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <asm/smp.h> |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 61 | #include <asm/io.h> |
Jaswinder Singh | 6ac8d51 | 2008-07-15 21:09:13 +0530 | [diff] [blame] | 62 | #include <asm/traps.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #include "mach_traps.h" |
Alexander van Heukelum | eb642f6 | 2008-09-09 21:56:11 +0200 | [diff] [blame] | 65 | #include "cpu/mcheck/mce.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Rusty Russell | dbeb2be | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 67 | DECLARE_BITMAP(used_vectors, NR_VECTORS); |
| 68 | EXPORT_SYMBOL_GPL(used_vectors); |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | asmlinkage int system_call(void); |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* Do we ignore FPU interrupts ? */ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 73 | char ignore_fpu_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * The IDT has to be page-aligned to simplify the Pentium |
| 77 | * F0 0F bug workaround.. We have a special link segment |
| 78 | * for this. |
| 79 | */ |
Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 80 | gate_desc idt_table[256] |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 81 | __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Alexander van Heukelum | badc765 | 2008-07-02 01:30:30 +0200 | [diff] [blame] | 83 | static int ignore_nmis; |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 84 | |
Alexander van Heukelum | 762db43 | 2008-09-09 21:55:55 +0200 | [diff] [blame] | 85 | static inline void conditional_sti(struct pt_regs *regs) |
| 86 | { |
| 87 | if (regs->flags & X86_EFLAGS_IF) |
| 88 | local_irq_enable(); |
| 89 | } |
| 90 | |
Alexander van Heukelum | 3d2a71a | 2008-09-30 18:41:37 +0200 | [diff] [blame] | 91 | static inline void preempt_conditional_sti(struct pt_regs *regs) |
| 92 | { |
| 93 | inc_preempt_count(); |
| 94 | if (regs->flags & X86_EFLAGS_IF) |
| 95 | local_irq_enable(); |
| 96 | } |
| 97 | |
| 98 | static inline void preempt_conditional_cli(struct pt_regs *regs) |
| 99 | { |
| 100 | if (regs->flags & X86_EFLAGS_IF) |
| 101 | local_irq_disable(); |
| 102 | dec_preempt_count(); |
| 103 | } |
| 104 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 105 | static inline void |
| 106 | die_if_kernel(const char *str, struct pt_regs *regs, long err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 108 | if (!user_mode_vm(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | die(str, regs, err); |
| 110 | } |
| 111 | |
Alexander van Heukelum | ae82157 | 2008-09-30 18:41:35 +0200 | [diff] [blame] | 112 | /* |
| 113 | * Perform the lazy TSS's I/O bitmap copy. If the TSS has an |
| 114 | * invalid offset set (the LAZY one) and the faulting thread has |
| 115 | * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS, |
| 116 | * we set the offset field correctly and return 1. |
| 117 | */ |
| 118 | static int lazy_iobitmap_copy(void) |
| 119 | { |
| 120 | struct thread_struct *thread; |
| 121 | struct tss_struct *tss; |
| 122 | int cpu; |
| 123 | |
| 124 | cpu = get_cpu(); |
| 125 | tss = &per_cpu(init_tss, cpu); |
| 126 | thread = ¤t->thread; |
| 127 | |
| 128 | if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY && |
| 129 | thread->io_bitmap_ptr) { |
| 130 | memcpy(tss->io_bitmap, thread->io_bitmap_ptr, |
| 131 | thread->io_bitmap_max); |
| 132 | /* |
| 133 | * If the previously set map was extending to higher ports |
| 134 | * than the current one, pad extra space with 0xff (no access). |
| 135 | */ |
| 136 | if (thread->io_bitmap_max < tss->io_bitmap_max) { |
| 137 | memset((char *) tss->io_bitmap + |
| 138 | thread->io_bitmap_max, 0xff, |
| 139 | tss->io_bitmap_max - thread->io_bitmap_max); |
| 140 | } |
| 141 | tss->io_bitmap_max = thread->io_bitmap_max; |
| 142 | tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET; |
| 143 | tss->io_bitmap_owner = thread; |
| 144 | put_cpu(); |
| 145 | |
| 146 | return 1; |
| 147 | } |
| 148 | put_cpu(); |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 153 | static void __kprobes |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 154 | do_trap(int trapnr, int signr, char *str, struct pt_regs *regs, |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 155 | long error_code, siginfo_t *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Alexander Nyberg | 4f339ec | 2005-06-25 14:58:27 -0700 | [diff] [blame] | 157 | struct task_struct *tsk = current; |
Alexander Nyberg | 4f339ec | 2005-06-25 14:58:27 -0700 | [diff] [blame] | 158 | |
gorcunov@gmail.com | 6b6891f | 2008-03-28 17:56:57 +0300 | [diff] [blame] | 159 | if (regs->flags & X86_VM_MASK) { |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 160 | /* |
| 161 | * traps 0, 1, 3, 4, and 5 should be forwarded to vm86. |
| 162 | * On nmi (interrupt 2), do_trap should not be called. |
| 163 | */ |
| 164 | if (trapnr < 6) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | goto vm86_trap; |
| 166 | goto trap_signal; |
| 167 | } |
| 168 | |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 169 | if (!user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | goto kernel_trap; |
| 171 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 172 | trap_signal: |
| 173 | /* |
| 174 | * We want error_code and trap_no set for userspace faults and |
| 175 | * kernelspace faults which result in die(), but not |
| 176 | * kernelspace faults which are fixed up. die() gives the |
| 177 | * process no chance to handle the signal and notice the |
| 178 | * kernel fault information, so that won't result in polluting |
| 179 | * the information about previously queued, but not yet |
| 180 | * delivered, faults. See also do_general_protection below. |
| 181 | */ |
| 182 | tsk->thread.error_code = error_code; |
| 183 | tsk->thread.trap_no = trapnr; |
| 184 | |
| 185 | if (info) |
| 186 | force_sig_info(signr, info, tsk); |
| 187 | else |
| 188 | force_sig(signr, tsk); |
| 189 | return; |
| 190 | |
| 191 | kernel_trap: |
| 192 | if (!fixup_exception(regs)) { |
Andi Kleen | d189518 | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 193 | tsk->thread.error_code = error_code; |
| 194 | tsk->thread.trap_no = trapnr; |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 195 | die(str, regs, error_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 197 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 199 | vm86_trap: |
| 200 | if (handle_vm86_trap((struct kernel_vm86_regs *) regs, |
| 201 | error_code, trapnr)) |
| 202 | goto trap_signal; |
| 203 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 206 | #define DO_ERROR(trapnr, signr, str, name) \ |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 207 | dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 208 | { \ |
| 209 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 210 | == NOTIFY_STOP) \ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 211 | return; \ |
Alexander van Heukelum | 61aef7d | 2008-09-09 21:55:56 +0200 | [diff] [blame] | 212 | conditional_sti(regs); \ |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 213 | do_trap(trapnr, signr, str, regs, error_code, NULL); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 216 | #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 217 | dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 218 | { \ |
| 219 | siginfo_t info; \ |
| 220 | info.si_signo = signr; \ |
| 221 | info.si_errno = 0; \ |
| 222 | info.si_code = sicode; \ |
| 223 | info.si_addr = (void __user *)siaddr; \ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 224 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 225 | == NOTIFY_STOP) \ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 226 | return; \ |
Alexander van Heukelum | 61aef7d | 2008-09-09 21:55:56 +0200 | [diff] [blame] | 227 | conditional_sti(regs); \ |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 228 | do_trap(trapnr, signr, str, regs, error_code, &info); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 231 | DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip) |
| 232 | DO_ERROR(4, SIGSEGV, "overflow", overflow) |
| 233 | DO_ERROR(5, SIGSEGV, "bounds", bounds) |
| 234 | DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip) |
Alexander van Heukelum | 51bc1ed | 2008-09-09 21:56:03 +0200 | [diff] [blame] | 235 | DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun) |
Alexander van Heukelum | 6bf77bf | 2008-09-09 21:56:04 +0200 | [diff] [blame] | 236 | DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS) |
Alexander van Heukelum | 36d936c | 2008-09-09 21:56:05 +0200 | [diff] [blame] | 237 | DO_ERROR(11, SIGBUS, "segment not present", segment_not_present) |
Alexander van Heukelum | f5ca818 | 2008-09-09 21:56:06 +0200 | [diff] [blame] | 238 | DO_ERROR(12, SIGBUS, "stack segment", stack_segment) |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 239 | DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 241 | dotraplinkage void __kprobes |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 242 | do_general_protection(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 244 | struct task_struct *tsk; |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 245 | |
Alexander van Heukelum | c6df0d7 | 2008-09-09 21:56:07 +0200 | [diff] [blame] | 246 | conditional_sti(regs); |
| 247 | |
Alexander van Heukelum | ae82157 | 2008-09-30 18:41:35 +0200 | [diff] [blame] | 248 | if (lazy_iobitmap_copy()) { |
| 249 | /* restart the faulting instruction */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | return; |
| 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
gorcunov@gmail.com | 6b6891f | 2008-03-28 17:56:57 +0300 | [diff] [blame] | 253 | if (regs->flags & X86_VM_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | goto gp_in_vm86; |
| 255 | |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 256 | tsk = current; |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 257 | if (!user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | goto gp_in_kernel; |
| 259 | |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 260 | tsk->thread.error_code = error_code; |
| 261 | tsk->thread.trap_no = 13; |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 262 | |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 263 | if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) && |
| 264 | printk_ratelimit()) { |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 265 | printk(KERN_INFO |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 266 | "%s[%d] general protection ip:%lx sp:%lx error:%lx", |
| 267 | tsk->comm, task_pid_nr(tsk), |
| 268 | regs->ip, regs->sp, error_code); |
Andi Kleen | 0325291 | 2008-01-30 13:33:18 +0100 | [diff] [blame] | 269 | print_vma_addr(" in ", regs->ip); |
| 270 | printk("\n"); |
| 271 | } |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 272 | |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 273 | force_sig(SIGSEGV, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | return; |
| 275 | |
| 276 | gp_in_vm86: |
| 277 | local_irq_enable(); |
| 278 | handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); |
| 279 | return; |
| 280 | |
| 281 | gp_in_kernel: |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 282 | if (fixup_exception(regs)) |
| 283 | return; |
| 284 | |
| 285 | tsk->thread.error_code = error_code; |
| 286 | tsk->thread.trap_no = 13; |
| 287 | if (notify_die(DIE_GPF, "general protection fault", regs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | error_code, 13, SIGSEGV) == NOTIFY_STOP) |
Alexander van Heukelum | 13485ab | 2008-07-02 01:32:04 +0200 | [diff] [blame] | 289 | return; |
| 290 | die("general protection fault", regs, error_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Steven Rostedt | 5deb45e | 2008-04-19 19:19:55 +0200 | [diff] [blame] | 293 | static notrace __kprobes void |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 294 | mem_parity_error(unsigned char reason, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 296 | printk(KERN_EMERG |
| 297 | "Uhhuh. NMI received for unknown reason %02x on CPU %d.\n", |
| 298 | reason, smp_processor_id()); |
| 299 | |
| 300 | printk(KERN_EMERG |
| 301 | "You have some hardware problem, likely on the PCI bus.\n"); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 302 | |
| 303 | #if defined(CONFIG_EDAC) |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 304 | if (edac_handler_set()) { |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 305 | edac_atomic_assert_error(); |
| 306 | return; |
| 307 | } |
| 308 | #endif |
| 309 | |
Don Zickus | 8da5add | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 310 | if (panic_on_unrecovered_nmi) |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 311 | panic("NMI: Not continuing"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 313 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | /* Clear and disable the memory parity error line. */ |
Alexander van Heukelum | 7970479 | 2008-10-03 22:00:36 +0200 | [diff] [blame^] | 316 | reason = (reason & 0xf) | 4; |
| 317 | outb(reason, 0x61); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Steven Rostedt | 5deb45e | 2008-04-19 19:19:55 +0200 | [diff] [blame] | 320 | static notrace __kprobes void |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 321 | io_check_error(unsigned char reason, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | unsigned long i; |
| 324 | |
Dave Jones | 9c10780 | 2006-01-09 20:51:32 -0800 | [diff] [blame] | 325 | printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | show_registers(regs); |
| 327 | |
| 328 | /* Re-enable the IOCK line, wait for a few seconds */ |
| 329 | reason = (reason & 0xf) | 8; |
| 330 | outb(reason, 0x61); |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | i = 2000; |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 333 | while (--i) |
| 334 | udelay(1000); |
| 335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | reason &= ~8; |
| 337 | outb(reason, 0x61); |
| 338 | } |
| 339 | |
Steven Rostedt | 5deb45e | 2008-04-19 19:19:55 +0200 | [diff] [blame] | 340 | static notrace __kprobes void |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 341 | unknown_nmi_error(unsigned char reason, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | { |
Jason Wessel | d359752 | 2008-02-15 14:55:53 -0600 | [diff] [blame] | 343 | if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP) |
| 344 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | #ifdef CONFIG_MCA |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 346 | /* |
| 347 | * Might actually be able to figure out what the guilty party |
| 348 | * is: |
| 349 | */ |
| 350 | if (MCA_bus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | mca_handle_nmi(); |
| 352 | return; |
| 353 | } |
| 354 | #endif |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 355 | printk(KERN_EMERG |
| 356 | "Uhhuh. NMI received for unknown reason %02x on CPU %d.\n", |
| 357 | reason, smp_processor_id()); |
| 358 | |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 359 | 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] | 360 | if (panic_on_unrecovered_nmi) |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 361 | panic("NMI: Not continuing"); |
Don Zickus | 8da5add | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 362 | |
Don Zickus | c41c5cd | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 363 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static DEFINE_SPINLOCK(nmi_print_lock); |
| 367 | |
Cyrill Gorcunov | ddca03c | 2008-05-24 19:36:31 +0400 | [diff] [blame] | 368 | void notrace __kprobes die_nmi(char *str, struct pt_regs *regs, int do_panic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { |
Cyrill Gorcunov | ddca03c | 2008-05-24 19:36:31 +0400 | [diff] [blame] | 370 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP) |
George Anzinger | 748f2ed | 2005-09-03 15:56:48 -0700 | [diff] [blame] | 371 | return; |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | spin_lock(&nmi_print_lock); |
| 374 | /* |
| 375 | * We are in trouble anyway, lets at least try |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 376 | * to get a message out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | */ |
| 378 | bust_spinlocks(1); |
Cyrill Gorcunov | ddca03c | 2008-05-24 19:36:31 +0400 | [diff] [blame] | 379 | printk(KERN_EMERG "%s", str); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 380 | printk(" on CPU%d, ip %08lx, registers:\n", |
| 381 | smp_processor_id(), regs->ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | show_registers(regs); |
Cyrill Gorcunov | ddca03c | 2008-05-24 19:36:31 +0400 | [diff] [blame] | 383 | if (do_panic) |
| 384 | panic("Non maskable interrupt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | console_silent(); |
| 386 | spin_unlock(&nmi_print_lock); |
| 387 | bust_spinlocks(0); |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 388 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 389 | /* |
| 390 | * If we are in kernel we are probably nested up pretty bad |
| 391 | * and might aswell get out now while we still can: |
| 392 | */ |
Jan Beulich | db753bd | 2006-03-23 02:59:46 -0800 | [diff] [blame] | 393 | if (!user_mode_vm(regs)) { |
Alexander Nyberg | 6e274d1 | 2005-06-25 14:58:26 -0700 | [diff] [blame] | 394 | current->thread.trap_no = 2; |
| 395 | crash_kexec(regs); |
| 396 | } |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | do_exit(SIGSEGV); |
| 399 | } |
| 400 | |
Steven Rostedt | 5deb45e | 2008-04-19 19:19:55 +0200 | [diff] [blame] | 401 | static notrace __kprobes void default_do_nmi(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
| 403 | unsigned char reason = 0; |
Alexander van Heukelum | abd3480 | 2008-07-02 18:39:01 +0200 | [diff] [blame] | 404 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Alexander van Heukelum | abd3480 | 2008-07-02 18:39:01 +0200 | [diff] [blame] | 406 | cpu = smp_processor_id(); |
| 407 | |
| 408 | /* Only the BSP gets external NMIs from the system. */ |
| 409 | if (!cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | reason = get_nmi_reason(); |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | if (!(reason & 0xc0)) { |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 413 | if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT) |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 414 | == NOTIFY_STOP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | return; |
| 416 | #ifdef CONFIG_X86_LOCAL_APIC |
| 417 | /* |
| 418 | * Ok, so this is none of the documented NMI sources, |
| 419 | * so it must be the NMI watchdog. |
| 420 | */ |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 421 | if (nmi_watchdog_tick(regs, reason)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | return; |
Alexander van Heukelum | abd3480 | 2008-07-02 18:39:01 +0200 | [diff] [blame] | 423 | if (!do_nmi_callback(regs, cpu)) |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 424 | unknown_nmi_error(reason, regs); |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 425 | #else |
| 426 | unknown_nmi_error(reason, regs); |
| 427 | #endif |
Don Zickus | 2fbe7b2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return; |
| 430 | } |
Jan Beulich | 20c0d2d | 2006-03-26 01:37:01 -0800 | [diff] [blame] | 431 | if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | return; |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 433 | |
| 434 | /* AK: following checks seem to be broken on modern chipsets. FIXME */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | if (reason & 0x80) |
| 436 | mem_parity_error(reason, regs); |
| 437 | if (reason & 0x40) |
| 438 | io_check_error(reason, regs); |
| 439 | /* |
| 440 | * Reassert NMI in case it became active meanwhile |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 441 | * as it's edge-triggered: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | */ |
| 443 | reassert_nmi(); |
| 444 | } |
| 445 | |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 446 | dotraplinkage notrace __kprobes void |
| 447 | do_nmi(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
| 449 | int cpu; |
| 450 | |
| 451 | nmi_enter(); |
| 452 | |
| 453 | cpu = smp_processor_id(); |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | ++nmi_count(cpu); |
| 456 | |
Andi Kleen | 8f4e956 | 2007-07-22 11:12:32 +0200 | [diff] [blame] | 457 | if (!ignore_nmis) |
| 458 | default_do_nmi(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | nmi_exit(); |
| 461 | } |
| 462 | |
Andi Kleen | 8f4e956 | 2007-07-22 11:12:32 +0200 | [diff] [blame] | 463 | void stop_nmi(void) |
| 464 | { |
| 465 | acpi_nmi_disable(); |
| 466 | ignore_nmis++; |
| 467 | } |
| 468 | |
| 469 | void restart_nmi(void) |
| 470 | { |
| 471 | ignore_nmis--; |
| 472 | acpi_nmi_enable(); |
| 473 | } |
| 474 | |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 475 | dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Alexander van Heukelum | b94da1e | 2008-09-09 21:55:58 +0200 | [diff] [blame] | 477 | #ifdef CONFIG_KPROBES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) |
| 479 | == NOTIFY_STOP) |
Stas Sergeev | 48c88211 | 2005-05-01 08:58:49 -0700 | [diff] [blame] | 480 | return; |
Alexander van Heukelum | b94da1e | 2008-09-09 21:55:58 +0200 | [diff] [blame] | 481 | #else |
| 482 | if (notify_die(DIE_TRAP, "int3", regs, error_code, 3, SIGTRAP) |
| 483 | == NOTIFY_STOP) |
| 484 | return; |
| 485 | #endif |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 486 | |
Alexander van Heukelum | 4915a35 | 2008-10-03 22:00:34 +0200 | [diff] [blame] | 487 | preempt_conditional_sti(regs); |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 488 | do_trap(3, SIGTRAP, "int3", regs, error_code, NULL); |
Alexander van Heukelum | 4915a35 | 2008-10-03 22:00:34 +0200 | [diff] [blame] | 489 | preempt_conditional_cli(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | /* |
| 493 | * Our handling of the processor debug registers is non-trivial. |
| 494 | * We do not clear them on entry and exit from the kernel. Therefore |
| 495 | * it is possible to get a watchpoint trap here from inside the kernel. |
| 496 | * However, the code in ./ptrace.c has ensured that the user can |
| 497 | * only set watchpoints on userspace addresses. Therefore the in-kernel |
| 498 | * watchpoint trap can only occur in code which is reading/writing |
| 499 | * from user space. Such code must not hold kernel locks (since it |
| 500 | * can equally take a page fault), therefore it is safe to call |
| 501 | * force_sig_info even though that claims and releases locks. |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 502 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | * Code in ./signal.c ensures that the debug control register |
| 504 | * is restored before we deliver any signal, and therefore that |
| 505 | * user code runs with the correct debug control register even though |
| 506 | * we clear it here. |
| 507 | * |
| 508 | * Being careful here means that we don't have to be as careful in a |
| 509 | * lot of more complicated places (task switching can be a bit lazy |
| 510 | * about restoring all the debug state, and ptrace doesn't have to |
| 511 | * find every occurrence of the TF bit that could be saved away even |
| 512 | * by user code) |
| 513 | */ |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 514 | dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | struct task_struct *tsk = current; |
Alexander van Heukelum | 3d2a71a | 2008-09-30 18:41:37 +0200 | [diff] [blame] | 517 | unsigned long condition; |
Srinivasa Ds | da654b7 | 2008-09-23 15:23:52 +0530 | [diff] [blame] | 518 | int si_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
Vincent Hanquez | 1cc6f12 | 2005-06-23 00:08:43 -0700 | [diff] [blame] | 520 | get_debugreg(condition, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Roland McGrath | 10faa81 | 2008-01-30 13:30:54 +0100 | [diff] [blame] | 522 | /* |
| 523 | * The processor cleared BTF, so don't mark that we need it set. |
| 524 | */ |
| 525 | clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR); |
| 526 | tsk->thread.debugctlmsr = 0; |
| 527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code, |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 529 | SIGTRAP) == NOTIFY_STOP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return; |
Alexander van Heukelum | 3d2a71a | 2008-09-30 18:41:37 +0200 | [diff] [blame] | 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | /* It's safe to allow irq's after DR6 has been saved */ |
Alexander van Heukelum | 3d2a71a | 2008-09-30 18:41:37 +0200 | [diff] [blame] | 533 | preempt_conditional_sti(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | /* Mask out spurious debug traps due to lazy DR7 setting */ |
| 536 | if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) { |
Roland McGrath | 0f53409 | 2008-01-30 13:30:59 +0100 | [diff] [blame] | 537 | if (!tsk->thread.debugreg7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | goto clear_dr7; |
| 539 | } |
| 540 | |
gorcunov@gmail.com | 6b6891f | 2008-03-28 17:56:57 +0300 | [diff] [blame] | 541 | if (regs->flags & X86_VM_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | goto debug_vm86; |
| 543 | |
| 544 | /* Save debug status register where ptrace can see it */ |
Roland McGrath | 0f53409 | 2008-01-30 13:30:59 +0100 | [diff] [blame] | 545 | tsk->thread.debugreg6 = condition; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | /* |
| 548 | * Single-stepping through TF: make sure we ignore any events in |
| 549 | * kernel space (but re-enable TF when returning to user mode). |
| 550 | */ |
| 551 | if (condition & DR_STEP) { |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 552 | if (!user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | goto clear_TF_reenable; |
| 554 | } |
| 555 | |
Alexander van Heukelum | 3d2a71a | 2008-09-30 18:41:37 +0200 | [diff] [blame] | 556 | si_code = get_si_code(condition); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | /* Ok, finally something we can handle */ |
Srinivasa Ds | da654b7 | 2008-09-23 15:23:52 +0530 | [diff] [blame] | 558 | send_sigtrap(tsk, regs, error_code, si_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 560 | /* |
| 561 | * Disable additional traps. They'll be re-enabled when |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | * the signal is delivered. |
| 563 | */ |
| 564 | clear_dr7: |
Vincent Hanquez | 1cc6f12 | 2005-06-23 00:08:43 -0700 | [diff] [blame] | 565 | set_debugreg(0, 7); |
Alexander van Heukelum | 3d2a71a | 2008-09-30 18:41:37 +0200 | [diff] [blame] | 566 | preempt_conditional_cli(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | return; |
| 568 | |
| 569 | debug_vm86: |
| 570 | handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1); |
Alexander van Heukelum | 3d2a71a | 2008-09-30 18:41:37 +0200 | [diff] [blame] | 571 | preempt_conditional_cli(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return; |
| 573 | |
| 574 | clear_TF_reenable: |
| 575 | set_tsk_thread_flag(tsk, TIF_SINGLESTEP); |
Ingo Molnar | 6093015 | 2008-03-30 11:45:23 +0200 | [diff] [blame] | 576 | regs->flags &= ~X86_EFLAGS_TF; |
Alexander van Heukelum | 3d2a71a | 2008-09-30 18:41:37 +0200 | [diff] [blame] | 577 | preempt_conditional_cli(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | return; |
| 579 | } |
| 580 | |
| 581 | /* |
| 582 | * Note that we play around with the 'TS' bit in an attempt to get |
| 583 | * the correct behaviour even in the presence of the asynchronous |
| 584 | * IRQ13 behaviour |
| 585 | */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 586 | void math_error(void __user *ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 588 | struct task_struct *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | siginfo_t info; |
Alexander van Heukelum | 7b4fd4b | 2008-07-02 01:33:14 +0200 | [diff] [blame] | 590 | unsigned short cwd, swd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
| 592 | /* |
| 593 | * Save the info for the exception handler and clear the error. |
| 594 | */ |
| 595 | task = current; |
| 596 | save_init_fpu(task); |
| 597 | task->thread.trap_no = 16; |
| 598 | task->thread.error_code = 0; |
| 599 | info.si_signo = SIGFPE; |
| 600 | info.si_errno = 0; |
| 601 | info.si_code = __SI_FAULT; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 602 | info.si_addr = ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | /* |
| 604 | * (~cwd & swd) will mask out exceptions that are not set to unmasked |
| 605 | * status. 0x3f is the exception bits in these regs, 0x200 is the |
| 606 | * C1 reg you need in case of a stack fault, 0x040 is the stack |
| 607 | * fault bit. We should only be taking one exception at a time, |
| 608 | * so if this combination doesn't produce any single exception, |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 609 | * then we have a bad program that isn't synchronizing its FPU usage |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | * and it will suffer the consequences since we won't be able to |
| 611 | * fully reproduce the context of the exception |
| 612 | */ |
| 613 | cwd = get_fpu_cwd(task); |
| 614 | swd = get_fpu_swd(task); |
Chuck Ebbert | b1daec3 | 2005-08-23 21:36:40 -0400 | [diff] [blame] | 615 | switch (swd & ~cwd & 0x3f) { |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 616 | case 0x000: /* No unmasked exception */ |
| 617 | return; |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 618 | default: /* Multiple exceptions */ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 619 | break; |
| 620 | case 0x001: /* Invalid Op */ |
| 621 | /* |
| 622 | * swd & 0x240 == 0x040: Stack Underflow |
| 623 | * swd & 0x240 == 0x240: Stack Overflow |
| 624 | * User must clear the SF bit (0x40) if set |
| 625 | */ |
| 626 | info.si_code = FPE_FLTINV; |
| 627 | break; |
| 628 | case 0x002: /* Denormalize */ |
| 629 | case 0x010: /* Underflow */ |
| 630 | info.si_code = FPE_FLTUND; |
| 631 | break; |
| 632 | case 0x004: /* Zero Divide */ |
| 633 | info.si_code = FPE_FLTDIV; |
| 634 | break; |
| 635 | case 0x008: /* Overflow */ |
| 636 | info.si_code = FPE_FLTOVF; |
| 637 | break; |
| 638 | case 0x020: /* Precision */ |
| 639 | info.si_code = FPE_FLTRES; |
| 640 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | force_sig_info(SIGFPE, &info, task); |
| 643 | } |
| 644 | |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 645 | dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
Alexander van Heukelum | 252d28f | 2008-09-09 21:56:09 +0200 | [diff] [blame] | 647 | conditional_sti(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | ignore_fpu_irq = 1; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 649 | math_error((void __user *)regs->ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | } |
| 651 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 652 | static void simd_math_error(void __user *ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 654 | struct task_struct *task; |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 655 | siginfo_t info; |
Alexander van Heukelum | 7b4fd4b | 2008-07-02 01:33:14 +0200 | [diff] [blame] | 656 | unsigned short mxcsr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
| 658 | /* |
| 659 | * Save the info for the exception handler and clear the error. |
| 660 | */ |
| 661 | task = current; |
| 662 | save_init_fpu(task); |
| 663 | task->thread.trap_no = 19; |
| 664 | task->thread.error_code = 0; |
| 665 | info.si_signo = SIGFPE; |
| 666 | info.si_errno = 0; |
| 667 | info.si_code = __SI_FAULT; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 668 | info.si_addr = ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | /* |
| 670 | * The SIMD FPU exceptions are handled a little differently, as there |
| 671 | * is only a single status/control register. Thus, to determine which |
| 672 | * unmasked exception was caught we must mask the exception mask bits |
| 673 | * at 0x1f80, and then use these to mask the exception bits at 0x3f. |
| 674 | */ |
| 675 | mxcsr = get_fpu_mxcsr(task); |
| 676 | switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) { |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 677 | case 0x000: |
| 678 | default: |
| 679 | break; |
| 680 | case 0x001: /* Invalid Op */ |
| 681 | info.si_code = FPE_FLTINV; |
| 682 | break; |
| 683 | case 0x002: /* Denormalize */ |
| 684 | case 0x010: /* Underflow */ |
| 685 | info.si_code = FPE_FLTUND; |
| 686 | break; |
| 687 | case 0x004: /* Zero Divide */ |
| 688 | info.si_code = FPE_FLTDIV; |
| 689 | break; |
| 690 | case 0x008: /* Overflow */ |
| 691 | info.si_code = FPE_FLTOVF; |
| 692 | break; |
| 693 | case 0x020: /* Precision */ |
| 694 | info.si_code = FPE_FLTRES; |
| 695 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
| 697 | force_sig_info(SIGFPE, &info, task); |
| 698 | } |
| 699 | |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 700 | dotraplinkage void |
| 701 | do_simd_coprocessor_error(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | { |
Alexander van Heukelum | b939bde | 2008-09-09 21:56:12 +0200 | [diff] [blame] | 703 | conditional_sti(regs); |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if (cpu_has_xmm) { |
| 706 | /* Handle SIMD FPU exceptions on PIII+ processors. */ |
| 707 | ignore_fpu_irq = 1; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 708 | simd_math_error((void __user *)regs->ip); |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 709 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 711 | /* |
| 712 | * Handle strange cache flush from user space exception |
| 713 | * in all other cases. This is undocumented behaviour. |
| 714 | */ |
gorcunov@gmail.com | 6b6891f | 2008-03-28 17:56:57 +0300 | [diff] [blame] | 715 | if (regs->flags & X86_VM_MASK) { |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 716 | handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code); |
| 717 | return; |
| 718 | } |
| 719 | current->thread.trap_no = 19; |
| 720 | current->thread.error_code = error_code; |
| 721 | die_if_kernel("cache flush denied", regs, error_code); |
| 722 | force_sig(SIGSEGV, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 725 | dotraplinkage void |
| 726 | do_spurious_interrupt_bug(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
Alexander van Heukelum | cf81978 | 2008-09-09 21:56:08 +0200 | [diff] [blame] | 728 | conditional_sti(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | #if 0 |
| 730 | /* No need to warn about this any longer. */ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 731 | printk(KERN_INFO "Ignoring P6 Local APIC Spurious Interrupt Bug...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | #endif |
| 733 | } |
| 734 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 735 | unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | { |
Glauber Costa | 736f12b | 2008-05-27 20:14:51 -0700 | [diff] [blame] | 737 | struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id()); |
Stas Sergeev | be44d2a | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 738 | unsigned long base = (kesp - uesp) & -THREAD_SIZE; |
| 739 | unsigned long new_kesp = kesp - base; |
| 740 | unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT; |
| 741 | __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS]; |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 742 | |
Stas Sergeev | be44d2a | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 743 | /* Set up base for espfix segment */ |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 744 | desc &= 0x00f0ff0000000000ULL; |
| 745 | desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) | |
Stas Sergeev | be44d2a | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 746 | ((((__u64)base) << 32) & 0xff00000000000000ULL) | |
| 747 | ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) | |
| 748 | (lim_pages & 0xffff); |
| 749 | *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc; |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 750 | |
Stas Sergeev | be44d2a | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 751 | return new_kesp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /* |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 755 | * 'math_state_restore()' saves the current math information in the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | * old math state array, and gets the new ones from the current task |
| 757 | * |
| 758 | * Careful.. There are problems with IBM-designed IRQ13 behaviour. |
| 759 | * Don't touch unless you *really* know how it works. |
| 760 | * |
| 761 | * Must be called with kernel preemption disabled (in this case, |
| 762 | * local interrupts are disabled at the call-site in entry.S). |
| 763 | */ |
Chuck Ebbert | acc2076 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 764 | asmlinkage void math_state_restore(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | { |
| 766 | struct thread_info *thread = current_thread_info(); |
| 767 | struct task_struct *tsk = thread->task; |
| 768 | |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 769 | if (!tsk_used_math(tsk)) { |
| 770 | local_irq_enable(); |
| 771 | /* |
| 772 | * does a slab alloc which can sleep |
| 773 | */ |
| 774 | if (init_fpu(tsk)) { |
| 775 | /* |
| 776 | * ran out of memory! |
| 777 | */ |
| 778 | do_group_exit(SIGKILL); |
| 779 | return; |
| 780 | } |
| 781 | local_irq_disable(); |
| 782 | } |
| 783 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 784 | clts(); /* Allow maths ops (or we recurse) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | restore_fpu(tsk); |
| 786 | thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */ |
Chuck Ebbert | acc2076 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 787 | tsk->fpu_counter++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
Rusty Russell | 5992b6d | 2007-07-19 01:49:21 -0700 | [diff] [blame] | 789 | EXPORT_SYMBOL_GPL(math_state_restore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | #ifndef CONFIG_MATH_EMULATION |
| 792 | |
| 793 | asmlinkage void math_emulate(long arg) |
| 794 | { |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 795 | printk(KERN_EMERG |
| 796 | "math-emulation not enabled and no coprocessor found.\n"); |
| 797 | printk(KERN_EMERG "killing %s.\n", current->comm); |
| 798 | force_sig(SIGFPE, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | schedule(); |
| 800 | } |
| 801 | |
| 802 | #endif /* CONFIG_MATH_EMULATION */ |
| 803 | |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 804 | dotraplinkage void __kprobes |
| 805 | do_device_not_available(struct pt_regs *regs, long error) |
Alexander van Heukelum | 7643e9b | 2008-09-09 21:56:02 +0200 | [diff] [blame] | 806 | { |
| 807 | if (read_cr0() & X86_CR0_EM) { |
| 808 | conditional_sti(regs); |
| 809 | math_emulate(0); |
| 810 | } else { |
| 811 | math_state_restore(); /* interrupts still off */ |
| 812 | conditional_sti(regs); |
| 813 | } |
| 814 | } |
| 815 | |
Alexander van Heukelum | eb642f6 | 2008-09-09 21:56:11 +0200 | [diff] [blame] | 816 | #ifdef CONFIG_X86_MCE |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 817 | dotraplinkage void __kprobes do_machine_check(struct pt_regs *regs, long error) |
Alexander van Heukelum | eb642f6 | 2008-09-09 21:56:11 +0200 | [diff] [blame] | 818 | { |
| 819 | conditional_sti(regs); |
| 820 | machine_check_vector(regs, error); |
| 821 | } |
| 822 | #endif |
| 823 | |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 824 | dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) |
Alexander van Heukelum | f8e0870 | 2008-09-09 21:56:13 +0200 | [diff] [blame] | 825 | { |
| 826 | siginfo_t info; |
| 827 | local_irq_enable(); |
| 828 | |
| 829 | info.si_signo = SIGILL; |
| 830 | info.si_errno = 0; |
| 831 | info.si_code = ILL_BADSTK; |
| 832 | info.si_addr = 0; |
| 833 | if (notify_die(DIE_TRAP, "iret exception", |
| 834 | regs, error_code, 32, SIGILL) == NOTIFY_STOP) |
| 835 | return; |
Alexander van Heukelum | 3c1326f | 2008-09-26 14:03:08 +0200 | [diff] [blame] | 836 | do_trap(32, SIGILL, "iret exception", regs, error_code, &info); |
Alexander van Heukelum | f8e0870 | 2008-09-09 21:56:13 +0200 | [diff] [blame] | 837 | } |
| 838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | void __init trap_init(void) |
| 840 | { |
Rusty Russell | dbeb2be | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 841 | int i; |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | #ifdef CONFIG_EISA |
Ingo Molnar | 927222b | 2008-01-30 13:33:49 +0100 | [diff] [blame] | 844 | void __iomem *p = early_ioremap(0x0FFFD9, 4); |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 845 | |
| 846 | if (readl(p) == 'E' + ('I'<<8) + ('S'<<16) + ('A'<<24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | EISA_bus = 1; |
Ingo Molnar | 927222b | 2008-01-30 13:33:49 +0100 | [diff] [blame] | 848 | early_iounmap(p, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | #endif |
| 850 | |
Alexander van Heukelum | 976382d | 2008-09-09 21:55:57 +0200 | [diff] [blame] | 851 | set_intr_gate(0, ÷_error); |
Alexander van Heukelum | 699d293 | 2008-10-03 22:00:32 +0200 | [diff] [blame] | 852 | set_intr_gate_ist(1, &debug, DEBUG_STACK); |
| 853 | set_intr_gate_ist(2, &nmi, NMI_STACK); |
| 854 | /* int3 can be called from all */ |
| 855 | set_system_intr_gate_ist(3, &int3, DEBUG_STACK); |
| 856 | /* int4 can be called from all */ |
| 857 | set_system_intr_gate(4, &overflow); |
Alexander van Heukelum | 64f644c | 2008-09-09 21:56:00 +0200 | [diff] [blame] | 858 | set_intr_gate(5, &bounds); |
Alexander van Heukelum | 12394cf | 2008-09-09 21:56:01 +0200 | [diff] [blame] | 859 | set_intr_gate(6, &invalid_op); |
Alexander van Heukelum | 7643e9b | 2008-09-09 21:56:02 +0200 | [diff] [blame] | 860 | set_intr_gate(7, &device_not_available); |
Alexander van Heukelum | a8c1be9 | 2008-07-02 01:29:44 +0200 | [diff] [blame] | 861 | set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS); |
Alexander van Heukelum | 51bc1ed | 2008-09-09 21:56:03 +0200 | [diff] [blame] | 862 | set_intr_gate(9, &coprocessor_segment_overrun); |
Alexander van Heukelum | 6bf77bf | 2008-09-09 21:56:04 +0200 | [diff] [blame] | 863 | set_intr_gate(10, &invalid_TSS); |
Alexander van Heukelum | 36d936c | 2008-09-09 21:56:05 +0200 | [diff] [blame] | 864 | set_intr_gate(11, &segment_not_present); |
Alexander van Heukelum | 699d293 | 2008-10-03 22:00:32 +0200 | [diff] [blame] | 865 | set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK); |
Alexander van Heukelum | c6df0d7 | 2008-09-09 21:56:07 +0200 | [diff] [blame] | 866 | set_intr_gate(13, &general_protection); |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 867 | set_intr_gate(14, &page_fault); |
Alexander van Heukelum | cf81978 | 2008-09-09 21:56:08 +0200 | [diff] [blame] | 868 | set_intr_gate(15, &spurious_interrupt_bug); |
Alexander van Heukelum | 252d28f | 2008-09-09 21:56:09 +0200 | [diff] [blame] | 869 | set_intr_gate(16, &coprocessor_error); |
Alexander van Heukelum | 5feedfd | 2008-09-09 21:56:10 +0200 | [diff] [blame] | 870 | set_intr_gate(17, &alignment_check); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | #ifdef CONFIG_X86_MCE |
Alexander van Heukelum | 699d293 | 2008-10-03 22:00:32 +0200 | [diff] [blame] | 872 | set_intr_gate_ist(18, &machine_check, MCE_STACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | #endif |
Alexander van Heukelum | b939bde | 2008-09-09 21:56:12 +0200 | [diff] [blame] | 874 | set_intr_gate(19, &simd_coprocessor_error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Jan Beulich | d43c6e8 | 2006-01-06 00:11:49 -0800 | [diff] [blame] | 876 | if (cpu_has_fxsr) { |
Jan Beulich | d43c6e8 | 2006-01-06 00:11:49 -0800 | [diff] [blame] | 877 | printk(KERN_INFO "Enabling fast FPU save and restore... "); |
| 878 | set_in_cr4(X86_CR4_OSFXSR); |
| 879 | printk("done.\n"); |
| 880 | } |
| 881 | if (cpu_has_xmm) { |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 882 | printk(KERN_INFO |
| 883 | "Enabling unmasked SIMD FPU exception support... "); |
Jan Beulich | d43c6e8 | 2006-01-06 00:11:49 -0800 | [diff] [blame] | 884 | set_in_cr4(X86_CR4_OSXMMEXCPT); |
| 885 | printk("done.\n"); |
| 886 | } |
| 887 | |
Alexander van Heukelum | 699d293 | 2008-10-03 22:00:32 +0200 | [diff] [blame] | 888 | set_system_trap_gate(SYSCALL_VECTOR, &system_call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 890 | /* Reserve all the builtin and the syscall vector: */ |
Rusty Russell | dbeb2be | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 891 | for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++) |
| 892 | set_bit(i, used_vectors); |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 893 | |
Rusty Russell | dbeb2be | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 894 | set_bit(SYSCALL_VECTOR, used_vectors); |
| 895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | /* |
Ingo Molnar | b596440 | 2008-02-26 11:15:50 +0100 | [diff] [blame] | 897 | * Should be a barrier for any external CPU state: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | */ |
| 899 | cpu_init(); |
| 900 | |
| 901 | trap_init_hook(); |
| 902 | } |