fault.c 17 KB

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