diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -224,8 +224,7 @@ * Variable panicstr contains argument to first call to panic; used as flag * to indicate that the kernel has already called panic. */ -const char *panicstr; -bool __read_frequently panicked; +const char *panicstr __read_mostly; int __read_mostly dumping; /* system is dumping */ int rebooting; /* system is rebooting */ @@ -899,6 +898,15 @@ int bootopt, newpanic; static char buf[256]; + /* + * 'fmt' must not be NULL as it is put into 'panicstr' which is then + * used as a flag to detect if the kernel has panicked. Also, although + * vsnprintf() supports a NULL 'fmt' argument, use a more informative + * message. + */ + if (fmt == NULL) + fmt = ""; + spinlock_enter(); #ifdef SMP @@ -907,7 +915,7 @@ * concurrently entering panic. Only the winner will proceed * further. */ - if (panicstr == NULL && !kdb_active) { + if (KERNEL_PANICKED() && !kdb_active) { other_cpus = all_cpus; CPU_CLR(PCPU_GET(cpuid), &other_cpus); stop_cpus_hard(other_cpus); @@ -927,7 +935,6 @@ else { bootopt |= RB_DUMP; panicstr = fmt; - panicked = true; newpanic = 1; } diff --git a/sys/sys/kassert.h b/sys/sys/kassert.h --- a/sys/sys/kassert.h +++ b/sys/sys/kassert.h @@ -35,8 +35,7 @@ #ifdef _KERNEL extern const char *panicstr; /* panic message */ -extern bool panicked; -#define KERNEL_PANICKED() __predict_false(panicked) +#define KERNEL_PANICKED() __predict_false(panicstr != NULL) /* * Trap accesses going through a pointer. Moreover if kasan is available trap