1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/arm/mm/fault.c
4 *
5 * Copyright (C) 1995 Linus Torvalds
6 * Modifications for ARM processor (c) 1995-2004 Russell King
7 */
8 #include <linux/extable.h>
9 #include <linux/signal.h>
10 #include <linux/mm.h>
11 #include <linux/hardirq.h>
12 #include <linux/init.h>
13 #include <linux/kprobes.h>
14 #include <linux/uaccess.h>
15 #include <linux/page-flags.h>
16 #include <linux/sched/signal.h>
17 #include <linux/sched/debug.h>
18 #include <linux/highmem.h>
19 #include <linux/perf_event.h>
20 #include <linux/kfence.h>
21
22 #include <asm/system_misc.h>
23 #include <asm/system_info.h>
24 #include <asm/tlbflush.h>
25
26 #include "fault.h"
27
28 #ifdef CONFIG_MMU
29
copy_from_kernel_nofault_allowed(const void * unsafe_src,size_t size)30 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
31 {
32 unsigned long addr = (unsigned long)unsafe_src;
33
34 return addr >= TASK_SIZE && ULONG_MAX - addr >= size;
35 }
36
37 /*
38 * This is useful to dump out the page tables associated with
39 * 'addr' in mm 'mm'.
40 */
show_pte(const char * lvl,struct mm_struct * mm,unsigned long addr)41 void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr)
42 {
43 pgd_t *pgd;
44
45 if (!mm)
46 mm = &init_mm;
47
48 pgd = pgd_offset(mm, addr);
49 printk("%s[%08lx] *pgd=%08llx", lvl, addr, (long long)pgd_val(*pgd));
50
51 do {
52 p4d_t *p4d;
53 pud_t *pud;
54 pmd_t *pmd;
55 pte_t *pte;
56
57 p4d = p4d_offset(pgd, addr);
58 if (p4d_none(*p4d))
59 break;
60
61 if (p4d_bad(*p4d)) {
62 pr_cont("(bad)");
63 break;
64 }
65
66 pud = pud_offset(p4d, addr);
67 if (PTRS_PER_PUD != 1)
68 pr_cont(", *pud=%08llx", (long long)pud_val(*pud));
69
70 if (pud_none(*pud))
71 break;
72
73 if (pud_bad(*pud)) {
74 pr_cont("(bad)");
75 break;
76 }
77
78 pmd = pmd_offset(pud, addr);
79 if (PTRS_PER_PMD != 1)
80 pr_cont(", *pmd=%08llx", (long long)pmd_val(*pmd));
81
82 if (pmd_none(*pmd))
83 break;
84
85 if (pmd_bad(*pmd)) {
86 pr_cont("(bad)");
87 break;
88 }
89
90 /* We must not map this if we have highmem enabled */
91 if (PageHighMem(pfn_to_page(pmd_val(*pmd) >> PAGE_SHIFT)))
92 break;
93
94 pte = pte_offset_map(pmd, addr);
95 if (!pte)
96 break;
97
98 pr_cont(", *pte=%08llx", (long long)pte_val(*pte));
99 #ifndef CONFIG_ARM_LPAE
100 pr_cont(", *ppte=%08llx",
101 (long long)pte_val(pte[PTE_HWTABLE_PTRS]));
102 #endif
103 pte_unmap(pte);
104 } while(0);
105
106 pr_cont("\n");
107 }
108 #else /* CONFIG_MMU */
show_pte(const char * lvl,struct mm_struct * mm,unsigned long addr)109 void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr)
110 { }
111 #endif /* CONFIG_MMU */
112
is_write_fault(unsigned int fsr)113 static inline bool is_write_fault(unsigned int fsr)
114 {
115 return (fsr & FSR_WRITE) && !(fsr & FSR_CM);
116 }
117
die_kernel_fault(const char * msg,struct mm_struct * mm,unsigned long addr,unsigned int fsr,struct pt_regs * regs)118 static void die_kernel_fault(const char *msg, struct mm_struct *mm,
119 unsigned long addr, unsigned int fsr,
120 struct pt_regs *regs)
121 {
122 bust_spinlocks(1);
123 pr_alert("8<--- cut here ---\n");
124 pr_alert("Unable to handle kernel %s at virtual address %08lx when %s\n",
125 msg, addr, fsr & FSR_LNX_PF ? "execute" : str_write_read(fsr & FSR_WRITE));
126
127 show_pte(KERN_ALERT, mm, addr);
128 die("Oops", regs, fsr);
129 bust_spinlocks(0);
130 make_task_dead(SIGKILL);
131 }
132
133 /*
134 * Oops. The kernel tried to access some page that wasn't present.
135 */
136 static void
__do_kernel_fault(struct mm_struct * mm,unsigned long addr,unsigned int fsr,struct pt_regs * regs)137 __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
138 struct pt_regs *regs)
139 {
140 const char *msg;
141 /*
142 * Are we prepared to handle this kernel fault?
143 */
144 if (fixup_exception(regs))
145 return;
146
147 /*
148 * No handler, we'll have to terminate things with extreme prejudice.
149 */
150 if (addr < PAGE_SIZE) {
151 msg = "NULL pointer dereference";
152 } else if (is_permission_fault(fsr) && fsr & FSR_LNX_PF) {
153 msg = "execution of memory";
154 } else {
155 if (is_translation_fault(fsr) &&
156 kfence_handle_page_fault(addr, is_write_fault(fsr), regs))
157 return;
158
159 msg = "paging request";
160 }
161
162 die_kernel_fault(msg, mm, addr, fsr, regs);
163 }
164
165 /*
166 * Something tried to access memory that isn't in our memory map..
167 * User mode accesses just cause a SIGSEGV. Ensure interrupts are enabled
168 * for preempt RT.
169 */
170 static void
__do_user_fault(unsigned long addr,unsigned int fsr,unsigned int sig,int code,struct pt_regs * regs)171 __do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig,
172 int code, struct pt_regs *regs)
173 {
174 struct task_struct *tsk = current;
175
176 local_irq_enable();
177
178 #ifdef CONFIG_DEBUG_USER
179 if (((user_debug & UDBG_SEGV) && (sig == SIGSEGV)) ||
180 ((user_debug & UDBG_BUS) && (sig == SIGBUS))) {
181 pr_err("8<--- cut here ---\n");
182 pr_err("%s: unhandled page fault (%d) at 0x%08lx, code 0x%03x\n",
183 tsk->comm, sig, addr, fsr);
184 if (likely(addr < TASK_SIZE)) {
185 mmap_write_lock(tsk->mm);
186 show_pte(KERN_ERR, tsk->mm, addr);
187 mmap_write_unlock(tsk->mm);
188 }
189 show_regs(regs);
190 }
191 #endif
192 #ifndef CONFIG_KUSER_HELPERS
193 if ((sig == SIGSEGV) && ((addr & PAGE_MASK) == 0xffff0000))
194 printk_ratelimited(KERN_DEBUG
195 "%s: CONFIG_KUSER_HELPERS disabled at 0x%08lx\n",
196 tsk->comm, addr);
197 #endif
198
199 tsk->thread.address = addr;
200 tsk->thread.error_code = fsr;
201 tsk->thread.trap_no = 14;
202 force_sig_fault(sig, code, (void __user *)addr);
203 }
204
do_bad_area(unsigned long addr,unsigned int fsr,struct pt_regs * regs)205 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
206 {
207 struct task_struct *tsk = current;
208 struct mm_struct *mm = tsk->active_mm;
209
210 /*
211 * If we are in kernel mode at this point, we
212 * have no context to handle this fault with.
213 */
214 if (user_mode(regs))
215 __do_user_fault(addr, fsr, SIGSEGV, SEGV_MAPERR, regs);
216 else
217 __do_kernel_fault(mm, addr, fsr, regs);
218 }
219
220 #ifdef CONFIG_MMU
221 #ifdef CONFIG_CPU_TTBR0_PAN
ttbr0_usermode_access_allowed(struct pt_regs * regs)222 static inline bool ttbr0_usermode_access_allowed(struct pt_regs *regs)
223 {
224 struct svc_pt_regs *svcregs;
225
226 /* If we are in user mode: permission granted */
227 if (user_mode(regs))
228 return true;
229
230 /* uaccess state saved above pt_regs on SVC exception entry */
231 svcregs = to_svc_pt_regs(regs);
232
233 return !(svcregs->ttbcr & TTBCR_EPD0);
234 }
235 #else
ttbr0_usermode_access_allowed(struct pt_regs * regs)236 static inline bool ttbr0_usermode_access_allowed(struct pt_regs *regs)
237 {
238 return true;
239 }
240 #endif
241
242 /*
243 * Handle a vmalloc fault, copying the non-leaf page table entries from
244 * init_mm.pgd. Any kernel context can trigger this, so we must not sleep
245 * or enable interrupts. Having two CPUs execute this for the same page is
246 * no problem, we'll just copy the same data twice.
247 *
248 * Returns false on failure.
249 */
vmalloc_fault(unsigned long addr)250 static bool __kprobes __maybe_unused vmalloc_fault(unsigned long addr)
251 {
252 unsigned int index;
253 pgd_t *pgd, *pgd_k;
254 p4d_t *p4d, *p4d_k;
255 pud_t *pud, *pud_k;
256 pmd_t *pmd, *pmd_k;
257
258 index = pgd_index(addr);
259
260 pgd = cpu_get_pgd() + index;
261 pgd_k = init_mm.pgd + index;
262
263 p4d = p4d_offset(pgd, addr);
264 p4d_k = p4d_offset(pgd_k, addr);
265
266 if (p4d_none(*p4d_k))
267 return false;
268 if (!p4d_present(*p4d))
269 set_p4d(p4d, *p4d_k);
270
271 pud = pud_offset(p4d, addr);
272 pud_k = pud_offset(p4d_k, addr);
273
274 if (pud_none(*pud_k))
275 return false;
276 if (!pud_present(*pud))
277 set_pud(pud, *pud_k);
278
279 pmd = pmd_offset(pud, addr);
280 pmd_k = pmd_offset(pud_k, addr);
281
282 #ifdef CONFIG_ARM_LPAE
283 /*
284 * Only one hardware entry per PMD with LPAE.
285 */
286 index = 0;
287 #else
288 /*
289 * On ARM one Linux PGD entry contains two hardware entries (see page
290 * tables layout in pgtable.h). We normally guarantee that we always
291 * fill both L1 entries. But create_mapping() doesn't follow the rule.
292 * It can create inidividual L1 entries, so here we have to call
293 * pmd_none() check for the entry really corresponded to address, not
294 * for the first of pair.
295 */
296 index = (addr >> SECTION_SHIFT) & 1;
297 #endif
298 if (pmd_none(pmd_k[index]))
299 return false;
300
301 copy_pmd(pmd, pmd_k);
302
303 return true;
304 }
305
306 static int __kprobes
do_kernel_address_page_fault(struct mm_struct * mm,unsigned long addr,unsigned int fsr,struct pt_regs * regs)307 do_kernel_address_page_fault(struct mm_struct *mm, unsigned long addr,
308 unsigned int fsr, struct pt_regs *regs)
309 {
310 if (user_mode(regs)) {
311 /*
312 * Fault from user mode for a kernel space address. User mode
313 * should not be faulting in kernel space, which includes the
314 * vector/khelper page. Handle the branch predictor hardening
315 * while interrupts are still disabled, then send a SIGSEGV.
316 * Note that __do_user_fault() will enable interrupts.
317 */
318 harden_branch_predictor();
319 __do_user_fault(addr, fsr, SIGSEGV, SEGV_MAPERR, regs);
320 } else {
321 /*
322 * Fault from kernel mode. Enable interrupts if they were
323 * enabled in the parent context. Section (upper page table)
324 * translation faults are handled via do_translation_fault(),
325 * so we will only get here for a non-present kernel space
326 * PTE or PTE permission fault. This may happen in exceptional
327 * circumstances and need the fixup tables to be walked.
328 */
329 if (interrupts_enabled(regs))
330 local_irq_enable();
331
332 __do_kernel_fault(mm, addr, fsr, regs);
333 }
334
335 return 0;
336 }
337
338 static int __kprobes
do_page_fault(unsigned long addr,unsigned int fsr,struct pt_regs * regs)339 do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
340 {
341 struct mm_struct *mm = current->mm;
342 struct vm_area_struct *vma;
343 int sig, code;
344 vm_fault_t fault;
345 unsigned int flags = FAULT_FLAG_DEFAULT;
346 vm_flags_t vm_flags = VM_ACCESS_FLAGS;
347
348 if (kprobe_page_fault(regs, fsr))
349 return 0;
350
351 /*
352 * Handle kernel addresses faults separately, which avoids touching
353 * the mmap lock from contexts that are not able to sleep.
354 */
355 if (addr >= TASK_SIZE)
356 return do_kernel_address_page_fault(mm, addr, fsr, regs);
357
358 /* Enable interrupts if they were enabled in the parent context. */
359 if (interrupts_enabled(regs))
360 local_irq_enable();
361
362 /*
363 * If we're in an interrupt or have no user
364 * context, we must not take the fault..
365 */
366 if (faulthandler_disabled() || !mm)
367 goto no_context;
368
369 if (user_mode(regs))
370 flags |= FAULT_FLAG_USER;
371
372 if (is_write_fault(fsr)) {
373 flags |= FAULT_FLAG_WRITE;
374 vm_flags = VM_WRITE;
375 }
376
377 if (fsr & FSR_LNX_PF) {
378 vm_flags = VM_EXEC;
379
380 if (is_permission_fault(fsr) && !user_mode(regs))
381 die_kernel_fault("execution of memory",
382 mm, addr, fsr, regs);
383 }
384
385 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
386
387 /*
388 * Privileged access aborts with CONFIG_CPU_TTBR0_PAN enabled are
389 * routed via the translation fault mechanism. Check whether uaccess
390 * is disabled while in kernel mode.
391 */
392 if (!ttbr0_usermode_access_allowed(regs))
393 goto no_context;
394
395 if (!(flags & FAULT_FLAG_USER))
396 goto lock_mmap;
397
398 vma = lock_vma_under_rcu(mm, addr);
399 if (!vma)
400 goto lock_mmap;
401
402 if (!(vma->vm_flags & vm_flags)) {
403 vma_end_read(vma);
404 count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
405 fault = 0;
406 code = SEGV_ACCERR;
407 goto bad_area;
408 }
409 fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
410 if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
411 vma_end_read(vma);
412
413 if (!(fault & VM_FAULT_RETRY)) {
414 count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
415 goto done;
416 }
417 count_vm_vma_lock_event(VMA_LOCK_RETRY);
418 if (fault & VM_FAULT_MAJOR)
419 flags |= FAULT_FLAG_TRIED;
420
421 /* Quick path to respond to signals */
422 if (fault_signal_pending(fault, regs)) {
423 if (!user_mode(regs))
424 goto no_context;
425 return 0;
426 }
427 lock_mmap:
428
429 retry:
430 vma = lock_mm_and_find_vma(mm, addr, regs);
431 if (unlikely(!vma)) {
432 fault = 0;
433 code = SEGV_MAPERR;
434 goto bad_area;
435 }
436
437 /*
438 * ok, we have a good vm_area for this memory access, check the
439 * permissions on the VMA allow for the fault which occurred.
440 */
441 if (!(vma->vm_flags & vm_flags)) {
442 mmap_read_unlock(mm);
443 fault = 0;
444 code = SEGV_ACCERR;
445 goto bad_area;
446 }
447
448 fault = handle_mm_fault(vma, addr & PAGE_MASK, flags, regs);
449
450 /* If we need to retry but a fatal signal is pending, handle the
451 * signal first. We do not need to release the mmap_lock because
452 * it would already be released in __lock_page_or_retry in
453 * mm/filemap.c. */
454 if (fault_signal_pending(fault, regs)) {
455 if (!user_mode(regs))
456 goto no_context;
457 return 0;
458 }
459
460 /* The fault is fully completed (including releasing mmap lock) */
461 if (fault & VM_FAULT_COMPLETED)
462 return 0;
463
464 if (!(fault & VM_FAULT_ERROR)) {
465 if (fault & VM_FAULT_RETRY) {
466 flags |= FAULT_FLAG_TRIED;
467 goto retry;
468 }
469 }
470
471 mmap_read_unlock(mm);
472 done:
473
474 /* Handle the "normal" case first */
475 if (likely(!(fault & VM_FAULT_ERROR)))
476 return 0;
477
478 code = SEGV_MAPERR;
479 bad_area:
480 /*
481 * If we are in kernel mode at this point, we
482 * have no context to handle this fault with.
483 */
484 if (!user_mode(regs))
485 goto no_context;
486
487 if (fault & VM_FAULT_OOM) {
488 /*
489 * We ran out of memory, call the OOM killer, and return to
490 * userspace (which will retry the fault, or kill us if we
491 * got oom-killed)
492 */
493 pagefault_out_of_memory();
494 return 0;
495 }
496
497 if (fault & VM_FAULT_SIGBUS) {
498 /*
499 * We had some memory, but were unable to
500 * successfully fix up this page fault.
501 */
502 sig = SIGBUS;
503 code = BUS_ADRERR;
504 } else {
505 /*
506 * Something tried to access memory that
507 * isn't in our memory map..
508 */
509 sig = SIGSEGV;
510 }
511
512 __do_user_fault(addr, fsr, sig, code, regs);
513 return 0;
514
515 no_context:
516 __do_kernel_fault(mm, addr, fsr, regs);
517 return 0;
518 }
519 #else /* CONFIG_MMU */
520 static int
do_page_fault(unsigned long addr,unsigned int fsr,struct pt_regs * regs)521 do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
522 {
523 return 0;
524 }
525 #endif /* CONFIG_MMU */
526
527 /*
528 * First Level Translation Fault Handler
529 *
530 * We enter here because the first level page table doesn't contain
531 * a valid entry for the address.
532 *
533 * If this is a user address (addr < TASK_SIZE), we handle this as a
534 * normal page fault. This leaves the remainder of the function to handle
535 * kernel address translation faults.
536 *
537 * Since user mode is not permitted to access kernel addresses, pass these
538 * directly to do_kernel_address_page_fault() to handle.
539 *
540 * Otherwise, we're probably faulting in the vmalloc() area, so try to fix
541 * that up via vmalloc_fault().
542 *
543 * If vmalloc_fault() fails, that means the non-leaf page tables did not
544 * contain an entry for this address, so handle this via
545 * do_kernel_address_page_fault().
546 */
547 #ifdef CONFIG_MMU
548 static int __kprobes
do_translation_fault(unsigned long addr,unsigned int fsr,struct pt_regs * regs)549 do_translation_fault(unsigned long addr, unsigned int fsr,
550 struct pt_regs *regs)
551 {
552 if (addr < TASK_SIZE)
553 return do_page_fault(addr, fsr, regs);
554
555 if (!user_mode(regs) && vmalloc_fault(addr))
556 return 0;
557
558 do_kernel_address_page_fault(current->mm, addr, fsr, regs);
559
560 return 0;
561 }
562 #else /* CONFIG_MMU */
563 static int
do_translation_fault(unsigned long addr,unsigned int fsr,struct pt_regs * regs)564 do_translation_fault(unsigned long addr, unsigned int fsr,
565 struct pt_regs *regs)
566 {
567 return 0;
568 }
569 #endif /* CONFIG_MMU */
570
571 /*
572 * Some section permission faults need to be handled gracefully.
573 * They can happen due to a __{get,put}_user during an oops.
574 */
575 #ifndef CONFIG_ARM_LPAE
576 static int
do_sect_fault(unsigned long addr,unsigned int fsr,struct pt_regs * regs)577 do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
578 {
579 /*
580 * If this is a kernel address, but from user mode, then userspace
581 * is trying bad stuff. Invoke the branch predictor handling.
582 * Interrupts are disabled here.
583 */
584 if (addr >= TASK_SIZE && user_mode(regs))
585 harden_branch_predictor();
586
587 do_bad_area(addr, fsr, regs);
588
589 return 0;
590 }
591 #endif /* CONFIG_ARM_LPAE */
592
593 /*
594 * This abort handler always returns "fault".
595 */
596 static int
do_bad(unsigned long addr,unsigned int fsr,struct pt_regs * regs)597 do_bad(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
598 {
599 return 1;
600 }
601
602 struct fsr_info {
603 int (*fn)(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
604 int sig;
605 int code;
606 const char *name;
607 };
608
609 /* FSR definition */
610 #ifdef CONFIG_ARM_LPAE
611 #include "fsr-3level.c"
612 #else
613 #include "fsr-2level.c"
614 #endif
615
616 void __init
hook_fault_code(int nr,int (* fn)(unsigned long,unsigned int,struct pt_regs *),int sig,int code,const char * name)617 hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *),
618 int sig, int code, const char *name)
619 {
620 if (nr < 0 || nr >= ARRAY_SIZE(fsr_info))
621 BUG();
622
623 fsr_info[nr].fn = fn;
624 fsr_info[nr].sig = sig;
625 fsr_info[nr].code = code;
626 fsr_info[nr].name = name;
627 }
628
629 /*
630 * Dispatch a data abort to the relevant handler.
631 */
632 asmlinkage void
do_DataAbort(unsigned long addr,unsigned int fsr,struct pt_regs * regs)633 do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
634 {
635 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
636
637 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
638 return;
639
640 if (likely(user_mode(regs)))
641 local_irq_enable();
642
643 pr_alert("8<--- cut here ---\n");
644 pr_alert("Unhandled fault: %s (0x%03x) at 0x%08lx\n",
645 inf->name, fsr, addr);
646 if (likely(user_mode(regs))) {
647 if (addr < TASK_SIZE) {
648 mmap_write_lock(current->mm);
649 show_pte(KERN_ALERT, current->mm, addr);
650 mmap_write_unlock(current->mm);
651 }
652 } else {
653 show_pte(KERN_ALERT, current->mm, addr);
654 }
655
656 arm_notify_die("", regs, inf->sig, inf->code, (void __user *)addr,
657 fsr, 0);
658 }
659
660 void __init
hook_ifault_code(int nr,int (* fn)(unsigned long,unsigned int,struct pt_regs *),int sig,int code,const char * name)661 hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *),
662 int sig, int code, const char *name)
663 {
664 if (nr < 0 || nr >= ARRAY_SIZE(ifsr_info))
665 BUG();
666
667 ifsr_info[nr].fn = fn;
668 ifsr_info[nr].sig = sig;
669 ifsr_info[nr].code = code;
670 ifsr_info[nr].name = name;
671 }
672
673 asmlinkage void
do_PrefetchAbort(unsigned long addr,unsigned int ifsr,struct pt_regs * regs)674 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
675 {
676 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
677
678 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
679 return;
680
681 if (likely(user_mode(regs)))
682 local_irq_enable();
683
684 pr_alert("8<--- cut here ---\n");
685 pr_alert("Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
686 inf->name, ifsr, addr);
687
688 arm_notify_die("", regs, inf->sig, inf->code, (void __user *)addr,
689 ifsr, 0);
690 }
691
692 /*
693 * Abort handler to be used only during first unmasking of asynchronous aborts
694 * on the boot CPU. This makes sure that the machine will not die if the
695 * firmware/bootloader left an imprecise abort pending for us to trip over.
696 */
early_abort_handler(unsigned long addr,unsigned int fsr,struct pt_regs * regs)697 static int __init early_abort_handler(unsigned long addr, unsigned int fsr,
698 struct pt_regs *regs)
699 {
700 pr_warn("Hit pending asynchronous external abort (FSR=0x%08x) during "
701 "first unmask, this is most likely caused by a "
702 "firmware/bootloader bug.\n", fsr);
703
704 return 0;
705 }
706
early_abt_enable(void)707 void __init early_abt_enable(void)
708 {
709 fsr_info[FSR_FS_AEA].fn = early_abort_handler;
710 local_abt_enable();
711 fsr_info[FSR_FS_AEA].fn = do_bad;
712 }
713
714 #ifndef CONFIG_ARM_LPAE
exceptions_init(void)715 static int __init exceptions_init(void)
716 {
717 if (cpu_architecture() >= CPU_ARCH_ARMv6) {
718 hook_fault_code(4, do_translation_fault, SIGSEGV, SEGV_MAPERR,
719 "I-cache maintenance fault");
720 }
721
722 if (cpu_architecture() >= CPU_ARCH_ARMv7) {
723 /*
724 * TODO: Access flag faults introduced in ARMv6K.
725 * Runtime check for 'K' extension is needed
726 */
727 hook_fault_code(3, do_bad, SIGSEGV, SEGV_MAPERR,
728 "section access flag fault");
729 hook_fault_code(6, do_bad, SIGSEGV, SEGV_MAPERR,
730 "section access flag fault");
731 }
732
733 return 0;
734 }
735
736 arch_initcall(exceptions_init);
737 #endif
738