Merge remote-tracking branch 's5p/for-next'
[linux-2.6/next.git] / arch / arm / mm / fault.c
blob91d1768023534b0bb306bbad5d7d8c69672cb20c
1 /*
2 * linux/arch/arm/mm/fault.c
4 * Copyright (C) 1995 Linus Torvalds
5 * Modifications for ARM processor (c) 1995-2004 Russell King
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.
11 #include <linux/module.h>
12 #include <linux/signal.h>
13 #include <linux/mm.h>
14 #include <linux/hardirq.h>
15 #include <linux/init.h>
16 #include <linux/kprobes.h>
17 #include <linux/uaccess.h>
18 #include <linux/page-flags.h>
19 #include <linux/sched.h>
20 #include <linux/highmem.h>
21 #include <linux/perf_event.h>
23 #include <asm/system.h>
24 #include <asm/pgtable.h>
25 #include <asm/tlbflush.h>
27 #include "fault.h"
30 * Fault status register encodings. We steal bit 31 for our own purposes.
32 #define FSR_LNX_PF (1 << 31)
33 #define FSR_WRITE (1 << 11)
34 #define FSR_FS4 (1 << 10)
35 #define FSR_FS3_0 (15)
36 #define FSR_FS5_0 (0x3f)
38 static inline int fsr_fs(unsigned int fsr)
40 #ifdef CONFIG_ARM_LPAE
41 return fsr & FSR_FS5_0;
42 #else
43 return (fsr & FSR_FS3_0) | (fsr & FSR_FS4) >> 6;
44 #endif
47 #ifdef CONFIG_MMU
49 #ifdef CONFIG_KPROBES
50 static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)
52 int ret = 0;
54 if (!user_mode(regs)) {
55 /* kprobe_running() needs smp_processor_id() */
56 preempt_disable();
57 if (kprobe_running() && kprobe_fault_handler(regs, fsr))
58 ret = 1;
59 preempt_enable();
62 return ret;
64 #else
65 static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)
67 return 0;
69 #endif
72 * This is useful to dump out the page tables associated with
73 * 'addr' in mm 'mm'.
75 void show_pte(struct mm_struct *mm, unsigned long addr)
77 pgd_t *pgd;
79 if (!mm)
80 mm = &init_mm;
82 printk(KERN_ALERT "pgd = %p\n", mm->pgd);
83 pgd = pgd_offset(mm, addr);
84 printk(KERN_ALERT "[%08lx] *pgd=%08llx",
85 addr, (long long)pgd_val(*pgd));
87 do {
88 pud_t *pud;
89 pmd_t *pmd;
90 pte_t *pte;
92 if (pgd_none(*pgd))
93 break;
95 if (pgd_bad(*pgd)) {
96 printk("(bad)");
97 break;
100 pud = pud_offset(pgd, addr);
101 if (PTRS_PER_PUD != 1)
102 printk(", *pud=%08llx", (long long)pud_val(*pud));
104 if (pud_none(*pud))
105 break;
107 if (pud_bad(*pud)) {
108 printk("(bad)");
109 break;
112 pmd = pmd_offset(pud, addr);
113 if (PTRS_PER_PMD != 1)
114 printk(", *pmd=%08llx", (long long)pmd_val(*pmd));
116 if (pmd_none(*pmd))
117 break;
119 if (pmd_bad(*pmd)) {
120 printk("(bad)");
121 break;
124 /* We must not map this if we have highmem enabled */
125 if (PageHighMem(pfn_to_page(pmd_val(*pmd) >> PAGE_SHIFT)))
126 break;
128 pte = pte_offset_map(pmd, addr);
129 printk(", *pte=%08llx", (long long)pte_val(*pte));
130 #ifndef CONFIG_ARM_LPAE
131 printk(", *ppte=%08llx",
132 (long long)pte_val(pte[PTE_HWTABLE_PTRS]));
133 #endif
134 pte_unmap(pte);
135 } while(0);
137 printk("\n");
139 #else /* CONFIG_MMU */
140 void show_pte(struct mm_struct *mm, unsigned long addr)
142 #endif /* CONFIG_MMU */
145 * Oops. The kernel tried to access some page that wasn't present.
147 static void
148 __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
149 struct pt_regs *regs)
152 * Are we prepared to handle this kernel fault?
154 if (fixup_exception(regs))
155 return;
158 * No handler, we'll have to terminate things with extreme prejudice.
160 bust_spinlocks(1);
161 printk(KERN_ALERT
162 "Unable to handle kernel %s at virtual address %08lx\n",
163 (addr < PAGE_SIZE) ? "NULL pointer dereference" :
164 "paging request", addr);
166 show_pte(mm, addr);
167 die("Oops", regs, fsr);
168 bust_spinlocks(0);
169 do_exit(SIGKILL);
173 * Something tried to access memory that isn't in our memory map..
174 * User mode accesses just cause a SIGSEGV
176 static void
177 __do_user_fault(struct task_struct *tsk, unsigned long addr,
178 unsigned int fsr, unsigned int sig, int code,
179 struct pt_regs *regs)
181 struct siginfo si;
183 #ifdef CONFIG_DEBUG_USER
184 if (user_debug & UDBG_SEGV) {
185 printk(KERN_DEBUG "%s: unhandled page fault (%d) at 0x%08lx, code 0x%03x\n",
186 tsk->comm, sig, addr, fsr);
187 show_pte(tsk->mm, addr);
188 show_regs(regs);
190 #endif
192 tsk->thread.address = addr;
193 tsk->thread.error_code = fsr;
194 tsk->thread.trap_no = 14;
195 si.si_signo = sig;
196 si.si_errno = 0;
197 si.si_code = code;
198 si.si_addr = (void __user *)addr;
199 force_sig_info(sig, &si, tsk);
202 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
204 struct task_struct *tsk = current;
205 struct mm_struct *mm = tsk->active_mm;
208 * If we are in kernel mode at this point, we
209 * have no context to handle this fault with.
211 if (user_mode(regs))
212 __do_user_fault(tsk, addr, fsr, SIGSEGV, SEGV_MAPERR, regs);
213 else
214 __do_kernel_fault(mm, addr, fsr, regs);
217 #ifdef CONFIG_MMU
218 #define VM_FAULT_BADMAP 0x010000
219 #define VM_FAULT_BADACCESS 0x020000
222 * Check that the permissions on the VMA allow for the fault which occurred.
223 * If we encountered a write fault, we must have write permission, otherwise
224 * we allow any permission.
226 static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma)
228 unsigned int mask = VM_READ | VM_WRITE | VM_EXEC;
230 if (fsr & FSR_WRITE)
231 mask = VM_WRITE;
232 if (fsr & FSR_LNX_PF)
233 mask = VM_EXEC;
235 return vma->vm_flags & mask ? false : true;
238 static int __kprobes
239 __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
240 struct task_struct *tsk)
242 struct vm_area_struct *vma;
243 int fault;
245 vma = find_vma(mm, addr);
246 fault = VM_FAULT_BADMAP;
247 if (unlikely(!vma))
248 goto out;
249 if (unlikely(vma->vm_start > addr))
250 goto check_stack;
253 * Ok, we have a good vm_area for this
254 * memory access, so we can handle it.
256 good_area:
257 if (access_error(fsr, vma)) {
258 fault = VM_FAULT_BADACCESS;
259 goto out;
263 * If for any reason at all we couldn't handle the fault, make
264 * sure we exit gracefully rather than endlessly redo the fault.
266 fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, (fsr & FSR_WRITE) ? FAULT_FLAG_WRITE : 0);
267 if (unlikely(fault & VM_FAULT_ERROR))
268 return fault;
269 if (fault & VM_FAULT_MAJOR)
270 tsk->maj_flt++;
271 else
272 tsk->min_flt++;
273 return fault;
275 check_stack:
276 if (vma->vm_flags & VM_GROWSDOWN && !expand_stack(vma, addr))
277 goto good_area;
278 out:
279 return fault;
282 static int __kprobes
283 do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
285 struct task_struct *tsk;
286 struct mm_struct *mm;
287 int fault, sig, code;
289 if (notify_page_fault(regs, fsr))
290 return 0;
292 tsk = current;
293 mm = tsk->mm;
295 /* Enable interrupts if they were enabled in the parent context. */
296 if (interrupts_enabled(regs))
297 local_irq_enable();
300 * If we're in an interrupt or have no user
301 * context, we must not take the fault..
303 if (in_atomic() || !mm)
304 goto no_context;
307 * As per x86, we may deadlock here. However, since the kernel only
308 * validly references user space from well defined areas of the code,
309 * we can bug out early if this is from code which shouldn't.
311 if (!down_read_trylock(&mm->mmap_sem)) {
312 if (!user_mode(regs) && !search_exception_tables(regs->ARM_pc))
313 goto no_context;
314 down_read(&mm->mmap_sem);
315 } else {
317 * The above down_read_trylock() might have succeeded in
318 * which case, we'll have missed the might_sleep() from
319 * down_read()
321 might_sleep();
322 #ifdef CONFIG_DEBUG_VM
323 if (!user_mode(regs) &&
324 !search_exception_tables(regs->ARM_pc))
325 goto no_context;
326 #endif
329 fault = __do_page_fault(mm, addr, fsr, tsk);
330 up_read(&mm->mmap_sem);
332 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
333 if (fault & VM_FAULT_MAJOR)
334 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, addr);
335 else if (fault & VM_FAULT_MINOR)
336 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, addr);
339 * Handle the "normal" case first - VM_FAULT_MAJOR / VM_FAULT_MINOR
341 if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP | VM_FAULT_BADACCESS))))
342 return 0;
344 if (fault & VM_FAULT_OOM) {
346 * We ran out of memory, call the OOM killer, and return to
347 * userspace (which will retry the fault, or kill us if we
348 * got oom-killed)
350 pagefault_out_of_memory();
351 return 0;
355 * If we are in kernel mode at this point, we
356 * have no context to handle this fault with.
358 if (!user_mode(regs))
359 goto no_context;
361 if (fault & VM_FAULT_SIGBUS) {
363 * We had some memory, but were unable to
364 * successfully fix up this page fault.
366 sig = SIGBUS;
367 code = BUS_ADRERR;
368 } else {
370 * Something tried to access memory that
371 * isn't in our memory map..
373 sig = SIGSEGV;
374 code = fault == VM_FAULT_BADACCESS ?
375 SEGV_ACCERR : SEGV_MAPERR;
378 __do_user_fault(tsk, addr, fsr, sig, code, regs);
379 return 0;
381 no_context:
382 __do_kernel_fault(mm, addr, fsr, regs);
383 return 0;
385 #else /* CONFIG_MMU */
386 static int
387 do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
389 return 0;
391 #endif /* CONFIG_MMU */
394 * First Level Translation Fault Handler
396 * We enter here because the first level page table doesn't contain
397 * a valid entry for the address.
399 * If the address is in kernel space (>= TASK_SIZE), then we are
400 * probably faulting in the vmalloc() area.
402 * If the init_task's first level page tables contains the relevant
403 * entry, we copy the it to this task. If not, we send the process
404 * a signal, fixup the exception, or oops the kernel.
406 * NOTE! We MUST NOT take any locks for this case. We may be in an
407 * interrupt or a critical region, and should only copy the information
408 * from the master page table, nothing more.
410 #ifdef CONFIG_MMU
411 static int __kprobes
412 do_translation_fault(unsigned long addr, unsigned int fsr,
413 struct pt_regs *regs)
415 unsigned int index;
416 pgd_t *pgd, *pgd_k;
417 pud_t *pud, *pud_k;
418 pmd_t *pmd, *pmd_k;
420 if (addr < TASK_SIZE)
421 return do_page_fault(addr, fsr, regs);
423 if (user_mode(regs))
424 goto bad_area;
426 index = pgd_index(addr);
429 * FIXME: CP15 C1 is write only on ARMv3 architectures.
431 pgd = cpu_get_pgd() + index;
432 pgd_k = init_mm.pgd + index;
434 if (pgd_none(*pgd_k))
435 goto bad_area;
436 if (!pgd_present(*pgd))
437 set_pgd(pgd, *pgd_k);
439 pud = pud_offset(pgd, addr);
440 pud_k = pud_offset(pgd_k, addr);
442 if (pud_none(*pud_k))
443 goto bad_area;
444 if (!pud_present(*pud))
445 set_pud(pud, *pud_k);
447 pmd = pmd_offset(pud, addr);
448 pmd_k = pmd_offset(pud_k, addr);
450 #ifdef CONFIG_ARM_LPAE
452 * Only one hardware entry per PMD with LPAE.
454 index = 0;
455 #else
457 * On ARM one Linux PGD entry contains two hardware entries (see page
458 * tables layout in pgtable.h). We normally guarantee that we always
459 * fill both L1 entries. But create_mapping() doesn't follow the rule.
460 * It can create inidividual L1 entries, so here we have to call
461 * pmd_none() check for the entry really corresponded to address, not
462 * for the first of pair.
464 index = (addr >> SECTION_SHIFT) & 1;
465 #endif
466 if (pmd_none(pmd_k[index]))
467 goto bad_area;
469 copy_pmd(pmd, pmd_k);
470 return 0;
472 bad_area:
473 do_bad_area(addr, fsr, regs);
474 return 0;
476 #else /* CONFIG_MMU */
477 static int
478 do_translation_fault(unsigned long addr, unsigned int fsr,
479 struct pt_regs *regs)
481 return 0;
483 #endif /* CONFIG_MMU */
486 * Some section permission faults need to be handled gracefully.
487 * They can happen due to a __{get,put}_user during an oops.
489 static int
490 do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
492 do_bad_area(addr, fsr, regs);
493 return 0;
497 * This abort handler always returns "fault".
499 static int
500 do_bad(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
502 return 1;
505 static struct fsr_info {
506 int (*fn)(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
507 int sig;
508 int code;
509 const char *name;
510 } fsr_info[] = {
511 #ifdef CONFIG_ARM_LPAE
512 { do_bad, SIGBUS, 0, "unknown 0" },
513 { do_bad, SIGBUS, 0, "unknown 1" },
514 { do_bad, SIGBUS, 0, "unknown 2" },
515 { do_bad, SIGBUS, 0, "unknown 3" },
516 { do_bad, SIGBUS, 0, "reserved translation fault" },
517 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "level 1 translation fault" },
518 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "level 2 translation fault" },
519 { do_page_fault, SIGSEGV, SEGV_MAPERR, "level 3 translation fault" },
520 { do_bad, SIGBUS, 0, "reserved access flag fault" },
521 { do_bad, SIGSEGV, SEGV_ACCERR, "level 1 access flag fault" },
522 { do_bad, SIGSEGV, SEGV_ACCERR, "level 2 access flag fault" },
523 { do_page_fault, SIGSEGV, SEGV_ACCERR, "level 3 access flag fault" },
524 { do_bad, SIGBUS, 0, "reserved permission fault" },
525 { do_bad, SIGSEGV, SEGV_ACCERR, "level 1 permission fault" },
526 { do_sect_fault, SIGSEGV, SEGV_ACCERR, "level 2 permission fault" },
527 { do_page_fault, SIGSEGV, SEGV_ACCERR, "level 3 permission fault" },
528 { do_bad, SIGBUS, 0, "synchronous external abort" },
529 { do_bad, SIGBUS, 0, "asynchronous external abort" },
530 { do_bad, SIGBUS, 0, "unknown 18" },
531 { do_bad, SIGBUS, 0, "unknown 19" },
532 { do_bad, SIGBUS, 0, "synchronous abort (translation table walk)" },
533 { do_bad, SIGBUS, 0, "synchronous abort (translation table walk)" },
534 { do_bad, SIGBUS, 0, "synchronous abort (translation table walk)" },
535 { do_bad, SIGBUS, 0, "synchronous abort (translation table walk)" },
536 { do_bad, SIGBUS, 0, "synchronous parity error" },
537 { do_bad, SIGBUS, 0, "asynchronous parity error" },
538 { do_bad, SIGBUS, 0, "unknown 26" },
539 { do_bad, SIGBUS, 0, "unknown 27" },
540 { do_bad, SIGBUS, 0, "synchronous parity error (translation table walk" },
541 { do_bad, SIGBUS, 0, "synchronous parity error (translation table walk" },
542 { do_bad, SIGBUS, 0, "synchronous parity error (translation table walk" },
543 { do_bad, SIGBUS, 0, "synchronous parity error (translation table walk" },
544 { do_bad, SIGBUS, 0, "unknown 32" },
545 { do_bad, SIGBUS, BUS_ADRALN, "alignment fault" },
546 { do_bad, SIGBUS, 0, "debug event" },
547 { do_bad, SIGBUS, 0, "unknown 35" },
548 { do_bad, SIGBUS, 0, "unknown 36" },
549 { do_bad, SIGBUS, 0, "unknown 37" },
550 { do_bad, SIGBUS, 0, "unknown 38" },
551 { do_bad, SIGBUS, 0, "unknown 39" },
552 { do_bad, SIGBUS, 0, "unknown 40" },
553 { do_bad, SIGBUS, 0, "unknown 41" },
554 { do_bad, SIGBUS, 0, "unknown 42" },
555 { do_bad, SIGBUS, 0, "unknown 43" },
556 { do_bad, SIGBUS, 0, "unknown 44" },
557 { do_bad, SIGBUS, 0, "unknown 45" },
558 { do_bad, SIGBUS, 0, "unknown 46" },
559 { do_bad, SIGBUS, 0, "unknown 47" },
560 { do_bad, SIGBUS, 0, "unknown 48" },
561 { do_bad, SIGBUS, 0, "unknown 49" },
562 { do_bad, SIGBUS, 0, "unknown 50" },
563 { do_bad, SIGBUS, 0, "unknown 51" },
564 { do_bad, SIGBUS, 0, "implementation fault (lockdown abort)" },
565 { do_bad, SIGBUS, 0, "unknown 53" },
566 { do_bad, SIGBUS, 0, "unknown 54" },
567 { do_bad, SIGBUS, 0, "unknown 55" },
568 { do_bad, SIGBUS, 0, "unknown 56" },
569 { do_bad, SIGBUS, 0, "unknown 57" },
570 { do_bad, SIGBUS, 0, "implementation fault (coprocessor abort)" },
571 { do_bad, SIGBUS, 0, "unknown 59" },
572 { do_bad, SIGBUS, 0, "unknown 60" },
573 { do_bad, SIGBUS, 0, "unknown 61" },
574 { do_bad, SIGBUS, 0, "unknown 62" },
575 { do_bad, SIGBUS, 0, "unknown 63" },
576 #else /* !CONFIG_ARM_LPAE */
578 * The following are the standard ARMv3 and ARMv4 aborts. ARMv5
579 * defines these to be "precise" aborts.
581 { do_bad, SIGSEGV, 0, "vector exception" },
582 { do_bad, SIGBUS, BUS_ADRALN, "alignment exception" },
583 { do_bad, SIGKILL, 0, "terminal exception" },
584 { do_bad, SIGBUS, BUS_ADRALN, "alignment exception" },
585 { do_bad, SIGBUS, 0, "external abort on linefetch" },
586 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "section translation fault" },
587 { do_bad, SIGBUS, 0, "external abort on linefetch" },
588 { do_page_fault, SIGSEGV, SEGV_MAPERR, "page translation fault" },
589 { do_bad, SIGBUS, 0, "external abort on non-linefetch" },
590 { do_bad, SIGSEGV, SEGV_ACCERR, "section domain fault" },
591 { do_bad, SIGBUS, 0, "external abort on non-linefetch" },
592 { do_bad, SIGSEGV, SEGV_ACCERR, "page domain fault" },
593 { do_bad, SIGBUS, 0, "external abort on translation" },
594 { do_sect_fault, SIGSEGV, SEGV_ACCERR, "section permission fault" },
595 { do_bad, SIGBUS, 0, "external abort on translation" },
596 { do_page_fault, SIGSEGV, SEGV_ACCERR, "page permission fault" },
598 * The following are "imprecise" aborts, which are signalled by bit
599 * 10 of the FSR, and may not be recoverable. These are only
600 * supported if the CPU abort handler supports bit 10.
602 { do_bad, SIGBUS, 0, "unknown 16" },
603 { do_bad, SIGBUS, 0, "unknown 17" },
604 { do_bad, SIGBUS, 0, "unknown 18" },
605 { do_bad, SIGBUS, 0, "unknown 19" },
606 { do_bad, SIGBUS, 0, "lock abort" }, /* xscale */
607 { do_bad, SIGBUS, 0, "unknown 21" },
608 { do_bad, SIGBUS, BUS_OBJERR, "imprecise external abort" }, /* xscale */
609 { do_bad, SIGBUS, 0, "unknown 23" },
610 { do_bad, SIGBUS, 0, "dcache parity error" }, /* xscale */
611 { do_bad, SIGBUS, 0, "unknown 25" },
612 { do_bad, SIGBUS, 0, "unknown 26" },
613 { do_bad, SIGBUS, 0, "unknown 27" },
614 { do_bad, SIGBUS, 0, "unknown 28" },
615 { do_bad, SIGBUS, 0, "unknown 29" },
616 { do_bad, SIGBUS, 0, "unknown 30" },
617 { do_bad, SIGBUS, 0, "unknown 31" }
618 #endif /* CONFIG_ARM_LPAE */
621 void __init
622 hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *),
623 int sig, int code, const char *name)
625 if (nr < 0 || nr >= ARRAY_SIZE(fsr_info))
626 BUG();
628 fsr_info[nr].fn = fn;
629 fsr_info[nr].sig = sig;
630 fsr_info[nr].code = code;
631 fsr_info[nr].name = name;
635 * Dispatch a data abort to the relevant handler.
637 asmlinkage void __exception
638 do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
640 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
641 struct siginfo info;
643 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
644 return;
646 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
647 inf->name, fsr, addr);
649 info.si_signo = inf->sig;
650 info.si_errno = 0;
651 info.si_code = inf->code;
652 info.si_addr = (void __user *)addr;
653 arm_notify_die("", regs, &info, fsr, 0);
657 #ifdef CONFIG_ARM_LPAE
658 #define ifsr_info fsr_info
659 #else /* !CONFIG_ARM_LPAE */
660 static struct fsr_info ifsr_info[] = {
661 { do_bad, SIGBUS, 0, "unknown 0" },
662 { do_bad, SIGBUS, 0, "unknown 1" },
663 { do_bad, SIGBUS, 0, "debug event" },
664 { do_bad, SIGSEGV, SEGV_ACCERR, "section access flag fault" },
665 { do_bad, SIGBUS, 0, "unknown 4" },
666 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "section translation fault" },
667 { do_bad, SIGSEGV, SEGV_ACCERR, "page access flag fault" },
668 { do_page_fault, SIGSEGV, SEGV_MAPERR, "page translation fault" },
669 { do_bad, SIGBUS, 0, "external abort on non-linefetch" },
670 { do_bad, SIGSEGV, SEGV_ACCERR, "section domain fault" },
671 { do_bad, SIGBUS, 0, "unknown 10" },
672 { do_bad, SIGSEGV, SEGV_ACCERR, "page domain fault" },
673 { do_bad, SIGBUS, 0, "external abort on translation" },
674 { do_sect_fault, SIGSEGV, SEGV_ACCERR, "section permission fault" },
675 { do_bad, SIGBUS, 0, "external abort on translation" },
676 { do_page_fault, SIGSEGV, SEGV_ACCERR, "page permission fault" },
677 { do_bad, SIGBUS, 0, "unknown 16" },
678 { do_bad, SIGBUS, 0, "unknown 17" },
679 { do_bad, SIGBUS, 0, "unknown 18" },
680 { do_bad, SIGBUS, 0, "unknown 19" },
681 { do_bad, SIGBUS, 0, "unknown 20" },
682 { do_bad, SIGBUS, 0, "unknown 21" },
683 { do_bad, SIGBUS, 0, "unknown 22" },
684 { do_bad, SIGBUS, 0, "unknown 23" },
685 { do_bad, SIGBUS, 0, "unknown 24" },
686 { do_bad, SIGBUS, 0, "unknown 25" },
687 { do_bad, SIGBUS, 0, "unknown 26" },
688 { do_bad, SIGBUS, 0, "unknown 27" },
689 { do_bad, SIGBUS, 0, "unknown 28" },
690 { do_bad, SIGBUS, 0, "unknown 29" },
691 { do_bad, SIGBUS, 0, "unknown 30" },
692 { do_bad, SIGBUS, 0, "unknown 31" },
694 #endif /* CONFIG_ARM_LPAE */
696 void __init
697 hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *),
698 int sig, int code, const char *name)
700 if (nr < 0 || nr >= ARRAY_SIZE(ifsr_info))
701 BUG();
703 ifsr_info[nr].fn = fn;
704 ifsr_info[nr].sig = sig;
705 ifsr_info[nr].code = code;
706 ifsr_info[nr].name = name;
709 asmlinkage void __exception
710 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
712 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
713 struct siginfo info;
715 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
716 return;
718 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
719 inf->name, ifsr, addr);
721 info.si_signo = inf->sig;
722 info.si_errno = 0;
723 info.si_code = inf->code;
724 info.si_addr = (void __user *)addr;
725 arm_notify_die("", regs, &info, ifsr, 0);
728 static int __init exceptions_init(void)
730 #ifndef CONFIG_ARM_LPAE
731 if (cpu_architecture() >= CPU_ARCH_ARMv6) {
732 hook_fault_code(4, do_translation_fault, SIGSEGV, SEGV_MAPERR,
733 "I-cache maintenance fault");
736 if (cpu_architecture() >= CPU_ARCH_ARMv7) {
738 * TODO: Access flag faults introduced in ARMv6K.
739 * Runtime check for 'K' extension is needed
741 hook_fault_code(3, do_bad, SIGSEGV, SEGV_MAPERR,
742 "section access flag fault");
743 hook_fault_code(6, do_bad, SIGSEGV, SEGV_MAPERR,
744 "section access flag fault");
746 #endif
748 return 0;
751 arch_initcall(exceptions_init);