xref: /illumos-gate/usr/src/uts/common/os/panic.c (revision 3df2e8b2)
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 /*
2290aaf355SRafael Vanoni  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
2584058112SBryan Cantrill /*
2684058112SBryan Cantrill  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
273f11de9dSSara Hartse  * Copyright (c) 2016 by Delphix. All rights reserved.
2884058112SBryan Cantrill  */
2984058112SBryan Cantrill 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * When the operating system detects that it is in an invalid state, a panic
327c478bd9Sstevel@tonic-gate  * is initiated in order to minimize potential damage to user data and to
337c478bd9Sstevel@tonic-gate  * facilitate debugging.  There are three major tasks to be performed in
347c478bd9Sstevel@tonic-gate  * a system panic: recording information about the panic in memory (and thus
357c478bd9Sstevel@tonic-gate  * making it part of the crash dump), synchronizing the file systems to
367c478bd9Sstevel@tonic-gate  * preserve user file data, and generating the crash dump.  We define the
377c478bd9Sstevel@tonic-gate  * system to be in one of four states with respect to the panic code:
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * CALM    - the state of the system prior to any thread initiating a panic
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  * QUIESCE - the state of the system when the first thread to initiate
427c478bd9Sstevel@tonic-gate  *           a system panic records information about the cause of the panic
437c478bd9Sstevel@tonic-gate  *           and renders the system quiescent by stopping other processors
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * SYNC    - the state of the system when we synchronize the file systems
467c478bd9Sstevel@tonic-gate  * DUMP    - the state when we generate the crash dump.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * The transitions between these states are irreversible: once we begin
497c478bd9Sstevel@tonic-gate  * panicking, we only make one attempt to perform the actions associated with
507c478bd9Sstevel@tonic-gate  * each state.
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * The panic code itself must be re-entrant because actions taken during any
537c478bd9Sstevel@tonic-gate  * state may lead to another system panic.  Additionally, any Solaris
547c478bd9Sstevel@tonic-gate  * thread may initiate a panic at any time, and so we must have synchronization
557c478bd9Sstevel@tonic-gate  * between threads which attempt to initiate a state transition simultaneously.
567c478bd9Sstevel@tonic-gate  * The panic code makes use of a special locking primitive, a trigger, to
577c478bd9Sstevel@tonic-gate  * perform this synchronization.  A trigger is simply a word which is set
587c478bd9Sstevel@tonic-gate  * atomically and can only be set once.  We declare three triggers, one for
597c478bd9Sstevel@tonic-gate  * each transition between the four states.  When a thread enters the panic
607c478bd9Sstevel@tonic-gate  * code it attempts to set each trigger; if it fails it moves on to the
617c478bd9Sstevel@tonic-gate  * next trigger.  A special case is the first trigger: if two threads race
627c478bd9Sstevel@tonic-gate  * to perform the transition to QUIESCE, the losing thread may execute before
637c478bd9Sstevel@tonic-gate  * the winner has a chance to stop its CPU.  To solve this problem, we have
647c478bd9Sstevel@tonic-gate  * the loser look ahead to see if any other triggers are set; if not, it
657c478bd9Sstevel@tonic-gate  * presumes a panic is underway and simply spins.  Unfortunately, since we
667c478bd9Sstevel@tonic-gate  * are panicking, it is not possible to know this with absolute certainty.
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * There are two common reasons for re-entering the panic code once a panic
697c478bd9Sstevel@tonic-gate  * has been initiated: (1) after we debug_enter() at the end of QUIESCE,
707c478bd9Sstevel@tonic-gate  * the operator may type "sync" instead of "go", and the PROM's sync callback
717c478bd9Sstevel@tonic-gate  * routine will invoke panic(); (2) if the clock routine decides that sync
727c478bd9Sstevel@tonic-gate  * or dump is not making progress, it will invoke panic() to force a timeout.
737c478bd9Sstevel@tonic-gate  * The design assumes that a third possibility, another thread causing an
747c478bd9Sstevel@tonic-gate  * unrelated panic while sync or dump is still underway, is extremely unlikely.
757c478bd9Sstevel@tonic-gate  * If this situation occurs, we may end up triggering dump while sync is
767c478bd9Sstevel@tonic-gate  * still in progress.  This third case is considered extremely unlikely because
777c478bd9Sstevel@tonic-gate  * all other CPUs are stopped and low-level interrupts have been blocked.
787c478bd9Sstevel@tonic-gate  *
797c478bd9Sstevel@tonic-gate  * The panic code is entered via a call directly to the vpanic() function,
807c478bd9Sstevel@tonic-gate  * or its varargs wrappers panic() and cmn_err(9F).  The vpanic routine
817c478bd9Sstevel@tonic-gate  * is implemented in assembly language to record the current machine
827c478bd9Sstevel@tonic-gate  * registers, attempt to set the trigger for the QUIESCE state, and
837c478bd9Sstevel@tonic-gate  * if successful, switch stacks on to the panic_stack before calling into
847c478bd9Sstevel@tonic-gate  * the common panicsys() routine.  The first thread to initiate a panic
857c478bd9Sstevel@tonic-gate  * is allowed to make use of the reserved panic_stack so that executing
867c478bd9Sstevel@tonic-gate  * the panic code itself does not overwrite valuable data on that thread's
877c478bd9Sstevel@tonic-gate  * stack *ahead* of the current stack pointer.  This data will be preserved
887c478bd9Sstevel@tonic-gate  * in the crash dump and may prove invaluable in determining what this
897c478bd9Sstevel@tonic-gate  * thread has previously been doing.  The first thread, saved in panic_thread,
907c478bd9Sstevel@tonic-gate  * is also responsible for stopping the other CPUs as quickly as possible,
917c478bd9Sstevel@tonic-gate  * and then setting the various panic_* variables.  Most important among
927c478bd9Sstevel@tonic-gate  * these is panicstr, which allows threads to subsequently bypass held
937c478bd9Sstevel@tonic-gate  * locks so that we can proceed without ever blocking.  We must stop the
947c478bd9Sstevel@tonic-gate  * other CPUs *prior* to setting panicstr in case threads running there are
957c478bd9Sstevel@tonic-gate  * currently spinning to acquire a lock; we want that state to be preserved.
967c478bd9Sstevel@tonic-gate  * Every thread which initiates a panic has its T_PANIC flag set so we can
977c478bd9Sstevel@tonic-gate  * identify all such threads in the crash dump.
987c478bd9Sstevel@tonic-gate  *
997c478bd9Sstevel@tonic-gate  * The panic_thread is also allowed to make use of the special memory buffer
1007c478bd9Sstevel@tonic-gate  * panicbuf, which on machines with appropriate hardware is preserved across
1017c478bd9Sstevel@tonic-gate  * reboots.  We allow the panic_thread to store its register set and panic
1027c478bd9Sstevel@tonic-gate  * message in this buffer, so even if we fail to obtain a crash dump we will
1037c478bd9Sstevel@tonic-gate  * be able to examine the machine after reboot and determine some of the
1047c478bd9Sstevel@tonic-gate  * state at the time of the panic.  If we do get a dump, the panic buffer
1057c478bd9Sstevel@tonic-gate  * data is structured so that a debugger can easily consume the information
1067c478bd9Sstevel@tonic-gate  * therein (see <sys/panic.h>).
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  * Each platform or architecture is required to implement the functions
1097c478bd9Sstevel@tonic-gate  * panic_savetrap() to record trap-specific information to panicbuf,
1107c478bd9Sstevel@tonic-gate  * panic_saveregs() to record a register set to panicbuf, panic_stopcpus()
1117c478bd9Sstevel@tonic-gate  * to halt all CPUs but the panicking CPU, panic_quiesce_hw() to perform
1127c478bd9Sstevel@tonic-gate  * miscellaneous platform-specific tasks *after* panicstr is set,
1137c478bd9Sstevel@tonic-gate  * panic_showtrap() to print trap-specific information to the console,
1147c478bd9Sstevel@tonic-gate  * and panic_dump_hw() to perform platform tasks prior to calling dumpsys().
1157c478bd9Sstevel@tonic-gate  *
1167c478bd9Sstevel@tonic-gate  * A Note on Word Formation, courtesy of the Oxford Guide to English Usage:
1177c478bd9Sstevel@tonic-gate  *
1187c478bd9Sstevel@tonic-gate  * Words ending in -c interpose k before suffixes which otherwise would
1197c478bd9Sstevel@tonic-gate  * indicate a soft c, and thus the verb and adjective forms of 'panic' are
1207c478bd9Sstevel@tonic-gate  * spelled "panicked", "panicking", and "panicky" respectively.  Use of
1217c478bd9Sstevel@tonic-gate  * the ill-conceived "panicing" and "panic'd" is discouraged.
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #include <sys/types.h>
1257c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
1267c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
1277c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
1287c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
1297c478bd9Sstevel@tonic-gate #include <sys/thread.h>
1307c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
1317c478bd9Sstevel@tonic-gate #include <sys/cred.h>
1327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
133843e1988Sjohnlev #include <sys/archsystm.h>
1347c478bd9Sstevel@tonic-gate #include <sys/uadmin.h>
1357c478bd9Sstevel@tonic-gate #include <sys/callb.h>
1367c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
1377c478bd9Sstevel@tonic-gate #include <sys/log.h>
1387c478bd9Sstevel@tonic-gate #include <sys/disp.h>
1397c478bd9Sstevel@tonic-gate #include <sys/param.h>
1407c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h>
1417c478bd9Sstevel@tonic-gate #include <sys/ftrace.h>
1427c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
1437c478bd9Sstevel@tonic-gate #include <sys/debug.h>
1447c478bd9Sstevel@tonic-gate #include <sys/stack.h>
1457c478bd9Sstevel@tonic-gate #include <sys/spl.h>
1467c478bd9Sstevel@tonic-gate #include <sys/errorq.h>
1477c478bd9Sstevel@tonic-gate #include <sys/panic.h>
1487aec1d6eScindi #include <sys/fm/util.h>
149d3d50737SRafael Vanoni #include <sys/clock_impl.h>
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * Panic variables which are set once during the QUIESCE state by the
1537c478bd9Sstevel@tonic-gate  * first thread to initiate a panic.  These are examined by post-mortem
1547c478bd9Sstevel@tonic-gate  * debugging tools; the inconsistent use of 'panic' versus 'panic_' in
1557c478bd9Sstevel@tonic-gate  * the variable naming is historical and allows legacy tools to work.
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate #pragma align STACK_ALIGN(panic_stack)
1587c478bd9Sstevel@tonic-gate char panic_stack[PANICSTKSIZE];		/* reserved stack for panic_thread */
1597c478bd9Sstevel@tonic-gate kthread_t *panic_thread;		/* first thread to call panicsys() */
1607c478bd9Sstevel@tonic-gate cpu_t panic_cpu;			/* cpu from first call to panicsys() */
1617c478bd9Sstevel@tonic-gate label_t panic_regs;			/* setjmp label from panic_thread */
16284058112SBryan Cantrill label_t panic_pcb;			/* t_pcb at time of panic */
1637c478bd9Sstevel@tonic-gate struct regs *panic_reg;			/* regs struct from first panicsys() */
1647c478bd9Sstevel@tonic-gate char *volatile panicstr;		/* format string to first panicsys() */
1657c478bd9Sstevel@tonic-gate va_list panicargs;			/* arguments to first panicsys() */
1667c478bd9Sstevel@tonic-gate clock_t panic_lbolt;			/* lbolt at time of panic */
1677c478bd9Sstevel@tonic-gate int64_t panic_lbolt64;			/* lbolt64 at time of panic */
1687c478bd9Sstevel@tonic-gate hrtime_t panic_hrtime;			/* hrtime at time of panic */
1697c478bd9Sstevel@tonic-gate timespec_t panic_hrestime;		/* hrestime at time of panic */
1707c478bd9Sstevel@tonic-gate int panic_ipl;				/* ipl on panic_cpu at time of panic */
1717c478bd9Sstevel@tonic-gate ushort_t panic_schedflag;		/* t_schedflag for panic_thread */
1727c478bd9Sstevel@tonic-gate cpu_t *panic_bound_cpu;			/* t_bound_cpu for panic_thread */
1737c478bd9Sstevel@tonic-gate char panic_preempt;			/* t_preempt for panic_thread */
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate  * Panic variables which can be set via /etc/system or patched while
1777c478bd9Sstevel@tonic-gate  * the system is in operation.  Again, the stupid names are historic.
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate char *panic_bootstr = NULL;		/* mdboot string to use after panic */
1807c478bd9Sstevel@tonic-gate int panic_bootfcn = AD_BOOT;		/* mdboot function to use after panic */
1814da99751SToomas Soome int halt_on_panic = 0;			/* halt after dump instead of reboot? */
1827c478bd9Sstevel@tonic-gate int nopanicdebug = 0;			/* reboot instead of call debugger? */
1837c478bd9Sstevel@tonic-gate int in_sync = 0;			/* skip vfs_syncall() and just dump? */
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate  * The do_polled_io flag is set by the panic code to inform the SCSI subsystem
1877c478bd9Sstevel@tonic-gate  * to use polled mode instead of interrupt-driven i/o.
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate int do_polled_io = 0;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * The panic_forced flag is set by the uadmin A_DUMP code to inform the
1937c478bd9Sstevel@tonic-gate  * panic subsystem that it should not attempt an initial debug_enter.
1947c478bd9Sstevel@tonic-gate  */
1957c478bd9Sstevel@tonic-gate int panic_forced = 0;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * Triggers for panic state transitions:
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate int panic_quiesce;			/* trigger for CALM    -> QUIESCE */
2013f11de9dSSara Hartse int panic_dump;				/* trigger for QUIESCE    -> DUMP */
2027c478bd9Sstevel@tonic-gate 
203753a6d45SSherry Moore /*
204753a6d45SSherry Moore  * Variable signifying quiesce(9E) is in progress.
205753a6d45SSherry Moore  */
206753a6d45SSherry Moore volatile int quiesce_active = 0;
207753a6d45SSherry Moore 
2087c478bd9Sstevel@tonic-gate void
panicsys(const char * format,va_list alist,struct regs * rp,int on_panic_stack)2097c478bd9Sstevel@tonic-gate panicsys(const char *format, va_list alist, struct regs *rp, int on_panic_stack)
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate 	int s = spl8();
2127c478bd9Sstevel@tonic-gate 	kthread_t *t = curthread;
2137c478bd9Sstevel@tonic-gate 	cpu_t *cp = CPU;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	caddr_t intr_stack = NULL;
216*3df2e8b2SRobert Mustacchi 	volatile uint_t intr_actv;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	ushort_t schedflag = t->t_schedflag;
2197c478bd9Sstevel@tonic-gate 	cpu_t *bound_cpu = t->t_bound_cpu;
2207c478bd9Sstevel@tonic-gate 	char preempt = t->t_preempt;
22184058112SBryan Cantrill 	label_t pcb = t->t_pcb;
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	(void) setjmp(&t->t_pcb);
2247c478bd9Sstevel@tonic-gate 	t->t_flag |= T_PANIC;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	t->t_schedflag |= TS_DONT_SWAP;
2277c478bd9Sstevel@tonic-gate 	t->t_bound_cpu = cp;
2287c478bd9Sstevel@tonic-gate 	t->t_preempt++;
2297c478bd9Sstevel@tonic-gate 
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 
265f6e214c7SGavin Maltby 		(void) strncpy(pdp->pd_uuid, dump_get_uuid(),
266f6e214c7SGavin Maltby 		    sizeof (pdp->pd_uuid));
267f6e214c7SGavin Maltby 
2687c478bd9Sstevel@tonic-gate 		if (t->t_panic_trap != NULL)
2697c478bd9Sstevel@tonic-gate 			panic_savetrap(pdp, t->t_panic_trap);
2707c478bd9Sstevel@tonic-gate 		else
2717c478bd9Sstevel@tonic-gate 			panic_saveregs(pdp, rp);
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 		(void) vsnprintf(&panicbuf[pdp->pd_msgoff],
2747c478bd9Sstevel@tonic-gate 		    PANICBUFSIZE - pdp->pd_msgoff, format, alist);
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 		/*
2777c478bd9Sstevel@tonic-gate 		 * Call into the platform code to stop the other CPUs.
2787c478bd9Sstevel@tonic-gate 		 * We currently have all interrupts blocked, and expect that
2797c478bd9Sstevel@tonic-gate 		 * the platform code will lower ipl only as far as needed to
2807c478bd9Sstevel@tonic-gate 		 * perform cross-calls, and will acquire as *few* locks as is
2817c478bd9Sstevel@tonic-gate 		 * possible -- panicstr is not set so we can still deadlock.
2827c478bd9Sstevel@tonic-gate 		 */
2837c478bd9Sstevel@tonic-gate 		panic_stopcpus(cp, t, s);
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 		panicstr = (char *)format;
2867c478bd9Sstevel@tonic-gate 		va_copy(panicargs, alist);
2871b7f7204SRafael Vanoni 		panic_lbolt = LBOLT_NO_ACCOUNT;
2881b7f7204SRafael Vanoni 		panic_lbolt64 = LBOLT_NO_ACCOUNT64;
2897c478bd9Sstevel@tonic-gate 		panic_hrestime = hrestime;
2907c478bd9Sstevel@tonic-gate 		panic_hrtime = gethrtime_waitfree();
2917c478bd9Sstevel@tonic-gate 		panic_thread = t;
2927c478bd9Sstevel@tonic-gate 		panic_regs = t->t_pcb;
2937c478bd9Sstevel@tonic-gate 		panic_reg = rp;
2947c478bd9Sstevel@tonic-gate 		panic_cpu = *cp;
2957c478bd9Sstevel@tonic-gate 		panic_ipl = spltoipl(s);
2967c478bd9Sstevel@tonic-gate 		panic_schedflag = schedflag;
2977c478bd9Sstevel@tonic-gate 		panic_bound_cpu = bound_cpu;
2987c478bd9Sstevel@tonic-gate 		panic_preempt = preempt;
29984058112SBryan Cantrill 		panic_pcb = pcb;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 		if (intr_stack != NULL) {
3027c478bd9Sstevel@tonic-gate 			panic_cpu.cpu_intr_stack = intr_stack;
3037c478bd9Sstevel@tonic-gate 			panic_cpu.cpu_intr_actv = intr_actv;
3047c478bd9Sstevel@tonic-gate 		}
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 		/*
3077c478bd9Sstevel@tonic-gate 		 * Lower ipl to 10 to keep clock() from running, but allow
3087c478bd9Sstevel@tonic-gate 		 * keyboard interrupts to enter the debugger.  These callbacks
3097c478bd9Sstevel@tonic-gate 		 * are executed with panicstr set so they can bypass locks.
3107c478bd9Sstevel@tonic-gate 		 */
3117c478bd9Sstevel@tonic-gate 		splx(ipltospl(CLOCK_LEVEL));
3127c478bd9Sstevel@tonic-gate 		panic_quiesce_hw(pdp);
3137c478bd9Sstevel@tonic-gate 		(void) FTRACE_STOP();
3144da99751SToomas Soome 		(void) callb_execute_class(CB_CL_PANIC, 0);
3157c478bd9Sstevel@tonic-gate 
316281888b3Sjbeck 		if (log_intrq != NULL)
317281888b3Sjbeck 			log_flushq(log_intrq);
318281888b3Sjbeck 
319281888b3Sjbeck 		/*
320281888b3Sjbeck 		 * If log_consq has been initialized and syslogd has started,
321281888b3Sjbeck 		 * print any messages in log_consq that haven't been consumed.
322281888b3Sjbeck 		 */
323281888b3Sjbeck 		if (log_consq != NULL && log_consq != log_backlogq)
324281888b3Sjbeck 			log_printq(log_consq);
325281888b3Sjbeck 
3267c478bd9Sstevel@tonic-gate 		fm_banner();
3277c478bd9Sstevel@tonic-gate 
328843e1988Sjohnlev #if defined(__x86)
329843e1988Sjohnlev 		/*
330843e1988Sjohnlev 		 * A hypervisor panic originates outside of Solaris, so we
331843e1988Sjohnlev 		 * don't want to prepend the panic message with misleading
332843e1988Sjohnlev 		 * pointers from within Solaris.
333843e1988Sjohnlev 		 */
334843e1988Sjohnlev 		if (!IN_XPV_PANIC())
335843e1988Sjohnlev #endif
336843e1988Sjohnlev 			printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id,
337843e1988Sjohnlev 			    (void *)t);
3387c478bd9Sstevel@tonic-gate 		vprintf(format, alist);
3397c478bd9Sstevel@tonic-gate 		printf("\n\n");
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 		if (t->t_panic_trap != NULL) {
3427c478bd9Sstevel@tonic-gate 			panic_showtrap(t->t_panic_trap);
3437c478bd9Sstevel@tonic-gate 			printf("\n");
3447c478bd9Sstevel@tonic-gate 		}
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 		traceregs(rp);
3477c478bd9Sstevel@tonic-gate 		printf("\n");
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 		if (((boothowto & RB_DEBUG) || obpdebug) &&
3507c478bd9Sstevel@tonic-gate 		    !nopanicdebug && !panic_forced) {
3517c478bd9Sstevel@tonic-gate 			if (dumpvp != NULL) {
3527c478bd9Sstevel@tonic-gate 				debug_enter("panic: entering debugger "
3537c478bd9Sstevel@tonic-gate 				    "(continue to save dump)");
3547c478bd9Sstevel@tonic-gate 			} else {
3557c478bd9Sstevel@tonic-gate 				debug_enter("panic: entering debugger "
3567c478bd9Sstevel@tonic-gate 				    "(no dump device, continue to reboot)");
3577c478bd9Sstevel@tonic-gate 			}
3587c478bd9Sstevel@tonic-gate 		}
3597c478bd9Sstevel@tonic-gate 
3603f11de9dSSara Hartse 	} else if (panic_dump != 0 || panicstr != NULL) {
3617c478bd9Sstevel@tonic-gate 		printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id, (void *)t);
3627c478bd9Sstevel@tonic-gate 		vprintf(format, alist);
3637c478bd9Sstevel@tonic-gate 		printf("\n");
3647c478bd9Sstevel@tonic-gate 	} else
3657c478bd9Sstevel@tonic-gate 		goto spin;
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	/*
3683f11de9dSSara Hartse 	 * Prior to performing dump, we make sure that do_polled_io is
3697c478bd9Sstevel@tonic-gate 	 * set, but we'll leave ipl at 10; deadman(), a CY_HIGH_LEVEL cyclic,
3703f11de9dSSara Hartse 	 * will re-enter panic if we are not making progress with dump.
3717c478bd9Sstevel@tonic-gate 	 */
3727c478bd9Sstevel@tonic-gate 	/*
3737c478bd9Sstevel@tonic-gate 	 * Take the crash dump.  If the dump trigger is already set, try to
3747c478bd9Sstevel@tonic-gate 	 * enter the debugger again before rebooting the system.
3757c478bd9Sstevel@tonic-gate 	 */
3767c478bd9Sstevel@tonic-gate 	if (panic_trigger(&panic_dump)) {
3777c478bd9Sstevel@tonic-gate 		panic_dump_hw(s);
3787c478bd9Sstevel@tonic-gate 		splx(ipltospl(CLOCK_LEVEL));
3791d76b125Sstephh 		errorq_panic();
3807c478bd9Sstevel@tonic-gate 		do_polled_io = 1;
3817c478bd9Sstevel@tonic-gate 		dumpsys();
3827c478bd9Sstevel@tonic-gate 	} else if (((boothowto & RB_DEBUG) || obpdebug) && !nopanicdebug) {
3837c478bd9Sstevel@tonic-gate 		debug_enter("panic: entering debugger (continue to reboot)");
3847c478bd9Sstevel@tonic-gate 	} else
3857c478bd9Sstevel@tonic-gate 		printf("dump aborted: please record the above information!\n");
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 	if (halt_on_panic)
388edc40228Sachartre 		mdboot(A_REBOOT, AD_HALT, NULL, B_FALSE);
3897c478bd9Sstevel@tonic-gate 	else
390edc40228Sachartre 		mdboot(A_REBOOT, panic_bootfcn, panic_bootstr, B_FALSE);
3917c478bd9Sstevel@tonic-gate spin:
3927c478bd9Sstevel@tonic-gate 	/*
3937c478bd9Sstevel@tonic-gate 	 * Restore ipl to at most CLOCK_LEVEL so we don't end up spinning
3947c478bd9Sstevel@tonic-gate 	 * and unable to jump into the debugger.
3957c478bd9Sstevel@tonic-gate 	 */
3967c478bd9Sstevel@tonic-gate 	splx(MIN(s, ipltospl(CLOCK_LEVEL)));
397843e1988Sjohnlev 	for (;;)
398843e1988Sjohnlev 		;
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate void
panic(const char * format,...)4027c478bd9Sstevel@tonic-gate panic(const char *format, ...)
4037c478bd9Sstevel@tonic-gate {
4047c478bd9Sstevel@tonic-gate 	va_list alist;
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	va_start(alist, format);
4077c478bd9Sstevel@tonic-gate 	vpanic(format, alist);
4087c478bd9Sstevel@tonic-gate 	va_end(alist);
4097c478bd9Sstevel@tonic-gate }
410