Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mm/fault.c |
| 3 | * |
| 4 | * Copyright (C) 1995 Linus Torvalds |
| 5 | * Modifications for ARM processor (c) 1995-2004 Russell King |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/mm.h> |
Russell King | 67306da | 2008-12-14 18:01:44 +0000 | [diff] [blame] | 14 | #include <linux/hardirq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
Nicolas Pitre | 25ce1dd | 2007-12-03 15:21:57 -0500 | [diff] [blame] | 16 | #include <linux/kprobes.h> |
Russell King | 33fa9b1 | 2008-09-06 11:35:55 +0100 | [diff] [blame] | 17 | #include <linux/uaccess.h> |
Nicolas Pitre | 252d4c2 | 2008-09-11 11:52:02 -0400 | [diff] [blame] | 18 | #include <linux/page-flags.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include <asm/system.h> |
| 21 | #include <asm/pgtable.h> |
| 22 | #include <asm/tlbflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include "fault.h" |
| 25 | |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame^] | 26 | #ifdef CONFIG_MMU |
Nicolas Pitre | 25ce1dd | 2007-12-03 15:21:57 -0500 | [diff] [blame] | 27 | |
| 28 | #ifdef CONFIG_KPROBES |
| 29 | static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr) |
| 30 | { |
| 31 | int ret = 0; |
| 32 | |
| 33 | if (!user_mode(regs)) { |
| 34 | /* kprobe_running() needs smp_processor_id() */ |
| 35 | preempt_disable(); |
| 36 | if (kprobe_running() && kprobe_fault_handler(regs, fsr)) |
| 37 | ret = 1; |
| 38 | preempt_enable(); |
| 39 | } |
| 40 | |
| 41 | return ret; |
| 42 | } |
| 43 | #else |
| 44 | static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
| 48 | #endif |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* |
| 51 | * This is useful to dump out the page tables associated with |
| 52 | * 'addr' in mm 'mm'. |
| 53 | */ |
| 54 | void show_pte(struct mm_struct *mm, unsigned long addr) |
| 55 | { |
| 56 | pgd_t *pgd; |
| 57 | |
| 58 | if (!mm) |
| 59 | mm = &init_mm; |
| 60 | |
| 61 | printk(KERN_ALERT "pgd = %p\n", mm->pgd); |
| 62 | pgd = pgd_offset(mm, addr); |
| 63 | printk(KERN_ALERT "[%08lx] *pgd=%08lx", addr, pgd_val(*pgd)); |
| 64 | |
| 65 | do { |
| 66 | pmd_t *pmd; |
| 67 | pte_t *pte; |
| 68 | |
| 69 | if (pgd_none(*pgd)) |
| 70 | break; |
| 71 | |
| 72 | if (pgd_bad(*pgd)) { |
| 73 | printk("(bad)"); |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | pmd = pmd_offset(pgd, addr); |
Nicolas Pitre | da46c79 | 2008-09-30 16:10:11 +0100 | [diff] [blame] | 78 | if (PTRS_PER_PMD != 1) |
| 79 | printk(", *pmd=%08lx", pmd_val(*pmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | if (pmd_none(*pmd)) |
| 82 | break; |
| 83 | |
| 84 | if (pmd_bad(*pmd)) { |
| 85 | printk("(bad)"); |
| 86 | break; |
| 87 | } |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* We must not map this if we have highmem enabled */ |
Nicolas Pitre | 252d4c2 | 2008-09-11 11:52:02 -0400 | [diff] [blame] | 90 | if (PageHighMem(pfn_to_page(pmd_val(*pmd) >> PAGE_SHIFT))) |
| 91 | break; |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | pte = pte_offset_map(pmd, addr); |
| 94 | printk(", *pte=%08lx", pte_val(*pte)); |
| 95 | printk(", *ppte=%08lx", pte_val(pte[-PTRS_PER_PTE])); |
| 96 | pte_unmap(pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } while(0); |
| 98 | |
| 99 | printk("\n"); |
| 100 | } |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame^] | 101 | #else /* CONFIG_MMU */ |
| 102 | void show_pte(struct mm_struct *mm, unsigned long addr) |
| 103 | { } |
| 104 | #endif /* CONFIG_MMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * Oops. The kernel tried to access some page that wasn't present. |
| 108 | */ |
| 109 | static void |
| 110 | __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, |
| 111 | struct pt_regs *regs) |
| 112 | { |
| 113 | /* |
| 114 | * Are we prepared to handle this kernel fault? |
| 115 | */ |
| 116 | if (fixup_exception(regs)) |
| 117 | return; |
| 118 | |
| 119 | /* |
| 120 | * No handler, we'll have to terminate things with extreme prejudice. |
| 121 | */ |
| 122 | bust_spinlocks(1); |
| 123 | printk(KERN_ALERT |
| 124 | "Unable to handle kernel %s at virtual address %08lx\n", |
| 125 | (addr < PAGE_SIZE) ? "NULL pointer dereference" : |
| 126 | "paging request", addr); |
| 127 | |
| 128 | show_pte(mm, addr); |
| 129 | die("Oops", regs, fsr); |
| 130 | bust_spinlocks(0); |
| 131 | do_exit(SIGKILL); |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Something tried to access memory that isn't in our memory map.. |
| 136 | * User mode accesses just cause a SIGSEGV |
| 137 | */ |
| 138 | static void |
| 139 | __do_user_fault(struct task_struct *tsk, unsigned long addr, |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 140 | unsigned int fsr, unsigned int sig, int code, |
| 141 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | struct siginfo si; |
| 144 | |
| 145 | #ifdef CONFIG_DEBUG_USER |
| 146 | if (user_debug & UDBG_SEGV) { |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 147 | printk(KERN_DEBUG "%s: unhandled page fault (%d) at 0x%08lx, code 0x%03x\n", |
| 148 | tsk->comm, sig, addr, fsr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | show_pte(tsk->mm, addr); |
| 150 | show_regs(regs); |
| 151 | } |
| 152 | #endif |
| 153 | |
| 154 | tsk->thread.address = addr; |
| 155 | tsk->thread.error_code = fsr; |
| 156 | tsk->thread.trap_no = 14; |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 157 | si.si_signo = sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | si.si_errno = 0; |
| 159 | si.si_code = code; |
| 160 | si.si_addr = (void __user *)addr; |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 161 | force_sig_info(sig, &si, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Russell King | e5beac3 | 2006-09-27 16:13:48 +0100 | [diff] [blame] | 164 | void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
Russell King | e5beac3 | 2006-09-27 16:13:48 +0100 | [diff] [blame] | 166 | struct task_struct *tsk = current; |
| 167 | struct mm_struct *mm = tsk->active_mm; |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /* |
| 170 | * If we are in kernel mode at this point, we |
| 171 | * have no context to handle this fault with. |
| 172 | */ |
| 173 | if (user_mode(regs)) |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 174 | __do_user_fault(tsk, addr, fsr, SIGSEGV, SEGV_MAPERR, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | else |
| 176 | __do_kernel_fault(mm, addr, fsr, regs); |
| 177 | } |
| 178 | |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame^] | 179 | #ifdef CONFIG_MMU |
Nick Piggin | 5c72fc5 | 2007-07-20 09:21:06 +0200 | [diff] [blame] | 180 | #define VM_FAULT_BADMAP 0x010000 |
| 181 | #define VM_FAULT_BADACCESS 0x020000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | static int |
| 184 | __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, |
| 185 | struct task_struct *tsk) |
| 186 | { |
| 187 | struct vm_area_struct *vma; |
| 188 | int fault, mask; |
| 189 | |
| 190 | vma = find_vma(mm, addr); |
| 191 | fault = VM_FAULT_BADMAP; |
| 192 | if (!vma) |
| 193 | goto out; |
| 194 | if (vma->vm_start > addr) |
| 195 | goto check_stack; |
| 196 | |
| 197 | /* |
| 198 | * Ok, we have a good vm_area for this |
| 199 | * memory access, so we can handle it. |
| 200 | */ |
| 201 | good_area: |
| 202 | if (fsr & (1 << 11)) /* write? */ |
| 203 | mask = VM_WRITE; |
| 204 | else |
Jason Baron | df67b3d | 2006-09-29 01:58:58 -0700 | [diff] [blame] | 205 | mask = VM_READ|VM_EXEC|VM_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | fault = VM_FAULT_BADACCESS; |
| 208 | if (!(vma->vm_flags & mask)) |
| 209 | goto out; |
| 210 | |
| 211 | /* |
| 212 | * If for any reason at all we couldn't handle |
| 213 | * the fault, make sure we exit gracefully rather |
| 214 | * than endlessly redo the fault. |
| 215 | */ |
| 216 | survive: |
Linus Torvalds | d06063c | 2009-04-10 09:01:23 -0700 | [diff] [blame] | 217 | fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, (fsr & (1 << 11)) ? FAULT_FLAG_WRITE : 0); |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 218 | if (unlikely(fault & VM_FAULT_ERROR)) { |
| 219 | if (fault & VM_FAULT_OOM) |
| 220 | goto out_of_memory; |
| 221 | else if (fault & VM_FAULT_SIGBUS) |
| 222 | return fault; |
| 223 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 225 | if (fault & VM_FAULT_MAJOR) |
| 226 | tsk->maj_flt++; |
| 227 | else |
| 228 | tsk->min_flt++; |
| 229 | return fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 231 | out_of_memory: |
Serge E. Hallyn | b460cbc | 2007-10-18 23:39:52 -0700 | [diff] [blame] | 232 | if (!is_global_init(tsk)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | goto out; |
| 234 | |
| 235 | /* |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 236 | * If we are out of memory for pid1, sleep for a while and retry |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | */ |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 238 | up_read(&mm->mmap_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | yield(); |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 240 | down_read(&mm->mmap_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | goto survive; |
| 242 | |
| 243 | check_stack: |
| 244 | if (vma->vm_flags & VM_GROWSDOWN && !expand_stack(vma, addr)) |
| 245 | goto good_area; |
| 246 | out: |
| 247 | return fault; |
| 248 | } |
| 249 | |
Nicolas Pitre | 785d3cd | 2007-12-03 15:27:56 -0500 | [diff] [blame] | 250 | static int __kprobes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 252 | { |
| 253 | struct task_struct *tsk; |
| 254 | struct mm_struct *mm; |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 255 | int fault, sig, code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Nicolas Pitre | 25ce1dd | 2007-12-03 15:21:57 -0500 | [diff] [blame] | 257 | if (notify_page_fault(regs, fsr)) |
| 258 | return 0; |
| 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | tsk = current; |
| 261 | mm = tsk->mm; |
| 262 | |
| 263 | /* |
| 264 | * If we're in an interrupt or have no user |
| 265 | * context, we must not take the fault.. |
| 266 | */ |
Peter Zijlstra | 6edaf68 | 2006-12-06 20:32:18 -0800 | [diff] [blame] | 267 | if (in_atomic() || !mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | goto no_context; |
| 269 | |
Russell King | 840ff6a | 2005-09-20 17:52:13 +0100 | [diff] [blame] | 270 | /* |
| 271 | * As per x86, we may deadlock here. However, since the kernel only |
| 272 | * validly references user space from well defined areas of the code, |
| 273 | * we can bug out early if this is from code which shouldn't. |
| 274 | */ |
| 275 | if (!down_read_trylock(&mm->mmap_sem)) { |
| 276 | if (!user_mode(regs) && !search_exception_tables(regs->ARM_pc)) |
| 277 | goto no_context; |
| 278 | down_read(&mm->mmap_sem); |
| 279 | } |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | fault = __do_page_fault(mm, addr, fsr, tsk); |
| 282 | up_read(&mm->mmap_sem); |
| 283 | |
| 284 | /* |
Russell King | ff2afb9 | 2005-08-04 14:17:33 +0100 | [diff] [blame] | 285 | * Handle the "normal" case first - VM_FAULT_MAJOR / VM_FAULT_MINOR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | */ |
Nick Piggin | 5c72fc5 | 2007-07-20 09:21:06 +0200 | [diff] [blame] | 287 | if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP | VM_FAULT_BADACCESS)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | return 0; |
| 289 | |
| 290 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | * If we are in kernel mode at this point, we |
| 292 | * have no context to handle this fault with. |
| 293 | */ |
| 294 | if (!user_mode(regs)) |
| 295 | goto no_context; |
| 296 | |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 297 | if (fault & VM_FAULT_OOM) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 299 | * We ran out of memory, or some other thing |
| 300 | * happened to us that made us unable to handle |
| 301 | * the page fault gracefully. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | */ |
| 303 | printk("VM: killing process %s\n", tsk->comm); |
Will Schmidt | dcca2bd | 2007-10-16 01:24:18 -0700 | [diff] [blame] | 304 | do_group_exit(SIGKILL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | return 0; |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 306 | } |
| 307 | if (fault & VM_FAULT_SIGBUS) { |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 308 | /* |
| 309 | * We had some memory, but were unable to |
| 310 | * successfully fix up this page fault. |
| 311 | */ |
| 312 | sig = SIGBUS; |
| 313 | code = BUS_ADRERR; |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 314 | } else { |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 315 | /* |
| 316 | * Something tried to access memory that |
| 317 | * isn't in our memory map.. |
| 318 | */ |
| 319 | sig = SIGSEGV; |
| 320 | code = fault == VM_FAULT_BADACCESS ? |
| 321 | SEGV_ACCERR : SEGV_MAPERR; |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | __do_user_fault(tsk, addr, fsr, sig, code, regs); |
| 325 | return 0; |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | no_context: |
| 328 | __do_kernel_fault(mm, addr, fsr, regs); |
| 329 | return 0; |
| 330 | } |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame^] | 331 | #else /* CONFIG_MMU */ |
| 332 | static int |
| 333 | do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 334 | { |
| 335 | return 0; |
| 336 | } |
| 337 | #endif /* CONFIG_MMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | /* |
| 340 | * First Level Translation Fault Handler |
| 341 | * |
| 342 | * We enter here because the first level page table doesn't contain |
| 343 | * a valid entry for the address. |
| 344 | * |
| 345 | * If the address is in kernel space (>= TASK_SIZE), then we are |
| 346 | * probably faulting in the vmalloc() area. |
| 347 | * |
| 348 | * If the init_task's first level page tables contains the relevant |
| 349 | * entry, we copy the it to this task. If not, we send the process |
| 350 | * a signal, fixup the exception, or oops the kernel. |
| 351 | * |
| 352 | * NOTE! We MUST NOT take any locks for this case. We may be in an |
| 353 | * interrupt or a critical region, and should only copy the information |
| 354 | * from the master page table, nothing more. |
| 355 | */ |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame^] | 356 | #ifdef CONFIG_MMU |
Nicolas Pitre | 785d3cd | 2007-12-03 15:27:56 -0500 | [diff] [blame] | 357 | static int __kprobes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | do_translation_fault(unsigned long addr, unsigned int fsr, |
| 359 | struct pt_regs *regs) |
| 360 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | unsigned int index; |
| 362 | pgd_t *pgd, *pgd_k; |
| 363 | pmd_t *pmd, *pmd_k; |
| 364 | |
| 365 | if (addr < TASK_SIZE) |
| 366 | return do_page_fault(addr, fsr, regs); |
| 367 | |
| 368 | index = pgd_index(addr); |
| 369 | |
| 370 | /* |
| 371 | * FIXME: CP15 C1 is write only on ARMv3 architectures. |
| 372 | */ |
| 373 | pgd = cpu_get_pgd() + index; |
| 374 | pgd_k = init_mm.pgd + index; |
| 375 | |
| 376 | if (pgd_none(*pgd_k)) |
| 377 | goto bad_area; |
| 378 | |
| 379 | if (!pgd_present(*pgd)) |
| 380 | set_pgd(pgd, *pgd_k); |
| 381 | |
| 382 | pmd_k = pmd_offset(pgd_k, addr); |
| 383 | pmd = pmd_offset(pgd, addr); |
| 384 | |
| 385 | if (pmd_none(*pmd_k)) |
| 386 | goto bad_area; |
| 387 | |
| 388 | copy_pmd(pmd, pmd_k); |
| 389 | return 0; |
| 390 | |
| 391 | bad_area: |
Russell King | e5beac3 | 2006-09-27 16:13:48 +0100 | [diff] [blame] | 392 | do_bad_area(addr, fsr, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return 0; |
| 394 | } |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame^] | 395 | #else /* CONFIG_MMU */ |
| 396 | static int |
| 397 | do_translation_fault(unsigned long addr, unsigned int fsr, |
| 398 | struct pt_regs *regs) |
| 399 | { |
| 400 | return 0; |
| 401 | } |
| 402 | #endif /* CONFIG_MMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | /* |
| 405 | * Some section permission faults need to be handled gracefully. |
| 406 | * They can happen due to a __{get,put}_user during an oops. |
| 407 | */ |
| 408 | static int |
| 409 | do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 410 | { |
Russell King | e5beac3 | 2006-09-27 16:13:48 +0100 | [diff] [blame] | 411 | do_bad_area(addr, fsr, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * This abort handler always returns "fault". |
| 417 | */ |
| 418 | static int |
| 419 | do_bad(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 420 | { |
| 421 | return 1; |
| 422 | } |
| 423 | |
| 424 | static struct fsr_info { |
| 425 | int (*fn)(unsigned long addr, unsigned int fsr, struct pt_regs *regs); |
| 426 | int sig; |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 427 | int code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | const char *name; |
| 429 | } fsr_info[] = { |
| 430 | /* |
| 431 | * The following are the standard ARMv3 and ARMv4 aborts. ARMv5 |
| 432 | * defines these to be "precise" aborts. |
| 433 | */ |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 434 | { do_bad, SIGSEGV, 0, "vector exception" }, |
| 435 | { do_bad, SIGILL, BUS_ADRALN, "alignment exception" }, |
| 436 | { do_bad, SIGKILL, 0, "terminal exception" }, |
| 437 | { do_bad, SIGILL, BUS_ADRALN, "alignment exception" }, |
| 438 | { do_bad, SIGBUS, 0, "external abort on linefetch" }, |
| 439 | { do_translation_fault, SIGSEGV, SEGV_MAPERR, "section translation fault" }, |
| 440 | { do_bad, SIGBUS, 0, "external abort on linefetch" }, |
| 441 | { do_page_fault, SIGSEGV, SEGV_MAPERR, "page translation fault" }, |
| 442 | { do_bad, SIGBUS, 0, "external abort on non-linefetch" }, |
| 443 | { do_bad, SIGSEGV, SEGV_ACCERR, "section domain fault" }, |
| 444 | { do_bad, SIGBUS, 0, "external abort on non-linefetch" }, |
| 445 | { do_bad, SIGSEGV, SEGV_ACCERR, "page domain fault" }, |
| 446 | { do_bad, SIGBUS, 0, "external abort on translation" }, |
| 447 | { do_sect_fault, SIGSEGV, SEGV_ACCERR, "section permission fault" }, |
| 448 | { do_bad, SIGBUS, 0, "external abort on translation" }, |
| 449 | { do_page_fault, SIGSEGV, SEGV_ACCERR, "page permission fault" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | /* |
| 451 | * The following are "imprecise" aborts, which are signalled by bit |
| 452 | * 10 of the FSR, and may not be recoverable. These are only |
| 453 | * supported if the CPU abort handler supports bit 10. |
| 454 | */ |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 455 | { do_bad, SIGBUS, 0, "unknown 16" }, |
| 456 | { do_bad, SIGBUS, 0, "unknown 17" }, |
| 457 | { do_bad, SIGBUS, 0, "unknown 18" }, |
| 458 | { do_bad, SIGBUS, 0, "unknown 19" }, |
| 459 | { do_bad, SIGBUS, 0, "lock abort" }, /* xscale */ |
| 460 | { do_bad, SIGBUS, 0, "unknown 21" }, |
| 461 | { do_bad, SIGBUS, BUS_OBJERR, "imprecise external abort" }, /* xscale */ |
| 462 | { do_bad, SIGBUS, 0, "unknown 23" }, |
| 463 | { do_bad, SIGBUS, 0, "dcache parity error" }, /* xscale */ |
| 464 | { do_bad, SIGBUS, 0, "unknown 25" }, |
| 465 | { do_bad, SIGBUS, 0, "unknown 26" }, |
| 466 | { do_bad, SIGBUS, 0, "unknown 27" }, |
| 467 | { do_bad, SIGBUS, 0, "unknown 28" }, |
| 468 | { do_bad, SIGBUS, 0, "unknown 29" }, |
| 469 | { do_bad, SIGBUS, 0, "unknown 30" }, |
| 470 | { do_bad, SIGBUS, 0, "unknown 31" } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | }; |
| 472 | |
| 473 | void __init |
| 474 | hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *), |
| 475 | int sig, const char *name) |
| 476 | { |
| 477 | if (nr >= 0 && nr < ARRAY_SIZE(fsr_info)) { |
| 478 | fsr_info[nr].fn = fn; |
| 479 | fsr_info[nr].sig = sig; |
| 480 | fsr_info[nr].name = name; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Dispatch a data abort to the relevant handler. |
| 486 | */ |
Russell King | 7ab3f8d | 2007-03-02 15:01:36 +0000 | [diff] [blame] | 487 | asmlinkage void __exception |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 489 | { |
| 490 | const struct fsr_info *inf = fsr_info + (fsr & 15) + ((fsr & (1 << 10)) >> 6); |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 491 | struct siginfo info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | if (!inf->fn(addr, fsr, regs)) |
| 494 | return; |
| 495 | |
| 496 | printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n", |
| 497 | inf->name, fsr, addr); |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 498 | |
| 499 | info.si_signo = inf->sig; |
| 500 | info.si_errno = 0; |
| 501 | info.si_code = inf->code; |
| 502 | info.si_addr = (void __user *)addr; |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 503 | arm_notify_die("", regs, &info, fsr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Russell King | 7ab3f8d | 2007-03-02 15:01:36 +0000 | [diff] [blame] | 506 | asmlinkage void __exception |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | do_PrefetchAbort(unsigned long addr, struct pt_regs *regs) |
| 508 | { |
| 509 | do_translation_fault(addr, 0, regs); |
| 510 | } |
| 511 | |