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