traps.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/parisc/traps.c
  4. *
  5. * Copyright (C) 1991, 1992 Linus Torvalds
  6. * Copyright (C) 1999, 2000 Philipp Rumpf <prumpf@tux.org>
  7. */
  8. /*
  9. * 'Traps.c' handles hardware traps and faults after we have saved some
  10. * state in 'asm.s'.
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/sched/debug.h>
  14. #include <linux/kernel.h>
  15. #include <linux/string.h>
  16. #include <linux/errno.h>
  17. #include <linux/ptrace.h>
  18. #include <linux/timer.h>
  19. #include <linux/delay.h>
  20. #include <linux/mm.h>
  21. #include <linux/module.h>
  22. #include <linux/smp.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/console.h>
  27. #include <linux/bug.h>
  28. #include <linux/ratelimit.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/kdebug.h>
  31. #include <linux/kfence.h>
  32. #include <asm/assembly.h>
  33. #include <asm/io.h>
  34. #include <asm/irq.h>
  35. #include <asm/traps.h>
  36. #include <linux/unaligned.h>
  37. #include <linux/atomic.h>
  38. #include <asm/smp.h>
  39. #include <asm/pdc.h>
  40. #include <asm/pdc_chassis.h>
  41. #include <asm/unwind.h>
  42. #include <asm/tlbflush.h>
  43. #include <asm/cacheflush.h>
  44. #include <linux/kgdb.h>
  45. #include <linux/kprobes.h>
  46. #include "unaligned.h"
  47. #if defined(CONFIG_LIGHTWEIGHT_SPINLOCK_CHECK)
  48. #include <asm/spinlock.h>
  49. #endif
  50. #include "../math-emu/math-emu.h" /* for handle_fpe() */
  51. static void parisc_show_stack(struct task_struct *task,
  52. struct pt_regs *regs, const char *loglvl);
  53. static int printbinary(char *buf, unsigned long x, int nbits)
  54. {
  55. unsigned long mask = 1UL << (nbits - 1);
  56. while (mask != 0) {
  57. *buf++ = (mask & x ? '1' : '0');
  58. mask >>= 1;
  59. }
  60. *buf = '\0';
  61. return nbits;
  62. }
  63. #ifdef CONFIG_64BIT
  64. #define RFMT "%016lx"
  65. #else
  66. #define RFMT "%08lx"
  67. #endif
  68. #define FFMT "%016llx" /* fpregs are 64-bit always */
  69. #define PRINTREGS(lvl,r,f,fmt,x) \
  70. printk("%s%s%02d-%02d " fmt " " fmt " " fmt " " fmt "\n", \
  71. lvl, f, (x), (x+3), (r)[(x)+0], (r)[(x)+1], \
  72. (r)[(x)+2], (r)[(x)+3])
  73. static void print_gr(const char *level, struct pt_regs *regs)
  74. {
  75. int i;
  76. char buf[64];
  77. printk("%s\n", level);
  78. printk("%s YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI\n", level);
  79. printbinary(buf, regs->gr[0], 32);
  80. printk("%sPSW: %s %s\n", level, buf, print_tainted());
  81. for (i = 0; i < 32; i += 4)
  82. PRINTREGS(level, regs->gr, "r", RFMT, i);
  83. }
  84. static void print_fr(const char *level, struct pt_regs *regs)
  85. {
  86. int i;
  87. char buf[64];
  88. struct { u32 sw[2]; } s;
  89. /* FR are 64bit everywhere. Need to use asm to get the content
  90. * of fpsr/fper1, and we assume that we won't have a FP Identify
  91. * in our way, otherwise we're screwed.
  92. * The fldd is used to restore the T-bit if there was one, as the
  93. * store clears it anyway.
  94. * PA2.0 book says "thou shall not use fstw on FPSR/FPERs" - T-Bone */
  95. asm volatile ("fstd %%fr0,0(%1) \n\t"
  96. "fldd 0(%1),%%fr0 \n\t"
  97. : "=m" (s) : "r" (&s) : "r0");
  98. printk("%s\n", level);
  99. printk("%s VZOUICununcqcqcqcqcqcrmunTDVZOUI\n", level);
  100. printbinary(buf, s.sw[0], 32);
  101. printk("%sFPSR: %s\n", level, buf);
  102. printk("%sFPER1: %08x\n", level, s.sw[1]);
  103. /* here we'll print fr0 again, tho it'll be meaningless */
  104. for (i = 0; i < 32; i += 4)
  105. PRINTREGS(level, regs->fr, "fr", FFMT, i);
  106. }
  107. void show_regs(struct pt_regs *regs)
  108. {
  109. int i, user;
  110. const char *level;
  111. unsigned long cr30, cr31;
  112. user = user_mode(regs);
  113. level = user ? KERN_DEBUG : KERN_CRIT;
  114. show_regs_print_info(level);
  115. print_gr(level, regs);
  116. for (i = 0; i < 8; i += 4)
  117. PRINTREGS(level, regs->sr, "sr", RFMT, i);
  118. if (user)
  119. print_fr(level, regs);
  120. cr30 = mfctl(30);
  121. cr31 = mfctl(31);
  122. printk("%s\n", level);
  123. printk("%sIASQ: " RFMT " " RFMT " IAOQ: " RFMT " " RFMT "\n",
  124. level, regs->iasq[0], regs->iasq[1], regs->iaoq[0], regs->iaoq[1]);
  125. printk("%s IIR: %08lx ISR: " RFMT " IOR: " RFMT "\n",
  126. level, regs->iir, regs->isr, regs->ior);
  127. printk("%s CPU: %8d CR30: " RFMT " CR31: " RFMT "\n",
  128. level, task_cpu(current), cr30, cr31);
  129. printk("%s ORIG_R28: " RFMT "\n", level, regs->orig_r28);
  130. if (user) {
  131. printk("%s IAOQ[0]: " RFMT "\n", level, regs->iaoq[0]);
  132. printk("%s IAOQ[1]: " RFMT "\n", level, regs->iaoq[1]);
  133. printk("%s RP(r2): " RFMT "\n", level, regs->gr[2]);
  134. } else {
  135. printk("%s IAOQ[0]: %pS\n", level, (void *) regs->iaoq[0]);
  136. printk("%s IAOQ[1]: %pS\n", level, (void *) regs->iaoq[1]);
  137. printk("%s RP(r2): %pS\n", level, (void *) regs->gr[2]);
  138. parisc_show_stack(current, regs, KERN_DEFAULT);
  139. }
  140. }
  141. static DEFINE_RATELIMIT_STATE(_hppa_rs,
  142. DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);
  143. #define parisc_printk_ratelimited(critical, regs, fmt, ...) { \
  144. if ((critical || show_unhandled_signals) && __ratelimit(&_hppa_rs)) { \
  145. printk(fmt, ##__VA_ARGS__); \
  146. show_regs(regs); \
  147. } \
  148. }
  149. static void do_show_stack(struct unwind_frame_info *info, const char *loglvl)
  150. {
  151. int i = 1;
  152. printk("%sBacktrace:\n", loglvl);
  153. while (i <= MAX_UNWIND_ENTRIES) {
  154. if (unwind_once(info) < 0 || info->ip == 0)
  155. break;
  156. if (__kernel_text_address(info->ip)) {
  157. printk("%s [<" RFMT ">] %pS\n",
  158. loglvl, info->ip, (void *) info->ip);
  159. i++;
  160. }
  161. }
  162. printk("%s\n", loglvl);
  163. }
  164. static void parisc_show_stack(struct task_struct *task,
  165. struct pt_regs *regs, const char *loglvl)
  166. {
  167. struct unwind_frame_info info;
  168. unwind_frame_init_task(&info, task, regs);
  169. do_show_stack(&info, loglvl);
  170. }
  171. void show_stack(struct task_struct *t, unsigned long *sp, const char *loglvl)
  172. {
  173. parisc_show_stack(t, NULL, loglvl);
  174. }
  175. int is_valid_bugaddr(unsigned long iaoq)
  176. {
  177. return 1;
  178. }
  179. void die_if_kernel(char *str, struct pt_regs *regs, long err)
  180. {
  181. if (user_mode(regs)) {
  182. if (err == 0)
  183. return; /* STFU */
  184. parisc_printk_ratelimited(1, regs,
  185. KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
  186. current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
  187. return;
  188. }
  189. bust_spinlocks(1);
  190. oops_enter();
  191. /* Amuse the user in a SPARC fashion */
  192. if (err) printk(KERN_CRIT
  193. " _______________________________ \n"
  194. " < Your System ate a SPARC! Gah! >\n"
  195. " ------------------------------- \n"
  196. " \\ ^__^\n"
  197. " (__)\\ )\\/\\\n"
  198. " U ||----w |\n"
  199. " || ||\n");
  200. /* unlock the pdc lock if necessary */
  201. pdc_emergency_unlock();
  202. if (err)
  203. printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
  204. current->comm, task_pid_nr(current), str, err);
  205. /* Wot's wrong wif bein' racy? */
  206. if (current->thread.flags & PARISC_KERNEL_DEATH) {
  207. printk(KERN_CRIT "%s() recursion detected.\n", __func__);
  208. local_irq_enable();
  209. while (1);
  210. }
  211. current->thread.flags |= PARISC_KERNEL_DEATH;
  212. show_regs(regs);
  213. dump_stack();
  214. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  215. if (in_interrupt())
  216. panic("Fatal exception in interrupt");
  217. if (panic_on_oops)
  218. panic("Fatal exception");
  219. oops_exit();
  220. make_task_dead(SIGSEGV);
  221. }
  222. /* gdb uses break 4,8 */
  223. #define GDB_BREAK_INSN 0x10004
  224. static void handle_gdb_break(struct pt_regs *regs, int wot)
  225. {
  226. force_sig_fault(SIGTRAP, wot,
  227. (void __user *) (regs->iaoq[0] & ~3));
  228. }
  229. static void handle_break(struct pt_regs *regs)
  230. {
  231. unsigned iir = regs->iir;
  232. if (unlikely(iir == PARISC_BUG_BREAK_INSN && !user_mode(regs))) {
  233. /* check if a BUG() or WARN() trapped here. */
  234. enum bug_trap_type tt;
  235. tt = report_bug(regs->iaoq[0] & ~3, regs);
  236. if (tt == BUG_TRAP_TYPE_WARN) {
  237. regs->iaoq[0] += 4;
  238. regs->iaoq[1] += 4;
  239. return; /* return to next instruction when WARN_ON(). */
  240. }
  241. die_if_kernel("Unknown kernel breakpoint", regs,
  242. (tt == BUG_TRAP_TYPE_NONE) ? 9 : 0);
  243. }
  244. #ifdef CONFIG_KPROBES
  245. if (unlikely(iir == PARISC_KPROBES_BREAK_INSN && !user_mode(regs))) {
  246. parisc_kprobe_break_handler(regs);
  247. return;
  248. }
  249. if (unlikely(iir == PARISC_KPROBES_BREAK_INSN2 && !user_mode(regs))) {
  250. parisc_kprobe_ss_handler(regs);
  251. return;
  252. }
  253. #endif
  254. #ifdef CONFIG_KGDB
  255. if (unlikely((iir == PARISC_KGDB_COMPILED_BREAK_INSN ||
  256. iir == PARISC_KGDB_BREAK_INSN)) && !user_mode(regs)) {
  257. kgdb_handle_exception(9, SIGTRAP, 0, regs);
  258. return;
  259. }
  260. #endif
  261. #ifdef CONFIG_LIGHTWEIGHT_SPINLOCK_CHECK
  262. if ((iir == SPINLOCK_BREAK_INSN) && !user_mode(regs)) {
  263. die_if_kernel("Spinlock was trashed", regs, 1);
  264. }
  265. #endif
  266. if (unlikely(iir != GDB_BREAK_INSN))
  267. parisc_printk_ratelimited(0, regs,
  268. KERN_DEBUG "break %d,%d: pid=%d command='%s'\n",
  269. iir & 31, (iir>>13) & ((1<<13)-1),
  270. task_pid_nr(current), current->comm);
  271. /* send standard GDB signal */
  272. handle_gdb_break(regs, TRAP_BRKPT);
  273. }
  274. static void default_trap(int code, struct pt_regs *regs)
  275. {
  276. printk(KERN_ERR "Trap %d on CPU %d\n", code, smp_processor_id());
  277. show_regs(regs);
  278. }
  279. static void transfer_pim_to_trap_frame(struct pt_regs *regs)
  280. {
  281. register int i;
  282. extern unsigned int hpmc_pim_data[];
  283. struct pdc_hpmc_pim_11 *pim_narrow;
  284. struct pdc_hpmc_pim_20 *pim_wide;
  285. if (boot_cpu_data.cpu_type >= pcxu) {
  286. pim_wide = (struct pdc_hpmc_pim_20 *)hpmc_pim_data;
  287. /*
  288. * Note: The following code will probably generate a
  289. * bunch of truncation error warnings from the compiler.
  290. * Could be handled with an ifdef, but perhaps there
  291. * is a better way.
  292. */
  293. regs->gr[0] = pim_wide->cr[22];
  294. for (i = 1; i < 32; i++)
  295. regs->gr[i] = pim_wide->gr[i];
  296. for (i = 0; i < 32; i++)
  297. regs->fr[i] = pim_wide->fr[i];
  298. for (i = 0; i < 8; i++)
  299. regs->sr[i] = pim_wide->sr[i];
  300. regs->iasq[0] = pim_wide->cr[17];
  301. regs->iasq[1] = pim_wide->iasq_back;
  302. regs->iaoq[0] = pim_wide->cr[18];
  303. regs->iaoq[1] = pim_wide->iaoq_back;
  304. regs->sar = pim_wide->cr[11];
  305. regs->iir = pim_wide->cr[19];
  306. regs->isr = pim_wide->cr[20];
  307. regs->ior = pim_wide->cr[21];
  308. }
  309. else {
  310. pim_narrow = (struct pdc_hpmc_pim_11 *)hpmc_pim_data;
  311. regs->gr[0] = pim_narrow->cr[22];
  312. for (i = 1; i < 32; i++)
  313. regs->gr[i] = pim_narrow->gr[i];
  314. for (i = 0; i < 32; i++)
  315. regs->fr[i] = pim_narrow->fr[i];
  316. for (i = 0; i < 8; i++)
  317. regs->sr[i] = pim_narrow->sr[i];
  318. regs->iasq[0] = pim_narrow->cr[17];
  319. regs->iasq[1] = pim_narrow->iasq_back;
  320. regs->iaoq[0] = pim_narrow->cr[18];
  321. regs->iaoq[1] = pim_narrow->iaoq_back;
  322. regs->sar = pim_narrow->cr[11];
  323. regs->iir = pim_narrow->cr[19];
  324. regs->isr = pim_narrow->cr[20];
  325. regs->ior = pim_narrow->cr[21];
  326. }
  327. /*
  328. * The following fields only have meaning if we came through
  329. * another path. So just zero them here.
  330. */
  331. regs->ksp = 0;
  332. regs->kpc = 0;
  333. regs->orig_r28 = 0;
  334. }
  335. /*
  336. * This routine is called as a last resort when everything else
  337. * has gone clearly wrong. We get called for faults in kernel space,
  338. * and HPMC's.
  339. */
  340. void parisc_terminate(char *msg, struct pt_regs *regs, int code, unsigned long offset)
  341. {
  342. static DEFINE_SPINLOCK(terminate_lock);
  343. (void)notify_die(DIE_OOPS, msg, regs, 0, code, SIGTRAP);
  344. bust_spinlocks(1);
  345. set_eiem(0);
  346. local_irq_disable();
  347. spin_lock(&terminate_lock);
  348. /* unlock the pdc lock if necessary */
  349. pdc_emergency_unlock();
  350. /* Not all paths will gutter the processor... */
  351. switch(code){
  352. case 1:
  353. transfer_pim_to_trap_frame(regs);
  354. break;
  355. default:
  356. break;
  357. }
  358. {
  359. /* show_stack(NULL, (unsigned long *)regs->gr[30]); */
  360. struct unwind_frame_info info;
  361. unwind_frame_init(&info, current, regs);
  362. do_show_stack(&info, KERN_CRIT);
  363. }
  364. printk("\n");
  365. pr_crit("%s: Code=%d (%s) at addr " RFMT "\n",
  366. msg, code, trap_name(code), offset);
  367. show_regs(regs);
  368. spin_unlock(&terminate_lock);
  369. /* put soft power button back under hardware control;
  370. * if the user had pressed it once at any time, the
  371. * system will shut down immediately right here. */
  372. pdc_soft_power_button(0);
  373. /* Call kernel panic() so reboot timeouts work properly
  374. * FIXME: This function should be on the list of
  375. * panic notifiers, and we should call panic
  376. * directly from the location that we wish.
  377. * e.g. We should not call panic from
  378. * parisc_terminate, but rather the other way around.
  379. * This hack works, prints the panic message twice,
  380. * and it enables reboot timers!
  381. */
  382. panic(msg);
  383. }
  384. void notrace handle_interruption(int code, struct pt_regs *regs)
  385. {
  386. unsigned long fault_address = 0;
  387. unsigned long fault_space = 0;
  388. int si_code;
  389. if (!irqs_disabled_flags(regs->gr[0]))
  390. local_irq_enable();
  391. /* Security check:
  392. * If the priority level is still user, and the
  393. * faulting space is not equal to the active space
  394. * then the user is attempting something in a space
  395. * that does not belong to them. Kill the process.
  396. *
  397. * This is normally the situation when the user
  398. * attempts to jump into the kernel space at the
  399. * wrong offset, be it at the gateway page or a
  400. * random location.
  401. *
  402. * We cannot normally signal the process because it
  403. * could *be* on the gateway page, and processes
  404. * executing on the gateway page can't have signals
  405. * delivered.
  406. *
  407. * We merely readjust the address into the users
  408. * space, at a destination address of zero, and
  409. * allow processing to continue.
  410. */
  411. if (((unsigned long)regs->iaoq[0] & 3) &&
  412. ((unsigned long)regs->iasq[0] != (unsigned long)regs->sr[7])) {
  413. /* Kill the user process later */
  414. regs->iaoq[0] = 0 | PRIV_USER;
  415. regs->iaoq[1] = regs->iaoq[0] + 4;
  416. regs->iasq[0] = regs->iasq[1] = regs->sr[7];
  417. regs->gr[0] &= ~PSW_B;
  418. return;
  419. }
  420. #if 0
  421. printk(KERN_CRIT "Interruption # %d\n", code);
  422. #endif
  423. switch(code) {
  424. case 1:
  425. /* High-priority machine check (HPMC) */
  426. /* set up a new led state on systems shipped with a LED State panel */
  427. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_HPMC);
  428. parisc_terminate("High Priority Machine Check (HPMC)",
  429. regs, code, 0);
  430. /* NOT REACHED */
  431. case 2:
  432. /* Power failure interrupt */
  433. printk(KERN_CRIT "Power failure interrupt !\n");
  434. return;
  435. case 3:
  436. /* Recovery counter trap */
  437. regs->gr[0] &= ~PSW_R;
  438. #ifdef CONFIG_KGDB
  439. if (kgdb_single_step) {
  440. kgdb_handle_exception(0, SIGTRAP, 0, regs);
  441. return;
  442. }
  443. #endif
  444. if (user_space(regs))
  445. handle_gdb_break(regs, TRAP_TRACE);
  446. /* else this must be the start of a syscall - just let it run */
  447. return;
  448. case 5:
  449. /* Low-priority machine check */
  450. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_LPMC);
  451. flush_cache_all();
  452. flush_tlb_all();
  453. default_trap(code, regs);
  454. return;
  455. case PARISC_ITLB_TRAP:
  456. /* Instruction TLB miss fault/Instruction page fault */
  457. fault_address = regs->iaoq[0];
  458. fault_space = regs->iasq[0];
  459. break;
  460. case 8:
  461. /* Illegal instruction trap */
  462. die_if_kernel("Illegal instruction", regs, code);
  463. si_code = ILL_ILLOPC;
  464. goto give_sigill;
  465. case 9:
  466. /* Break instruction trap */
  467. handle_break(regs);
  468. return;
  469. case 10:
  470. /* Privileged operation trap */
  471. die_if_kernel("Privileged operation", regs, code);
  472. si_code = ILL_PRVOPC;
  473. goto give_sigill;
  474. case 11:
  475. /* Privileged register trap */
  476. if ((regs->iir & 0xffdfffe0) == 0x034008a0) {
  477. /* This is a MFCTL cr26/cr27 to gr instruction.
  478. * PCXS traps on this, so we need to emulate it.
  479. */
  480. if (regs->iir & 0x00200000)
  481. regs->gr[regs->iir & 0x1f] = mfctl(27);
  482. else
  483. regs->gr[regs->iir & 0x1f] = mfctl(26);
  484. regs->iaoq[0] = regs->iaoq[1];
  485. regs->iaoq[1] += 4;
  486. regs->iasq[0] = regs->iasq[1];
  487. return;
  488. }
  489. die_if_kernel("Privileged register usage", regs, code);
  490. si_code = ILL_PRVREG;
  491. give_sigill:
  492. force_sig_fault(SIGILL, si_code,
  493. (void __user *) regs->iaoq[0]);
  494. return;
  495. case 12:
  496. /* Overflow Trap, let the userland signal handler do the cleanup */
  497. force_sig_fault(SIGFPE, FPE_INTOVF,
  498. (void __user *) regs->iaoq[0]);
  499. return;
  500. case 13:
  501. /* Conditional Trap
  502. The condition succeeds in an instruction which traps
  503. on condition */
  504. if(user_mode(regs)){
  505. /* Let userspace app figure it out from the insn pointed
  506. * to by si_addr.
  507. */
  508. force_sig_fault(SIGFPE, FPE_CONDTRAP,
  509. (void __user *) regs->iaoq[0]);
  510. return;
  511. }
  512. /* The kernel doesn't want to handle condition codes */
  513. break;
  514. case 14:
  515. /* Assist Exception Trap, i.e. floating point exception. */
  516. die_if_kernel("Floating point exception", regs, 0); /* quiet */
  517. __inc_irq_stat(irq_fpassist_count);
  518. handle_fpe(regs);
  519. return;
  520. case 15:
  521. /* Data TLB miss fault/Data page fault */
  522. fallthrough;
  523. case 16:
  524. /* Non-access instruction TLB miss fault */
  525. /* The instruction TLB entry needed for the target address of the FIC
  526. is absent, and hardware can't find it, so we get to cleanup */
  527. fallthrough;
  528. case 17:
  529. /* Non-access data TLB miss fault/Non-access data page fault */
  530. /* FIXME:
  531. Still need to add slow path emulation code here!
  532. If the insn used a non-shadow register, then the tlb
  533. handlers could not have their side-effect (e.g. probe
  534. writing to a target register) emulated since rfir would
  535. erase the changes to said register. Instead we have to
  536. setup everything, call this function we are in, and emulate
  537. by hand. Technically we need to emulate:
  538. fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw
  539. */
  540. if (code == 17 && handle_nadtlb_fault(regs))
  541. return;
  542. fault_address = regs->ior;
  543. fault_space = regs->isr;
  544. break;
  545. case 18:
  546. /* PCXS only -- later cpu's split this into types 26,27 & 28 */
  547. /* Check for unaligned access */
  548. if (check_unaligned(regs)) {
  549. handle_unaligned(regs);
  550. return;
  551. }
  552. fallthrough;
  553. case 26:
  554. /* PCXL: Data memory access rights trap */
  555. fault_address = regs->ior;
  556. fault_space = regs->isr;
  557. break;
  558. case 19:
  559. /* Data memory break trap */
  560. regs->gr[0] |= PSW_X; /* So we can single-step over the trap */
  561. fallthrough;
  562. case 21:
  563. /* Page reference trap */
  564. handle_gdb_break(regs, TRAP_HWBKPT);
  565. return;
  566. case 25:
  567. /* Taken branch trap */
  568. regs->gr[0] &= ~PSW_T;
  569. if (user_space(regs))
  570. handle_gdb_break(regs, TRAP_BRANCH);
  571. /* else this must be the start of a syscall - just let it
  572. * run.
  573. */
  574. return;
  575. case 7:
  576. /* Instruction access rights */
  577. /* PCXL: Instruction memory protection trap */
  578. /*
  579. * This could be caused by either: 1) a process attempting
  580. * to execute within a vma that does not have execute
  581. * permission, or 2) an access rights violation caused by a
  582. * flush only translation set up by ptep_get_and_clear().
  583. * So we check the vma permissions to differentiate the two.
  584. * If the vma indicates we have execute permission, then
  585. * the cause is the latter one. In this case, we need to
  586. * call do_page_fault() to fix the problem.
  587. */
  588. if (user_mode(regs)) {
  589. struct vm_area_struct *vma;
  590. mmap_read_lock(current->mm);
  591. vma = find_vma(current->mm,regs->iaoq[0]);
  592. if (vma && (regs->iaoq[0] >= vma->vm_start)
  593. && (vma->vm_flags & VM_EXEC)) {
  594. fault_address = regs->iaoq[0];
  595. fault_space = regs->iasq[0];
  596. mmap_read_unlock(current->mm);
  597. break; /* call do_page_fault() */
  598. }
  599. mmap_read_unlock(current->mm);
  600. }
  601. /* CPU could not fetch instruction, so clear stale IIR value. */
  602. regs->iir = 0xbaadf00d;
  603. fallthrough;
  604. case 27:
  605. /* Data memory protection ID trap */
  606. if (code == 27 && !user_mode(regs) &&
  607. fixup_exception(regs))
  608. return;
  609. die_if_kernel("Protection id trap", regs, code);
  610. force_sig_fault(SIGSEGV, SEGV_MAPERR,
  611. (code == 7)?
  612. ((void __user *) regs->iaoq[0]) :
  613. ((void __user *) regs->ior));
  614. return;
  615. case 28:
  616. /* Unaligned data reference trap */
  617. handle_unaligned(regs);
  618. return;
  619. default:
  620. if (user_mode(regs)) {
  621. parisc_printk_ratelimited(0, regs, KERN_DEBUG
  622. "handle_interruption() pid=%d command='%s'\n",
  623. task_pid_nr(current), current->comm);
  624. /* SIGBUS, for lack of a better one. */
  625. force_sig_fault(SIGBUS, BUS_OBJERR,
  626. (void __user *)regs->ior);
  627. return;
  628. }
  629. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  630. parisc_terminate("Unexpected interruption", regs, code, 0);
  631. /* NOT REACHED */
  632. }
  633. if (user_mode(regs)) {
  634. if ((fault_space >> SPACEID_SHIFT) != (regs->sr[7] >> SPACEID_SHIFT)) {
  635. parisc_printk_ratelimited(0, regs, KERN_DEBUG
  636. "User fault %d on space 0x%08lx, pid=%d command='%s'\n",
  637. code, fault_space,
  638. task_pid_nr(current), current->comm);
  639. force_sig_fault(SIGSEGV, SEGV_MAPERR,
  640. (void __user *)regs->ior);
  641. return;
  642. }
  643. }
  644. else {
  645. /*
  646. * The kernel should never fault on its own address space,
  647. * unless pagefault_disable() was called before.
  648. */
  649. if (faulthandler_disabled() || fault_space == 0)
  650. {
  651. /* Clean up and return if in exception table. */
  652. if (fixup_exception(regs))
  653. return;
  654. /* Clean up and return if handled by kfence. */
  655. if (kfence_handle_page_fault(fault_address,
  656. parisc_acctyp(code, regs->iir) == VM_WRITE, regs))
  657. return;
  658. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  659. parisc_terminate("Kernel Fault", regs, code, fault_address);
  660. }
  661. }
  662. do_page_fault(regs, code, fault_address);
  663. }
  664. static void __init initialize_ivt(const void *iva)
  665. {
  666. extern const u32 os_hpmc[];
  667. int i;
  668. u32 check = 0;
  669. u32 *ivap;
  670. u32 instr;
  671. if (strcmp((const char *)iva, "cows can fly"))
  672. panic("IVT invalid");
  673. ivap = (u32 *)iva;
  674. for (i = 0; i < 8; i++)
  675. *ivap++ = 0;
  676. /*
  677. * Use PDC_INSTR firmware function to get instruction that invokes
  678. * PDCE_CHECK in HPMC handler. See programming note at page 1-31 of
  679. * the PA 1.1 Firmware Architecture document.
  680. */
  681. if (pdc_instr(&instr) == PDC_OK)
  682. ivap[0] = instr;
  683. /*
  684. * Rules for the checksum of the HPMC handler:
  685. * 1. The IVA does not point to PDC/PDH space (ie: the OS has installed
  686. * its own IVA).
  687. * 2. The word at IVA + 32 is nonzero.
  688. * 3. If Length (IVA + 60) is not zero, then Length (IVA + 60) and
  689. * Address (IVA + 56) are word-aligned.
  690. * 4. The checksum of the 8 words starting at IVA + 32 plus the sum of
  691. * the Length/4 words starting at Address is zero.
  692. */
  693. /* Setup IVA and compute checksum for HPMC handler */
  694. ivap[6] = (u32)__pa(os_hpmc);
  695. for (i=0; i<8; i++)
  696. check += ivap[i];
  697. ivap[5] = -check;
  698. pr_debug("initialize_ivt: IVA[6] = 0x%08x\n", ivap[6]);
  699. }
  700. /* early_trap_init() is called before we set up kernel mappings and
  701. * write-protect the kernel */
  702. void __init early_trap_init(void)
  703. {
  704. extern const void fault_vector_20;
  705. #ifndef CONFIG_64BIT
  706. extern const void fault_vector_11;
  707. initialize_ivt(&fault_vector_11);
  708. #endif
  709. initialize_ivt(&fault_vector_20);
  710. }