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