fault.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Derived from "arch/i386/mm/fault.c"
  6. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  7. *
  8. * Modified by Cort Dougan and Paul Mackerras.
  9. *
  10. * Modified for PPC64 by Dave Engebretsen (engebret@ibm.com)
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #include <linux/signal.h>
  18. #include <linux/sched.h>
  19. #include <linux/sched/task_stack.h>
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/string.h>
  23. #include <linux/types.h>
  24. #include <linux/pagemap.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/mman.h>
  27. #include <linux/mm.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/highmem.h>
  30. #include <linux/extable.h>
  31. #include <linux/kprobes.h>
  32. #include <linux/kdebug.h>
  33. #include <linux/perf_event.h>
  34. #include <linux/ratelimit.h>
  35. #include <linux/context_tracking.h>
  36. #include <linux/hugetlb.h>
  37. #include <linux/uaccess.h>
  38. #include <asm/firmware.h>
  39. #include <asm/page.h>
  40. #include <asm/pgtable.h>
  41. #include <asm/mmu.h>
  42. #include <asm/mmu_context.h>
  43. #include <asm/tlbflush.h>
  44. #include <asm/siginfo.h>
  45. #include <asm/debug.h>
  46. static inline bool notify_page_fault(struct pt_regs *regs)
  47. {
  48. bool ret = false;
  49. #ifdef CONFIG_KPROBES
  50. /* kprobe_running() needs smp_processor_id() */
  51. if (!user_mode(regs)) {
  52. preempt_disable();
  53. if (kprobe_running() && kprobe_fault_handler(regs, 11))
  54. ret = true;
  55. preempt_enable();
  56. }
  57. #endif /* CONFIG_KPROBES */
  58. if (unlikely(debugger_fault_handler(regs)))
  59. ret = true;
  60. return ret;
  61. }
  62. /*
  63. * Check whether the instruction inst is a store using
  64. * an update addressing form which will update r1.
  65. */
  66. static bool store_updates_sp(unsigned int inst)
  67. {
  68. /* check for 1 in the rA field */
  69. if (((inst >> 16) & 0x1f) != 1)
  70. return false;
  71. /* check major opcode */
  72. switch (inst >> 26) {
  73. case OP_STWU:
  74. case OP_STBU:
  75. case OP_STHU:
  76. case OP_STFSU:
  77. case OP_STFDU:
  78. return true;
  79. case OP_STD: /* std or stdu */
  80. return (inst & 3) == 1;
  81. case OP_31:
  82. /* check minor opcode */
  83. switch ((inst >> 1) & 0x3ff) {
  84. case OP_31_XOP_STDUX:
  85. case OP_31_XOP_STWUX:
  86. case OP_31_XOP_STBUX:
  87. case OP_31_XOP_STHUX:
  88. case OP_31_XOP_STFSUX:
  89. case OP_31_XOP_STFDUX:
  90. return true;
  91. }
  92. }
  93. return false;
  94. }
  95. /*
  96. * do_page_fault error handling helpers
  97. */
  98. static int
  99. __bad_area_nosemaphore(struct pt_regs *regs, unsigned long address, int si_code,
  100. int pkey)
  101. {
  102. /*
  103. * If we are in kernel mode, bail out with a SEGV, this will
  104. * be caught by the assembly which will restore the non-volatile
  105. * registers before calling bad_page_fault()
  106. */
  107. if (!user_mode(regs))
  108. return SIGSEGV;
  109. _exception_pkey(SIGSEGV, regs, si_code, address, pkey);
  110. return 0;
  111. }
  112. static noinline int bad_area_nosemaphore(struct pt_regs *regs, unsigned long address)
  113. {
  114. return __bad_area_nosemaphore(regs, address, SEGV_MAPERR, 0);
  115. }
  116. static int __bad_area(struct pt_regs *regs, unsigned long address, int si_code,
  117. int pkey)
  118. {
  119. struct mm_struct *mm = current->mm;
  120. /*
  121. * Something tried to access memory that isn't in our memory map..
  122. * Fix it, but check if it's kernel or user first..
  123. */
  124. up_read(&mm->mmap_sem);
  125. return __bad_area_nosemaphore(regs, address, si_code, pkey);
  126. }
  127. static noinline int bad_area(struct pt_regs *regs, unsigned long address)
  128. {
  129. return __bad_area(regs, address, SEGV_MAPERR, 0);
  130. }
  131. static int bad_key_fault_exception(struct pt_regs *regs, unsigned long address,
  132. int pkey)
  133. {
  134. return __bad_area_nosemaphore(regs, address, SEGV_PKUERR, pkey);
  135. }
  136. static noinline int bad_access(struct pt_regs *regs, unsigned long address)
  137. {
  138. return __bad_area(regs, address, SEGV_ACCERR, 0);
  139. }
  140. static int do_sigbus(struct pt_regs *regs, unsigned long address,
  141. unsigned int fault)
  142. {
  143. siginfo_t info;
  144. unsigned int lsb = 0;
  145. if (!user_mode(regs))
  146. return SIGBUS;
  147. current->thread.trap_nr = BUS_ADRERR;
  148. clear_siginfo(&info);
  149. info.si_signo = SIGBUS;
  150. info.si_errno = 0;
  151. info.si_code = BUS_ADRERR;
  152. info.si_addr = (void __user *)address;
  153. #ifdef CONFIG_MEMORY_FAILURE
  154. if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
  155. pr_err("MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
  156. current->comm, current->pid, address);
  157. info.si_code = BUS_MCEERR_AR;
  158. }
  159. if (fault & VM_FAULT_HWPOISON_LARGE)
  160. lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
  161. if (fault & VM_FAULT_HWPOISON)
  162. lsb = PAGE_SHIFT;
  163. #endif
  164. info.si_addr_lsb = lsb;
  165. force_sig_info(SIGBUS, &info, current);
  166. return 0;
  167. }
  168. static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault)
  169. {
  170. /*
  171. * Kernel page fault interrupted by SIGKILL. We have no reason to
  172. * continue processing.
  173. */
  174. if (fatal_signal_pending(current) && !user_mode(regs))
  175. return SIGKILL;
  176. /* Out of memory */
  177. if (fault & VM_FAULT_OOM) {
  178. /*
  179. * We ran out of memory, or some other thing happened to us that
  180. * made us unable to handle the page fault gracefully.
  181. */
  182. if (!user_mode(regs))
  183. return SIGSEGV;
  184. pagefault_out_of_memory();
  185. } else {
  186. if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|
  187. VM_FAULT_HWPOISON_LARGE))
  188. return do_sigbus(regs, addr, fault);
  189. else if (fault & VM_FAULT_SIGSEGV)
  190. return bad_area_nosemaphore(regs, addr);
  191. else
  192. BUG();
  193. }
  194. return 0;
  195. }
  196. /* Is this a bad kernel fault ? */
  197. static bool bad_kernel_fault(bool is_exec, unsigned long error_code,
  198. unsigned long address)
  199. {
  200. if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT))) {
  201. printk_ratelimited(KERN_CRIT "kernel tried to execute"
  202. " exec-protected page (%lx) -"
  203. "exploit attempt? (uid: %d)\n",
  204. address, from_kuid(&init_user_ns,
  205. current_uid()));
  206. }
  207. return is_exec || (address >= TASK_SIZE);
  208. }
  209. static bool bad_stack_expansion(struct pt_regs *regs, unsigned long address,
  210. struct vm_area_struct *vma, unsigned int flags,
  211. bool *must_retry)
  212. {
  213. /*
  214. * N.B. The POWER/Open ABI allows programs to access up to
  215. * 288 bytes below the stack pointer.
  216. * The kernel signal delivery code writes up to about 1.5kB
  217. * below the stack pointer (r1) before decrementing it.
  218. * The exec code can write slightly over 640kB to the stack
  219. * before setting the user r1. Thus we allow the stack to
  220. * expand to 1MB without further checks.
  221. */
  222. if (address + 0x100000 < vma->vm_end) {
  223. unsigned int __user *nip = (unsigned int __user *)regs->nip;
  224. /* get user regs even if this fault is in kernel mode */
  225. struct pt_regs *uregs = current->thread.regs;
  226. if (uregs == NULL)
  227. return true;
  228. /*
  229. * A user-mode access to an address a long way below
  230. * the stack pointer is only valid if the instruction
  231. * is one which would update the stack pointer to the
  232. * address accessed if the instruction completed,
  233. * i.e. either stwu rs,n(r1) or stwux rs,r1,rb
  234. * (or the byte, halfword, float or double forms).
  235. *
  236. * If we don't check this then any write to the area
  237. * between the last mapped region and the stack will
  238. * expand the stack rather than segfaulting.
  239. */
  240. if (address + 2048 >= uregs->gpr[1])
  241. return false;
  242. if ((flags & FAULT_FLAG_WRITE) && (flags & FAULT_FLAG_USER) &&
  243. access_ok(VERIFY_READ, nip, sizeof(*nip))) {
  244. unsigned int inst;
  245. int res;
  246. pagefault_disable();
  247. res = __get_user_inatomic(inst, nip);
  248. pagefault_enable();
  249. if (!res)
  250. return !store_updates_sp(inst);
  251. *must_retry = true;
  252. }
  253. return true;
  254. }
  255. return false;
  256. }
  257. static bool access_error(bool is_write, bool is_exec,
  258. struct vm_area_struct *vma)
  259. {
  260. /*
  261. * Allow execution from readable areas if the MMU does not
  262. * provide separate controls over reading and executing.
  263. *
  264. * Note: That code used to not be enabled for 4xx/BookE.
  265. * It is now as I/D cache coherency for these is done at
  266. * set_pte_at() time and I see no reason why the test
  267. * below wouldn't be valid on those processors. This -may-
  268. * break programs compiled with a really old ABI though.
  269. */
  270. if (is_exec) {
  271. return !(vma->vm_flags & VM_EXEC) &&
  272. (cpu_has_feature(CPU_FTR_NOEXECUTE) ||
  273. !(vma->vm_flags & (VM_READ | VM_WRITE)));
  274. }
  275. if (is_write) {
  276. if (unlikely(!(vma->vm_flags & VM_WRITE)))
  277. return true;
  278. return false;
  279. }
  280. if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
  281. return true;
  282. /*
  283. * We should ideally do the vma pkey access check here. But in the
  284. * fault path, handle_mm_fault() also does the same check. To avoid
  285. * these multiple checks, we skip it here and handle access error due
  286. * to pkeys later.
  287. */
  288. return false;
  289. }
  290. #ifdef CONFIG_PPC_SMLPAR
  291. static inline void cmo_account_page_fault(void)
  292. {
  293. if (firmware_has_feature(FW_FEATURE_CMO)) {
  294. u32 page_ins;
  295. preempt_disable();
  296. page_ins = be32_to_cpu(get_lppaca()->page_ins);
  297. page_ins += 1 << PAGE_FACTOR;
  298. get_lppaca()->page_ins = cpu_to_be32(page_ins);
  299. preempt_enable();
  300. }
  301. }
  302. #else
  303. static inline void cmo_account_page_fault(void) { }
  304. #endif /* CONFIG_PPC_SMLPAR */
  305. #ifdef CONFIG_PPC_STD_MMU
  306. static void sanity_check_fault(bool is_write, unsigned long error_code)
  307. {
  308. /*
  309. * For hash translation mode, we should never get a
  310. * PROTFAULT. Any update to pte to reduce access will result in us
  311. * removing the hash page table entry, thus resulting in a DSISR_NOHPTE
  312. * fault instead of DSISR_PROTFAULT.
  313. *
  314. * A pte update to relax the access will not result in a hash page table
  315. * entry invalidate and hence can result in DSISR_PROTFAULT.
  316. * ptep_set_access_flags() doesn't do a hpte flush. This is why we have
  317. * the special !is_write in the below conditional.
  318. *
  319. * For platforms that doesn't supports coherent icache and do support
  320. * per page noexec bit, we do setup things such that we do the
  321. * sync between D/I cache via fault. But that is handled via low level
  322. * hash fault code (hash_page_do_lazy_icache()) and we should not reach
  323. * here in such case.
  324. *
  325. * For wrong access that can result in PROTFAULT, the above vma->vm_flags
  326. * check should handle those and hence we should fall to the bad_area
  327. * handling correctly.
  328. *
  329. * For embedded with per page exec support that doesn't support coherent
  330. * icache we do get PROTFAULT and we handle that D/I cache sync in
  331. * set_pte_at while taking the noexec/prot fault. Hence this is WARN_ON
  332. * is conditional for server MMU.
  333. *
  334. * For radix, we can get prot fault for autonuma case, because radix
  335. * page table will have them marked noaccess for user.
  336. */
  337. if (!radix_enabled() && !is_write)
  338. WARN_ON_ONCE(error_code & DSISR_PROTFAULT);
  339. }
  340. #else
  341. static void sanity_check_fault(bool is_write, unsigned long error_code) { }
  342. #endif /* CONFIG_PPC_STD_MMU */
  343. /*
  344. * Define the correct "is_write" bit in error_code based
  345. * on the processor family
  346. */
  347. #if (defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  348. #define page_fault_is_write(__err) ((__err) & ESR_DST)
  349. #define page_fault_is_bad(__err) (0)
  350. #else
  351. #define page_fault_is_write(__err) ((__err) & DSISR_ISSTORE)
  352. #if defined(CONFIG_PPC_8xx)
  353. #define page_fault_is_bad(__err) ((__err) & DSISR_NOEXEC_OR_G)
  354. #elif defined(CONFIG_PPC64)
  355. #define page_fault_is_bad(__err) ((__err) & DSISR_BAD_FAULT_64S)
  356. #else
  357. #define page_fault_is_bad(__err) ((__err) & DSISR_BAD_FAULT_32S)
  358. #endif
  359. #endif
  360. /*
  361. * For 600- and 800-family processors, the error_code parameter is DSISR
  362. * for a data fault, SRR1 for an instruction fault. For 400-family processors
  363. * the error_code parameter is ESR for a data fault, 0 for an instruction
  364. * fault.
  365. * For 64-bit processors, the error_code parameter is
  366. * - DSISR for a non-SLB data access fault,
  367. * - SRR1 & 0x08000000 for a non-SLB instruction access fault
  368. * - 0 any SLB fault.
  369. *
  370. * The return value is 0 if the fault was handled, or the signal
  371. * number if this is a kernel fault that can't be handled here.
  372. */
  373. static int __do_page_fault(struct pt_regs *regs, unsigned long address,
  374. unsigned long error_code)
  375. {
  376. struct vm_area_struct * vma;
  377. struct mm_struct *mm = current->mm;
  378. unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
  379. int is_exec = TRAP(regs) == 0x400;
  380. int is_user = user_mode(regs);
  381. int is_write = page_fault_is_write(error_code);
  382. int fault, major = 0;
  383. bool must_retry = false;
  384. if (notify_page_fault(regs))
  385. return 0;
  386. if (unlikely(page_fault_is_bad(error_code))) {
  387. if (is_user) {
  388. _exception(SIGBUS, regs, BUS_OBJERR, address);
  389. return 0;
  390. }
  391. return SIGBUS;
  392. }
  393. /* Additional sanity check(s) */
  394. sanity_check_fault(is_write, error_code);
  395. /*
  396. * The kernel should never take an execute fault nor should it
  397. * take a page fault to a kernel address.
  398. */
  399. if (unlikely(!is_user && bad_kernel_fault(is_exec, error_code, address)))
  400. return SIGSEGV;
  401. /*
  402. * If we're in an interrupt, have no user context or are running
  403. * in a region with pagefaults disabled then we must not take the fault
  404. */
  405. if (unlikely(faulthandler_disabled() || !mm)) {
  406. if (is_user)
  407. printk_ratelimited(KERN_ERR "Page fault in user mode"
  408. " with faulthandler_disabled()=%d"
  409. " mm=%p\n",
  410. faulthandler_disabled(), mm);
  411. return bad_area_nosemaphore(regs, address);
  412. }
  413. /* We restore the interrupt state now */
  414. if (!arch_irq_disabled_regs(regs))
  415. local_irq_enable();
  416. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
  417. if (error_code & DSISR_KEYFAULT)
  418. return bad_key_fault_exception(regs, address,
  419. get_mm_addr_key(mm, address));
  420. /*
  421. * We want to do this outside mmap_sem, because reading code around nip
  422. * can result in fault, which will cause a deadlock when called with
  423. * mmap_sem held
  424. */
  425. if (is_user)
  426. flags |= FAULT_FLAG_USER;
  427. if (is_write)
  428. flags |= FAULT_FLAG_WRITE;
  429. if (is_exec)
  430. flags |= FAULT_FLAG_INSTRUCTION;
  431. /* When running in the kernel we expect faults to occur only to
  432. * addresses in user space. All other faults represent errors in the
  433. * kernel and should generate an OOPS. Unfortunately, in the case of an
  434. * erroneous fault occurring in a code path which already holds mmap_sem
  435. * we will deadlock attempting to validate the fault against the
  436. * address space. Luckily the kernel only validly references user
  437. * space from well defined areas of code, which are listed in the
  438. * exceptions table.
  439. *
  440. * As the vast majority of faults will be valid we will only perform
  441. * the source reference check when there is a possibility of a deadlock.
  442. * Attempt to lock the address space, if we cannot we then validate the
  443. * source. If this is invalid we can skip the address space check,
  444. * thus avoiding the deadlock.
  445. */
  446. if (unlikely(!down_read_trylock(&mm->mmap_sem))) {
  447. if (!is_user && !search_exception_tables(regs->nip))
  448. return bad_area_nosemaphore(regs, address);
  449. retry:
  450. down_read(&mm->mmap_sem);
  451. } else {
  452. /*
  453. * The above down_read_trylock() might have succeeded in
  454. * which case we'll have missed the might_sleep() from
  455. * down_read():
  456. */
  457. might_sleep();
  458. }
  459. vma = find_vma(mm, address);
  460. if (unlikely(!vma))
  461. return bad_area(regs, address);
  462. if (likely(vma->vm_start <= address))
  463. goto good_area;
  464. if (unlikely(!(vma->vm_flags & VM_GROWSDOWN)))
  465. return bad_area(regs, address);
  466. /* The stack is being expanded, check if it's valid */
  467. if (unlikely(bad_stack_expansion(regs, address, vma, flags,
  468. &must_retry))) {
  469. if (!must_retry)
  470. return bad_area(regs, address);
  471. up_read(&mm->mmap_sem);
  472. if (fault_in_pages_readable((const char __user *)regs->nip,
  473. sizeof(unsigned int)))
  474. return bad_area_nosemaphore(regs, address);
  475. goto retry;
  476. }
  477. /* Try to expand it */
  478. if (unlikely(expand_stack(vma, address)))
  479. return bad_area(regs, address);
  480. good_area:
  481. if (unlikely(access_error(is_write, is_exec, vma)))
  482. return bad_access(regs, address);
  483. /*
  484. * If for any reason at all we couldn't handle the fault,
  485. * make sure we exit gracefully rather than endlessly redo
  486. * the fault.
  487. */
  488. fault = handle_mm_fault(vma, address, flags);
  489. #ifdef CONFIG_PPC_MEM_KEYS
  490. /*
  491. * we skipped checking for access error due to key earlier.
  492. * Check that using handle_mm_fault error return.
  493. */
  494. if (unlikely(fault & VM_FAULT_SIGSEGV) &&
  495. !arch_vma_access_permitted(vma, is_write, is_exec, 0)) {
  496. int pkey = vma_pkey(vma);
  497. up_read(&mm->mmap_sem);
  498. return bad_key_fault_exception(regs, address, pkey);
  499. }
  500. #endif /* CONFIG_PPC_MEM_KEYS */
  501. major |= fault & VM_FAULT_MAJOR;
  502. /*
  503. * Handle the retry right now, the mmap_sem has been released in that
  504. * case.
  505. */
  506. if (unlikely(fault & VM_FAULT_RETRY)) {
  507. /* We retry only once */
  508. if (flags & FAULT_FLAG_ALLOW_RETRY) {
  509. /*
  510. * Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
  511. * of starvation.
  512. */
  513. flags &= ~FAULT_FLAG_ALLOW_RETRY;
  514. flags |= FAULT_FLAG_TRIED;
  515. if (!fatal_signal_pending(current))
  516. goto retry;
  517. }
  518. /*
  519. * User mode? Just return to handle the fatal exception otherwise
  520. * return to bad_page_fault
  521. */
  522. return is_user ? 0 : SIGBUS;
  523. }
  524. up_read(&current->mm->mmap_sem);
  525. if (unlikely(fault & VM_FAULT_ERROR))
  526. return mm_fault_error(regs, address, fault);
  527. /*
  528. * Major/minor page fault accounting.
  529. */
  530. if (major) {
  531. current->maj_flt++;
  532. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, address);
  533. cmo_account_page_fault();
  534. } else {
  535. current->min_flt++;
  536. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, address);
  537. }
  538. return 0;
  539. }
  540. NOKPROBE_SYMBOL(__do_page_fault);
  541. int do_page_fault(struct pt_regs *regs, unsigned long address,
  542. unsigned long error_code)
  543. {
  544. enum ctx_state prev_state = exception_enter();
  545. int rc = __do_page_fault(regs, address, error_code);
  546. exception_exit(prev_state);
  547. return rc;
  548. }
  549. NOKPROBE_SYMBOL(do_page_fault);
  550. /*
  551. * bad_page_fault is called when we have a bad access from the kernel.
  552. * It is called from the DSI and ISI handlers in head.S and from some
  553. * of the procedures in traps.c.
  554. */
  555. void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
  556. {
  557. const struct exception_table_entry *entry;
  558. /* Are we prepared to handle this fault? */
  559. if ((entry = search_exception_tables(regs->nip)) != NULL) {
  560. regs->nip = extable_fixup(entry);
  561. return;
  562. }
  563. /* kernel has accessed a bad area */
  564. switch (TRAP(regs)) {
  565. case 0x300:
  566. case 0x380:
  567. printk(KERN_ALERT "Unable to handle kernel paging request for "
  568. "data at address 0x%08lx\n", regs->dar);
  569. break;
  570. case 0x400:
  571. case 0x480:
  572. printk(KERN_ALERT "Unable to handle kernel paging request for "
  573. "instruction fetch\n");
  574. break;
  575. case 0x600:
  576. printk(KERN_ALERT "Unable to handle kernel paging request for "
  577. "unaligned access at address 0x%08lx\n", regs->dar);
  578. break;
  579. default:
  580. printk(KERN_ALERT "Unable to handle kernel paging request for "
  581. "unknown fault\n");
  582. break;
  583. }
  584. printk(KERN_ALERT "Faulting instruction address: 0x%08lx\n",
  585. regs->nip);
  586. if (task_stack_end_corrupted(current))
  587. printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");
  588. die("Kernel access of bad area", regs, sig);
  589. }