traps.c 21 KB

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