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> |
Jamie Iles | 7ada189 | 2010-02-02 20:24:58 +0100 | [diff] [blame] | 21 | #include <linux/perf_event.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include <asm/system.h> |
| 24 | #include <asm/pgtable.h> |
| 25 | #include <asm/tlbflush.h> |
Stepan Moskovchenko | 00da074 | 2011-07-08 14:06:44 -0700 | [diff] [blame^] | 26 | #include <asm/cputype.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | #if defined(CONFIG_ARCH_MSM_SCORPION) && !defined(CONFIG_MSM_SMP) |
| 28 | #include <asm/io.h> |
| 29 | #include <mach/msm_iomap.h> |
| 30 | #endif |
| 31 | |
| 32 | #ifdef CONFIG_EMULATE_DOMAIN_MANAGER_V7 |
| 33 | #include <asm/domain.h> |
| 34 | #endif /* CONFIG_EMULATE_DOMAIN_MANAGER_V7 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include "fault.h" |
| 37 | |
Russell King | c88d6aa | 2009-09-20 12:41:58 +0100 | [diff] [blame] | 38 | /* |
Russell King | df297bf | 2009-09-20 13:18:47 +0100 | [diff] [blame] | 39 | * Fault status register encodings. We steal bit 31 for our own purposes. |
Russell King | c88d6aa | 2009-09-20 12:41:58 +0100 | [diff] [blame] | 40 | */ |
Russell King | df297bf | 2009-09-20 13:18:47 +0100 | [diff] [blame] | 41 | #define FSR_LNX_PF (1 << 31) |
Russell King | c88d6aa | 2009-09-20 12:41:58 +0100 | [diff] [blame] | 42 | #define FSR_WRITE (1 << 11) |
| 43 | #define FSR_FS4 (1 << 10) |
| 44 | #define FSR_FS3_0 (15) |
| 45 | |
| 46 | static inline int fsr_fs(unsigned int fsr) |
| 47 | { |
| 48 | return (fsr & FSR_FS3_0) | (fsr & FSR_FS4) >> 6; |
| 49 | } |
| 50 | |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame] | 51 | #ifdef CONFIG_MMU |
Nicolas Pitre | 25ce1dd | 2007-12-03 15:21:57 -0500 | [diff] [blame] | 52 | |
| 53 | #ifdef CONFIG_KPROBES |
| 54 | static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr) |
| 55 | { |
| 56 | int ret = 0; |
| 57 | |
| 58 | if (!user_mode(regs)) { |
| 59 | /* kprobe_running() needs smp_processor_id() */ |
| 60 | preempt_disable(); |
| 61 | if (kprobe_running() && kprobe_fault_handler(regs, fsr)) |
| 62 | ret = 1; |
| 63 | preempt_enable(); |
| 64 | } |
| 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | #else |
| 69 | static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr) |
| 70 | { |
| 71 | return 0; |
| 72 | } |
| 73 | #endif |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* |
| 76 | * This is useful to dump out the page tables associated with |
| 77 | * 'addr' in mm 'mm'. |
| 78 | */ |
| 79 | void show_pte(struct mm_struct *mm, unsigned long addr) |
| 80 | { |
| 81 | pgd_t *pgd; |
| 82 | |
| 83 | if (!mm) |
| 84 | mm = &init_mm; |
| 85 | |
| 86 | printk(KERN_ALERT "pgd = %p\n", mm->pgd); |
| 87 | pgd = pgd_offset(mm, addr); |
Will Deacon | 29a3819 | 2011-02-15 14:31:37 +0100 | [diff] [blame] | 88 | printk(KERN_ALERT "[%08lx] *pgd=%08llx", |
| 89 | addr, (long long)pgd_val(*pgd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | do { |
Russell King | 516295e | 2010-11-21 16:27:49 +0000 | [diff] [blame] | 92 | pud_t *pud; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | pmd_t *pmd; |
| 94 | pte_t *pte; |
| 95 | |
| 96 | if (pgd_none(*pgd)) |
| 97 | break; |
| 98 | |
| 99 | if (pgd_bad(*pgd)) { |
| 100 | printk("(bad)"); |
| 101 | break; |
| 102 | } |
| 103 | |
Russell King | 516295e | 2010-11-21 16:27:49 +0000 | [diff] [blame] | 104 | pud = pud_offset(pgd, addr); |
| 105 | if (PTRS_PER_PUD != 1) |
| 106 | printk(", *pud=%08lx", pud_val(*pud)); |
| 107 | |
| 108 | if (pud_none(*pud)) |
| 109 | break; |
| 110 | |
| 111 | if (pud_bad(*pud)) { |
| 112 | printk("(bad)"); |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | pmd = pmd_offset(pud, addr); |
Nicolas Pitre | da46c79 | 2008-09-30 16:10:11 +0100 | [diff] [blame] | 117 | if (PTRS_PER_PMD != 1) |
Will Deacon | 29a3819 | 2011-02-15 14:31:37 +0100 | [diff] [blame] | 118 | printk(", *pmd=%08llx", (long long)pmd_val(*pmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | if (pmd_none(*pmd)) |
| 121 | break; |
| 122 | |
| 123 | if (pmd_bad(*pmd)) { |
| 124 | printk("(bad)"); |
| 125 | break; |
| 126 | } |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* We must not map this if we have highmem enabled */ |
Nicolas Pitre | 252d4c2 | 2008-09-11 11:52:02 -0400 | [diff] [blame] | 129 | if (PageHighMem(pfn_to_page(pmd_val(*pmd) >> PAGE_SHIFT))) |
| 130 | break; |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | pte = pte_offset_map(pmd, addr); |
Will Deacon | 29a3819 | 2011-02-15 14:31:37 +0100 | [diff] [blame] | 133 | printk(", *pte=%08llx", (long long)pte_val(*pte)); |
| 134 | printk(", *ppte=%08llx", |
| 135 | (long long)pte_val(pte[PTE_HWTABLE_PTRS])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | pte_unmap(pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } while(0); |
| 138 | |
| 139 | printk("\n"); |
| 140 | } |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame] | 141 | #else /* CONFIG_MMU */ |
| 142 | void show_pte(struct mm_struct *mm, unsigned long addr) |
| 143 | { } |
| 144 | #endif /* CONFIG_MMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* |
| 147 | * Oops. The kernel tried to access some page that wasn't present. |
| 148 | */ |
| 149 | static void |
| 150 | __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, |
| 151 | struct pt_regs *regs) |
| 152 | { |
| 153 | /* |
| 154 | * Are we prepared to handle this kernel fault? |
| 155 | */ |
| 156 | if (fixup_exception(regs)) |
| 157 | return; |
| 158 | |
| 159 | /* |
| 160 | * No handler, we'll have to terminate things with extreme prejudice. |
| 161 | */ |
| 162 | bust_spinlocks(1); |
| 163 | printk(KERN_ALERT |
| 164 | "Unable to handle kernel %s at virtual address %08lx\n", |
| 165 | (addr < PAGE_SIZE) ? "NULL pointer dereference" : |
| 166 | "paging request", addr); |
| 167 | |
| 168 | show_pte(mm, addr); |
| 169 | die("Oops", regs, fsr); |
| 170 | bust_spinlocks(0); |
| 171 | do_exit(SIGKILL); |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * Something tried to access memory that isn't in our memory map.. |
| 176 | * User mode accesses just cause a SIGSEGV |
| 177 | */ |
| 178 | static void |
| 179 | __do_user_fault(struct task_struct *tsk, unsigned long addr, |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 180 | unsigned int fsr, unsigned int sig, int code, |
| 181 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
| 183 | struct siginfo si; |
| 184 | |
| 185 | #ifdef CONFIG_DEBUG_USER |
| 186 | if (user_debug & UDBG_SEGV) { |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 187 | printk(KERN_DEBUG "%s: unhandled page fault (%d) at 0x%08lx, code 0x%03x\n", |
| 188 | tsk->comm, sig, addr, fsr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | show_pte(tsk->mm, addr); |
| 190 | show_regs(regs); |
| 191 | } |
| 192 | #endif |
| 193 | |
| 194 | tsk->thread.address = addr; |
| 195 | tsk->thread.error_code = fsr; |
| 196 | tsk->thread.trap_no = 14; |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 197 | si.si_signo = sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | si.si_errno = 0; |
| 199 | si.si_code = code; |
| 200 | si.si_addr = (void __user *)addr; |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 201 | force_sig_info(sig, &si, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Russell King | e5beac3 | 2006-09-27 16:13:48 +0100 | [diff] [blame] | 204 | 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] | 205 | { |
Russell King | e5beac3 | 2006-09-27 16:13:48 +0100 | [diff] [blame] | 206 | struct task_struct *tsk = current; |
| 207 | struct mm_struct *mm = tsk->active_mm; |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* |
| 210 | * If we are in kernel mode at this point, we |
| 211 | * have no context to handle this fault with. |
| 212 | */ |
| 213 | if (user_mode(regs)) |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 214 | __do_user_fault(tsk, addr, fsr, SIGSEGV, SEGV_MAPERR, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | else |
| 216 | __do_kernel_fault(mm, addr, fsr, regs); |
| 217 | } |
| 218 | |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame] | 219 | #ifdef CONFIG_MMU |
Nick Piggin | 5c72fc5 | 2007-07-20 09:21:06 +0200 | [diff] [blame] | 220 | #define VM_FAULT_BADMAP 0x010000 |
| 221 | #define VM_FAULT_BADACCESS 0x020000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Russell King | d374bf1 | 2009-09-20 12:53:01 +0100 | [diff] [blame] | 223 | /* |
| 224 | * Check that the permissions on the VMA allow for the fault which occurred. |
| 225 | * If we encountered a write fault, we must have write permission, otherwise |
| 226 | * we allow any permission. |
| 227 | */ |
| 228 | static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma) |
| 229 | { |
| 230 | unsigned int mask = VM_READ | VM_WRITE | VM_EXEC; |
| 231 | |
| 232 | if (fsr & FSR_WRITE) |
| 233 | mask = VM_WRITE; |
Russell King | df297bf | 2009-09-20 13:18:47 +0100 | [diff] [blame] | 234 | if (fsr & FSR_LNX_PF) |
| 235 | mask = VM_EXEC; |
Russell King | d374bf1 | 2009-09-20 12:53:01 +0100 | [diff] [blame] | 236 | |
| 237 | return vma->vm_flags & mask ? false : true; |
| 238 | } |
| 239 | |
| 240 | static int __kprobes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, |
| 242 | struct task_struct *tsk) |
| 243 | { |
| 244 | struct vm_area_struct *vma; |
Russell King | d374bf1 | 2009-09-20 12:53:01 +0100 | [diff] [blame] | 245 | int fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | vma = find_vma(mm, addr); |
| 248 | fault = VM_FAULT_BADMAP; |
Russell King | d374bf1 | 2009-09-20 12:53:01 +0100 | [diff] [blame] | 249 | if (unlikely(!vma)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | goto out; |
Russell King | d374bf1 | 2009-09-20 12:53:01 +0100 | [diff] [blame] | 251 | if (unlikely(vma->vm_start > addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | goto check_stack; |
| 253 | |
| 254 | /* |
| 255 | * Ok, we have a good vm_area for this |
| 256 | * memory access, so we can handle it. |
| 257 | */ |
| 258 | good_area: |
Russell King | d374bf1 | 2009-09-20 12:53:01 +0100 | [diff] [blame] | 259 | if (access_error(fsr, vma)) { |
| 260 | fault = VM_FAULT_BADACCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | goto out; |
Russell King | d374bf1 | 2009-09-20 12:53:01 +0100 | [diff] [blame] | 262 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | /* |
Russell King | b42c634 | 2009-09-20 12:47:40 +0100 | [diff] [blame] | 265 | * If for any reason at all we couldn't handle the fault, make |
| 266 | * sure we exit gracefully rather than endlessly redo the fault. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | */ |
Russell King | c88d6aa | 2009-09-20 12:41:58 +0100 | [diff] [blame] | 268 | 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] | 269 | if (unlikely(fault & VM_FAULT_ERROR)) |
| 270 | return fault; |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 271 | if (fault & VM_FAULT_MAJOR) |
| 272 | tsk->maj_flt++; |
| 273 | else |
| 274 | tsk->min_flt++; |
| 275 | return fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | check_stack: |
| 278 | if (vma->vm_flags & VM_GROWSDOWN && !expand_stack(vma, addr)) |
| 279 | goto good_area; |
| 280 | out: |
| 281 | return fault; |
| 282 | } |
| 283 | |
Nicolas Pitre | 785d3cd | 2007-12-03 15:27:56 -0500 | [diff] [blame] | 284 | static int __kprobes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 286 | { |
| 287 | struct task_struct *tsk; |
| 288 | struct mm_struct *mm; |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 289 | int fault, sig, code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Nicolas Pitre | 25ce1dd | 2007-12-03 15:21:57 -0500 | [diff] [blame] | 291 | if (notify_page_fault(regs, fsr)) |
| 292 | return 0; |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | tsk = current; |
| 295 | mm = tsk->mm; |
| 296 | |
| 297 | /* |
| 298 | * If we're in an interrupt or have no user |
| 299 | * context, we must not take the fault.. |
| 300 | */ |
Peter Zijlstra | 6edaf68 | 2006-12-06 20:32:18 -0800 | [diff] [blame] | 301 | if (in_atomic() || !mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | goto no_context; |
| 303 | |
Russell King | 840ff6a | 2005-09-20 17:52:13 +0100 | [diff] [blame] | 304 | /* |
| 305 | * As per x86, we may deadlock here. However, since the kernel only |
| 306 | * validly references user space from well defined areas of the code, |
| 307 | * we can bug out early if this is from code which shouldn't. |
| 308 | */ |
| 309 | if (!down_read_trylock(&mm->mmap_sem)) { |
| 310 | if (!user_mode(regs) && !search_exception_tables(regs->ARM_pc)) |
| 311 | goto no_context; |
| 312 | down_read(&mm->mmap_sem); |
Russell King | bf45699 | 2009-09-20 12:52:19 +0100 | [diff] [blame] | 313 | } else { |
| 314 | /* |
| 315 | * The above down_read_trylock() might have succeeded in |
| 316 | * which case, we'll have missed the might_sleep() from |
| 317 | * down_read() |
| 318 | */ |
| 319 | might_sleep(); |
Imre Deak | 1d21271 | 2009-10-05 13:40:44 +0100 | [diff] [blame] | 320 | #ifdef CONFIG_DEBUG_VM |
| 321 | if (!user_mode(regs) && |
| 322 | !search_exception_tables(regs->ARM_pc)) |
| 323 | goto no_context; |
| 324 | #endif |
Russell King | 840ff6a | 2005-09-20 17:52:13 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | fault = __do_page_fault(mm, addr, fsr, tsk); |
| 328 | up_read(&mm->mmap_sem); |
| 329 | |
Jamie Iles | 7ada189 | 2010-02-02 20:24:58 +0100 | [diff] [blame] | 330 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, 0, regs, addr); |
| 331 | if (fault & VM_FAULT_MAJOR) |
| 332 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 0, regs, addr); |
| 333 | else if (fault & VM_FAULT_MINOR) |
| 334 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, 0, regs, addr); |
| 335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | /* |
Russell King | ff2afb9 | 2005-08-04 14:17:33 +0100 | [diff] [blame] | 337 | * Handle the "normal" case first - VM_FAULT_MAJOR / VM_FAULT_MINOR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | */ |
Nick Piggin | 5c72fc5 | 2007-07-20 09:21:06 +0200 | [diff] [blame] | 339 | if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP | VM_FAULT_BADACCESS)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return 0; |
| 341 | |
Russell King | b42c634 | 2009-09-20 12:47:40 +0100 | [diff] [blame] | 342 | if (fault & VM_FAULT_OOM) { |
| 343 | /* |
| 344 | * We ran out of memory, call the OOM killer, and return to |
| 345 | * userspace (which will retry the fault, or kill us if we |
| 346 | * got oom-killed) |
| 347 | */ |
| 348 | pagefault_out_of_memory(); |
| 349 | return 0; |
| 350 | } |
| 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | * If we are in kernel mode at this point, we |
| 354 | * have no context to handle this fault with. |
| 355 | */ |
| 356 | if (!user_mode(regs)) |
| 357 | goto no_context; |
| 358 | |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 359 | if (fault & VM_FAULT_SIGBUS) { |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 360 | /* |
| 361 | * We had some memory, but were unable to |
| 362 | * successfully fix up this page fault. |
| 363 | */ |
| 364 | sig = SIGBUS; |
| 365 | code = BUS_ADRERR; |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 366 | } else { |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 367 | /* |
| 368 | * Something tried to access memory that |
| 369 | * isn't in our memory map.. |
| 370 | */ |
| 371 | sig = SIGSEGV; |
| 372 | code = fault == VM_FAULT_BADACCESS ? |
| 373 | SEGV_ACCERR : SEGV_MAPERR; |
akpm@osdl.org | 2d137c2 | 2005-04-16 15:23:55 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | __do_user_fault(tsk, addr, fsr, sig, code, regs); |
| 377 | return 0; |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | no_context: |
| 380 | __do_kernel_fault(mm, addr, fsr, regs); |
| 381 | return 0; |
| 382 | } |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame] | 383 | #else /* CONFIG_MMU */ |
| 384 | static int |
| 385 | do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 386 | { |
| 387 | return 0; |
| 388 | } |
| 389 | #endif /* CONFIG_MMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /* |
| 392 | * First Level Translation Fault Handler |
| 393 | * |
| 394 | * We enter here because the first level page table doesn't contain |
| 395 | * a valid entry for the address. |
| 396 | * |
| 397 | * If the address is in kernel space (>= TASK_SIZE), then we are |
| 398 | * probably faulting in the vmalloc() area. |
| 399 | * |
| 400 | * If the init_task's first level page tables contains the relevant |
| 401 | * entry, we copy the it to this task. If not, we send the process |
| 402 | * a signal, fixup the exception, or oops the kernel. |
| 403 | * |
| 404 | * NOTE! We MUST NOT take any locks for this case. We may be in an |
| 405 | * interrupt or a critical region, and should only copy the information |
| 406 | * from the master page table, nothing more. |
| 407 | */ |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame] | 408 | #ifdef CONFIG_MMU |
Nicolas Pitre | 785d3cd | 2007-12-03 15:27:56 -0500 | [diff] [blame] | 409 | static int __kprobes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | do_translation_fault(unsigned long addr, unsigned int fsr, |
| 411 | struct pt_regs *regs) |
| 412 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | unsigned int index; |
| 414 | pgd_t *pgd, *pgd_k; |
Russell King | 516295e | 2010-11-21 16:27:49 +0000 | [diff] [blame] | 415 | pud_t *pud, *pud_k; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | pmd_t *pmd, *pmd_k; |
| 417 | |
| 418 | if (addr < TASK_SIZE) |
| 419 | return do_page_fault(addr, fsr, regs); |
| 420 | |
Anfei | 5e27fb7 | 2010-06-08 15:16:49 +0100 | [diff] [blame] | 421 | if (user_mode(regs)) |
| 422 | goto bad_area; |
| 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | index = pgd_index(addr); |
| 425 | |
| 426 | /* |
| 427 | * FIXME: CP15 C1 is write only on ARMv3 architectures. |
| 428 | */ |
| 429 | pgd = cpu_get_pgd() + index; |
| 430 | pgd_k = init_mm.pgd + index; |
| 431 | |
| 432 | if (pgd_none(*pgd_k)) |
| 433 | goto bad_area; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (!pgd_present(*pgd)) |
| 435 | set_pgd(pgd, *pgd_k); |
| 436 | |
Russell King | 516295e | 2010-11-21 16:27:49 +0000 | [diff] [blame] | 437 | pud = pud_offset(pgd, addr); |
| 438 | pud_k = pud_offset(pgd_k, addr); |
| 439 | |
| 440 | if (pud_none(*pud_k)) |
| 441 | goto bad_area; |
| 442 | if (!pud_present(*pud)) |
| 443 | set_pud(pud, *pud_k); |
| 444 | |
| 445 | pmd = pmd_offset(pud, addr); |
| 446 | pmd_k = pmd_offset(pud_k, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Kirill A. Shutemov | 33a9c41 | 2010-07-22 13:20:22 +0100 | [diff] [blame] | 448 | /* |
| 449 | * On ARM one Linux PGD entry contains two hardware entries (see page |
| 450 | * tables layout in pgtable.h). We normally guarantee that we always |
| 451 | * fill both L1 entries. But create_mapping() doesn't follow the rule. |
| 452 | * It can create inidividual L1 entries, so here we have to call |
| 453 | * pmd_none() check for the entry really corresponded to address, not |
| 454 | * for the first of pair. |
| 455 | */ |
| 456 | index = (addr >> SECTION_SHIFT) & 1; |
| 457 | if (pmd_none(pmd_k[index])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | goto bad_area; |
| 459 | |
| 460 | copy_pmd(pmd, pmd_k); |
| 461 | return 0; |
| 462 | |
| 463 | bad_area: |
Russell King | e5beac3 | 2006-09-27 16:13:48 +0100 | [diff] [blame] | 464 | do_bad_area(addr, fsr, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | return 0; |
| 466 | } |
Catalin Marinas | 09529f7 | 2009-07-24 12:34:55 +0100 | [diff] [blame] | 467 | #else /* CONFIG_MMU */ |
| 468 | static int |
| 469 | do_translation_fault(unsigned long addr, unsigned int fsr, |
| 470 | struct pt_regs *regs) |
| 471 | { |
| 472 | return 0; |
| 473 | } |
| 474 | #endif /* CONFIG_MMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | /* |
| 477 | * Some section permission faults need to be handled gracefully. |
| 478 | * They can happen due to a __{get,put}_user during an oops. |
| 479 | */ |
| 480 | static int |
| 481 | do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 482 | { |
Russell King | e5beac3 | 2006-09-27 16:13:48 +0100 | [diff] [blame] | 483 | do_bad_area(addr, fsr, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | /* |
| 488 | * This abort handler always returns "fault". |
| 489 | */ |
| 490 | static int |
| 491 | do_bad(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 492 | { |
| 493 | return 1; |
| 494 | } |
| 495 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 496 | #if defined(CONFIG_ARCH_MSM_SCORPION) && !defined(CONFIG_MSM_SMP) |
| 497 | #define __str(x) #x |
| 498 | #define MRC(x, v1, v2, v4, v5, v6) do { \ |
| 499 | unsigned int __##x; \ |
| 500 | asm("mrc " __str(v1) ", " __str(v2) ", %0, " __str(v4) ", " \ |
| 501 | __str(v5) ", " __str(v6) "\n" \ |
| 502 | : "=r" (__##x)); \ |
| 503 | pr_info("%s: %s = 0x%.8x\n", __func__, #x, __##x); \ |
| 504 | } while(0) |
| 505 | |
| 506 | #define MSM_TCSR_SPARE2 (MSM_TCSR_BASE + 0x60) |
| 507 | |
| 508 | #endif |
| 509 | |
| 510 | static int |
| 511 | do_imprecise_ext(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 512 | { |
| 513 | #if defined(CONFIG_ARCH_MSM_SCORPION) && !defined(CONFIG_MSM_SMP) |
| 514 | MRC(ADFSR, p15, 0, c5, c1, 0); |
| 515 | MRC(DFSR, p15, 0, c5, c0, 0); |
| 516 | MRC(ACTLR, p15, 0, c1, c0, 1); |
| 517 | MRC(EFSR, p15, 7, c15, c0, 1); |
| 518 | MRC(L2SR, p15, 3, c15, c1, 0); |
| 519 | MRC(L2CR0, p15, 3, c15, c0, 1); |
| 520 | MRC(L2CPUESR, p15, 3, c15, c1, 1); |
| 521 | MRC(L2CPUCR, p15, 3, c15, c0, 2); |
| 522 | MRC(SPESR, p15, 1, c9, c7, 0); |
| 523 | MRC(SPCR, p15, 0, c9, c7, 0); |
| 524 | MRC(DMACHSR, p15, 1, c11, c0, 0); |
| 525 | MRC(DMACHESR, p15, 1, c11, c0, 1); |
| 526 | MRC(DMACHCR, p15, 0, c11, c0, 2); |
| 527 | |
| 528 | /* clear out EFSR and ADFSR after fault */ |
| 529 | asm volatile ("mcr p15, 7, %0, c15, c0, 1\n\t" |
| 530 | "mcr p15, 0, %0, c5, c1, 0" |
| 531 | : : "r" (0)); |
| 532 | #endif |
| 533 | #if defined(CONFIG_ARCH_MSM_SCORPION) && !defined(CONFIG_MSM_SMP) |
| 534 | pr_info("%s: TCSR_SPARE2 = 0x%.8x\n", __func__, readl(MSM_TCSR_SPARE2)); |
| 535 | #endif |
| 536 | return 1; |
| 537 | } |
| 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | static struct fsr_info { |
| 540 | int (*fn)(unsigned long addr, unsigned int fsr, struct pt_regs *regs); |
| 541 | int sig; |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 542 | int code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | const char *name; |
| 544 | } fsr_info[] = { |
| 545 | /* |
| 546 | * The following are the standard ARMv3 and ARMv4 aborts. ARMv5 |
| 547 | * defines these to be "precise" aborts. |
| 548 | */ |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 549 | { do_bad, SIGSEGV, 0, "vector exception" }, |
Kirill A. Shutemov | 3dc91af | 2010-07-22 13:16:49 +0100 | [diff] [blame] | 550 | { do_bad, SIGBUS, BUS_ADRALN, "alignment exception" }, |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 551 | { do_bad, SIGKILL, 0, "terminal exception" }, |
Kirill A. Shutemov | 3dc91af | 2010-07-22 13:16:49 +0100 | [diff] [blame] | 552 | { do_bad, SIGBUS, BUS_ADRALN, "alignment exception" }, |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 553 | { do_bad, SIGBUS, 0, "external abort on linefetch" }, |
| 554 | { do_translation_fault, SIGSEGV, SEGV_MAPERR, "section translation fault" }, |
| 555 | { do_bad, SIGBUS, 0, "external abort on linefetch" }, |
| 556 | { do_page_fault, SIGSEGV, SEGV_MAPERR, "page translation fault" }, |
| 557 | { do_bad, SIGBUS, 0, "external abort on non-linefetch" }, |
| 558 | { do_bad, SIGSEGV, SEGV_ACCERR, "section domain fault" }, |
| 559 | { do_bad, SIGBUS, 0, "external abort on non-linefetch" }, |
| 560 | { do_bad, SIGSEGV, SEGV_ACCERR, "page domain fault" }, |
| 561 | { do_bad, SIGBUS, 0, "external abort on translation" }, |
| 562 | { do_sect_fault, SIGSEGV, SEGV_ACCERR, "section permission fault" }, |
| 563 | { do_bad, SIGBUS, 0, "external abort on translation" }, |
| 564 | { do_page_fault, SIGSEGV, SEGV_ACCERR, "page permission fault" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | /* |
| 566 | * The following are "imprecise" aborts, which are signalled by bit |
| 567 | * 10 of the FSR, and may not be recoverable. These are only |
| 568 | * supported if the CPU abort handler supports bit 10. |
| 569 | */ |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 570 | { do_bad, SIGBUS, 0, "unknown 16" }, |
| 571 | { do_bad, SIGBUS, 0, "unknown 17" }, |
| 572 | { do_bad, SIGBUS, 0, "unknown 18" }, |
| 573 | { do_bad, SIGBUS, 0, "unknown 19" }, |
| 574 | { do_bad, SIGBUS, 0, "lock abort" }, /* xscale */ |
| 575 | { do_bad, SIGBUS, 0, "unknown 21" }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 576 | { do_imprecise_ext, SIGBUS, BUS_OBJERR, "imprecise external abort" }, /* xscale */ |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 577 | { do_bad, SIGBUS, 0, "unknown 23" }, |
| 578 | { do_bad, SIGBUS, 0, "dcache parity error" }, /* xscale */ |
| 579 | { do_bad, SIGBUS, 0, "unknown 25" }, |
| 580 | { do_bad, SIGBUS, 0, "unknown 26" }, |
| 581 | { do_bad, SIGBUS, 0, "unknown 27" }, |
| 582 | { do_bad, SIGBUS, 0, "unknown 28" }, |
| 583 | { do_bad, SIGBUS, 0, "unknown 29" }, |
| 584 | { do_bad, SIGBUS, 0, "unknown 30" }, |
| 585 | { do_bad, SIGBUS, 0, "unknown 31" } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | void __init |
| 589 | hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *), |
Kirill A. Shutemov | 6338a6a | 2010-07-22 13:18:19 +0100 | [diff] [blame] | 590 | int sig, int code, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Kirill A. Shutemov | 6338a6a | 2010-07-22 13:18:19 +0100 | [diff] [blame] | 592 | if (nr < 0 || nr >= ARRAY_SIZE(fsr_info)) |
| 593 | BUG(); |
| 594 | |
| 595 | fsr_info[nr].fn = fn; |
| 596 | fsr_info[nr].sig = sig; |
| 597 | fsr_info[nr].code = code; |
| 598 | fsr_info[nr].name = name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Stepan Moskovchenko | 00da074 | 2011-07-08 14:06:44 -0700 | [diff] [blame^] | 601 | #ifdef CONFIG_MSM_KRAIT_TBB_ABORT_HANDLER |
| 602 | static int krait_tbb_fixup(unsigned int fsr, struct pt_regs *regs) |
| 603 | { |
| 604 | int base_cond, cond = 0; |
| 605 | unsigned int p1, cpsr_z, cpsr_c, cpsr_n, cpsr_v; |
| 606 | |
| 607 | if ((read_cpuid_id() & 0xFFFFFFFC) != 0x510F04D0) |
| 608 | return 0; |
| 609 | |
| 610 | if (!thumb_mode(regs)) |
| 611 | return 0; |
| 612 | |
| 613 | /* If ITSTATE is 0, return quickly */ |
| 614 | if ((regs->ARM_cpsr & PSR_IT_MASK) == 0) |
| 615 | return 0; |
| 616 | |
| 617 | cpsr_n = (regs->ARM_cpsr & PSR_N_BIT) ? 1 : 0; |
| 618 | cpsr_z = (regs->ARM_cpsr & PSR_Z_BIT) ? 1 : 0; |
| 619 | cpsr_c = (regs->ARM_cpsr & PSR_C_BIT) ? 1 : 0; |
| 620 | cpsr_v = (regs->ARM_cpsr & PSR_V_BIT) ? 1 : 0; |
| 621 | |
| 622 | p1 = (regs->ARM_cpsr & BIT(12)) ? 1 : 0; |
| 623 | |
| 624 | base_cond = (regs->ARM_cpsr >> 13) & 0x07; |
| 625 | |
| 626 | switch (base_cond) { |
| 627 | case 0x0: /* equal */ |
| 628 | cond = cpsr_z; |
| 629 | break; |
| 630 | |
| 631 | case 0x1: /* carry set */ |
| 632 | cond = cpsr_c; |
| 633 | break; |
| 634 | |
| 635 | case 0x2: /* minus / negative */ |
| 636 | cond = cpsr_n; |
| 637 | break; |
| 638 | |
| 639 | case 0x3: /* overflow */ |
| 640 | cond = cpsr_v; |
| 641 | break; |
| 642 | |
| 643 | case 0x4: /* unsigned higher */ |
| 644 | cond = (cpsr_c == 1) && (cpsr_z == 0); |
| 645 | break; |
| 646 | |
| 647 | case 0x5: /* signed greater / equal */ |
| 648 | cond = (cpsr_n == cpsr_v); |
| 649 | break; |
| 650 | |
| 651 | case 0x6: /* signed greater */ |
| 652 | cond = (cpsr_z == 0) && (cpsr_n == cpsr_v); |
| 653 | break; |
| 654 | |
| 655 | case 0x7: /* always */ |
| 656 | cond = 1; |
| 657 | break; |
| 658 | }; |
| 659 | |
| 660 | if (cond == p1) { |
| 661 | pr_debug("Conditional abort fixup, PC=%08x, base=%d, cond=%d\n", |
| 662 | (unsigned int) regs->ARM_pc, base_cond, cond); |
| 663 | regs->ARM_pc += 2; |
| 664 | return 1; |
| 665 | } |
| 666 | return 0; |
| 667 | } |
| 668 | #endif |
| 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /* |
| 671 | * Dispatch a data abort to the relevant handler. |
| 672 | */ |
Russell King | 7ab3f8d | 2007-03-02 15:01:36 +0000 | [diff] [blame] | 673 | asmlinkage void __exception |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 675 | { |
Russell King | c88d6aa | 2009-09-20 12:41:58 +0100 | [diff] [blame] | 676 | const struct fsr_info *inf = fsr_info + fsr_fs(fsr); |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 677 | struct siginfo info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 679 | #ifdef CONFIG_EMULATE_DOMAIN_MANAGER_V7 |
| 680 | if (emulate_domain_manager_data_abort(fsr, addr)) |
| 681 | return; |
| 682 | #endif |
| 683 | |
Stepan Moskovchenko | 00da074 | 2011-07-08 14:06:44 -0700 | [diff] [blame^] | 684 | #ifdef CONFIG_MSM_KRAIT_TBB_ABORT_HANDLER |
| 685 | if (krait_tbb_fixup(fsr, regs)) |
| 686 | return; |
| 687 | #endif |
| 688 | |
Russell King | df297bf | 2009-09-20 13:18:47 +0100 | [diff] [blame] | 689 | if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | return; |
| 691 | |
| 692 | printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n", |
| 693 | inf->name, fsr, addr); |
Russell King | cfb0810 | 2005-06-30 11:06:49 +0100 | [diff] [blame] | 694 | |
| 695 | info.si_signo = inf->sig; |
| 696 | info.si_errno = 0; |
| 697 | info.si_code = inf->code; |
| 698 | info.si_addr = (void __user *)addr; |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 699 | arm_notify_die("", regs, &info, fsr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Kirill A. Shutemov | d25ef8b | 2009-09-25 13:40:49 +0100 | [diff] [blame] | 702 | |
| 703 | static struct fsr_info ifsr_info[] = { |
| 704 | { do_bad, SIGBUS, 0, "unknown 0" }, |
| 705 | { do_bad, SIGBUS, 0, "unknown 1" }, |
| 706 | { do_bad, SIGBUS, 0, "debug event" }, |
| 707 | { do_bad, SIGSEGV, SEGV_ACCERR, "section access flag fault" }, |
| 708 | { do_bad, SIGBUS, 0, "unknown 4" }, |
| 709 | { do_translation_fault, SIGSEGV, SEGV_MAPERR, "section translation fault" }, |
| 710 | { do_bad, SIGSEGV, SEGV_ACCERR, "page access flag fault" }, |
| 711 | { do_page_fault, SIGSEGV, SEGV_MAPERR, "page translation fault" }, |
| 712 | { do_bad, SIGBUS, 0, "external abort on non-linefetch" }, |
| 713 | { do_bad, SIGSEGV, SEGV_ACCERR, "section domain fault" }, |
| 714 | { do_bad, SIGBUS, 0, "unknown 10" }, |
| 715 | { do_bad, SIGSEGV, SEGV_ACCERR, "page domain fault" }, |
| 716 | { do_bad, SIGBUS, 0, "external abort on translation" }, |
| 717 | { do_sect_fault, SIGSEGV, SEGV_ACCERR, "section permission fault" }, |
| 718 | { do_bad, SIGBUS, 0, "external abort on translation" }, |
| 719 | { do_page_fault, SIGSEGV, SEGV_ACCERR, "page permission fault" }, |
| 720 | { do_bad, SIGBUS, 0, "unknown 16" }, |
| 721 | { do_bad, SIGBUS, 0, "unknown 17" }, |
| 722 | { do_bad, SIGBUS, 0, "unknown 18" }, |
| 723 | { do_bad, SIGBUS, 0, "unknown 19" }, |
| 724 | { do_bad, SIGBUS, 0, "unknown 20" }, |
| 725 | { do_bad, SIGBUS, 0, "unknown 21" }, |
| 726 | { do_bad, SIGBUS, 0, "unknown 22" }, |
| 727 | { do_bad, SIGBUS, 0, "unknown 23" }, |
| 728 | { do_bad, SIGBUS, 0, "unknown 24" }, |
| 729 | { do_bad, SIGBUS, 0, "unknown 25" }, |
| 730 | { do_bad, SIGBUS, 0, "unknown 26" }, |
| 731 | { do_bad, SIGBUS, 0, "unknown 27" }, |
| 732 | { do_bad, SIGBUS, 0, "unknown 28" }, |
| 733 | { do_bad, SIGBUS, 0, "unknown 29" }, |
| 734 | { do_bad, SIGBUS, 0, "unknown 30" }, |
| 735 | { do_bad, SIGBUS, 0, "unknown 31" }, |
| 736 | }; |
| 737 | |
Will Deacon | 3a4b5dc | 2010-09-03 10:39:59 +0100 | [diff] [blame] | 738 | void __init |
| 739 | hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *), |
| 740 | int sig, int code, const char *name) |
| 741 | { |
| 742 | if (nr < 0 || nr >= ARRAY_SIZE(ifsr_info)) |
| 743 | BUG(); |
| 744 | |
| 745 | ifsr_info[nr].fn = fn; |
| 746 | ifsr_info[nr].sig = sig; |
| 747 | ifsr_info[nr].code = code; |
| 748 | ifsr_info[nr].name = name; |
| 749 | } |
| 750 | |
Russell King | 7ab3f8d | 2007-03-02 15:01:36 +0000 | [diff] [blame] | 751 | asmlinkage void __exception |
Kirill A. Shutemov | 4fb2847 | 2009-09-25 13:39:47 +0100 | [diff] [blame] | 752 | do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | { |
Kirill A. Shutemov | d25ef8b | 2009-09-25 13:40:49 +0100 | [diff] [blame] | 754 | const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr); |
| 755 | struct siginfo info; |
| 756 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 757 | #ifdef CONFIG_EMULATE_DOMAIN_MANAGER_V7 |
| 758 | if (emulate_domain_manager_prefetch_abort(ifsr, addr)) |
| 759 | return; |
| 760 | #endif |
| 761 | |
Kirill A. Shutemov | d25ef8b | 2009-09-25 13:40:49 +0100 | [diff] [blame] | 762 | if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs)) |
| 763 | return; |
| 764 | |
| 765 | printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n", |
| 766 | inf->name, ifsr, addr); |
| 767 | |
| 768 | info.si_signo = inf->sig; |
| 769 | info.si_errno = 0; |
| 770 | info.si_code = inf->code; |
| 771 | info.si_addr = (void __user *)addr; |
| 772 | arm_notify_die("", regs, &info, ifsr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Kirill A. Shutemov | 993bf4e | 2010-07-22 13:23:25 +0100 | [diff] [blame] | 775 | static int __init exceptions_init(void) |
| 776 | { |
| 777 | if (cpu_architecture() >= CPU_ARCH_ARMv6) { |
| 778 | hook_fault_code(4, do_translation_fault, SIGSEGV, SEGV_MAPERR, |
| 779 | "I-cache maintenance fault"); |
| 780 | } |
| 781 | |
Kirill A. Shutemov | b8ab539 | 2010-07-26 11:20:41 +0100 | [diff] [blame] | 782 | if (cpu_architecture() >= CPU_ARCH_ARMv7) { |
| 783 | /* |
| 784 | * TODO: Access flag faults introduced in ARMv6K. |
| 785 | * Runtime check for 'K' extension is needed |
| 786 | */ |
| 787 | hook_fault_code(3, do_bad, SIGSEGV, SEGV_MAPERR, |
| 788 | "section access flag fault"); |
| 789 | hook_fault_code(6, do_bad, SIGSEGV, SEGV_MAPERR, |
| 790 | "section access flag fault"); |
| 791 | } |
| 792 | |
Kirill A. Shutemov | 993bf4e | 2010-07-22 13:23:25 +0100 | [diff] [blame] | 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | arch_initcall(exceptions_init); |