^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Architecture-specific trap handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1998-2003 Hewlett-Packard Co
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * David Mosberger-Tang <davidm@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * 05/12/00 grao <goutham.rao@intel.com> : added isr in siginfo for SIGFPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/vt_kern.h> /* For unblank_screen() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/hardirq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/delay.h> /* for ssleep() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/fpswa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/intrinsics.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/exception.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) fpswa_interface_t *fpswa_interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) EXPORT_SYMBOL(fpswa_interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) trap_init (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (ia64_boot_param->fpswa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* FPSWA fixup: make the interface pointer a kernel virtual address: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) fpswa_interface = __va(ia64_boot_param->fpswa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) die (const char *str, struct pt_regs *regs, long err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u32 lock_owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int lock_owner_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) } die = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .lock = __SPIN_LOCK_UNLOCKED(die.lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .lock_owner = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .lock_owner_depth = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static int die_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int cpu = get_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (die.lock_owner != cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) console_verbose();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) spin_lock_irq(&die.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) die.lock_owner = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) die.lock_owner_depth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) bust_spinlocks(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) put_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (++die.lock_owner_depth < 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) printk("%s[%d]: %s %ld [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) current->comm, task_pid_nr(current), str, err, ++die_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) != NOTIFY_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) show_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) regs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) printk(KERN_ERR "Recursive die() failure, output suppressed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) bust_spinlocks(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) die.lock_owner = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) spin_unlock_irq(&die.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (!regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (panic_on_oops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) panic("Fatal exception");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) do_exit(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) die_if_kernel (char *str, struct pt_regs *regs, long err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!user_mode(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return die(str, regs, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) __kprobes ia64_bad_break (unsigned long break_num, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int sig, code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) switch (break_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) case 0: /* unknown error (used by GCC for __builtin_abort()) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (notify_die(DIE_BREAK, "break 0", regs, break_num, TRAP_BRKPT, SIGTRAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) == NOTIFY_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (die_if_kernel("bugcheck!", regs, break_num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) sig = SIGILL; code = ILL_ILLOPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case 1: /* integer divide by zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) sig = SIGFPE; code = FPE_INTDIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) case 2: /* integer overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) sig = SIGFPE; code = FPE_INTOVF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) case 3: /* range check/bounds check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) sig = SIGFPE; code = FPE_FLTSUB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) case 4: /* null pointer dereference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) sig = SIGSEGV; code = SEGV_MAPERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) case 5: /* misaligned data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) sig = SIGSEGV; code = BUS_ADRALN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) case 6: /* decimal overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) sig = SIGFPE; code = __FPE_DECOVF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) case 7: /* decimal divide by zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) sig = SIGFPE; code = __FPE_DECDIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) case 8: /* packed decimal error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) sig = SIGFPE; code = __FPE_DECERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) case 9: /* invalid ASCII digit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) sig = SIGFPE; code = __FPE_INVASC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) case 10: /* invalid decimal digit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) sig = SIGFPE; code = __FPE_INVDEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) case 11: /* paragraph stack overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) sig = SIGSEGV; code = __SEGV_PSTKOVF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) case 0x3f000 ... 0x3ffff: /* bundle-update in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) sig = SIGILL; code = __ILL_BNDMOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if ((break_num < 0x40000 || break_num > 0x100000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) && die_if_kernel("Bad break", regs, break_num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (break_num < 0x80000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) sig = SIGILL; code = __ILL_BREAK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (notify_die(DIE_BREAK, "bad break", regs, break_num, TRAP_BRKPT, SIGTRAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) == NOTIFY_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) sig = SIGTRAP; code = TRAP_BRKPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) force_sig_fault(sig, code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) (void __user *) (regs->cr_iip + ia64_psr(regs)->ri),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) break_num, 0 /* clear __ISR_VALID */, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * disabled_fph_fault() is called when a user-level process attempts to access f32..f127
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * and it doesn't own the fp-high register partition. When this happens, we save the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * current fph partition in the task_struct of the fpu-owner (if necessary) and then load
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * the fp-high partition of the current task (if necessary). Note that the kernel has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * access to fph by the time we get here, as the IVT's "Disabled FP-Register" handler takes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * care of clearing psr.dfh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) disabled_fph_fault (struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct ia64_psr *psr = ia64_psr(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* first, grant user-level access to fph partition: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) psr->dfh = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * Make sure that no other task gets in on this processor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * while we're claiming the FPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct task_struct *fpu_owner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) = (struct task_struct *)ia64_get_kr(IA64_KR_FPU_OWNER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (ia64_is_local_fpu_owner(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) preempt_enable_no_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (fpu_owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ia64_flush_fph(fpu_owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #endif /* !CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ia64_set_local_fpu_owner(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if ((current->thread.flags & IA64_THREAD_FPH_VALID) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) __ia64_load_fpu(current->thread.fph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) psr->mfh = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) __ia64_init_fpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Set mfh because the state in thread.fph does not match the state in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * the fph partition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) psr->mfh = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) preempt_enable_no_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) fp_emulate (int fp_fault, void *bundle, long *ipsr, long *fpsr, long *isr, long *pr, long *ifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) fp_state_t fp_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) fpswa_ret_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (!fpswa_interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) memset(&fp_state, 0, sizeof(fp_state_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * compute fp_state. only FP registers f6 - f11 are used by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * kernel, so set those bits in the mask and set the low volatile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * pointer to point to these registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) fp_state.bitmask_low64 = 0xfc0; /* bit6..bit11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) fp_state.fp_state_low_volatile = (fp_state_low_volatile_t *) ®s->f6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * unsigned long (*EFI_FPSWA) (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * unsigned long trap_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * void *Bundle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * unsigned long *pipsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * unsigned long *pfsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * unsigned long *pisr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * unsigned long *ppreds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * unsigned long *pifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * void *fp_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ret = (*fpswa_interface->fpswa)((unsigned long) fp_fault, bundle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) (unsigned long *) ipsr, (unsigned long *) fpsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) (unsigned long *) isr, (unsigned long *) pr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) (unsigned long *) ifs, &fp_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return ret.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct fpu_swa_msg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) unsigned long count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) unsigned long time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static DEFINE_PER_CPU(struct fpu_swa_msg, cpulast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) DECLARE_PER_CPU(struct fpu_swa_msg, cpulast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static struct fpu_swa_msg last __cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * Handle floating-point assist faults and traps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) long exception, bundle[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) unsigned long fault_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) fault_ip = regs->cr_iip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (!fp_fault && (ia64_psr(regs)->ri == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) fault_ip -= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (copy_from_user(bundle, (void __user *) fault_ip, sizeof(bundle)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (!(current->thread.flags & IA64_THREAD_FPEMU_NOPRINT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) unsigned long count, current_jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct fpu_swa_msg *cp = this_cpu_ptr(&cpulast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (unlikely(current_jiffies > cp->time))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) cp->count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (unlikely(cp->count < 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) cp->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) cp->time = current_jiffies + 5 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* minimize races by grabbing a copy of count BEFORE checking last.time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) count = last.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * Lower 4 bits are used as a count. Upper bits are a sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * number that is updated when count is reset. The cmpxchg will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * fail is seqno has changed. This minimizes mutiple cpus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * resetting the count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (current_jiffies > last.time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) (void) cmpxchg_acq(&last.count, count, 16 + (count & ~15));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* used fetchadd to atomically update the count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) last.time = current_jiffies + 5 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) exception = fp_emulate(fp_fault, bundle, ®s->cr_ipsr, ®s->ar_fpsr, &isr, ®s->pr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) ®s->cr_ifs, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (fp_fault) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (exception == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /* emulation was successful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ia64_increment_ip(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) } else if (exception == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) printk(KERN_ERR "handle_fpu_swa: fp_emulate() returned -1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* is next instruction a trap? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int si_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (exception & 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) ia64_increment_ip(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) si_code = FPE_FLTUNK; /* default code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (isr & 0x11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) si_code = FPE_FLTINV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) } else if (isr & 0x22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* denormal operand gets the same si_code as underflow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * see arch/i386/kernel/traps.c:math_error() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) si_code = FPE_FLTUND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) } else if (isr & 0x44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) si_code = FPE_FLTDIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) force_sig_fault(SIGFPE, si_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) (void __user *) (regs->cr_iip + ia64_psr(regs)->ri),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 0, __ISR_VALID, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (exception == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) printk(KERN_ERR "handle_fpu_swa: fp_emulate() returned -1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) } else if (exception != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* raise exception */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int si_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) si_code = FPE_FLTUNK; /* default code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (isr & 0x880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) si_code = FPE_FLTOVF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) } else if (isr & 0x1100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) si_code = FPE_FLTUND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) } else if (isr & 0x2200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) si_code = FPE_FLTRES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) force_sig_fault(SIGFPE, si_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) (void __user *) (regs->cr_iip + ia64_psr(regs)->ri),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 0, __ISR_VALID, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) struct illegal_op_return {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) unsigned long fkt, arg1, arg2, arg3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct illegal_op_return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ia64_illegal_op_fault (unsigned long ec, long arg1, long arg2, long arg3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) long arg4, long arg5, long arg6, long arg7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct pt_regs regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct illegal_op_return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) char buf[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) #ifdef CONFIG_IA64_BRL_EMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) extern struct illegal_op_return ia64_emulate_brl (struct pt_regs *, unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) rv = ia64_emulate_brl(®s, ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (rv.fkt != (unsigned long) -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) sprintf(buf, "IA-64 Illegal operation fault");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) rv.fkt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (die_if_kernel(buf, ®s, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) force_sig_fault(SIGILL, ILL_ILLOPC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) (void __user *) (regs.cr_iip + ia64_psr(®s)->ri),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) void __kprobes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ia64_fault (unsigned long vector, unsigned long isr, unsigned long ifa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) unsigned long iim, unsigned long itir, long arg5, long arg6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) long arg7, struct pt_regs regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) unsigned long code, error = isr, iip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) char buf[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) int result, sig, si_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static const char *reason[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) "IA-64 Illegal Operation fault",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) "IA-64 Privileged Operation fault",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) "IA-64 Privileged Register fault",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) "IA-64 Reserved Register/Field fault",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) "Disabled Instruction Set Transition fault",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) "Unknown fault 5", "Unknown fault 6", "Unknown fault 7", "Illegal Hazard fault",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) "Unknown fault 9", "Unknown fault 10", "Unknown fault 11", "Unknown fault 12",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) "Unknown fault 13", "Unknown fault 14", "Unknown fault 15"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if ((isr & IA64_ISR_NA) && ((isr & IA64_ISR_CODE_MASK) == IA64_ISR_CODE_LFETCH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * This fault was due to lfetch.fault, set "ed" bit in the psr to cancel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * the lfetch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) ia64_psr(®s)->ed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) iip = regs.cr_iip + ia64_psr(®s)->ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) switch (vector) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) case 24: /* General Exception */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) code = (isr >> 4) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) sprintf(buf, "General Exception: %s%s", reason[code],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) (code == 3) ? ((isr & (1UL << 37))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) ? " (RSE access)" : " (data access)") : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (code == 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) # ifdef CONFIG_IA64_PRINT_HAZARDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) printk("%s[%d]: possible hazard @ ip=%016lx (pr = %016lx)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) current->comm, task_pid_nr(current),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) regs.cr_iip + ia64_psr(®s)->ri, regs.pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) case 25: /* Disabled FP-Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) if (isr & 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) disabled_fph_fault(®s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) sprintf(buf, "Disabled FPL fault---not supposed to happen!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) case 26: /* NaT Consumption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (user_mode(®s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) void __user *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (((isr >> 4) & 0xf) == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /* NaT page consumption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) sig = SIGSEGV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) code = SEGV_ACCERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) addr = (void __user *) ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* register NaT consumption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) sig = SIGILL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) code = ILL_ILLOPN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) addr = (void __user *) (regs.cr_iip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) + ia64_psr(®s)->ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) force_sig_fault(sig, code, addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) vector, __ISR_VALID, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) } else if (ia64_done_with_exception(®s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) sprintf(buf, "NaT consumption");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) case 31: /* Unsupported Data Reference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (user_mode(®s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) force_sig_fault(SIGILL, ILL_ILLOPN, (void __user *) iip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) vector, __ISR_VALID, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) sprintf(buf, "Unsupported data reference");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) case 29: /* Debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) case 35: /* Taken Branch Trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) case 36: /* Single Step Trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if (fsys_mode(current, ®s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) extern char __kernel_syscall_via_break[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * Got a trap in fsys-mode: Taken Branch Trap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * and Single Step trap need special handling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * Debug trap is ignored (we disable it here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * and re-enable it in the lower-privilege trap).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (unlikely(vector == 29)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) set_thread_flag(TIF_DB_DISABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) ia64_psr(®s)->db = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ia64_psr(®s)->lp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* re-do the system call via break 0x100000: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) regs.cr_iip = (unsigned long) __kernel_syscall_via_break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ia64_psr(®s)->ri = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) ia64_psr(®s)->cpl = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) switch (vector) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) case 29:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) si_code = TRAP_HWBKPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) #ifdef CONFIG_ITANIUM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * Erratum 10 (IFA may contain incorrect address) now has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * "NoFix" status. There are no plans for fixing this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (ia64_psr(®s)->is == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) ifa = regs.cr_iip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) case 35: si_code = TRAP_BRANCH; ifa = 0; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) case 36: si_code = TRAP_TRACE; ifa = 0; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (notify_die(DIE_FAULT, "ia64_fault", ®s, vector, si_code, SIGTRAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) == NOTIFY_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) force_sig_fault(SIGTRAP, si_code, (void __user *) ifa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 0, __ISR_VALID, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) case 32: /* fp fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) case 33: /* fp trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) result = handle_fpu_swa((vector == 32) ? 1 : 0, ®s, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if ((result < 0) || (current->thread.flags & IA64_THREAD_FPEMU_SIGFPE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) force_sig_fault(SIGFPE, FPE_FLTINV, (void __user *) iip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 0, __ISR_VALID, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) case 34:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (isr & 0x2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) /* Lower-Privilege Transfer Trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) /* If we disabled debug traps during an fsyscall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * re-enable them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (test_thread_flag(TIF_DB_DISABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) clear_thread_flag(TIF_DB_DISABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) ia64_psr(®s)->db = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * Just clear PSR.lp and then return immediately:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * all the interesting work (e.g., signal delivery)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * is done in the kernel exit path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) ia64_psr(®s)->lp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /* Unimplemented Instr. Address Trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (user_mode(®s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) force_sig_fault(SIGILL, ILL_BADIADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) (void __user *) iip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) sprintf(buf, "Unimplemented Instruction Address fault");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) case 45:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) printk(KERN_ERR "Unexpected IA-32 exception (Trap 45)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) printk(KERN_ERR " iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) iip, ifa, isr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) case 46:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) printk(KERN_ERR "Unexpected IA-32 intercept trap (Trap 46)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) printk(KERN_ERR " iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx, iim - 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) iip, ifa, isr, iim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) case 47:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) sprintf(buf, "IA-32 Interruption Fault (int 0x%lx)", isr >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) sprintf(buf, "Fault %lu", vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (!die_if_kernel(buf, ®s, error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) force_sig(SIGILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }