1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * When the operating system detects that it is in an invalid state, a panic 31*7c478bd9Sstevel@tonic-gate * is initiated in order to minimize potential damage to user data and to 32*7c478bd9Sstevel@tonic-gate * facilitate debugging. There are three major tasks to be performed in 33*7c478bd9Sstevel@tonic-gate * a system panic: recording information about the panic in memory (and thus 34*7c478bd9Sstevel@tonic-gate * making it part of the crash dump), synchronizing the file systems to 35*7c478bd9Sstevel@tonic-gate * preserve user file data, and generating the crash dump. We define the 36*7c478bd9Sstevel@tonic-gate * system to be in one of four states with respect to the panic code: 37*7c478bd9Sstevel@tonic-gate * 38*7c478bd9Sstevel@tonic-gate * CALM - the state of the system prior to any thread initiating a panic 39*7c478bd9Sstevel@tonic-gate * 40*7c478bd9Sstevel@tonic-gate * QUIESCE - the state of the system when the first thread to initiate 41*7c478bd9Sstevel@tonic-gate * a system panic records information about the cause of the panic 42*7c478bd9Sstevel@tonic-gate * and renders the system quiescent by stopping other processors 43*7c478bd9Sstevel@tonic-gate * 44*7c478bd9Sstevel@tonic-gate * SYNC - the state of the system when we synchronize the file systems 45*7c478bd9Sstevel@tonic-gate * DUMP - the state when we generate the crash dump. 46*7c478bd9Sstevel@tonic-gate * 47*7c478bd9Sstevel@tonic-gate * The transitions between these states are irreversible: once we begin 48*7c478bd9Sstevel@tonic-gate * panicking, we only make one attempt to perform the actions associated with 49*7c478bd9Sstevel@tonic-gate * each state. 50*7c478bd9Sstevel@tonic-gate * 51*7c478bd9Sstevel@tonic-gate * The panic code itself must be re-entrant because actions taken during any 52*7c478bd9Sstevel@tonic-gate * state may lead to another system panic. Additionally, any Solaris 53*7c478bd9Sstevel@tonic-gate * thread may initiate a panic at any time, and so we must have synchronization 54*7c478bd9Sstevel@tonic-gate * between threads which attempt to initiate a state transition simultaneously. 55*7c478bd9Sstevel@tonic-gate * The panic code makes use of a special locking primitive, a trigger, to 56*7c478bd9Sstevel@tonic-gate * perform this synchronization. A trigger is simply a word which is set 57*7c478bd9Sstevel@tonic-gate * atomically and can only be set once. We declare three triggers, one for 58*7c478bd9Sstevel@tonic-gate * each transition between the four states. When a thread enters the panic 59*7c478bd9Sstevel@tonic-gate * code it attempts to set each trigger; if it fails it moves on to the 60*7c478bd9Sstevel@tonic-gate * next trigger. A special case is the first trigger: if two threads race 61*7c478bd9Sstevel@tonic-gate * to perform the transition to QUIESCE, the losing thread may execute before 62*7c478bd9Sstevel@tonic-gate * the winner has a chance to stop its CPU. To solve this problem, we have 63*7c478bd9Sstevel@tonic-gate * the loser look ahead to see if any other triggers are set; if not, it 64*7c478bd9Sstevel@tonic-gate * presumes a panic is underway and simply spins. Unfortunately, since we 65*7c478bd9Sstevel@tonic-gate * are panicking, it is not possible to know this with absolute certainty. 66*7c478bd9Sstevel@tonic-gate * 67*7c478bd9Sstevel@tonic-gate * There are two common reasons for re-entering the panic code once a panic 68*7c478bd9Sstevel@tonic-gate * has been initiated: (1) after we debug_enter() at the end of QUIESCE, 69*7c478bd9Sstevel@tonic-gate * the operator may type "sync" instead of "go", and the PROM's sync callback 70*7c478bd9Sstevel@tonic-gate * routine will invoke panic(); (2) if the clock routine decides that sync 71*7c478bd9Sstevel@tonic-gate * or dump is not making progress, it will invoke panic() to force a timeout. 72*7c478bd9Sstevel@tonic-gate * The design assumes that a third possibility, another thread causing an 73*7c478bd9Sstevel@tonic-gate * unrelated panic while sync or dump is still underway, is extremely unlikely. 74*7c478bd9Sstevel@tonic-gate * If this situation occurs, we may end up triggering dump while sync is 75*7c478bd9Sstevel@tonic-gate * still in progress. This third case is considered extremely unlikely because 76*7c478bd9Sstevel@tonic-gate * all other CPUs are stopped and low-level interrupts have been blocked. 77*7c478bd9Sstevel@tonic-gate * 78*7c478bd9Sstevel@tonic-gate * The panic code is entered via a call directly to the vpanic() function, 79*7c478bd9Sstevel@tonic-gate * or its varargs wrappers panic() and cmn_err(9F). The vpanic routine 80*7c478bd9Sstevel@tonic-gate * is implemented in assembly language to record the current machine 81*7c478bd9Sstevel@tonic-gate * registers, attempt to set the trigger for the QUIESCE state, and 82*7c478bd9Sstevel@tonic-gate * if successful, switch stacks on to the panic_stack before calling into 83*7c478bd9Sstevel@tonic-gate * the common panicsys() routine. The first thread to initiate a panic 84*7c478bd9Sstevel@tonic-gate * is allowed to make use of the reserved panic_stack so that executing 85*7c478bd9Sstevel@tonic-gate * the panic code itself does not overwrite valuable data on that thread's 86*7c478bd9Sstevel@tonic-gate * stack *ahead* of the current stack pointer. This data will be preserved 87*7c478bd9Sstevel@tonic-gate * in the crash dump and may prove invaluable in determining what this 88*7c478bd9Sstevel@tonic-gate * thread has previously been doing. The first thread, saved in panic_thread, 89*7c478bd9Sstevel@tonic-gate * is also responsible for stopping the other CPUs as quickly as possible, 90*7c478bd9Sstevel@tonic-gate * and then setting the various panic_* variables. Most important among 91*7c478bd9Sstevel@tonic-gate * these is panicstr, which allows threads to subsequently bypass held 92*7c478bd9Sstevel@tonic-gate * locks so that we can proceed without ever blocking. We must stop the 93*7c478bd9Sstevel@tonic-gate * other CPUs *prior* to setting panicstr in case threads running there are 94*7c478bd9Sstevel@tonic-gate * currently spinning to acquire a lock; we want that state to be preserved. 95*7c478bd9Sstevel@tonic-gate * Every thread which initiates a panic has its T_PANIC flag set so we can 96*7c478bd9Sstevel@tonic-gate * identify all such threads in the crash dump. 97*7c478bd9Sstevel@tonic-gate * 98*7c478bd9Sstevel@tonic-gate * The panic_thread is also allowed to make use of the special memory buffer 99*7c478bd9Sstevel@tonic-gate * panicbuf, which on machines with appropriate hardware is preserved across 100*7c478bd9Sstevel@tonic-gate * reboots. We allow the panic_thread to store its register set and panic 101*7c478bd9Sstevel@tonic-gate * message in this buffer, so even if we fail to obtain a crash dump we will 102*7c478bd9Sstevel@tonic-gate * be able to examine the machine after reboot and determine some of the 103*7c478bd9Sstevel@tonic-gate * state at the time of the panic. If we do get a dump, the panic buffer 104*7c478bd9Sstevel@tonic-gate * data is structured so that a debugger can easily consume the information 105*7c478bd9Sstevel@tonic-gate * therein (see <sys/panic.h>). 106*7c478bd9Sstevel@tonic-gate * 107*7c478bd9Sstevel@tonic-gate * Each platform or architecture is required to implement the functions 108*7c478bd9Sstevel@tonic-gate * panic_savetrap() to record trap-specific information to panicbuf, 109*7c478bd9Sstevel@tonic-gate * panic_saveregs() to record a register set to panicbuf, panic_stopcpus() 110*7c478bd9Sstevel@tonic-gate * to halt all CPUs but the panicking CPU, panic_quiesce_hw() to perform 111*7c478bd9Sstevel@tonic-gate * miscellaneous platform-specific tasks *after* panicstr is set, 112*7c478bd9Sstevel@tonic-gate * panic_showtrap() to print trap-specific information to the console, 113*7c478bd9Sstevel@tonic-gate * and panic_dump_hw() to perform platform tasks prior to calling dumpsys(). 114*7c478bd9Sstevel@tonic-gate * 115*7c478bd9Sstevel@tonic-gate * A Note on Word Formation, courtesy of the Oxford Guide to English Usage: 116*7c478bd9Sstevel@tonic-gate * 117*7c478bd9Sstevel@tonic-gate * Words ending in -c interpose k before suffixes which otherwise would 118*7c478bd9Sstevel@tonic-gate * indicate a soft c, and thus the verb and adjective forms of 'panic' are 119*7c478bd9Sstevel@tonic-gate * spelled "panicked", "panicking", and "panicky" respectively. Use of 120*7c478bd9Sstevel@tonic-gate * the ill-conceived "panicing" and "panic'd" is discouraged. 121*7c478bd9Sstevel@tonic-gate */ 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 124*7c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 125*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 126*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 127*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 128*7c478bd9Sstevel@tonic-gate #include <sys/thread.h> 129*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 130*7c478bd9Sstevel@tonic-gate #include <sys/cred.h> 131*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 132*7c478bd9Sstevel@tonic-gate #include <sys/uadmin.h> 133*7c478bd9Sstevel@tonic-gate #include <sys/callb.h> 134*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 135*7c478bd9Sstevel@tonic-gate #include <sys/log.h> 136*7c478bd9Sstevel@tonic-gate #include <sys/disp.h> 137*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 138*7c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h> 139*7c478bd9Sstevel@tonic-gate #include <sys/ftrace.h> 140*7c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 141*7c478bd9Sstevel@tonic-gate #include <sys/debug.h> 142*7c478bd9Sstevel@tonic-gate #include <sys/stack.h> 143*7c478bd9Sstevel@tonic-gate #include <sys/spl.h> 144*7c478bd9Sstevel@tonic-gate #include <sys/errorq.h> 145*7c478bd9Sstevel@tonic-gate #include <sys/panic.h> 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate /* 148*7c478bd9Sstevel@tonic-gate * Panic variables which are set once during the QUIESCE state by the 149*7c478bd9Sstevel@tonic-gate * first thread to initiate a panic. These are examined by post-mortem 150*7c478bd9Sstevel@tonic-gate * debugging tools; the inconsistent use of 'panic' versus 'panic_' in 151*7c478bd9Sstevel@tonic-gate * the variable naming is historical and allows legacy tools to work. 152*7c478bd9Sstevel@tonic-gate */ 153*7c478bd9Sstevel@tonic-gate #pragma align STACK_ALIGN(panic_stack) 154*7c478bd9Sstevel@tonic-gate char panic_stack[PANICSTKSIZE]; /* reserved stack for panic_thread */ 155*7c478bd9Sstevel@tonic-gate kthread_t *panic_thread; /* first thread to call panicsys() */ 156*7c478bd9Sstevel@tonic-gate cpu_t panic_cpu; /* cpu from first call to panicsys() */ 157*7c478bd9Sstevel@tonic-gate label_t panic_regs; /* setjmp label from panic_thread */ 158*7c478bd9Sstevel@tonic-gate struct regs *panic_reg; /* regs struct from first panicsys() */ 159*7c478bd9Sstevel@tonic-gate char *volatile panicstr; /* format string to first panicsys() */ 160*7c478bd9Sstevel@tonic-gate va_list panicargs; /* arguments to first panicsys() */ 161*7c478bd9Sstevel@tonic-gate clock_t panic_lbolt; /* lbolt at time of panic */ 162*7c478bd9Sstevel@tonic-gate int64_t panic_lbolt64; /* lbolt64 at time of panic */ 163*7c478bd9Sstevel@tonic-gate hrtime_t panic_hrtime; /* hrtime at time of panic */ 164*7c478bd9Sstevel@tonic-gate timespec_t panic_hrestime; /* hrestime at time of panic */ 165*7c478bd9Sstevel@tonic-gate int panic_ipl; /* ipl on panic_cpu at time of panic */ 166*7c478bd9Sstevel@tonic-gate ushort_t panic_schedflag; /* t_schedflag for panic_thread */ 167*7c478bd9Sstevel@tonic-gate cpu_t *panic_bound_cpu; /* t_bound_cpu for panic_thread */ 168*7c478bd9Sstevel@tonic-gate char panic_preempt; /* t_preempt for panic_thread */ 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /* 171*7c478bd9Sstevel@tonic-gate * Panic variables which can be set via /etc/system or patched while 172*7c478bd9Sstevel@tonic-gate * the system is in operation. Again, the stupid names are historic. 173*7c478bd9Sstevel@tonic-gate */ 174*7c478bd9Sstevel@tonic-gate char *panic_bootstr = NULL; /* mdboot string to use after panic */ 175*7c478bd9Sstevel@tonic-gate int panic_bootfcn = AD_BOOT; /* mdboot function to use after panic */ 176*7c478bd9Sstevel@tonic-gate int halt_on_panic = 0; /* halt after dump instead of reboot? */ 177*7c478bd9Sstevel@tonic-gate int nopanicdebug = 0; /* reboot instead of call debugger? */ 178*7c478bd9Sstevel@tonic-gate int in_sync = 0; /* skip vfs_syncall() and just dump? */ 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate /* 181*7c478bd9Sstevel@tonic-gate * The do_polled_io flag is set by the panic code to inform the SCSI subsystem 182*7c478bd9Sstevel@tonic-gate * to use polled mode instead of interrupt-driven i/o. 183*7c478bd9Sstevel@tonic-gate */ 184*7c478bd9Sstevel@tonic-gate int do_polled_io = 0; 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate /* 187*7c478bd9Sstevel@tonic-gate * The panic_forced flag is set by the uadmin A_DUMP code to inform the 188*7c478bd9Sstevel@tonic-gate * panic subsystem that it should not attempt an initial debug_enter. 189*7c478bd9Sstevel@tonic-gate */ 190*7c478bd9Sstevel@tonic-gate int panic_forced = 0; 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate /* 193*7c478bd9Sstevel@tonic-gate * Triggers for panic state transitions: 194*7c478bd9Sstevel@tonic-gate */ 195*7c478bd9Sstevel@tonic-gate int panic_quiesce; /* trigger for CALM -> QUIESCE */ 196*7c478bd9Sstevel@tonic-gate int panic_sync; /* trigger for QUIESCE -> SYNC */ 197*7c478bd9Sstevel@tonic-gate int panic_dump; /* trigger for SYNC -> DUMP */ 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate void 200*7c478bd9Sstevel@tonic-gate panicsys(const char *format, va_list alist, struct regs *rp, int on_panic_stack) 201*7c478bd9Sstevel@tonic-gate { 202*7c478bd9Sstevel@tonic-gate int s = spl8(); 203*7c478bd9Sstevel@tonic-gate kthread_t *t = curthread; 204*7c478bd9Sstevel@tonic-gate cpu_t *cp = CPU; 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate caddr_t intr_stack = NULL; 207*7c478bd9Sstevel@tonic-gate uint_t intr_actv; 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate ushort_t schedflag = t->t_schedflag; 210*7c478bd9Sstevel@tonic-gate cpu_t *bound_cpu = t->t_bound_cpu; 211*7c478bd9Sstevel@tonic-gate char preempt = t->t_preempt; 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate (void) setjmp(&t->t_pcb); 214*7c478bd9Sstevel@tonic-gate t->t_flag |= T_PANIC; 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate t->t_schedflag |= TS_DONT_SWAP; 217*7c478bd9Sstevel@tonic-gate t->t_bound_cpu = cp; 218*7c478bd9Sstevel@tonic-gate t->t_preempt++; 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate panic_enter_hw(s); 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate /* 223*7c478bd9Sstevel@tonic-gate * If we're on the interrupt stack and an interrupt thread is available 224*7c478bd9Sstevel@tonic-gate * in this CPU's pool, preserve the interrupt stack by detaching an 225*7c478bd9Sstevel@tonic-gate * interrupt thread and making its stack the intr_stack. 226*7c478bd9Sstevel@tonic-gate */ 227*7c478bd9Sstevel@tonic-gate if (CPU_ON_INTR(cp) && cp->cpu_intr_thread != NULL) { 228*7c478bd9Sstevel@tonic-gate kthread_t *it = cp->cpu_intr_thread; 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate intr_stack = cp->cpu_intr_stack; 231*7c478bd9Sstevel@tonic-gate intr_actv = cp->cpu_intr_actv; 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate cp->cpu_intr_stack = thread_stk_init(it->t_stk); 234*7c478bd9Sstevel@tonic-gate cp->cpu_intr_thread = it->t_link; 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate /* 237*7c478bd9Sstevel@tonic-gate * Clear only the high level bits of cpu_intr_actv. 238*7c478bd9Sstevel@tonic-gate * We want to indicate that high-level interrupts are 239*7c478bd9Sstevel@tonic-gate * not active without destroying the low-level interrupt 240*7c478bd9Sstevel@tonic-gate * information stored there. 241*7c478bd9Sstevel@tonic-gate */ 242*7c478bd9Sstevel@tonic-gate cp->cpu_intr_actv &= ((1 << (LOCK_LEVEL + 1)) - 1); 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate /* 246*7c478bd9Sstevel@tonic-gate * Record one-time panic information and quiesce the other CPUs. 247*7c478bd9Sstevel@tonic-gate * Then print out the panic message and stack trace. 248*7c478bd9Sstevel@tonic-gate */ 249*7c478bd9Sstevel@tonic-gate if (on_panic_stack) { 250*7c478bd9Sstevel@tonic-gate panic_data_t *pdp = (panic_data_t *)panicbuf; 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate pdp->pd_version = PANICBUFVERS; 253*7c478bd9Sstevel@tonic-gate pdp->pd_msgoff = sizeof (panic_data_t) - sizeof (panic_nv_t); 254*7c478bd9Sstevel@tonic-gate 255*7c478bd9Sstevel@tonic-gate if (t->t_panic_trap != NULL) 256*7c478bd9Sstevel@tonic-gate panic_savetrap(pdp, t->t_panic_trap); 257*7c478bd9Sstevel@tonic-gate else 258*7c478bd9Sstevel@tonic-gate panic_saveregs(pdp, rp); 259*7c478bd9Sstevel@tonic-gate 260*7c478bd9Sstevel@tonic-gate (void) vsnprintf(&panicbuf[pdp->pd_msgoff], 261*7c478bd9Sstevel@tonic-gate PANICBUFSIZE - pdp->pd_msgoff, format, alist); 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate /* 264*7c478bd9Sstevel@tonic-gate * Call into the platform code to stop the other CPUs. 265*7c478bd9Sstevel@tonic-gate * We currently have all interrupts blocked, and expect that 266*7c478bd9Sstevel@tonic-gate * the platform code will lower ipl only as far as needed to 267*7c478bd9Sstevel@tonic-gate * perform cross-calls, and will acquire as *few* locks as is 268*7c478bd9Sstevel@tonic-gate * possible -- panicstr is not set so we can still deadlock. 269*7c478bd9Sstevel@tonic-gate */ 270*7c478bd9Sstevel@tonic-gate panic_stopcpus(cp, t, s); 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate panicstr = (char *)format; 273*7c478bd9Sstevel@tonic-gate va_copy(panicargs, alist); 274*7c478bd9Sstevel@tonic-gate panic_lbolt = lbolt; 275*7c478bd9Sstevel@tonic-gate panic_lbolt64 = lbolt64; 276*7c478bd9Sstevel@tonic-gate panic_hrestime = hrestime; 277*7c478bd9Sstevel@tonic-gate panic_hrtime = gethrtime_waitfree(); 278*7c478bd9Sstevel@tonic-gate panic_thread = t; 279*7c478bd9Sstevel@tonic-gate panic_regs = t->t_pcb; 280*7c478bd9Sstevel@tonic-gate panic_reg = rp; 281*7c478bd9Sstevel@tonic-gate panic_cpu = *cp; 282*7c478bd9Sstevel@tonic-gate panic_ipl = spltoipl(s); 283*7c478bd9Sstevel@tonic-gate panic_schedflag = schedflag; 284*7c478bd9Sstevel@tonic-gate panic_bound_cpu = bound_cpu; 285*7c478bd9Sstevel@tonic-gate panic_preempt = preempt; 286*7c478bd9Sstevel@tonic-gate 287*7c478bd9Sstevel@tonic-gate if (intr_stack != NULL) { 288*7c478bd9Sstevel@tonic-gate panic_cpu.cpu_intr_stack = intr_stack; 289*7c478bd9Sstevel@tonic-gate panic_cpu.cpu_intr_actv = intr_actv; 290*7c478bd9Sstevel@tonic-gate } 291*7c478bd9Sstevel@tonic-gate 292*7c478bd9Sstevel@tonic-gate /* 293*7c478bd9Sstevel@tonic-gate * Lower ipl to 10 to keep clock() from running, but allow 294*7c478bd9Sstevel@tonic-gate * keyboard interrupts to enter the debugger. These callbacks 295*7c478bd9Sstevel@tonic-gate * are executed with panicstr set so they can bypass locks. 296*7c478bd9Sstevel@tonic-gate */ 297*7c478bd9Sstevel@tonic-gate splx(ipltospl(CLOCK_LEVEL)); 298*7c478bd9Sstevel@tonic-gate panic_quiesce_hw(pdp); 299*7c478bd9Sstevel@tonic-gate (void) FTRACE_STOP(); 300*7c478bd9Sstevel@tonic-gate (void) callb_execute_class(CB_CL_PANIC, NULL); 301*7c478bd9Sstevel@tonic-gate 302*7c478bd9Sstevel@tonic-gate if (log_intrq != NULL) 303*7c478bd9Sstevel@tonic-gate log_flushq(log_intrq); 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate /* 306*7c478bd9Sstevel@tonic-gate * If log_consq has been initialized and syslogd has started, 307*7c478bd9Sstevel@tonic-gate * print any messages in log_consq that haven't been consumed. 308*7c478bd9Sstevel@tonic-gate */ 309*7c478bd9Sstevel@tonic-gate if (log_consq != NULL && log_consq != log_backlogq) 310*7c478bd9Sstevel@tonic-gate log_printq(log_consq); 311*7c478bd9Sstevel@tonic-gate 312*7c478bd9Sstevel@tonic-gate fm_banner(); 313*7c478bd9Sstevel@tonic-gate errorq_panic(); 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id, (void *)t); 316*7c478bd9Sstevel@tonic-gate vprintf(format, alist); 317*7c478bd9Sstevel@tonic-gate printf("\n\n"); 318*7c478bd9Sstevel@tonic-gate 319*7c478bd9Sstevel@tonic-gate if (t->t_panic_trap != NULL) { 320*7c478bd9Sstevel@tonic-gate panic_showtrap(t->t_panic_trap); 321*7c478bd9Sstevel@tonic-gate printf("\n"); 322*7c478bd9Sstevel@tonic-gate } 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate traceregs(rp); 325*7c478bd9Sstevel@tonic-gate printf("\n"); 326*7c478bd9Sstevel@tonic-gate 327*7c478bd9Sstevel@tonic-gate if (((boothowto & RB_DEBUG) || obpdebug) && 328*7c478bd9Sstevel@tonic-gate !nopanicdebug && !panic_forced) { 329*7c478bd9Sstevel@tonic-gate if (dumpvp != NULL) { 330*7c478bd9Sstevel@tonic-gate debug_enter("panic: entering debugger " 331*7c478bd9Sstevel@tonic-gate "(continue to save dump)"); 332*7c478bd9Sstevel@tonic-gate } else { 333*7c478bd9Sstevel@tonic-gate debug_enter("panic: entering debugger " 334*7c478bd9Sstevel@tonic-gate "(no dump device, continue to reboot)"); 335*7c478bd9Sstevel@tonic-gate } 336*7c478bd9Sstevel@tonic-gate } 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate } else if (panic_dump != 0 || panic_sync != 0 || panicstr != NULL) { 339*7c478bd9Sstevel@tonic-gate printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id, (void *)t); 340*7c478bd9Sstevel@tonic-gate vprintf(format, alist); 341*7c478bd9Sstevel@tonic-gate printf("\n"); 342*7c478bd9Sstevel@tonic-gate } else 343*7c478bd9Sstevel@tonic-gate goto spin; 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate /* 346*7c478bd9Sstevel@tonic-gate * Prior to performing sync or dump, we make sure that do_polled_io is 347*7c478bd9Sstevel@tonic-gate * set, but we'll leave ipl at 10; deadman(), a CY_HIGH_LEVEL cyclic, 348*7c478bd9Sstevel@tonic-gate * will re-enter panic if we are not making progress with sync or dump. 349*7c478bd9Sstevel@tonic-gate */ 350*7c478bd9Sstevel@tonic-gate 351*7c478bd9Sstevel@tonic-gate /* 352*7c478bd9Sstevel@tonic-gate * Sync the filesystems. Reset t_cred if not set because much of 353*7c478bd9Sstevel@tonic-gate * the filesystem code depends on CRED() being valid. 354*7c478bd9Sstevel@tonic-gate */ 355*7c478bd9Sstevel@tonic-gate if (!in_sync && panic_trigger(&panic_sync)) { 356*7c478bd9Sstevel@tonic-gate if (t->t_cred == NULL) 357*7c478bd9Sstevel@tonic-gate t->t_cred = kcred; 358*7c478bd9Sstevel@tonic-gate splx(ipltospl(CLOCK_LEVEL)); 359*7c478bd9Sstevel@tonic-gate do_polled_io = 1; 360*7c478bd9Sstevel@tonic-gate vfs_syncall(); 361*7c478bd9Sstevel@tonic-gate } 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate /* 364*7c478bd9Sstevel@tonic-gate * Take the crash dump. If the dump trigger is already set, try to 365*7c478bd9Sstevel@tonic-gate * enter the debugger again before rebooting the system. 366*7c478bd9Sstevel@tonic-gate */ 367*7c478bd9Sstevel@tonic-gate if (panic_trigger(&panic_dump)) { 368*7c478bd9Sstevel@tonic-gate panic_dump_hw(s); 369*7c478bd9Sstevel@tonic-gate splx(ipltospl(CLOCK_LEVEL)); 370*7c478bd9Sstevel@tonic-gate do_polled_io = 1; 371*7c478bd9Sstevel@tonic-gate dumpsys(); 372*7c478bd9Sstevel@tonic-gate } else if (((boothowto & RB_DEBUG) || obpdebug) && !nopanicdebug) { 373*7c478bd9Sstevel@tonic-gate debug_enter("panic: entering debugger (continue to reboot)"); 374*7c478bd9Sstevel@tonic-gate } else 375*7c478bd9Sstevel@tonic-gate printf("dump aborted: please record the above information!\n"); 376*7c478bd9Sstevel@tonic-gate 377*7c478bd9Sstevel@tonic-gate if (halt_on_panic) 378*7c478bd9Sstevel@tonic-gate mdboot(A_REBOOT, AD_HALT, NULL); 379*7c478bd9Sstevel@tonic-gate else 380*7c478bd9Sstevel@tonic-gate mdboot(A_REBOOT, panic_bootfcn, panic_bootstr); 381*7c478bd9Sstevel@tonic-gate spin: 382*7c478bd9Sstevel@tonic-gate /* 383*7c478bd9Sstevel@tonic-gate * Restore ipl to at most CLOCK_LEVEL so we don't end up spinning 384*7c478bd9Sstevel@tonic-gate * and unable to jump into the debugger. 385*7c478bd9Sstevel@tonic-gate */ 386*7c478bd9Sstevel@tonic-gate splx(MIN(s, ipltospl(CLOCK_LEVEL))); 387*7c478bd9Sstevel@tonic-gate for (;;); 388*7c478bd9Sstevel@tonic-gate } 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate void 391*7c478bd9Sstevel@tonic-gate panic(const char *format, ...) 392*7c478bd9Sstevel@tonic-gate { 393*7c478bd9Sstevel@tonic-gate va_list alist; 394*7c478bd9Sstevel@tonic-gate 395*7c478bd9Sstevel@tonic-gate va_start(alist, format); 396*7c478bd9Sstevel@tonic-gate vpanic(format, alist); 397*7c478bd9Sstevel@tonic-gate va_end(alist); 398*7c478bd9Sstevel@tonic-gate } 399