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) 1995 Linus Torvalds |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 3 | * Copyright (C) 2001, 2002 Andi Kleen, SuSE Labs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/interrupt.h> |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 6 | #include <linux/mmiotrace.h> |
| 7 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/compiler.h> |
Harvey Harrison | c61e211 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 9 | #include <linux/highmem.h> |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 10 | #include <linux/kprobes.h> |
Andi Kleen | ab2bf0c | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 11 | #include <linux/uaccess.h> |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 12 | #include <linux/vmalloc.h> |
| 13 | #include <linux/vt_kern.h> |
| 14 | #include <linux/signal.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/ptrace.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/module.h> |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 19 | #include <linux/kdebug.h> |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 20 | #include <linux/errno.h> |
Eric Sandeen | 7c9f886 | 2008-04-22 16:38:23 -0500 | [diff] [blame] | 21 | #include <linux/magic.h> |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 22 | #include <linux/sched.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/mman.h> |
| 26 | #include <linux/tty.h> |
| 27 | #include <linux/smp.h> |
| 28 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm-generic/sections.h> |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 31 | |
| 32 | #include <asm/tlbflush.h> |
| 33 | #include <asm/pgalloc.h> |
| 34 | #include <asm/segment.h> |
| 35 | #include <asm/system.h> |
| 36 | #include <asm/proto.h> |
Jaswinder Singh | 70ef564 | 2008-07-23 17:36:37 +0530 | [diff] [blame] | 37 | #include <asm/traps.h> |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 38 | #include <asm/desc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 40 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 41 | * Page fault error code bits: |
| 42 | * |
| 43 | * bit 0 == 0: no page found 1: protection fault |
| 44 | * bit 1 == 0: read access 1: write access |
| 45 | * bit 2 == 0: kernel-mode access 1: user-mode access |
| 46 | * bit 3 == 1: use of reserved bit detected |
| 47 | * bit 4 == 1: fault was an instruction fetch |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 48 | */ |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 49 | enum x86_pf_error_code { |
| 50 | |
| 51 | PF_PROT = 1 << 0, |
| 52 | PF_WRITE = 1 << 1, |
| 53 | PF_USER = 1 << 2, |
| 54 | PF_RSVD = 1 << 3, |
| 55 | PF_INSTR = 1 << 4, |
| 56 | }; |
Andi Kleen | 66c5815 | 2006-01-11 22:44:09 +0100 | [diff] [blame] | 57 | |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 58 | static inline int kmmio_fault(struct pt_regs *regs, unsigned long addr) |
Pekka Paalanen | 8606978 | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 59 | { |
Pekka Paalanen | fd3fdf1 | 2008-10-24 20:08:11 +0300 | [diff] [blame] | 60 | #ifdef CONFIG_MMIOTRACE |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 61 | if (unlikely(is_kmmio_active())) |
| 62 | if (kmmio_handler(regs, addr) == 1) |
| 63 | return -1; |
Pekka Paalanen | 8606978 | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 64 | #endif |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 65 | return 0; |
Pekka Paalanen | 8606978 | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Christoph Hellwig | 74a0b57 | 2007-10-16 01:24:07 -0700 | [diff] [blame] | 68 | static inline int notify_page_fault(struct pt_regs *regs) |
Anil S Keshavamurthy | 1bd858a | 2006-06-26 00:25:25 -0700 | [diff] [blame] | 69 | { |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 70 | #ifdef CONFIG_KPROBES |
Christoph Hellwig | 74a0b57 | 2007-10-16 01:24:07 -0700 | [diff] [blame] | 71 | int ret = 0; |
Anil S Keshavamurthy | 1bd858a | 2006-06-26 00:25:25 -0700 | [diff] [blame] | 72 | |
Christoph Hellwig | 74a0b57 | 2007-10-16 01:24:07 -0700 | [diff] [blame] | 73 | /* kprobe_running() needs smp_processor_id() */ |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 74 | if (!user_mode_vm(regs)) { |
Christoph Hellwig | 74a0b57 | 2007-10-16 01:24:07 -0700 | [diff] [blame] | 75 | preempt_disable(); |
| 76 | if (kprobe_running() && kprobe_fault_handler(regs, 14)) |
| 77 | ret = 1; |
| 78 | preempt_enable(); |
| 79 | } |
Anil S Keshavamurthy | 1bd858a | 2006-06-26 00:25:25 -0700 | [diff] [blame] | 80 | |
Christoph Hellwig | 74a0b57 | 2007-10-16 01:24:07 -0700 | [diff] [blame] | 81 | return ret; |
Christoph Hellwig | 74a0b57 | 2007-10-16 01:24:07 -0700 | [diff] [blame] | 82 | #else |
Christoph Hellwig | 74a0b57 | 2007-10-16 01:24:07 -0700 | [diff] [blame] | 83 | return 0; |
Christoph Hellwig | 74a0b57 | 2007-10-16 01:24:07 -0700 | [diff] [blame] | 84 | #endif |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 85 | } |
Anil S Keshavamurthy | 1bd858a | 2006-06-26 00:25:25 -0700 | [diff] [blame] | 86 | |
Harvey Harrison | 1dc85be | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 87 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 88 | * Prefetch quirks: |
Harvey Harrison | 1dc85be | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 89 | * |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 90 | * 32-bit mode: |
Harvey Harrison | 1dc85be | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 91 | * |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 92 | * Sometimes AMD Athlon/Opteron CPUs report invalid exceptions on prefetch. |
| 93 | * Check that here and ignore it. |
| 94 | * |
| 95 | * 64-bit mode: |
| 96 | * |
| 97 | * Sometimes the CPU reports invalid exceptions on prefetch. |
| 98 | * Check that here and ignore it. |
| 99 | * |
| 100 | * Opcode checker based on code by Richard Brunner. |
Harvey Harrison | 1dc85be | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 101 | */ |
Ingo Molnar | 107a036 | 2009-02-20 20:37:05 +0100 | [diff] [blame] | 102 | static inline int |
| 103 | check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr, |
| 104 | unsigned char opcode, int *prefetch) |
| 105 | { |
| 106 | unsigned char instr_hi = opcode & 0xf0; |
| 107 | unsigned char instr_lo = opcode & 0x0f; |
| 108 | |
| 109 | switch (instr_hi) { |
| 110 | case 0x20: |
| 111 | case 0x30: |
| 112 | /* |
| 113 | * Values 0x26,0x2E,0x36,0x3E are valid x86 prefixes. |
| 114 | * In X86_64 long mode, the CPU will signal invalid |
| 115 | * opcode if some of these prefixes are present so |
| 116 | * X86_64 will never get here anyway |
| 117 | */ |
| 118 | return ((instr_lo & 7) == 0x6); |
| 119 | #ifdef CONFIG_X86_64 |
| 120 | case 0x40: |
| 121 | /* |
| 122 | * In AMD64 long mode 0x40..0x4F are valid REX prefixes |
| 123 | * Need to figure out under what instruction mode the |
| 124 | * instruction was issued. Could check the LDT for lm, |
| 125 | * but for now it's good enough to assume that long |
| 126 | * mode only uses well known segments or kernel. |
| 127 | */ |
| 128 | return (!user_mode(regs)) || (regs->cs == __USER_CS); |
| 129 | #endif |
| 130 | case 0x60: |
| 131 | /* 0x64 thru 0x67 are valid prefixes in all modes. */ |
| 132 | return (instr_lo & 0xC) == 0x4; |
| 133 | case 0xF0: |
| 134 | /* 0xF0, 0xF2, 0xF3 are valid prefixes in all modes. */ |
| 135 | return !instr_lo || (instr_lo>>1) == 1; |
| 136 | case 0x00: |
| 137 | /* Prefetch instruction is 0x0F0D or 0x0F18 */ |
| 138 | if (probe_kernel_address(instr, opcode)) |
| 139 | return 0; |
| 140 | |
| 141 | *prefetch = (instr_lo == 0xF) && |
| 142 | (opcode == 0x0D || opcode == 0x18); |
| 143 | return 0; |
| 144 | default: |
| 145 | return 0; |
| 146 | } |
| 147 | } |
| 148 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 149 | static int |
| 150 | is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr) |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 151 | { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 152 | unsigned char *max_instr; |
Andi Kleen | ab2bf0c | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 153 | unsigned char *instr; |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 154 | int prefetch = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Ingo Molnar | 3085354 | 2008-03-27 21:29:09 +0100 | [diff] [blame] | 156 | /* |
| 157 | * If it was a exec (instruction fetch) fault on NX page, then |
| 158 | * do not ignore the fault: |
| 159 | */ |
Andi Kleen | 66c5815 | 2006-01-11 22:44:09 +0100 | [diff] [blame] | 160 | if (error_code & PF_INSTR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | return 0; |
Harvey Harrison | 1dc85be | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 162 | |
Ingo Molnar | 107a036 | 2009-02-20 20:37:05 +0100 | [diff] [blame] | 163 | instr = (void *)convert_ip_to_linear(current, regs); |
Andi Kleen | f1290ec | 2005-04-16 15:24:59 -0700 | [diff] [blame] | 164 | max_instr = instr + 15; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Vincent Hanquez | 76381fe | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 166 | if (user_mode(regs) && instr >= (unsigned char *)TASK_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return 0; |
| 168 | |
Ingo Molnar | 107a036 | 2009-02-20 20:37:05 +0100 | [diff] [blame] | 169 | while (instr < max_instr) { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 170 | unsigned char opcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Andi Kleen | ab2bf0c | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 172 | if (probe_kernel_address(instr, opcode)) |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 173 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | instr++; |
| 176 | |
Ingo Molnar | 107a036 | 2009-02-20 20:37:05 +0100 | [diff] [blame] | 177 | if (!check_prefetch_opcode(regs, instr, opcode, &prefetch)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | return prefetch; |
| 181 | } |
| 182 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 183 | static void |
| 184 | force_sig_info_fault(int si_signo, int si_code, unsigned long address, |
| 185 | struct task_struct *tsk) |
Harvey Harrison | c4aba4a | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 186 | { |
| 187 | siginfo_t info; |
| 188 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 189 | info.si_signo = si_signo; |
| 190 | info.si_errno = 0; |
| 191 | info.si_code = si_code; |
| 192 | info.si_addr = (void __user *)address; |
| 193 | |
Harvey Harrison | c4aba4a | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 194 | force_sig_info(si_signo, &info, tsk); |
| 195 | } |
| 196 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 197 | #ifdef CONFIG_X86_64 |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 198 | static int bad_address(void *p) |
| 199 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | unsigned long dummy; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 201 | |
Andi Kleen | ab2bf0c | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 202 | return probe_kernel_address((unsigned long *)p, dummy); |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 203 | } |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 204 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Adrian Bunk | cae30f8 | 2008-02-13 23:31:31 +0200 | [diff] [blame] | 206 | static void dump_pagetable(unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 208 | #ifdef CONFIG_X86_32 |
| 209 | __typeof__(pte_val(__pte(0))) page; |
| 210 | |
| 211 | page = read_cr3(); |
| 212 | page = ((__typeof__(page) *) __va(page))[address >> PGDIR_SHIFT]; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 213 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 214 | #ifdef CONFIG_X86_PAE |
| 215 | printk("*pdpt = %016Lx ", page); |
| 216 | if ((page >> PAGE_SHIFT) < max_low_pfn |
| 217 | && page & _PAGE_PRESENT) { |
| 218 | page &= PAGE_MASK; |
| 219 | page = ((__typeof__(page) *) __va(page))[(address >> PMD_SHIFT) |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 220 | & (PTRS_PER_PMD - 1)]; |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 221 | printk(KERN_CONT "*pde = %016Lx ", page); |
| 222 | page &= ~_PAGE_NX; |
| 223 | } |
| 224 | #else |
| 225 | printk("*pde = %08lx ", page); |
| 226 | #endif |
| 227 | |
| 228 | /* |
| 229 | * We must not directly access the pte in the highpte |
| 230 | * case if the page table is located in highmem. |
| 231 | * And let's rather not kmap-atomic the pte, just in case |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 232 | * it's allocated already: |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 233 | */ |
| 234 | if ((page >> PAGE_SHIFT) < max_low_pfn |
| 235 | && (page & _PAGE_PRESENT) |
| 236 | && !(page & _PAGE_PSE)) { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 237 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 238 | page &= PAGE_MASK; |
| 239 | page = ((__typeof__(page) *) __va(page))[(address >> PAGE_SHIFT) |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 240 | & (PTRS_PER_PTE - 1)]; |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 241 | printk("*pte = %0*Lx ", sizeof(page)*2, (u64)page); |
| 242 | } |
| 243 | |
| 244 | printk("\n"); |
| 245 | #else /* CONFIG_X86_64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | pgd_t *pgd; |
| 247 | pud_t *pud; |
| 248 | pmd_t *pmd; |
| 249 | pte_t *pte; |
| 250 | |
Glauber de Oliveira Costa | f51c945 | 2007-07-22 11:12:29 +0200 | [diff] [blame] | 251 | pgd = (pgd_t *)read_cr3(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 253 | pgd = __va((unsigned long)pgd & PHYSICAL_PAGE_MASK); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | pgd += pgd_index(address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 256 | if (bad_address(pgd)) |
| 257 | goto bad; |
| 258 | |
Jan Beulich | d646bce | 2006-02-03 21:51:47 +0100 | [diff] [blame] | 259 | printk("PGD %lx ", pgd_val(*pgd)); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 260 | |
| 261 | if (!pgd_present(*pgd)) |
| 262 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Andi Kleen | d2ae5b5 | 2006-06-26 13:57:56 +0200 | [diff] [blame] | 264 | pud = pud_offset(pgd, address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 265 | if (bad_address(pud)) |
| 266 | goto bad; |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | printk("PUD %lx ", pud_val(*pud)); |
Andi Kleen | b536022 | 2008-02-04 16:48:09 +0100 | [diff] [blame] | 269 | if (!pud_present(*pud) || pud_large(*pud)) |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 270 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | pmd = pmd_offset(pud, address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 273 | if (bad_address(pmd)) |
| 274 | goto bad; |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | printk("PMD %lx ", pmd_val(*pmd)); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 277 | if (!pmd_present(*pmd) || pmd_large(*pmd)) |
| 278 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | pte = pte_offset_kernel(pmd, address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 281 | if (bad_address(pte)) |
| 282 | goto bad; |
| 283 | |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 284 | printk("PTE %lx", pte_val(*pte)); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 285 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | printk("\n"); |
| 287 | return; |
| 288 | bad: |
| 289 | printk("BAD\n"); |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 290 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 293 | #ifdef CONFIG_X86_32 |
| 294 | static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) |
| 295 | { |
| 296 | unsigned index = pgd_index(address); |
| 297 | pgd_t *pgd_k; |
| 298 | pud_t *pud, *pud_k; |
| 299 | pmd_t *pmd, *pmd_k; |
| 300 | |
| 301 | pgd += index; |
| 302 | pgd_k = init_mm.pgd + index; |
| 303 | |
| 304 | if (!pgd_present(*pgd_k)) |
| 305 | return NULL; |
| 306 | |
| 307 | /* |
| 308 | * set_pgd(pgd, *pgd_k); here would be useless on PAE |
| 309 | * and redundant with the set_pmd() on non-PAE. As would |
| 310 | * set_pud. |
| 311 | */ |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 312 | pud = pud_offset(pgd, address); |
| 313 | pud_k = pud_offset(pgd_k, address); |
| 314 | if (!pud_present(*pud_k)) |
| 315 | return NULL; |
| 316 | |
| 317 | pmd = pmd_offset(pud, address); |
| 318 | pmd_k = pmd_offset(pud_k, address); |
| 319 | if (!pmd_present(*pmd_k)) |
| 320 | return NULL; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 321 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 322 | if (!pmd_present(*pmd)) { |
| 323 | set_pmd(pmd, *pmd_k); |
| 324 | arch_flush_lazy_mmu_mode(); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 325 | } else { |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 326 | BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k)); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 329 | return pmd_k; |
| 330 | } |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 331 | |
Ingo Molnar | 8c938f9 | 2009-02-20 22:12:18 +0100 | [diff] [blame^] | 332 | /* |
| 333 | * Did it hit the DOS screen memory VA from vm86 mode? |
| 334 | */ |
| 335 | static inline void |
| 336 | check_v8086_mode(struct pt_regs *regs, unsigned long address, |
| 337 | struct task_struct *tsk) |
| 338 | { |
| 339 | unsigned long bit; |
| 340 | |
| 341 | if (!v8086_mode(regs)) |
| 342 | return; |
| 343 | |
| 344 | bit = (address - 0xA0000) >> PAGE_SHIFT; |
| 345 | if (bit < 32) |
| 346 | tsk->thread.screen_bitmap |= 1 << bit; |
| 347 | } |
| 348 | |
| 349 | #else /* CONFIG_X86_64: */ |
| 350 | |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 351 | static const char errata93_warning[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | KERN_ERR "******* Your BIOS seems to not contain a fix for K8 errata #93\n" |
| 353 | KERN_ERR "******* Working around it, but it may cause SEGVs or burn power.\n" |
| 354 | KERN_ERR "******* Please consider a BIOS update.\n" |
| 355 | KERN_ERR "******* Disabling USB legacy in the BIOS may also help.\n"; |
Ingo Molnar | 8c938f9 | 2009-02-20 22:12:18 +0100 | [diff] [blame^] | 356 | |
| 357 | /* |
| 358 | * No vm86 mode in 64-bit mode: |
| 359 | */ |
| 360 | static inline void |
| 361 | check_v8086_mode(struct pt_regs *regs, unsigned long address, |
| 362 | struct task_struct *tsk) |
| 363 | { |
| 364 | } |
| 365 | |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 366 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 368 | /* |
| 369 | * Workaround for K8 erratum #93 & buggy BIOS. |
| 370 | * |
| 371 | * BIOS SMM functions are required to use a specific workaround |
| 372 | * to avoid corruption of the 64bit RIP register on C stepping K8. |
| 373 | * |
| 374 | * A lot of BIOS that didn't get tested properly miss this. |
| 375 | * |
| 376 | * The OS sees this as a page fault with the upper 32bits of RIP cleared. |
| 377 | * Try to work around it here. |
| 378 | * |
| 379 | * Note we only handle faults in kernel here. |
| 380 | * Does nothing on 32-bit. |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 381 | */ |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 382 | static int is_errata93(struct pt_regs *regs, unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 384 | #ifdef CONFIG_X86_64 |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 385 | static int once; |
| 386 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 387 | if (address != regs->ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | return 0; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 389 | |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 390 | if ((address >> 32) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | return 0; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | address |= 0xffffffffUL << 32; |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 394 | if ((address >= (u64)_stext && address <= (u64)_etext) || |
| 395 | (address >= MODULES_VADDR && address <= MODULES_END)) { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 396 | if (!once) { |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 397 | printk(errata93_warning); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 398 | once = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 400 | regs->ip = address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | return 1; |
| 402 | } |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 403 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | return 0; |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 405 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Harvey Harrison | 35f3266 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 407 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 408 | * Work around K8 erratum #100 K8 in compat mode occasionally jumps |
| 409 | * to illegal addresses >4GB. |
| 410 | * |
| 411 | * We catch this in the page fault handler because these addresses |
| 412 | * are not reachable. Just detect this case and return. Any code |
Harvey Harrison | 35f3266 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 413 | * segment in LDT is compatibility mode. |
| 414 | */ |
| 415 | static int is_errata100(struct pt_regs *regs, unsigned long address) |
| 416 | { |
| 417 | #ifdef CONFIG_X86_64 |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 418 | if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32)) |
Harvey Harrison | 35f3266 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 419 | return 1; |
| 420 | #endif |
| 421 | return 0; |
| 422 | } |
| 423 | |
Harvey Harrison | 29caf2f | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 424 | static int is_f00f_bug(struct pt_regs *regs, unsigned long address) |
| 425 | { |
| 426 | #ifdef CONFIG_X86_F00F_BUG |
| 427 | unsigned long nr; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 428 | |
Harvey Harrison | 29caf2f | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 429 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 430 | * Pentium F0 0F C7 C8 bug workaround: |
Harvey Harrison | 29caf2f | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 431 | */ |
| 432 | if (boot_cpu_data.f00f_bug) { |
| 433 | nr = (address - idt_descr.address) >> 3; |
| 434 | |
| 435 | if (nr == 6) { |
| 436 | do_invalid_op(regs, 0); |
| 437 | return 1; |
| 438 | } |
| 439 | } |
| 440 | #endif |
| 441 | return 0; |
| 442 | } |
| 443 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 444 | static void |
| 445 | show_fault_oops(struct pt_regs *regs, unsigned long error_code, |
| 446 | unsigned long address) |
Harvey Harrison | b3279c7 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 447 | { |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 448 | #ifdef CONFIG_X86_32 |
| 449 | if (!oops_may_print()) |
| 450 | return; |
Harvey Harrison | fd40d6e | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 451 | #endif |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 452 | |
| 453 | #ifdef CONFIG_X86_PAE |
| 454 | if (error_code & PF_INSTR) { |
Harvey Harrison | 93809be | 2008-02-01 17:49:43 +0100 | [diff] [blame] | 455 | unsigned int level; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 456 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 457 | pte_t *pte = lookup_address(address, &level); |
| 458 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 459 | if (pte && pte_present(*pte) && !pte_exec(*pte)) { |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 460 | printk(KERN_CRIT "kernel tried to execute " |
| 461 | "NX-protected page - exploit attempt? " |
David Howells | 350b4da | 2008-11-14 10:38:40 +1100 | [diff] [blame] | 462 | "(uid: %d)\n", current_uid()); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 463 | } |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 464 | } |
| 465 | #endif |
Harvey Harrison | fd40d6e | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 466 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 467 | printk(KERN_ALERT "BUG: unable to handle kernel "); |
| 468 | if (address < PAGE_SIZE) |
| 469 | printk(KERN_CONT "NULL pointer dereference"); |
| 470 | else |
| 471 | printk(KERN_CONT "paging request"); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 472 | |
Vegard Nossum | f294a8c | 2008-07-01 15:38:13 +0200 | [diff] [blame] | 473 | printk(KERN_CONT " at %p\n", (void *) address); |
Harvey Harrison | 19f0dda | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 474 | printk(KERN_ALERT "IP:"); |
Harvey Harrison | b3279c7 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 475 | printk_address(regs->ip, 1); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 476 | |
Harvey Harrison | b3279c7 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 477 | dump_pagetable(address); |
| 478 | } |
| 479 | |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 480 | #ifdef CONFIG_X86_64 |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 481 | static noinline void |
| 482 | pgtable_bad(struct pt_regs *regs, unsigned long error_code, |
| 483 | unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 485 | struct task_struct *tsk; |
| 486 | unsigned long flags; |
| 487 | int sig; |
| 488 | |
| 489 | flags = oops_begin(); |
| 490 | tsk = current; |
| 491 | sig = SIGKILL; |
Jan Beulich | 1209140 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | printk(KERN_ALERT "%s: Corrupted page table at address %lx\n", |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 494 | tsk->comm, address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | dump_pagetable(address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 496 | |
| 497 | tsk->thread.cr2 = address; |
| 498 | tsk->thread.trap_no = 14; |
| 499 | tsk->thread.error_code = error_code; |
| 500 | |
Jan Beulich | 22f5991 | 2008-01-30 13:31:23 +0100 | [diff] [blame] | 501 | if (__die("Bad pagetable", regs, error_code)) |
Alexander van Heukelum | 874d93d | 2008-10-22 12:00:09 +0200 | [diff] [blame] | 502 | sig = 0; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 503 | |
Alexander van Heukelum | 874d93d | 2008-10-22 12:00:09 +0200 | [diff] [blame] | 504 | oops_end(flags, regs, sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 506 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 508 | static noinline void |
| 509 | no_context(struct pt_regs *regs, unsigned long error_code, |
| 510 | unsigned long address) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 511 | { |
| 512 | struct task_struct *tsk = current; |
Ingo Molnar | 1980307 | 2009-01-21 10:39:51 +0100 | [diff] [blame] | 513 | unsigned long *stackend; |
| 514 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 515 | #ifdef CONFIG_X86_64 |
| 516 | unsigned long flags; |
| 517 | int sig; |
| 518 | #endif |
| 519 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 520 | /* Are we prepared to handle this kernel fault? */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 521 | if (fixup_exception(regs)) |
| 522 | return; |
| 523 | |
| 524 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 525 | * 32-bit: |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 526 | * |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 527 | * Valid to do another page fault here, because if this fault |
| 528 | * had been triggered by is_prefetch fixup_exception would have |
| 529 | * handled it. |
| 530 | * |
| 531 | * 64-bit: |
| 532 | * |
| 533 | * Hall of shame of CPU/BIOS bugs. |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 534 | */ |
| 535 | if (is_prefetch(regs, error_code, address)) |
| 536 | return; |
| 537 | |
| 538 | if (is_errata93(regs, address)) |
| 539 | return; |
| 540 | |
| 541 | /* |
| 542 | * Oops. The kernel tried to access some bad page. We'll have to |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 543 | * terminate things with extreme prejudice: |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 544 | */ |
| 545 | #ifdef CONFIG_X86_32 |
| 546 | bust_spinlocks(1); |
| 547 | #else |
| 548 | flags = oops_begin(); |
| 549 | #endif |
| 550 | |
| 551 | show_fault_oops(regs, error_code, address); |
| 552 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 553 | stackend = end_of_stack(tsk); |
Ingo Molnar | 1980307 | 2009-01-21 10:39:51 +0100 | [diff] [blame] | 554 | if (*stackend != STACK_END_MAGIC) |
| 555 | printk(KERN_ALERT "Thread overran stack, or stack corrupted\n"); |
| 556 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 557 | tsk->thread.cr2 = address; |
| 558 | tsk->thread.trap_no = 14; |
| 559 | tsk->thread.error_code = error_code; |
| 560 | |
| 561 | #ifdef CONFIG_X86_32 |
| 562 | die("Oops", regs, error_code); |
| 563 | bust_spinlocks(0); |
| 564 | do_exit(SIGKILL); |
| 565 | #else |
| 566 | sig = SIGKILL; |
| 567 | if (__die("Oops", regs, error_code)) |
| 568 | sig = 0; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 569 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 570 | /* Executive summary in case the body of the oops scrolled away */ |
| 571 | printk(KERN_EMERG "CR2: %016lx\n", address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 572 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 573 | oops_end(flags, regs, sig); |
| 574 | #endif |
| 575 | } |
| 576 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 577 | /* |
| 578 | * Print out info about fatal segfaults, if the show_unhandled_signals |
| 579 | * sysctl is set: |
| 580 | */ |
| 581 | static inline void |
| 582 | show_signal_msg(struct pt_regs *regs, unsigned long error_code, |
| 583 | unsigned long address, struct task_struct *tsk) |
| 584 | { |
| 585 | if (!unhandled_signal(tsk, SIGSEGV)) |
| 586 | return; |
| 587 | |
| 588 | if (!printk_ratelimit()) |
| 589 | return; |
| 590 | |
| 591 | printk(KERN_CONT "%s%s[%d]: segfault at %lx ip %p sp %p error %lx", |
| 592 | task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG, |
| 593 | tsk->comm, task_pid_nr(tsk), address, |
| 594 | (void *)regs->ip, (void *)regs->sp, error_code); |
| 595 | |
| 596 | print_vma_addr(KERN_CONT " in ", regs->ip); |
| 597 | |
| 598 | printk(KERN_CONT "\n"); |
| 599 | } |
| 600 | |
| 601 | static void |
| 602 | __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, |
| 603 | unsigned long address, int si_code) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 604 | { |
| 605 | struct task_struct *tsk = current; |
| 606 | |
| 607 | /* User mode accesses just cause a SIGSEGV */ |
| 608 | if (error_code & PF_USER) { |
| 609 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 610 | * It's possible to have interrupts off here: |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 611 | */ |
| 612 | local_irq_enable(); |
| 613 | |
| 614 | /* |
| 615 | * Valid to do another page fault here because this one came |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 616 | * from user space: |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 617 | */ |
| 618 | if (is_prefetch(regs, error_code, address)) |
| 619 | return; |
| 620 | |
| 621 | if (is_errata100(regs, address)) |
| 622 | return; |
| 623 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 624 | if (unlikely(show_unhandled_signals)) |
| 625 | show_signal_msg(regs, error_code, address, tsk); |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 626 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 627 | /* Kernel addresses are always protection faults: */ |
| 628 | tsk->thread.cr2 = address; |
| 629 | tsk->thread.error_code = error_code | (address >= TASK_SIZE); |
| 630 | tsk->thread.trap_no = 14; |
| 631 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 632 | force_sig_info_fault(SIGSEGV, si_code, address, tsk); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 633 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 634 | return; |
| 635 | } |
| 636 | |
| 637 | if (is_f00f_bug(regs, address)) |
| 638 | return; |
| 639 | |
| 640 | no_context(regs, error_code, address); |
| 641 | } |
| 642 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 643 | static noinline void |
| 644 | bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, |
| 645 | unsigned long address) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 646 | { |
| 647 | __bad_area_nosemaphore(regs, error_code, address, SEGV_MAPERR); |
| 648 | } |
| 649 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 650 | static void |
| 651 | __bad_area(struct pt_regs *regs, unsigned long error_code, |
| 652 | unsigned long address, int si_code) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 653 | { |
| 654 | struct mm_struct *mm = current->mm; |
| 655 | |
| 656 | /* |
| 657 | * Something tried to access memory that isn't in our memory map.. |
| 658 | * Fix it, but check if it's kernel or user first.. |
| 659 | */ |
| 660 | up_read(&mm->mmap_sem); |
| 661 | |
| 662 | __bad_area_nosemaphore(regs, error_code, address, si_code); |
| 663 | } |
| 664 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 665 | static noinline void |
| 666 | bad_area(struct pt_regs *regs, unsigned long error_code, unsigned long address) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 667 | { |
| 668 | __bad_area(regs, error_code, address, SEGV_MAPERR); |
| 669 | } |
| 670 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 671 | static noinline void |
| 672 | bad_area_access_error(struct pt_regs *regs, unsigned long error_code, |
| 673 | unsigned long address) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 674 | { |
| 675 | __bad_area(regs, error_code, address, SEGV_ACCERR); |
| 676 | } |
| 677 | |
| 678 | /* TODO: fixup for "mm-invoke-oom-killer-from-page-fault.patch" */ |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 679 | static void |
| 680 | out_of_memory(struct pt_regs *regs, unsigned long error_code, |
| 681 | unsigned long address) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 682 | { |
| 683 | /* |
| 684 | * We ran out of memory, call the OOM killer, and return the userspace |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 685 | * (which will retry the fault, or kill us if we got oom-killed): |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 686 | */ |
| 687 | up_read(¤t->mm->mmap_sem); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 688 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 689 | pagefault_out_of_memory(); |
| 690 | } |
| 691 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 692 | static void |
| 693 | do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 694 | { |
| 695 | struct task_struct *tsk = current; |
| 696 | struct mm_struct *mm = tsk->mm; |
| 697 | |
| 698 | up_read(&mm->mmap_sem); |
| 699 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 700 | /* Kernel mode? Handle exceptions or die: */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 701 | if (!(error_code & PF_USER)) |
| 702 | no_context(regs, error_code, address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 703 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 704 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 705 | /* User space => ok to do another page fault: */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 706 | if (is_prefetch(regs, error_code, address)) |
| 707 | return; |
| 708 | #endif |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 709 | |
| 710 | tsk->thread.cr2 = address; |
| 711 | tsk->thread.error_code = error_code; |
| 712 | tsk->thread.trap_no = 14; |
| 713 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 714 | force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk); |
| 715 | } |
| 716 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 717 | static noinline void |
| 718 | mm_fault_error(struct pt_regs *regs, unsigned long error_code, |
| 719 | unsigned long address, unsigned int fault) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 720 | { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 721 | if (fault & VM_FAULT_OOM) { |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 722 | out_of_memory(regs, error_code, address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 723 | } else { |
| 724 | if (fault & VM_FAULT_SIGBUS) |
| 725 | do_sigbus(regs, error_code, address); |
| 726 | else |
| 727 | BUG(); |
| 728 | } |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 729 | } |
| 730 | |
Thomas Gleixner | d8b57bb | 2008-02-06 22:39:43 +0100 | [diff] [blame] | 731 | static int spurious_fault_check(unsigned long error_code, pte_t *pte) |
| 732 | { |
| 733 | if ((error_code & PF_WRITE) && !pte_write(*pte)) |
| 734 | return 0; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 735 | |
Thomas Gleixner | d8b57bb | 2008-02-06 22:39:43 +0100 | [diff] [blame] | 736 | if ((error_code & PF_INSTR) && !pte_exec(*pte)) |
| 737 | return 0; |
| 738 | |
| 739 | return 1; |
| 740 | } |
| 741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 743 | * Handle a spurious fault caused by a stale TLB entry. |
| 744 | * |
| 745 | * This allows us to lazily refresh the TLB when increasing the |
| 746 | * permissions of a kernel page (RO -> RW or NX -> X). Doing it |
| 747 | * eagerly is very expensive since that implies doing a full |
| 748 | * cross-processor TLB flush, even if no stale TLB entries exist |
| 749 | * on other processors. |
| 750 | * |
Jeremy Fitzhardinge | 5b727a3 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 751 | * There are no security implications to leaving a stale TLB when |
| 752 | * increasing the permissions on a page. |
| 753 | */ |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 754 | static noinline int |
| 755 | spurious_fault(unsigned long error_code, unsigned long address) |
Jeremy Fitzhardinge | 5b727a3 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 756 | { |
| 757 | pgd_t *pgd; |
| 758 | pud_t *pud; |
| 759 | pmd_t *pmd; |
| 760 | pte_t *pte; |
Steven Rostedt | 3c3e569 | 2009-02-19 11:46:36 -0500 | [diff] [blame] | 761 | int ret; |
Jeremy Fitzhardinge | 5b727a3 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 762 | |
| 763 | /* Reserved-bit violation or user access to kernel space? */ |
| 764 | if (error_code & (PF_USER | PF_RSVD)) |
| 765 | return 0; |
| 766 | |
| 767 | pgd = init_mm.pgd + pgd_index(address); |
| 768 | if (!pgd_present(*pgd)) |
| 769 | return 0; |
| 770 | |
| 771 | pud = pud_offset(pgd, address); |
| 772 | if (!pud_present(*pud)) |
| 773 | return 0; |
| 774 | |
Thomas Gleixner | d8b57bb | 2008-02-06 22:39:43 +0100 | [diff] [blame] | 775 | if (pud_large(*pud)) |
| 776 | return spurious_fault_check(error_code, (pte_t *) pud); |
| 777 | |
Jeremy Fitzhardinge | 5b727a3 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 778 | pmd = pmd_offset(pud, address); |
| 779 | if (!pmd_present(*pmd)) |
| 780 | return 0; |
| 781 | |
Thomas Gleixner | d8b57bb | 2008-02-06 22:39:43 +0100 | [diff] [blame] | 782 | if (pmd_large(*pmd)) |
| 783 | return spurious_fault_check(error_code, (pte_t *) pmd); |
| 784 | |
Jeremy Fitzhardinge | 5b727a3 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 785 | pte = pte_offset_kernel(pmd, address); |
| 786 | if (!pte_present(*pte)) |
| 787 | return 0; |
| 788 | |
Steven Rostedt | 3c3e569 | 2009-02-19 11:46:36 -0500 | [diff] [blame] | 789 | ret = spurious_fault_check(error_code, pte); |
| 790 | if (!ret) |
| 791 | return 0; |
| 792 | |
| 793 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 794 | * Make sure we have permissions in PMD. |
| 795 | * If not, then there's a bug in the page tables: |
Steven Rostedt | 3c3e569 | 2009-02-19 11:46:36 -0500 | [diff] [blame] | 796 | */ |
| 797 | ret = spurious_fault_check(error_code, (pte_t *) pmd); |
| 798 | WARN_ONCE(!ret, "PMD has incorrect permission bits\n"); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 799 | |
Steven Rostedt | 3c3e569 | 2009-02-19 11:46:36 -0500 | [diff] [blame] | 800 | return ret; |
Jeremy Fitzhardinge | 5b727a3 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 804 | * 32-bit: |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 805 | * |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 806 | * Handle a fault on the vmalloc or module mapping area |
| 807 | * |
| 808 | * 64-bit: |
| 809 | * |
| 810 | * Handle a fault on the vmalloc area |
Andi Kleen | 3b9ba4d | 2005-05-16 21:53:31 -0700 | [diff] [blame] | 811 | * |
| 812 | * This assumes no large pages in there. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 814 | static noinline int vmalloc_fault(unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 816 | #ifdef CONFIG_X86_32 |
| 817 | unsigned long pgd_paddr; |
| 818 | pmd_t *pmd_k; |
| 819 | pte_t *pte_k; |
Henry Nestler | b29c701 | 2008-05-12 15:44:39 +0200 | [diff] [blame] | 820 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 821 | /* Make sure we are in vmalloc area: */ |
Henry Nestler | b29c701 | 2008-05-12 15:44:39 +0200 | [diff] [blame] | 822 | if (!(address >= VMALLOC_START && address < VMALLOC_END)) |
| 823 | return -1; |
| 824 | |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 825 | /* |
| 826 | * Synchronize this task's top level page-table |
| 827 | * with the 'reference' page table. |
| 828 | * |
| 829 | * Do _not_ use "current" here. We might be inside |
| 830 | * an interrupt in the middle of a task switch.. |
| 831 | */ |
| 832 | pgd_paddr = read_cr3(); |
| 833 | pmd_k = vmalloc_sync_one(__va(pgd_paddr), address); |
| 834 | if (!pmd_k) |
| 835 | return -1; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 836 | |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 837 | pte_k = pte_offset_kernel(pmd_k, address); |
| 838 | if (!pte_present(*pte_k)) |
| 839 | return -1; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 840 | |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 841 | return 0; |
| 842 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | pgd_t *pgd, *pgd_ref; |
| 844 | pud_t *pud, *pud_ref; |
| 845 | pmd_t *pmd, *pmd_ref; |
| 846 | pte_t *pte, *pte_ref; |
| 847 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 848 | /* Make sure we are in vmalloc area: */ |
Harvey Harrison | cf89ec9 | 2008-02-04 16:47:56 +0100 | [diff] [blame] | 849 | if (!(address >= VMALLOC_START && address < VMALLOC_END)) |
| 850 | return -1; |
| 851 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 852 | /* |
| 853 | * Copy kernel mappings over when needed. This can also |
| 854 | * happen within a race in page table update. In the later |
| 855 | * case just flush: |
| 856 | */ |
Andi Kleen | f313e12 | 2009-01-09 12:17:43 -0800 | [diff] [blame] | 857 | pgd = pgd_offset(current->active_mm, address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | pgd_ref = pgd_offset_k(address); |
| 859 | if (pgd_none(*pgd_ref)) |
| 860 | return -1; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | if (pgd_none(*pgd)) |
| 863 | set_pgd(pgd, *pgd_ref); |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 864 | else |
Dave McCracken | 46a82b2 | 2006-09-25 23:31:48 -0700 | [diff] [blame] | 865 | BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 867 | /* |
| 868 | * Below here mismatches are bugs because these lower tables |
| 869 | * are shared: |
| 870 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
| 872 | pud = pud_offset(pgd, address); |
| 873 | pud_ref = pud_offset(pgd_ref, address); |
| 874 | if (pud_none(*pud_ref)) |
| 875 | return -1; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 876 | |
Dave McCracken | 46a82b2 | 2006-09-25 23:31:48 -0700 | [diff] [blame] | 877 | if (pud_none(*pud) || pud_page_vaddr(*pud) != pud_page_vaddr(*pud_ref)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | BUG(); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | pmd = pmd_offset(pud, address); |
| 881 | pmd_ref = pmd_offset(pud_ref, address); |
| 882 | if (pmd_none(*pmd_ref)) |
| 883 | return -1; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | if (pmd_none(*pmd) || pmd_page(*pmd) != pmd_page(*pmd_ref)) |
| 886 | BUG(); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | pte_ref = pte_offset_kernel(pmd_ref, address); |
| 889 | if (!pte_present(*pte_ref)) |
| 890 | return -1; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | pte = pte_offset_kernel(pmd, address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 893 | |
| 894 | /* |
| 895 | * Don't use pte_page here, because the mappings can point |
| 896 | * outside mem_map, and the NUMA hash lookup cannot handle |
| 897 | * that: |
| 898 | */ |
Andi Kleen | 3b9ba4d | 2005-05-16 21:53:31 -0700 | [diff] [blame] | 899 | if (!pte_present(*pte) || pte_pfn(*pte) != pte_pfn(*pte_ref)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | BUG(); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | return 0; |
Harvey Harrison | fdfe8aa | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 903 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 906 | int show_unhandled_signals = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 908 | static inline int |
| 909 | access_error(unsigned long error_code, int write, struct vm_area_struct *vma) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 910 | { |
| 911 | if (write) { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 912 | /* write, present and write, not present: */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 913 | if (unlikely(!(vma->vm_flags & VM_WRITE))) |
| 914 | return 1; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 915 | return 0; |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 916 | } |
| 917 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 918 | /* read, present: */ |
| 919 | if (unlikely(error_code & PF_PROT)) |
| 920 | return 1; |
| 921 | |
| 922 | /* read, not present: */ |
| 923 | if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))) |
| 924 | return 1; |
| 925 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 926 | return 0; |
| 927 | } |
| 928 | |
Hiroshi Shimamoto | 0973a06 | 2009-02-04 15:24:09 -0800 | [diff] [blame] | 929 | static int fault_in_kernel_space(unsigned long address) |
| 930 | { |
| 931 | #ifdef CONFIG_X86_32 |
| 932 | return address >= TASK_SIZE; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 933 | #else |
Hiroshi Shimamoto | 0973a06 | 2009-02-04 15:24:09 -0800 | [diff] [blame] | 934 | return address >= TASK_SIZE64; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 935 | #endif |
Hiroshi Shimamoto | 0973a06 | 2009-02-04 15:24:09 -0800 | [diff] [blame] | 936 | } |
| 937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | /* |
| 939 | * This routine handles page faults. It determines the address, |
| 940 | * and the problem, and then passes it off to one of the appropriate |
| 941 | * routines. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | */ |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 943 | #ifdef CONFIG_X86_64 |
| 944 | asmlinkage |
| 945 | #endif |
| 946 | void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | { |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 948 | struct vm_area_struct *vma; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 949 | struct task_struct *tsk; |
| 950 | unsigned long address; |
| 951 | struct mm_struct *mm; |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 952 | int write; |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 953 | int fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Arjan van de Ven | a9ba9a3 | 2006-03-25 16:30:10 +0100 | [diff] [blame] | 955 | tsk = current; |
| 956 | mm = tsk->mm; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 957 | |
Arjan van de Ven | a9ba9a3 | 2006-03-25 16:30:10 +0100 | [diff] [blame] | 958 | prefetchw(&mm->mmap_sem); |
| 959 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 960 | /* Get the faulting address: */ |
Glauber de Oliveira Costa | f51c945 | 2007-07-22 11:12:29 +0200 | [diff] [blame] | 961 | address = read_cr2(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 963 | if (unlikely(kmmio_fault(regs, address))) |
Pekka Paalanen | 8606978 | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 964 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
| 966 | /* |
| 967 | * We fault-in kernel-space virtual memory on-demand. The |
| 968 | * 'reference' page table is init_mm.pgd. |
| 969 | * |
| 970 | * NOTE! We MUST NOT take any locks for this case. We may |
| 971 | * be in an interrupt or a critical region, and should |
| 972 | * only copy the information from the master page table, |
| 973 | * nothing more. |
| 974 | * |
| 975 | * This verifies that the fault happens in kernel space |
| 976 | * (error_code & 4) == 0, and that the fault was not a |
Jan Beulich | 8b1bde9 | 2006-01-11 22:42:23 +0100 | [diff] [blame] | 977 | * protection error (error_code & 9) == 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | */ |
Hiroshi Shimamoto | 0973a06 | 2009-02-04 15:24:09 -0800 | [diff] [blame] | 979 | if (unlikely(fault_in_kernel_space(address))) { |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 980 | if (!(error_code & (PF_RSVD|PF_USER|PF_PROT)) && |
| 981 | vmalloc_fault(address) >= 0) |
| 982 | return; |
Jeremy Fitzhardinge | 5b727a3 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 983 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 984 | /* Can handle a stale RO->RW TLB: */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 985 | if (spurious_fault(error_code, address)) |
Jeremy Fitzhardinge | 5b727a3 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 986 | return; |
| 987 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 988 | /* kprobes don't want to hook the spurious faults: */ |
Masami Hiramatsu | 9be260a | 2009-02-05 17:12:39 -0500 | [diff] [blame] | 989 | if (notify_page_fault(regs)) |
| 990 | return; |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 991 | /* |
| 992 | * Don't take the mm semaphore here. If we fixup a prefetch |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 993 | * fault we could otherwise deadlock: |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 994 | */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 995 | bad_area_nosemaphore(regs, error_code, address); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 996 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 997 | return; |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 998 | } |
| 999 | |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1000 | /* kprobes don't want to hook the spurious faults: */ |
Ingo Molnar | f8a6b2b | 2009-02-13 09:44:22 +0100 | [diff] [blame] | 1001 | if (unlikely(notify_page_fault(regs))) |
Masami Hiramatsu | 9be260a | 2009-02-05 17:12:39 -0500 | [diff] [blame] | 1002 | return; |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1003 | /* |
Linus Torvalds | 891cffb | 2008-10-12 13:16:12 -0700 | [diff] [blame] | 1004 | * It's safe to allow irq's after cr2 has been saved and the |
| 1005 | * vmalloc fault has been handled. |
| 1006 | * |
| 1007 | * User-mode registers count as a user access even for any |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1008 | * potential system fault or CPU buglet: |
Harvey Harrison | f8c2ee2 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1009 | */ |
Linus Torvalds | 891cffb | 2008-10-12 13:16:12 -0700 | [diff] [blame] | 1010 | if (user_mode_vm(regs)) { |
| 1011 | local_irq_enable(); |
| 1012 | error_code |= PF_USER; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1013 | } else { |
| 1014 | if (regs->flags & X86_EFLAGS_IF) |
| 1015 | local_irq_enable(); |
| 1016 | } |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 1017 | |
Linus Torvalds | 891cffb | 2008-10-12 13:16:12 -0700 | [diff] [blame] | 1018 | #ifdef CONFIG_X86_64 |
Andi Kleen | 66c5815 | 2006-01-11 22:44:09 +0100 | [diff] [blame] | 1019 | if (unlikely(error_code & PF_RSVD)) |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1020 | pgtable_bad(regs, error_code, address); |
Linus Torvalds | 891cffb | 2008-10-12 13:16:12 -0700 | [diff] [blame] | 1021 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | |
| 1023 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1024 | * If we're in an interrupt, have no user context or are running |
| 1025 | * in an atomic region then we must not take the fault: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1027 | if (unlikely(in_atomic() || !mm)) { |
| 1028 | bad_area_nosemaphore(regs, error_code, address); |
| 1029 | return; |
| 1030 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Ingo Molnar | 3a1dfe6 | 2008-10-13 17:49:02 +0200 | [diff] [blame] | 1032 | /* |
| 1033 | * When running in the kernel we expect faults to occur only to |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1034 | * addresses in user space. All other faults represent errors in |
| 1035 | * the kernel and should generate an OOPS. Unfortunately, in the |
| 1036 | * case of an erroneous fault occurring in a code path which already |
| 1037 | * holds mmap_sem we will deadlock attempting to validate the fault |
| 1038 | * against the address space. Luckily the kernel only validly |
| 1039 | * references user space from well defined areas of code, which are |
| 1040 | * listed in the exceptions table. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | * |
| 1042 | * As the vast majority of faults will be valid we will only perform |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1043 | * the source reference check when there is a possibility of a |
| 1044 | * deadlock. Attempt to lock the address space, if we cannot we then |
| 1045 | * validate the source. If this is invalid we can skip the address |
| 1046 | * space check, thus avoiding the deadlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1048 | if (unlikely(!down_read_trylock(&mm->mmap_sem))) { |
Andi Kleen | 66c5815 | 2006-01-11 22:44:09 +0100 | [diff] [blame] | 1049 | if ((error_code & PF_USER) == 0 && |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1050 | !search_exception_tables(regs->ip)) { |
| 1051 | bad_area_nosemaphore(regs, error_code, address); |
| 1052 | return; |
| 1053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | down_read(&mm->mmap_sem); |
Peter Zijlstra | 0100607 | 2009-01-29 16:02:12 +0100 | [diff] [blame] | 1055 | } else { |
| 1056 | /* |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1057 | * The above down_read_trylock() might have succeeded in |
| 1058 | * which case we'll have missed the might_sleep() from |
| 1059 | * down_read(): |
Peter Zijlstra | 0100607 | 2009-01-29 16:02:12 +0100 | [diff] [blame] | 1060 | */ |
| 1061 | might_sleep(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | vma = find_vma(mm, address); |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1065 | if (unlikely(!vma)) { |
| 1066 | bad_area(regs, error_code, address); |
| 1067 | return; |
| 1068 | } |
| 1069 | if (likely(vma->vm_start <= address)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | goto good_area; |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1071 | if (unlikely(!(vma->vm_flags & VM_GROWSDOWN))) { |
| 1072 | bad_area(regs, error_code, address); |
| 1073 | return; |
| 1074 | } |
Harvey Harrison | 33cb524 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 1075 | if (error_code & PF_USER) { |
Harvey Harrison | 6f4d368 | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 1076 | /* |
| 1077 | * Accessing the stack below %sp is always a bug. |
| 1078 | * The large cushion allows instructions like enter |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1079 | * and pusha to work. ("enter $65535, $31" pushes |
Harvey Harrison | 6f4d368 | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 1080 | * 32 pointers and then decrements %sp by 65535.) |
Chuck Ebbert | 03fdc2c | 2006-06-26 13:59:50 +0200 | [diff] [blame] | 1081 | */ |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1082 | if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) { |
| 1083 | bad_area(regs, error_code, address); |
| 1084 | return; |
| 1085 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | } |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1087 | if (unlikely(expand_stack(vma, address))) { |
| 1088 | bad_area(regs, error_code, address); |
| 1089 | return; |
| 1090 | } |
| 1091 | |
| 1092 | /* |
| 1093 | * Ok, we have a good vm_area for this memory access, so |
| 1094 | * we can handle it.. |
| 1095 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | good_area: |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1097 | write = error_code & PF_WRITE; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1098 | |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1099 | if (unlikely(access_error(error_code, write, vma))) { |
| 1100 | bad_area_access_error(regs, error_code, address); |
| 1101 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /* |
| 1105 | * If for any reason at all we couldn't handle the fault, |
| 1106 | * make sure we exit gracefully rather than endlessly redo |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1107 | * the fault: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | */ |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 1109 | fault = handle_mm_fault(mm, vma, address, write); |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1110 | |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 1111 | if (unlikely(fault & VM_FAULT_ERROR)) { |
Nick Piggin | 92181f1 | 2009-01-20 04:24:26 +0100 | [diff] [blame] | 1112 | mm_fault_error(regs, error_code, address, fault); |
| 1113 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | } |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1115 | |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 1116 | if (fault & VM_FAULT_MAJOR) |
| 1117 | tsk->maj_flt++; |
| 1118 | else |
| 1119 | tsk->min_flt++; |
Harvey Harrison | d729ab3 | 2008-01-30 13:33:23 +0100 | [diff] [blame] | 1120 | |
Ingo Molnar | 8c938f9 | 2009-02-20 22:12:18 +0100 | [diff] [blame^] | 1121 | check_v8086_mode(regs, address, tsk); |
| 1122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | up_read(&mm->mmap_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | } |
Andi Kleen | 9e43e1b | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 1125 | |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 1126 | DEFINE_SPINLOCK(pgd_lock); |
Christoph Lameter | 2bff738 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 1127 | LIST_HEAD(pgd_list); |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 1128 | |
| 1129 | void vmalloc_sync_all(void) |
| 1130 | { |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1131 | unsigned long address; |
| 1132 | |
Jan Beulich | cc643d4 | 2008-08-29 12:53:45 +0100 | [diff] [blame] | 1133 | #ifdef CONFIG_X86_32 |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1134 | if (SHARED_KERNEL_PMD) |
| 1135 | return; |
| 1136 | |
Jan Beulich | cc643d4 | 2008-08-29 12:53:45 +0100 | [diff] [blame] | 1137 | for (address = VMALLOC_START & PMD_MASK; |
| 1138 | address >= TASK_SIZE && address < FIXADDR_TOP; |
| 1139 | address += PMD_SIZE) { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1140 | |
Jeremy Fitzhardinge | 67350a5 | 2008-06-25 00:19:11 -0400 | [diff] [blame] | 1141 | unsigned long flags; |
| 1142 | struct page *page; |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1143 | |
Jeremy Fitzhardinge | 67350a5 | 2008-06-25 00:19:11 -0400 | [diff] [blame] | 1144 | spin_lock_irqsave(&pgd_lock, flags); |
| 1145 | list_for_each_entry(page, &pgd_list, lru) { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1146 | if (!vmalloc_sync_one(page_address(page), address)) |
Jeremy Fitzhardinge | 67350a5 | 2008-06-25 00:19:11 -0400 | [diff] [blame] | 1147 | break; |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1148 | } |
Jeremy Fitzhardinge | 67350a5 | 2008-06-25 00:19:11 -0400 | [diff] [blame] | 1149 | spin_unlock_irqrestore(&pgd_lock, flags); |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1150 | } |
| 1151 | #else /* CONFIG_X86_64 */ |
Jan Beulich | cc643d4 | 2008-08-29 12:53:45 +0100 | [diff] [blame] | 1152 | for (address = VMALLOC_START & PGDIR_MASK; address <= VMALLOC_END; |
| 1153 | address += PGDIR_SIZE) { |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1154 | |
Jeremy Fitzhardinge | 67350a5 | 2008-06-25 00:19:11 -0400 | [diff] [blame] | 1155 | const pgd_t *pgd_ref = pgd_offset_k(address); |
| 1156 | unsigned long flags; |
| 1157 | struct page *page; |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 1158 | |
Jeremy Fitzhardinge | 67350a5 | 2008-06-25 00:19:11 -0400 | [diff] [blame] | 1159 | if (pgd_none(*pgd_ref)) |
| 1160 | continue; |
Ingo Molnar | 2d4a716 | 2009-02-20 19:56:40 +0100 | [diff] [blame] | 1161 | |
Jeremy Fitzhardinge | 67350a5 | 2008-06-25 00:19:11 -0400 | [diff] [blame] | 1162 | spin_lock_irqsave(&pgd_lock, flags); |
| 1163 | list_for_each_entry(page, &pgd_list, lru) { |
| 1164 | pgd_t *pgd; |
| 1165 | pgd = (pgd_t *)page_address(page) + pgd_index(address); |
| 1166 | if (pgd_none(*pgd)) |
| 1167 | set_pgd(pgd, *pgd_ref); |
| 1168 | else |
| 1169 | BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref)); |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 1170 | } |
Jeremy Fitzhardinge | 67350a5 | 2008-06-25 00:19:11 -0400 | [diff] [blame] | 1171 | spin_unlock_irqrestore(&pgd_lock, flags); |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 1172 | } |
Harvey Harrison | 1156e09 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1173 | #endif |
Jan Beulich | 8c914cb | 2006-03-25 16:29:40 +0100 | [diff] [blame] | 1174 | } |