fault.c 17 KB

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