// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) * Copyright 2007-2010 Freescale Semiconductor, Inc. * * Modified by Cort Dougan (cort@cs.nmt.edu) * and Paul Mackerras (paulus@samba.org)
*/
/* * This file handles the architecture-dependent parts of hardware exceptions
*/
staticconstchar *signame(int signr)
{ switch (signr) { case SIGBUS: return"bus error"; case SIGFPE: return"floating point exception"; case SIGILL: return"illegal instruction"; case SIGSEGV: return"segfault"; case SIGTRAP: return"unhandled trap";
}
/* * If oops/die is expected to crash the machine, return true here. * * This should not be expected to be 100% accurate, there may be * notifiers registered or other unexpected conditions that may bring * down the kernel. Or if the current process in the kernel is holding * locks or has other critical state, the kernel may become effectively * unusable anyway.
*/ bool die_will_crash(void)
{ if (should_fadump_crash()) returntrue; if (kexec_should_crash(current)) returntrue; if (in_interrupt() || panic_on_oops ||
!current->pid || is_global_init(current)) returntrue;
void panic_flush_kmsg_start(void)
{ /* * These are mostly taken from kernel/panic.c, but tries to do * relatively minimal work. Don't use delay functions (TB may * be broken), don't crash dump (need to set a firmware log), * don't run notifiers. We do want to get some information to * Linux console.
*/
console_verbose();
bust_spinlocks(1);
}
/* * system_reset_excption handles debugger, crash dump, panic, for 0x100
*/ if (TRAP(regs) == INTERRUPT_SYSTEM_RESET) return;
crash_fadump(regs, "die oops");
if (kexec_should_crash(current))
crash_kexec(regs);
if (!signr) return;
/* * While our oops output is serialised by a spinlock, output * from panic() called below can race and corrupt it. If we * know we are going to panic, delay for 1 second so we have a * chance to get clean backtraces from all CPUs that are oopsing.
*/ if (in_interrupt() || panic_on_oops || !current->pid ||
is_global_init(current)) {
mdelay(MSEC_PER_SEC);
}
if (panic_on_oops)
panic("Fatal exception");
make_task_dead(signr);
}
NOKPROBE_SYMBOL(oops_end);
staticchar *get_mmu_str(void)
{ if (early_radix_enabled()) return" MMU=Radix"; if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) return" MMU=Hash"; return"";
}
pr_info("%s[%d]: %s (%d) at %lx nip %lx lr %lx code %x",
current->comm, current->pid, signame(signr), signr,
addr, regs->nip, regs->link, code);
print_vma_addr(KERN_CONT " in ", regs->nip);
pr_cont("\n");
show_user_instructions(regs);
}
staticbool exception_common(int signr, struct pt_regs *regs, int code, unsignedlong addr)
{ if (!user_mode(regs)) {
die("Exception in kernel mode", regs, signr); returnfalse;
}
/* * Must not enable interrupts even for user-mode exception, because * this can be called from machine check, which may be a NMI or IRQ * which don't like interrupts being enabled. Could check for * in_hardirq || in_nmi perhaps, but there doesn't seem to be a good * reason why _exception() should enable irqs for an exception handler, * the handlers themselves do that directly.
*/
show_signal_msg(signr, regs, code, addr);
current->thread.trap_nr = code;
returntrue;
}
void _exception_pkey(struct pt_regs *regs, unsignedlong addr, int key)
{ if (!exception_common(SIGSEGV, regs, SEGV_PKUERR, addr)) return;
force_sig_pkuerr((void __user *) addr, key);
}
void _exception(int signr, struct pt_regs *regs, int code, unsignedlong addr)
{ if (!exception_common(signr, regs, code, addr)) return;
/* * The interrupt architecture has a quirk in that the HV interrupts excluding * the NMIs (0x100 and 0x200) do not clear MSR[RI] at entry. The first thing * that an interrupt handler must do is save off a GPR into a scratch register, * and all interrupts on POWERNV (HV=1) use the HSPRG1 register as scratch. * Therefore an NMI can clobber an HV interrupt's live HSPRG1 without noticing * that it is non-reentrant, which leads to random data corruption. * * The solution is for NMI interrupts in HV mode to check if they originated * from these critical HV interrupt regions. If so, then mark them not * recoverable. * * An alternative would be for HV NMIs to use SPRG for scratch to avoid the * HSPRG1 clobber, however this would cause guest SPRG to be clobbered. Linux * guests should always have MSR[RI]=0 when its scratch SPRG is in use, so * that would work. However any other guest OS that may have the SPRG live * and MSR[RI]=1 could encounter silent corruption. * * Builds that do not support KVM could take this second option to increase * the recoverability of NMIs.
*/
noinstr void hv_nmi_check_nonrecoverable(struct pt_regs *regs)
{ #ifdef CONFIG_PPC_POWERNV unsignedlong kbase = (unsignedlong)_stext; unsignedlong nip = regs->nip;
if (!(regs->msr & MSR_RI)) return; if (!(regs->msr & MSR_HV)) return; if (user_mode(regs)) return;
/* * Now test if the interrupt has hit a range that may be using * HSPRG1 without having RI=0 (i.e., an HSRR interrupt). The * problem ranges all run un-relocated. Test real and virt modes * at the same time by dropping the high bit of the nip (virt mode * entry points still have the +0x4000 offset).
*/
nip &= ~0xc000000000000000ULL; if ((nip >= 0x500 && nip < 0x600) || (nip >= 0x4500 && nip < 0x4600)) goto nonrecoverable; if ((nip >= 0x980 && nip < 0xa00) || (nip >= 0x4980 && nip < 0x4a00)) goto nonrecoverable; if ((nip >= 0xe00 && nip < 0xec0) || (nip >= 0x4e00 && nip < 0x4ec0)) goto nonrecoverable; if ((nip >= 0xf80 && nip < 0xfa0) || (nip >= 0x4f80 && nip < 0x4fa0)) goto nonrecoverable;
/* * System reset can interrupt code where HSRRs are live and MSR[RI]=1. * The system reset interrupt itself may clobber HSRRs (e.g., to call * OPAL), so save them here and restore them before returning. * * Machine checks don't need to save HSRRs, as the real mode handler * is careful to avoid them, and the regular handler is not delivered * as an NMI.
*/ if (cpu_has_feature(CPU_FTR_HVMODE)) {
hsrr0 = mfspr(SPRN_HSRR0);
hsrr1 = mfspr(SPRN_HSRR1);
saved_hsrrs = true;
}
hv_nmi_check_nonrecoverable(regs);
__this_cpu_inc(irq_stat.sreset_irqs);
/* See if any machine dependent calls */ if (ppc_md.system_reset_exception) { if (ppc_md.system_reset_exception(regs)) goto out;
}
if (debugger(regs)) goto out;
kmsg_dump(KMSG_DUMP_OOPS); /* * A system reset is a request to dump, so we always send * it through the crashdump code (if fadump or kdump are * registered).
*/
crash_fadump(regs, "System Reset");
crash_kexec(regs);
/* * We aren't the primary crash CPU. We need to send it * to a holding pattern to avoid it ending up in the panic * code.
*/
crash_kexec_secondary(regs);
/* * No debugger or crash dump registered, print logs then * panic.
*/
die("System Reset", regs, SIGABRT);
mdelay(2*MSEC_PER_SEC); /* Wait a little while for others to print */
add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
nmi_panic(regs, "System Reset");
out: #ifdef CONFIG_PPC_BOOK3S_64
BUG_ON(get_paca()->in_nmi == 0); if (get_paca()->in_nmi > 1)
die("Unrecoverable nested System Reset", regs, SIGABRT); #endif /* Must die if the interrupt is not recoverable */ if (regs_is_unrecoverable(regs)) { /* For the reason explained in die_mce, nmi_exit before die */
nmi_exit();
die("Unrecoverable System Reset", regs, SIGABRT);
}
if (saved_hsrrs) {
mtspr(SPRN_HSRR0, hsrr0);
mtspr(SPRN_HSRR1, hsrr1);
}
/* What should we do here? We could issue a shutdown or hard reset. */
return 0;
}
/* * I/O accesses can cause machine checks on powermacs. * Check if the NIP corresponds to the address of a sync * instruction for which there is an entry in the exception * table. * -- paulus.
*/ staticinlineint check_io_access(struct pt_regs *regs)
{ #ifdef CONFIG_PPC32 unsignedlong msr = regs->msr; conststruct exception_table_entry *entry; unsignedint *nip = (unsignedint *)regs->nip;
if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
&& (entry = search_exception_tables(regs->nip)) != NULL) { /* * Check that it's a sync instruction, or somewhere * in the twi; isync; nop sequence that inb/inw/inl uses. * As the address is in the exception table * we should be able to read the instr there. * For the debug message, we look at the preceding * load or store.
*/ if (*nip == PPC_RAW_NOP())
nip -= 2; elseif (*nip == PPC_RAW_ISYNC())
--nip; if (*nip == PPC_RAW_SYNC() || get_op(*nip) == OP_TRAP) { unsignedint rb;
--nip;
rb = (*nip >> 11) & 0x1f;
printk(KERN_DEBUG "%s bad port %lx at %p\n",
(*nip & 0x100)? "OUT to": "IN from",
regs->gpr[rb] - _IO_BASE, nip);
regs_set_recoverable(regs);
regs_set_return_ip(regs, extable_fixup(entry)); return 1;
}
} #endif/* CONFIG_PPC32 */ return 0;
}
#ifdef CONFIG_PPC_ADV_DEBUG_REGS /* On 4xx, the reason for the machine check or program exception
is in the ESR. */ #define get_reason(regs) ((regs)->esr) #define REASON_FP ESR_FP #define REASON_ILLEGAL (ESR_PIL | ESR_PUO) #define REASON_PRIVILEGED ESR_PPR #define REASON_TRAP ESR_PTR #define REASON_PREFIXED 0 #define REASON_BOUNDARY 0
/* single-step stuff */ #define single_stepping(regs) (current->thread.debug.dbcr0 & DBCR0_IC) #define clear_single_step(regs) (current->thread.debug.dbcr0 &= ~DBCR0_IC) #define clear_br_trace(regs) do {} while(0) #else /* On non-4xx, the reason for the machine check or program
exception is in the MSR. */ #define get_reason(regs) ((regs)->msr) #define REASON_TM SRR1_PROGTM #define REASON_FP SRR1_PROGFPE #define REASON_ILLEGAL SRR1_PROGILL #define REASON_PRIVILEGED SRR1_PROGPRIV #define REASON_TRAP SRR1_PROGTRAP #define REASON_PREFIXED SRR1_PREFIXED #define REASON_BOUNDARY SRR1_BOUNDARY
if (reason & MCSR_LD) {
recoverable = fsl_rio_mcheck_exception(regs); if (recoverable == 1) goto silent_out;
}
printk("Machine check in kernel mode.\n");
printk("Caused by (from MCSR=%lx): ", reason);
if (reason & MCSR_MCP)
pr_cont("Machine Check Signal\n");
if (reason & MCSR_ICPERR) {
pr_cont("Instruction Cache Parity Error\n");
/* * This is recoverable by invalidating the i-cache.
*/
mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI); while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI)
;
/* * This will generally be accompanied by an instruction * fetch error report -- only treat MCSR_IF as fatal * if it wasn't due to an L1 parity error.
*/
reason &= ~MCSR_IF;
}
if (reason & MCSR_DCPERR_MC) {
pr_cont("Data Cache Parity Error\n");
/* * In write shadow mode we auto-recover from the error, but it * may still get logged and cause a machine check. We should * only treat the non-write shadow case as non-recoverable.
*/ /* On e6500 core, L1 DCWS (Data cache write shadow mode) bit * is not implemented but L1 data cache always runs in write * shadow mode. Hence on data cache parity errors HW will * automatically invalidate the L1 Data Cache.
*/ if (PVR_VER(pvr) != PVR_VER_E6500) { if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS))
recoverable = 0;
}
}
if (reason & MCSR_L2MMU_MHIT) {
pr_cont("Hit on multiple TLB entries\n");
recoverable = 0;
}
if (reason & MCSR_NMI)
pr_cont("Non-maskable interrupt\n");
int machine_check_e500(struct pt_regs *regs)
{ unsignedlong reason = mfspr(SPRN_MCSR);
if (reason & MCSR_BUS_RBERR) { if (fsl_rio_mcheck_exception(regs)) return 1; if (fsl_pci_mcheck_exception(regs)) return 1;
}
printk("Machine check in kernel mode.\n");
printk("Caused by (from MCSR=%lx): ", reason);
if (reason & MCSR_MCP)
pr_cont("Machine Check Signal\n"); if (reason & MCSR_ICPERR)
pr_cont("Instruction Cache Parity Error\n"); if (reason & MCSR_DCP_PERR)
pr_cont("Data Cache Push Parity Error\n"); if (reason & MCSR_DCPERR)
pr_cont("Data Cache Parity Error\n"); if (reason & MCSR_BUS_IAERR)
pr_cont("Bus - Instruction Address Error\n"); if (reason & MCSR_BUS_RAERR)
pr_cont("Bus - Read Address Error\n"); if (reason & MCSR_BUS_WAERR)
pr_cont("Bus - Write Address Error\n"); if (reason & MCSR_BUS_IBERR)
pr_cont("Bus - Instruction Data Error\n"); if (reason & MCSR_BUS_RBERR)
pr_cont("Bus - Read Data Bus Error\n"); if (reason & MCSR_BUS_WBERR)
pr_cont("Bus - Write Data Bus Error\n"); if (reason & MCSR_BUS_IPERR)
pr_cont("Bus - Instruction Parity Error\n"); if (reason & MCSR_BUS_RPERR)
pr_cont("Bus - Read Parity Error\n");
return 0;
}
int machine_check_generic(struct pt_regs *regs)
{ return 0;
} #elifdefined(CONFIG_PPC32) int machine_check_generic(struct pt_regs *regs)
{ unsignedlong reason = regs->msr;
printk("Machine check in kernel mode.\n");
printk("Caused by (from SRR1=%lx): ", reason); switch (reason & 0x601F0000) { case 0x80000:
pr_cont("Machine check signal\n"); break; case 0x40000: case 0x140000: /* 7450 MSS error and TEA */
pr_cont("Transfer error ack signal\n"); break; case 0x20000:
pr_cont("Data parity error signal\n"); break; case 0x10000:
pr_cont("Address parity error signal\n"); break; case 0x20000000:
pr_cont("L1 Data Cache error\n"); break; case 0x40000000:
pr_cont("L1 Instruction Cache error\n"); break; case 0x00100000:
pr_cont("L2 data cache parity error\n"); break; default:
pr_cont("Unknown values in msr\n");
} return 0;
} #endif/* everything else */
void die_mce(constchar *str, struct pt_regs *regs, long err)
{ /* * The machine check wants to kill the interrupted context, * but make_task_dead() checks for in_interrupt() and panics * in that case, so exit the irq/nmi before calling die.
*/ if (in_nmi())
nmi_exit(); else
irq_exit();
die(str, regs, err);
}
/* * BOOK3S_64 does not usually call this handler as a non-maskable interrupt * (it uses its own early real-mode handler to handle the MCE proper * and then raises irq_work to call this handler when interrupts are * enabled). The only time when this is not true is if the early handler * is unrecoverable, then it does call this directly to try to get a * message out.
*/ staticvoid __machine_check_exception(struct pt_regs *regs)
{ int recover = 0;
/* See if any machine dependent calls. In theory, we would want * to call the CPU first, and call the ppc_md. one if the CPU * one returns a positive number. However there is existing code * that assumes the board gets a first chance, so let's keep it * that way for now and fix things later. --BenH.
*/ if (ppc_md.machine_check_exception)
recover = ppc_md.machine_check_exception(regs); elseif (cur_cpu_spec->machine_check)
recover = cur_cpu_spec->machine_check(regs);
if (recover > 0) goto bail;
if (debugger_fault_handler(regs)) goto bail;
if (check_io_access(regs)) goto bail;
die_mce("Machine check", regs, SIGBUS);
bail: /* Must die if the interrupt is not recoverable */ if (regs_is_unrecoverable(regs))
die_mce("Unrecoverable Machine check", regs, SIGBUS);
}
/* Grab vector registers into the task struct */
msr = regs->msr; /* Grab msr before we flush the bits */
flush_vsx_to_thread(current);
enable_kernel_altivec();
/* * Is userspace running with a different endian (this is rare but * not impossible)
*/
swap = (msr & MSR_LE) != (MSR_KERNEL & MSR_LE);
/* Decode the instruction */
ra = (instr >> 16) & 0x1f;
rb = (instr >> 11) & 0x1f;
t = (instr >> 21) & 0x1f; if (instr & 1)
vdst = (u8 *)¤t->thread.vr_state.vr[t]; else
vdst = (u8 *)¤t->thread.fp_state.fpr[t][0];
/* Grab the vector address */
ea = regs->gpr[rb] + (ra ? regs->gpr[ra] : 0); if (is_32bit_task())
ea &= 0xfffffffful;
addr = (__force constvoid __user *)ea;
/* Check it */ if (!access_ok(addr, 16)) {
pr_devel("HMI vec emu: bad access %i:%s[%d] nip=%016lx" " instr=%08x addr=%016lx\n",
smp_processor_id(), current->comm, current->pid,
regs->nip, instr, (unsignedlong)addr); return;
}
/* * Check to make sure the facility is actually enabled. This * could happen if we get a false positive hit. * * lxvd2x/lxvw4x always check MSR VSX sel = 0,2 * lxvh8x/lxvb16x check MSR VSX or VEC depending on VSR used sel = 1,3
*/
msr_mask = MSR_VSX; if ((sel & 1) && (instr & 1)) /* lxvh8x & lxvb16x + VSR >= 32 */
msr_mask = MSR_VEC; if (!(msr & msr_mask)) {
pr_devel("HMI vec emu: MSR fac clear %i:%s[%d] nip=%016lx" " instr=%08x msr:%016lx\n",
smp_processor_id(), current->comm, current->pid,
regs->nip, instr, msr); return;
}
/* Do logging here before we modify sel based on endian */ switch (sel) { case 0: /* lxvw4x */
PPC_WARN_EMULATED(lxvw4x, regs); break; case 1: /* lxvh8x */
PPC_WARN_EMULATED(lxvh8x, regs); break; case 2: /* lxvd2x */
PPC_WARN_EMULATED(lxvd2x, regs); break; case 3: /* lxvb16x */
PPC_WARN_EMULATED(lxvb16x, regs); break;
}
#ifdef __LITTLE_ENDIAN__ /* * An LE kernel stores the vector in the task struct as an LE * byte array (effectively swapping both the components and * the content of the components). Those instructions expect * the components to remain in ascending address order, so we * swap them back. * * If we are running a BE user space, the expectation is that * of a simple memcpy, so forcing the emulation to look like * a lxvb16x should do the trick.
*/ if (swap)
sel = 3;
switch (sel) { case 0: /* lxvw4x */ for (i = 0; i < 4; i++)
((u32 *)vdst)[i] = ((u32 *)vbuf)[3-i]; break; case 1: /* lxvh8x */ for (i = 0; i < 8; i++)
((u16 *)vdst)[i] = ((u16 *)vbuf)[7-i]; break; case 2: /* lxvd2x */ for (i = 0; i < 2; i++)
((u64 *)vdst)[i] = ((u64 *)vbuf)[1-i]; break; case 3: /* lxvb16x */ for (i = 0; i < 16; i++)
vdst[i] = vbuf[15-i]; break;
} #else/* __LITTLE_ENDIAN__ */ /* On a big endian kernel, a BE userspace only needs a memcpy */ if (!swap)
sel = 3;
/* Otherwise, we need to swap the content of the components */ switch (sel) { case 0: /* lxvw4x */ for (i = 0; i < 4; i++)
((u32 *)vdst)[i] = cpu_to_le32(((u32 *)vbuf)[i]); break; case 1: /* lxvh8x */ for (i = 0; i < 8; i++)
((u16 *)vdst)[i] = cpu_to_le16(((u16 *)vbuf)[i]); break; case 2: /* lxvd2x */ for (i = 0; i < 2; i++)
((u64 *)vdst)[i] = cpu_to_le64(((u64 *)vbuf)[i]); break; case 3: /* lxvb16x */
memcpy(vdst, vbuf, 16); break;
} #endif/* !__LITTLE_ENDIAN__ */
/* Go to next instruction */
regs_add_return_ip(regs, 4);
} #endif/* CONFIG_VSX */
#ifdef CONFIG_VSX /* Real mode flagged P9 special emu is needed */ if (local_paca->hmi_p9_special_emu) {
local_paca->hmi_p9_special_emu = 0;
/* * We don't want to take page faults while doing the * emulation, we just replay the instruction if necessary.
*/
pagefault_disable();
p9_hmi_special_emu(regs);
pagefault_enable();
} #endif/* CONFIG_VSX */
if (ppc_md.handle_hmi_exception)
ppc_md.handle_hmi_exception(regs);
/* * After we have successfully emulated an instruction, we have to * check if the instruction was being single-stepped, and if so, * pretend we got a single-step exception. This was pointed out * by Kumar Gala. -- paulus
*/ void emulate_single_step(struct pt_regs *regs)
{ if (single_stepping(regs))
__single_step_exception(regs);
}
#ifdef CONFIG_PPC_FPU_REGS staticinlineint __parse_fpscr(unsignedlong fpscr)
{ int ret = FPE_FLTUNK;
/* Invalid operation */ if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
ret = FPE_FLTINV;
/* * Illegal instruction emulation support. Originally written to * provide the PVR to user applications using the mfspr rd, PVR. * Return non-zero if we can't emulate, or -EFAULT if the associated * memory access caused an access fault. Return zero on success. * * There are a couple of ways to do this, either "decode" the instruction * or directly match lots of bits. In this case, matching lots of * bits is faster and easier. *
*/ staticint emulate_string_inst(struct pt_regs *regs, u32 instword)
{
u8 rT = (instword >> 21) & 0x1f;
u8 rA = (instword >> 16) & 0x1f;
u8 NB_RB = (instword >> 11) & 0x1f;
u32 num_bytes; unsignedlong EA; int pos = 0;
/* Early out if we are an invalid form of lswx */ if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX) if ((rT == rA) || (rT == NB_RB)) return -EINVAL;
EA = (rA == 0) ? 0 : regs->gpr[rA];
switch (instword & PPC_INST_STRING_MASK) { case PPC_INST_LSWX: case PPC_INST_STSWX:
EA += NB_RB;
num_bytes = regs->xer & 0x7f; break; case PPC_INST_LSWI: case PPC_INST_STSWI:
num_bytes = (NB_RB == 0) ? 32 : NB_RB; break; default: return -EINVAL;
}
/* if process is 32-bit, clear upper 32 bits of EA */ if ((regs->msr & MSR_64BIT) == 0)
EA &= 0xFFFFFFFF;
switch ((instword & PPC_INST_STRING_MASK)) { case PPC_INST_LSWX: case PPC_INST_LSWI: if (get_user(val, (u8 __user *)EA)) return -EFAULT; /* first time updating this reg,
* zero it out */ if (pos == 0)
regs->gpr[rT] = 0;
regs->gpr[rT] |= val << shift; break; case PPC_INST_STSWI: case PPC_INST_STSWX:
val = regs->gpr[rT] >> shift; if (put_user(val, (u8 __user *)EA)) return -EFAULT; break;
} /* move EA to next address */
EA += 1;
num_bytes--;
/* manage our position within the register */ if (++pos == 4) {
pos = 0; if (++rT == 32)
rT = 0;
}
}
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM staticinlinebool tm_abort_check(struct pt_regs *regs, int cause)
{ /* If we're emulating a load/store in an active transaction, we cannot * emulate it as the kernel operates in transaction suspended context. * We need to abort the transaction. This creates a persistent TM * abort so tell the user what caused it with a new code.
*/ if (MSR_TM_TRANSACTIONAL(regs->msr)) {
tm_enable();
tm_abort(cause); returntrue;
} returnfalse;
} #else staticinlinebool tm_abort_check(struct pt_regs *regs, int reason)
{ returnfalse;
} #endif
/* We can now get here via a FP Unavailable exception if the core
* has no FPU, in that case the reason flags will be 0 */
if (reason & REASON_FP) { /* IEEE FP exception */
parse_fpe(regs); return;
} if (reason & REASON_TRAP) { unsignedlong bugaddr; /* Debugger is first in line to stop recursive faults in
* rcu_lock, notify_die, or atomic_notifier_call_chain */ if (debugger_bpt(regs)) return;
/* User mode considers other cases after enabling IRQs */ if (!user_mode(regs)) {
_exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); return;
}
} #ifdef CONFIG_PPC_TRANSACTIONAL_MEM if (reason & REASON_TM) { /* This is a TM "Bad Thing Exception" program check. * This occurs when: * - An rfid/hrfid/mtmsrd attempts to cause an illegal * transition in TM states. * - A trechkpt is attempted when transactional. * - A treclaim is attempted when non transactional. * - A tend is illegally attempted. * - writing a TM SPR when transactional. * * If usermode caused this, it's done something illegal and * gets a SIGILL slap on the wrist. We call it an illegal * operand to distinguish from the instruction just being bad * (e.g. executing a 'tend' on a CPU without TM!); it's an * illegal /placement/ of a valid instruction.
*/ if (user_mode(regs)) {
_exception(SIGILL, regs, ILL_ILLOPN, regs->nip); return;
} else {
printk(KERN_EMERG "Unexpected TM Bad Thing exception " "at %lx (msr 0x%lx) tm_scratch=%llx\n",
regs->nip, regs->msr, get_paca()->tm_scratch);
die("Unrecoverable exception", regs, SIGABRT);
}
} #endif
/* * If we took the program check in the kernel skip down to sending a * SIGILL. The subsequent cases all relate to user space, such as * emulating instructions which we should only do for user space. We * also do not want to enable interrupts for kernel faults because that * might lead to further faults, and loose the context of the original * exception.
*/ if (!user_mode(regs)) goto sigill;
interrupt_cond_local_irq_enable(regs);
/* * (reason & REASON_TRAP) is mostly handled before enabling IRQs, * except get_user_instr() can sleep so we cannot reliably inspect the * current instruction in that context. Now that we know we are * handling a user space trap and can sleep, we can check if the trap * was a hashchk failure.
*/ if (reason & REASON_TRAP) { if (cpu_has_feature(CPU_FTR_DEXCR_NPHIE)) {
ppc_inst_t insn;
/* (reason & REASON_ILLEGAL) would be the obvious thing here, * but there seems to be a hardware bug on the 405GP (RevD) * that means ESR is sometimes set incorrectly - either to * ESR_DST (!?) or 0. In the process of chasing this with the * hardware people - not sure if it can happen on any illegal * instruction or only on FP instructions, whether there is a * pattern to occurrences etc. -dgibson 31/Mar/2003
*/ if (!emulate_math(regs)) return;
/* Try to emulate it if we should. */ if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { switch (emulate_instruction(regs)) { case 0:
regs_add_return_ip(regs, 4);
emulate_single_step(regs); return; case -EFAULT:
_exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); return;
}
}
/* * This occurs when running in hypervisor mode on POWER6 or later * and an illegal instruction is encountered.
*/
DEFINE_INTERRUPT_HANDLER(emulation_assist_interrupt)
{
regs_set_return_msr(regs, regs->msr | REASON_ILLEGAL);
do_program_check(regs);
}
DEFINE_INTERRUPT_HANDLER(alignment_exception)
{ int sig, code, fixed = 0; unsignedlong reason;
interrupt_cond_local_irq_enable(regs);
reason = get_reason(regs); if (reason & REASON_BOUNDARY) {
sig = SIGBUS;
code = BUS_ADRALN; goto bad;
}
if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT)) return;
/* we don't implement logging of alignment exceptions */ if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS))
fixed = fix_alignment(regs);
if (fixed == 1) { /* skip over emulated instruction */
regs_add_return_ip(regs, inst_length(reason));
emulate_single_step(regs); return;
}
/* Operand address was bad */ if (fixed == -EFAULT) {
sig = SIGSEGV;
code = SEGV_ACCERR;
} else {
sig = SIGBUS;
code = BUS_ADRALN;
}
bad: if (user_mode(regs))
_exception(sig, regs, code, regs->dar); else
bad_page_fault(regs, sig);
}
DEFINE_INTERRUPT_HANDLER(altivec_unavailable_exception)
{ if (user_mode(regs)) { /* A user program has executed an altivec instruction,
but this kernel doesn't support altivec. */
_exception(SIGILL, regs, ILL_ILLOPC, regs->nip); return;
}
DEFINE_INTERRUPT_HANDLER(vsx_unavailable_exception)
{ if (user_mode(regs)) { /* A user program has executed an vsx instruction,
but this kernel doesn't support vsx. */
_exception(SIGILL, regs, ILL_ILLOPC, regs->nip); return;
}
hv = (TRAP(regs) == INTERRUPT_H_FAC_UNAVAIL); if (hv)
value = mfspr(SPRN_HFSCR); else
value = mfspr(SPRN_FSCR);
status = value >> 56; if ((hv || status >= 2) &&
(status < ARRAY_SIZE(facility_strings)) &&
facility_strings[status])
facility = facility_strings[status];
/* We should not have taken this interrupt in kernel */ if (!user_mode(regs)) {
pr_emerg("Facility '%s' unavailable (%d) exception in kernel mode at %lx\n",
facility, status, regs->nip);
die("Unexpected facility unavailable exception", regs, SIGABRT);
}
interrupt_cond_local_irq_enable(regs);
if (status == FSCR_DSCR_LG) { /* * User is accessing the DSCR register using the problem * state only SPR number (0x03) either through a mfspr or * a mtspr instruction. If it is a write attempt through * a mtspr, then we set the inherit bit. This also allows * the user to write or read the register directly in the * future by setting via the FSCR DSCR bit. But in case it * is a read DSCR attempt through a mfspr instruction, we * just emulate the instruction instead. This code path will * always emulate all the mfspr instructions till the user * has attempted at least one mtspr instruction. This way it * preserves the same behaviour when the user is accessing * the DSCR through privilege level only SPR number (0x11) * which is emulated through illegal instruction exception. * We always leave HFSCR DSCR set.
*/ if (get_user(instword, (u32 __user *)(regs->nip))) {
pr_err("Failed to fetch the user instruction\n"); return;
}
/* Read from DSCR (mfspr RT, 0x03) */ if ((instword & PPC_INST_MFSPR_DSCR_USER_MASK)
== PPC_INST_MFSPR_DSCR_USER) { if (emulate_instruction(regs)) {
pr_err("DSCR based mfspr emulation failed\n"); return;
}
regs_add_return_ip(regs, 4);
emulate_single_step(regs);
} return;
}
if (status == FSCR_TM_LG) { /* * If we're here then the hardware is TM aware because it * generated an exception with FSRM_TM set. * * If cpu_has_feature(CPU_FTR_TM) is false, then either firmware * told us not to do TM, or the kernel is not built with TM * support. * * If both of those things are true, then userspace can spam the * console by triggering the printk() below just by continually * doing tbegin (or any TM instruction). So in that case just * send the process a SIGILL immediately.
*/ if (!cpu_has_feature(CPU_FTR_TM)) goto out;
DEFINE_INTERRUPT_HANDLER(fp_unavailable_tm)
{ /* Note: This does not handle any kind of FP laziness. */
TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n",
regs->nip, regs->msr);
/* We can only have got here if the task started using FP after * beginning the transaction. So, the transactional regs are just a * copy of the checkpointed ones. But, we still need to recheckpoint * as we're enabling FP for the process; it will return, abort the * transaction, and probably retry but now with FP enabled. So the * checkpointed FP registers need to be loaded.
*/
tm_reclaim_current(TM_CAUSE_FAC_UNAV);
/* * Reclaim initially saved out bogus (lazy) FPRs to ckfp_state, and * then it was overwrite by the thr->fp_state by tm_reclaim_thread(). * * At this point, ck{fp,vr}_state contains the exact values we want to * recheckpoint.
*/
/* Enable FP for the task: */
current->thread.load_fp = 1;
/* * Recheckpoint all the checkpointed ckpt, ck{fp, vr}_state registers.
*/
tm_recheckpoint(¤t->thread);
}
DEFINE_INTERRUPT_HANDLER(altivec_unavailable_tm)
{ /* See the comments in fp_unavailable_tm(). This function operates * the same way.
*/
DEFINE_INTERRUPT_HANDLER(vsx_unavailable_tm)
{ /* See the comments in fp_unavailable_tm(). This works similarly, * though we're loading both FP and VEC registers in here. * * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC * regs. Either way, set MSR_VSX.
*/
TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx," "MSR=%lx\n",
regs->nip, regs->msr);
current->thread.used_vsr = 1;
/* This reclaims FP and/or VR regs if they're already enabled */
tm_reclaim_current(TM_CAUSE_FAC_UNAV);
DEFINE_INTERRUPT_HANDLER_RAW(performance_monitor_exception)
{ /* * On 64-bit, if perf interrupts hit in a local_irq_disable * (soft-masked) region, we consider them as NMIs. This is required to * prevent hash faults on user addresses when reading callchains (and * looks better from an irq tracing perspective).
*/ if (IS_ENABLED(CONFIG_PPC64) && unlikely(arch_irq_disabled_regs(regs)))
performance_monitor_exception_nmi(regs); else
performance_monitor_exception_async(regs);
return 0;
}
#ifdef CONFIG_PPC_ADV_DEBUG_REGS staticvoid handle_debug(struct pt_regs *regs, unsignedlong debug_status)
{ int changed = 0; /* * Determine the cause of the debug event, clear the * event flags and send a trap to the handler. Torez
*/ if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) {
dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W); #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
current->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; #endif
do_send_trap(regs, mfspr(SPRN_DAC1), debug_status,
5);
changed |= 0x01;
} elseif (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) {
dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W);
do_send_trap(regs, mfspr(SPRN_DAC2), debug_status,
6);
changed |= 0x01;
} elseif (debug_status & DBSR_IAC1) {
current->thread.debug.dbcr0 &= ~DBCR0_IAC1;
dbcr_iac_range(current) &= ~DBCR_IAC12MODE;
do_send_trap(regs, mfspr(SPRN_IAC1), debug_status,
1);
changed |= 0x01;
} elseif (debug_status & DBSR_IAC2) {
current->thread.debug.dbcr0 &= ~DBCR0_IAC2;
do_send_trap(regs, mfspr(SPRN_IAC2), debug_status,
2);
changed |= 0x01;
} elseif (debug_status & DBSR_IAC3) {
current->thread.debug.dbcr0 &= ~DBCR0_IAC3;
dbcr_iac_range(current) &= ~DBCR_IAC34MODE;
do_send_trap(regs, mfspr(SPRN_IAC3), debug_status,
3);
changed |= 0x01;
} elseif (debug_status & DBSR_IAC4) {
current->thread.debug.dbcr0 &= ~DBCR0_IAC4;
do_send_trap(regs, mfspr(SPRN_IAC4), debug_status,
4);
changed |= 0x01;
} /* * At the point this routine was called, the MSR(DE) was turned off. * Check all other debug flags and see if that bit needs to be turned * back on or not.
*/ if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0,
current->thread.debug.dbcr1))
regs_set_return_msr(regs, regs->msr | MSR_DE); else /* Make sure the IDM flag is off */
current->thread.debug.dbcr0 &= ~DBCR0_IDM;
if (changed & 0x01)
mtspr(SPRN_DBCR0, current->thread.debug.dbcr0);
}
/* Hack alert: On BookE, Branch Taken stops on the branch itself, while * on server, it stops on the target of the branch. In order to simulate * the server behaviour, we thus restart right away with a single step * instead of stopping here when hitting a BT
*/ if (debug_status & DBSR_BT) {
regs_set_return_msr(regs, regs->msr & ~MSR_DE);
/* Do the single step trick only when coming from userspace */ if (user_mode(regs)) {
current->thread.debug.dbcr0 &= ~DBCR0_BT;
current->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC;
regs_set_return_msr(regs, regs->msr | MSR_DE); return;
}
if (user_mode(regs)) {
current->thread.debug.dbcr0 &= ~DBCR0_IC; if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0,
current->thread.debug.dbcr1))
regs_set_return_msr(regs, regs->msr | MSR_DE); else /* Make sure the IDM bit is off */
current->thread.debug.dbcr0 &= ~DBCR0_IDM;
}
if (err == -EFAULT) { /* got an error reading the instruction */
_exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
} else { /* didn't recognize the instruction */ /* XXX quick hack for now: set the non-Java bit in the VSCR */
printk_ratelimited(KERN_ERR "Unrecognized altivec instruction " "in %s at %lx\n", current->comm, regs->nip);
current->thread.vr_state.vscr.u[3] |= 0x10000;
}
} #endif/* CONFIG_ALTIVEC */
/* We treat cache locking instructions from the user * as priv ops, in the future we could try to do * something smarter
*/ if (error_code & (ESR_DLK|ESR_ILK))
_exception(SIGILL, regs, ILL_PRVOPC, regs->nip); return;
} #endif/* CONFIG_PPC_85xx */
#ifdef CONFIG_SPE
DEFINE_INTERRUPT_HANDLER(SPEFloatingPointException)
{ unsignedlong spefscr; int fpexc_mode; int code = FPE_FLTUNK; int err;
if (err == -EFAULT) { /* got an error reading the instruction */
_exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
} elseif (err == -EINVAL) { /* didn't recognize the instruction */
printk(KERN_ERR "unrecognized spe instruction " "in %s at %lx\n", current->comm, regs->nip);
} else {
_exception(SIGFPE, regs, FPE_FLTUNK, regs->nip); return;
}
} #endif
/* * We enter here if we get an unrecoverable exception, that is, one * that happened at a point where the RI (recoverable interrupt) bit * in the MSR is 0. This indicates that SRR0/1 are live, and that * we therefore lost state by taking this exception.
*/ void __noreturn unrecoverable_exception(struct pt_regs *regs)
{
pr_emerg("Unrecoverable exception %lx at %lx (msr=%lx)\n",
regs->trap, regs->nip, regs->msr);
die("Unrecoverable exception", regs, SIGABRT); /* die() should not return */ for (;;)
;
}
/* * We enter here if we discover during exception entry that we are * running in supervisor mode with a userspace value in the stack pointer.
*/
DEFINE_INTERRUPT_HANDLER(kernel_bad_stack)
{
printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
regs->gpr[1], regs->nip);
die("Bad kernel stack pointer", regs, SIGABRT);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.