17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5843e1988Sjohnlev * Common Development and Distribution License (the "License"). 6843e1988Sjohnlev * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22753a6d45SSherry Moore * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * When the operating system detects that it is in an invalid state, a panic 287c478bd9Sstevel@tonic-gate * is initiated in order to minimize potential damage to user data and to 297c478bd9Sstevel@tonic-gate * facilitate debugging. There are three major tasks to be performed in 307c478bd9Sstevel@tonic-gate * a system panic: recording information about the panic in memory (and thus 317c478bd9Sstevel@tonic-gate * making it part of the crash dump), synchronizing the file systems to 327c478bd9Sstevel@tonic-gate * preserve user file data, and generating the crash dump. We define the 337c478bd9Sstevel@tonic-gate * system to be in one of four states with respect to the panic code: 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * CALM - the state of the system prior to any thread initiating a panic 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * QUIESCE - the state of the system when the first thread to initiate 387c478bd9Sstevel@tonic-gate * a system panic records information about the cause of the panic 397c478bd9Sstevel@tonic-gate * and renders the system quiescent by stopping other processors 407c478bd9Sstevel@tonic-gate * 417c478bd9Sstevel@tonic-gate * SYNC - the state of the system when we synchronize the file systems 427c478bd9Sstevel@tonic-gate * DUMP - the state when we generate the crash dump. 437c478bd9Sstevel@tonic-gate * 447c478bd9Sstevel@tonic-gate * The transitions between these states are irreversible: once we begin 457c478bd9Sstevel@tonic-gate * panicking, we only make one attempt to perform the actions associated with 467c478bd9Sstevel@tonic-gate * each state. 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate * The panic code itself must be re-entrant because actions taken during any 497c478bd9Sstevel@tonic-gate * state may lead to another system panic. Additionally, any Solaris 507c478bd9Sstevel@tonic-gate * thread may initiate a panic at any time, and so we must have synchronization 517c478bd9Sstevel@tonic-gate * between threads which attempt to initiate a state transition simultaneously. 527c478bd9Sstevel@tonic-gate * The panic code makes use of a special locking primitive, a trigger, to 537c478bd9Sstevel@tonic-gate * perform this synchronization. A trigger is simply a word which is set 547c478bd9Sstevel@tonic-gate * atomically and can only be set once. We declare three triggers, one for 557c478bd9Sstevel@tonic-gate * each transition between the four states. When a thread enters the panic 567c478bd9Sstevel@tonic-gate * code it attempts to set each trigger; if it fails it moves on to the 577c478bd9Sstevel@tonic-gate * next trigger. A special case is the first trigger: if two threads race 587c478bd9Sstevel@tonic-gate * to perform the transition to QUIESCE, the losing thread may execute before 597c478bd9Sstevel@tonic-gate * the winner has a chance to stop its CPU. To solve this problem, we have 607c478bd9Sstevel@tonic-gate * the loser look ahead to see if any other triggers are set; if not, it 617c478bd9Sstevel@tonic-gate * presumes a panic is underway and simply spins. Unfortunately, since we 627c478bd9Sstevel@tonic-gate * are panicking, it is not possible to know this with absolute certainty. 637c478bd9Sstevel@tonic-gate * 647c478bd9Sstevel@tonic-gate * There are two common reasons for re-entering the panic code once a panic 657c478bd9Sstevel@tonic-gate * has been initiated: (1) after we debug_enter() at the end of QUIESCE, 667c478bd9Sstevel@tonic-gate * the operator may type "sync" instead of "go", and the PROM's sync callback 677c478bd9Sstevel@tonic-gate * routine will invoke panic(); (2) if the clock routine decides that sync 687c478bd9Sstevel@tonic-gate * or dump is not making progress, it will invoke panic() to force a timeout. 697c478bd9Sstevel@tonic-gate * The design assumes that a third possibility, another thread causing an 707c478bd9Sstevel@tonic-gate * unrelated panic while sync or dump is still underway, is extremely unlikely. 717c478bd9Sstevel@tonic-gate * If this situation occurs, we may end up triggering dump while sync is 727c478bd9Sstevel@tonic-gate * still in progress. This third case is considered extremely unlikely because 737c478bd9Sstevel@tonic-gate * all other CPUs are stopped and low-level interrupts have been blocked. 747c478bd9Sstevel@tonic-gate * 757c478bd9Sstevel@tonic-gate * The panic code is entered via a call directly to the vpanic() function, 767c478bd9Sstevel@tonic-gate * or its varargs wrappers panic() and cmn_err(9F). The vpanic routine 777c478bd9Sstevel@tonic-gate * is implemented in assembly language to record the current machine 787c478bd9Sstevel@tonic-gate * registers, attempt to set the trigger for the QUIESCE state, and 797c478bd9Sstevel@tonic-gate * if successful, switch stacks on to the panic_stack before calling into 807c478bd9Sstevel@tonic-gate * the common panicsys() routine. The first thread to initiate a panic 817c478bd9Sstevel@tonic-gate * is allowed to make use of the reserved panic_stack so that executing 827c478bd9Sstevel@tonic-gate * the panic code itself does not overwrite valuable data on that thread's 837c478bd9Sstevel@tonic-gate * stack *ahead* of the current stack pointer. This data will be preserved 847c478bd9Sstevel@tonic-gate * in the crash dump and may prove invaluable in determining what this 857c478bd9Sstevel@tonic-gate * thread has previously been doing. The first thread, saved in panic_thread, 867c478bd9Sstevel@tonic-gate * is also responsible for stopping the other CPUs as quickly as possible, 877c478bd9Sstevel@tonic-gate * and then setting the various panic_* variables. Most important among 887c478bd9Sstevel@tonic-gate * these is panicstr, which allows threads to subsequently bypass held 897c478bd9Sstevel@tonic-gate * locks so that we can proceed without ever blocking. We must stop the 907c478bd9Sstevel@tonic-gate * other CPUs *prior* to setting panicstr in case threads running there are 917c478bd9Sstevel@tonic-gate * currently spinning to acquire a lock; we want that state to be preserved. 927c478bd9Sstevel@tonic-gate * Every thread which initiates a panic has its T_PANIC flag set so we can 937c478bd9Sstevel@tonic-gate * identify all such threads in the crash dump. 947c478bd9Sstevel@tonic-gate * 957c478bd9Sstevel@tonic-gate * The panic_thread is also allowed to make use of the special memory buffer 967c478bd9Sstevel@tonic-gate * panicbuf, which on machines with appropriate hardware is preserved across 977c478bd9Sstevel@tonic-gate * reboots. We allow the panic_thread to store its register set and panic 987c478bd9Sstevel@tonic-gate * message in this buffer, so even if we fail to obtain a crash dump we will 997c478bd9Sstevel@tonic-gate * be able to examine the machine after reboot and determine some of the 1007c478bd9Sstevel@tonic-gate * state at the time of the panic. If we do get a dump, the panic buffer 1017c478bd9Sstevel@tonic-gate * data is structured so that a debugger can easily consume the information 1027c478bd9Sstevel@tonic-gate * therein (see <sys/panic.h>). 1037c478bd9Sstevel@tonic-gate * 1047c478bd9Sstevel@tonic-gate * Each platform or architecture is required to implement the functions 1057c478bd9Sstevel@tonic-gate * panic_savetrap() to record trap-specific information to panicbuf, 1067c478bd9Sstevel@tonic-gate * panic_saveregs() to record a register set to panicbuf, panic_stopcpus() 1077c478bd9Sstevel@tonic-gate * to halt all CPUs but the panicking CPU, panic_quiesce_hw() to perform 1087c478bd9Sstevel@tonic-gate * miscellaneous platform-specific tasks *after* panicstr is set, 1097c478bd9Sstevel@tonic-gate * panic_showtrap() to print trap-specific information to the console, 1107c478bd9Sstevel@tonic-gate * and panic_dump_hw() to perform platform tasks prior to calling dumpsys(). 1117c478bd9Sstevel@tonic-gate * 1127c478bd9Sstevel@tonic-gate * A Note on Word Formation, courtesy of the Oxford Guide to English Usage: 1137c478bd9Sstevel@tonic-gate * 1147c478bd9Sstevel@tonic-gate * Words ending in -c interpose k before suffixes which otherwise would 1157c478bd9Sstevel@tonic-gate * indicate a soft c, and thus the verb and adjective forms of 'panic' are 1167c478bd9Sstevel@tonic-gate * spelled "panicked", "panicking", and "panicky" respectively. Use of 1177c478bd9Sstevel@tonic-gate * the ill-conceived "panicing" and "panic'd" is discouraged. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate #include <sys/types.h> 1217c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 1227c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 1237c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 1247c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 1257c478bd9Sstevel@tonic-gate #include <sys/thread.h> 1267c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 1277c478bd9Sstevel@tonic-gate #include <sys/cred.h> 1287c478bd9Sstevel@tonic-gate #include <sys/systm.h> 129843e1988Sjohnlev #include <sys/archsystm.h> 1307c478bd9Sstevel@tonic-gate #include <sys/uadmin.h> 1317c478bd9Sstevel@tonic-gate #include <sys/callb.h> 1327c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 1337c478bd9Sstevel@tonic-gate #include <sys/log.h> 1347c478bd9Sstevel@tonic-gate #include <sys/disp.h> 1357c478bd9Sstevel@tonic-gate #include <sys/param.h> 1367c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h> 1377c478bd9Sstevel@tonic-gate #include <sys/ftrace.h> 1387c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 1397c478bd9Sstevel@tonic-gate #include <sys/debug.h> 1407c478bd9Sstevel@tonic-gate #include <sys/stack.h> 1417c478bd9Sstevel@tonic-gate #include <sys/spl.h> 1427c478bd9Sstevel@tonic-gate #include <sys/errorq.h> 1437c478bd9Sstevel@tonic-gate #include <sys/panic.h> 1447aec1d6eScindi #include <sys/fm/util.h> 145*d3d50737SRafael Vanoni #include <sys/clock_impl.h> 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * Panic variables which are set once during the QUIESCE state by the 1497c478bd9Sstevel@tonic-gate * first thread to initiate a panic. These are examined by post-mortem 1507c478bd9Sstevel@tonic-gate * debugging tools; the inconsistent use of 'panic' versus 'panic_' in 1517c478bd9Sstevel@tonic-gate * the variable naming is historical and allows legacy tools to work. 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate #pragma align STACK_ALIGN(panic_stack) 1547c478bd9Sstevel@tonic-gate char panic_stack[PANICSTKSIZE]; /* reserved stack for panic_thread */ 1557c478bd9Sstevel@tonic-gate kthread_t *panic_thread; /* first thread to call panicsys() */ 1567c478bd9Sstevel@tonic-gate cpu_t panic_cpu; /* cpu from first call to panicsys() */ 1577c478bd9Sstevel@tonic-gate label_t panic_regs; /* setjmp label from panic_thread */ 1587c478bd9Sstevel@tonic-gate struct regs *panic_reg; /* regs struct from first panicsys() */ 1597c478bd9Sstevel@tonic-gate char *volatile panicstr; /* format string to first panicsys() */ 1607c478bd9Sstevel@tonic-gate va_list panicargs; /* arguments to first panicsys() */ 1617c478bd9Sstevel@tonic-gate clock_t panic_lbolt; /* lbolt at time of panic */ 1627c478bd9Sstevel@tonic-gate int64_t panic_lbolt64; /* lbolt64 at time of panic */ 1637c478bd9Sstevel@tonic-gate hrtime_t panic_hrtime; /* hrtime at time of panic */ 1647c478bd9Sstevel@tonic-gate timespec_t panic_hrestime; /* hrestime at time of panic */ 1657c478bd9Sstevel@tonic-gate int panic_ipl; /* ipl on panic_cpu at time of panic */ 1667c478bd9Sstevel@tonic-gate ushort_t panic_schedflag; /* t_schedflag for panic_thread */ 1677c478bd9Sstevel@tonic-gate cpu_t *panic_bound_cpu; /* t_bound_cpu for panic_thread */ 1687c478bd9Sstevel@tonic-gate char panic_preempt; /* t_preempt for panic_thread */ 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * Panic variables which can be set via /etc/system or patched while 1727c478bd9Sstevel@tonic-gate * the system is in operation. Again, the stupid names are historic. 1737c478bd9Sstevel@tonic-gate */ 1747c478bd9Sstevel@tonic-gate char *panic_bootstr = NULL; /* mdboot string to use after panic */ 1757c478bd9Sstevel@tonic-gate int panic_bootfcn = AD_BOOT; /* mdboot function to use after panic */ 1767c478bd9Sstevel@tonic-gate int halt_on_panic = 0; /* halt after dump instead of reboot? */ 1777c478bd9Sstevel@tonic-gate int nopanicdebug = 0; /* reboot instead of call debugger? */ 1787c478bd9Sstevel@tonic-gate int in_sync = 0; /* skip vfs_syncall() and just dump? */ 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* 1817c478bd9Sstevel@tonic-gate * The do_polled_io flag is set by the panic code to inform the SCSI subsystem 1827c478bd9Sstevel@tonic-gate * to use polled mode instead of interrupt-driven i/o. 1837c478bd9Sstevel@tonic-gate */ 1847c478bd9Sstevel@tonic-gate int do_polled_io = 0; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * The panic_forced flag is set by the uadmin A_DUMP code to inform the 1887c478bd9Sstevel@tonic-gate * panic subsystem that it should not attempt an initial debug_enter. 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate int panic_forced = 0; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * Triggers for panic state transitions: 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate int panic_quiesce; /* trigger for CALM -> QUIESCE */ 1967c478bd9Sstevel@tonic-gate int panic_sync; /* trigger for QUIESCE -> SYNC */ 1977c478bd9Sstevel@tonic-gate int panic_dump; /* trigger for SYNC -> DUMP */ 1987c478bd9Sstevel@tonic-gate 199753a6d45SSherry Moore /* 200753a6d45SSherry Moore * Variable signifying quiesce(9E) is in progress. 201753a6d45SSherry Moore */ 202753a6d45SSherry Moore volatile int quiesce_active = 0; 203753a6d45SSherry Moore 2047c478bd9Sstevel@tonic-gate void 2057c478bd9Sstevel@tonic-gate panicsys(const char *format, va_list alist, struct regs *rp, int on_panic_stack) 2067c478bd9Sstevel@tonic-gate { 2077c478bd9Sstevel@tonic-gate int s = spl8(); 2087c478bd9Sstevel@tonic-gate kthread_t *t = curthread; 2097c478bd9Sstevel@tonic-gate cpu_t *cp = CPU; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate caddr_t intr_stack = NULL; 2127c478bd9Sstevel@tonic-gate uint_t intr_actv; 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate ushort_t schedflag = t->t_schedflag; 2157c478bd9Sstevel@tonic-gate cpu_t *bound_cpu = t->t_bound_cpu; 2167c478bd9Sstevel@tonic-gate char preempt = t->t_preempt; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate (void) setjmp(&t->t_pcb); 2197c478bd9Sstevel@tonic-gate t->t_flag |= T_PANIC; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate t->t_schedflag |= TS_DONT_SWAP; 2227c478bd9Sstevel@tonic-gate t->t_bound_cpu = cp; 2237c478bd9Sstevel@tonic-gate t->t_preempt++; 2247c478bd9Sstevel@tonic-gate 225*d3d50737SRafael Vanoni /* 226*d3d50737SRafael Vanoni * Switch lbolt to event driven mode. 227*d3d50737SRafael Vanoni */ 228*d3d50737SRafael Vanoni lbolt_hybrid = lbolt_event_driven; 229*d3d50737SRafael Vanoni 2307c478bd9Sstevel@tonic-gate panic_enter_hw(s); 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate /* 2337c478bd9Sstevel@tonic-gate * If we're on the interrupt stack and an interrupt thread is available 2347c478bd9Sstevel@tonic-gate * in this CPU's pool, preserve the interrupt stack by detaching an 2357c478bd9Sstevel@tonic-gate * interrupt thread and making its stack the intr_stack. 2367c478bd9Sstevel@tonic-gate */ 2377c478bd9Sstevel@tonic-gate if (CPU_ON_INTR(cp) && cp->cpu_intr_thread != NULL) { 2387c478bd9Sstevel@tonic-gate kthread_t *it = cp->cpu_intr_thread; 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate intr_stack = cp->cpu_intr_stack; 2417c478bd9Sstevel@tonic-gate intr_actv = cp->cpu_intr_actv; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate cp->cpu_intr_stack = thread_stk_init(it->t_stk); 2447c478bd9Sstevel@tonic-gate cp->cpu_intr_thread = it->t_link; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * Clear only the high level bits of cpu_intr_actv. 2487c478bd9Sstevel@tonic-gate * We want to indicate that high-level interrupts are 2497c478bd9Sstevel@tonic-gate * not active without destroying the low-level interrupt 2507c478bd9Sstevel@tonic-gate * information stored there. 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate cp->cpu_intr_actv &= ((1 << (LOCK_LEVEL + 1)) - 1); 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * Record one-time panic information and quiesce the other CPUs. 2577c478bd9Sstevel@tonic-gate * Then print out the panic message and stack trace. 2587c478bd9Sstevel@tonic-gate */ 2597c478bd9Sstevel@tonic-gate if (on_panic_stack) { 2607c478bd9Sstevel@tonic-gate panic_data_t *pdp = (panic_data_t *)panicbuf; 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate pdp->pd_version = PANICBUFVERS; 2637c478bd9Sstevel@tonic-gate pdp->pd_msgoff = sizeof (panic_data_t) - sizeof (panic_nv_t); 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate if (t->t_panic_trap != NULL) 2667c478bd9Sstevel@tonic-gate panic_savetrap(pdp, t->t_panic_trap); 2677c478bd9Sstevel@tonic-gate else 2687c478bd9Sstevel@tonic-gate panic_saveregs(pdp, rp); 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate (void) vsnprintf(&panicbuf[pdp->pd_msgoff], 2717c478bd9Sstevel@tonic-gate PANICBUFSIZE - pdp->pd_msgoff, format, alist); 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate /* 2747c478bd9Sstevel@tonic-gate * Call into the platform code to stop the other CPUs. 2757c478bd9Sstevel@tonic-gate * We currently have all interrupts blocked, and expect that 2767c478bd9Sstevel@tonic-gate * the platform code will lower ipl only as far as needed to 2777c478bd9Sstevel@tonic-gate * perform cross-calls, and will acquire as *few* locks as is 2787c478bd9Sstevel@tonic-gate * possible -- panicstr is not set so we can still deadlock. 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate panic_stopcpus(cp, t, s); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate panicstr = (char *)format; 2837c478bd9Sstevel@tonic-gate va_copy(panicargs, alist); 284*d3d50737SRafael Vanoni panic_lbolt = (clock_t)LBOLT_NO_ACCOUNT; 285*d3d50737SRafael Vanoni panic_lbolt64 = LBOLT_NO_ACCOUNT; 2867c478bd9Sstevel@tonic-gate panic_hrestime = hrestime; 2877c478bd9Sstevel@tonic-gate panic_hrtime = gethrtime_waitfree(); 2887c478bd9Sstevel@tonic-gate panic_thread = t; 2897c478bd9Sstevel@tonic-gate panic_regs = t->t_pcb; 2907c478bd9Sstevel@tonic-gate panic_reg = rp; 2917c478bd9Sstevel@tonic-gate panic_cpu = *cp; 2927c478bd9Sstevel@tonic-gate panic_ipl = spltoipl(s); 2937c478bd9Sstevel@tonic-gate panic_schedflag = schedflag; 2947c478bd9Sstevel@tonic-gate panic_bound_cpu = bound_cpu; 2957c478bd9Sstevel@tonic-gate panic_preempt = preempt; 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate if (intr_stack != NULL) { 2987c478bd9Sstevel@tonic-gate panic_cpu.cpu_intr_stack = intr_stack; 2997c478bd9Sstevel@tonic-gate panic_cpu.cpu_intr_actv = intr_actv; 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate /* 3037c478bd9Sstevel@tonic-gate * Lower ipl to 10 to keep clock() from running, but allow 3047c478bd9Sstevel@tonic-gate * keyboard interrupts to enter the debugger. These callbacks 3057c478bd9Sstevel@tonic-gate * are executed with panicstr set so they can bypass locks. 3067c478bd9Sstevel@tonic-gate */ 3077c478bd9Sstevel@tonic-gate splx(ipltospl(CLOCK_LEVEL)); 3087c478bd9Sstevel@tonic-gate panic_quiesce_hw(pdp); 3097c478bd9Sstevel@tonic-gate (void) FTRACE_STOP(); 3107c478bd9Sstevel@tonic-gate (void) callb_execute_class(CB_CL_PANIC, NULL); 3117c478bd9Sstevel@tonic-gate 312281888b3Sjbeck if (log_intrq != NULL) 313281888b3Sjbeck log_flushq(log_intrq); 314281888b3Sjbeck 315281888b3Sjbeck /* 316281888b3Sjbeck * If log_consq has been initialized and syslogd has started, 317281888b3Sjbeck * print any messages in log_consq that haven't been consumed. 318281888b3Sjbeck */ 319281888b3Sjbeck if (log_consq != NULL && log_consq != log_backlogq) 320281888b3Sjbeck log_printq(log_consq); 321281888b3Sjbeck 3227c478bd9Sstevel@tonic-gate fm_banner(); 3237c478bd9Sstevel@tonic-gate 324843e1988Sjohnlev #if defined(__x86) 325843e1988Sjohnlev /* 326843e1988Sjohnlev * A hypervisor panic originates outside of Solaris, so we 327843e1988Sjohnlev * don't want to prepend the panic message with misleading 328843e1988Sjohnlev * pointers from within Solaris. 329843e1988Sjohnlev */ 330843e1988Sjohnlev if (!IN_XPV_PANIC()) 331843e1988Sjohnlev #endif 332843e1988Sjohnlev printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id, 333843e1988Sjohnlev (void *)t); 3347c478bd9Sstevel@tonic-gate vprintf(format, alist); 3357c478bd9Sstevel@tonic-gate printf("\n\n"); 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate if (t->t_panic_trap != NULL) { 3387c478bd9Sstevel@tonic-gate panic_showtrap(t->t_panic_trap); 3397c478bd9Sstevel@tonic-gate printf("\n"); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate traceregs(rp); 3437c478bd9Sstevel@tonic-gate printf("\n"); 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate if (((boothowto & RB_DEBUG) || obpdebug) && 3467c478bd9Sstevel@tonic-gate !nopanicdebug && !panic_forced) { 3477c478bd9Sstevel@tonic-gate if (dumpvp != NULL) { 3487c478bd9Sstevel@tonic-gate debug_enter("panic: entering debugger " 3497c478bd9Sstevel@tonic-gate "(continue to save dump)"); 3507c478bd9Sstevel@tonic-gate } else { 3517c478bd9Sstevel@tonic-gate debug_enter("panic: entering debugger " 3527c478bd9Sstevel@tonic-gate "(no dump device, continue to reboot)"); 3537c478bd9Sstevel@tonic-gate } 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate } else if (panic_dump != 0 || panic_sync != 0 || panicstr != NULL) { 3577c478bd9Sstevel@tonic-gate printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id, (void *)t); 3587c478bd9Sstevel@tonic-gate vprintf(format, alist); 3597c478bd9Sstevel@tonic-gate printf("\n"); 3607c478bd9Sstevel@tonic-gate } else 3617c478bd9Sstevel@tonic-gate goto spin; 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate /* 3647c478bd9Sstevel@tonic-gate * Prior to performing sync or dump, we make sure that do_polled_io is 3657c478bd9Sstevel@tonic-gate * set, but we'll leave ipl at 10; deadman(), a CY_HIGH_LEVEL cyclic, 3667c478bd9Sstevel@tonic-gate * will re-enter panic if we are not making progress with sync or dump. 3677c478bd9Sstevel@tonic-gate */ 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate /* 3707c478bd9Sstevel@tonic-gate * Sync the filesystems. Reset t_cred if not set because much of 3717c478bd9Sstevel@tonic-gate * the filesystem code depends on CRED() being valid. 3727c478bd9Sstevel@tonic-gate */ 3737c478bd9Sstevel@tonic-gate if (!in_sync && panic_trigger(&panic_sync)) { 3747c478bd9Sstevel@tonic-gate if (t->t_cred == NULL) 3757c478bd9Sstevel@tonic-gate t->t_cred = kcred; 3767c478bd9Sstevel@tonic-gate splx(ipltospl(CLOCK_LEVEL)); 3777c478bd9Sstevel@tonic-gate do_polled_io = 1; 3787c478bd9Sstevel@tonic-gate vfs_syncall(); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate /* 3827c478bd9Sstevel@tonic-gate * Take the crash dump. If the dump trigger is already set, try to 3837c478bd9Sstevel@tonic-gate * enter the debugger again before rebooting the system. 3847c478bd9Sstevel@tonic-gate */ 3857c478bd9Sstevel@tonic-gate if (panic_trigger(&panic_dump)) { 3867c478bd9Sstevel@tonic-gate panic_dump_hw(s); 3877c478bd9Sstevel@tonic-gate splx(ipltospl(CLOCK_LEVEL)); 3881d76b125Sstephh errorq_panic(); 3897c478bd9Sstevel@tonic-gate do_polled_io = 1; 3907c478bd9Sstevel@tonic-gate dumpsys(); 3917c478bd9Sstevel@tonic-gate } else if (((boothowto & RB_DEBUG) || obpdebug) && !nopanicdebug) { 3927c478bd9Sstevel@tonic-gate debug_enter("panic: entering debugger (continue to reboot)"); 3937c478bd9Sstevel@tonic-gate } else 3947c478bd9Sstevel@tonic-gate printf("dump aborted: please record the above information!\n"); 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate if (halt_on_panic) 397edc40228Sachartre mdboot(A_REBOOT, AD_HALT, NULL, B_FALSE); 3987c478bd9Sstevel@tonic-gate else 399edc40228Sachartre mdboot(A_REBOOT, panic_bootfcn, panic_bootstr, B_FALSE); 4007c478bd9Sstevel@tonic-gate spin: 4017c478bd9Sstevel@tonic-gate /* 4027c478bd9Sstevel@tonic-gate * Restore ipl to at most CLOCK_LEVEL so we don't end up spinning 4037c478bd9Sstevel@tonic-gate * and unable to jump into the debugger. 4047c478bd9Sstevel@tonic-gate */ 4057c478bd9Sstevel@tonic-gate splx(MIN(s, ipltospl(CLOCK_LEVEL))); 406843e1988Sjohnlev for (;;) 407843e1988Sjohnlev ; 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate void 4117c478bd9Sstevel@tonic-gate panic(const char *format, ...) 4127c478bd9Sstevel@tonic-gate { 4137c478bd9Sstevel@tonic-gate va_list alist; 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate va_start(alist, format); 4167c478bd9Sstevel@tonic-gate vpanic(format, alist); 4177c478bd9Sstevel@tonic-gate va_end(alist); 4187c478bd9Sstevel@tonic-gate } 419