fault.c 18 KB

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