From nobody Fri Jan 26 21:11:27 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TM9Nb3GPVz58r55; Fri, 26 Jan 2024 21:11:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TM9Nb2j9mz4R8F; Fri, 26 Jan 2024 21:11:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706303487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n/Evg1IeKMGhgLJ6QLIVR1NIRbIKjgeZBeGox/TQKBs=; b=CGwmDsrWOZH/fAFxjHlScGD7WvISNTv0l/KGZ4tIQDebu4bM1UI9A71L1M0nmF6aO3qYBQ ZfS6VemN2Dxtm3D9GYpl25b4z5S0bnnLZZi98hZxEShuUTk/mM4z/PgCm5/xfNZWPDJQeH 37Dh1SJlnnT8UDd7UKTWE3btHDs/lIvdwvNLPh4P2WaKS8sHlqpfW24jy/CYl1zfqnL8ZB 5GidPdXgCN55+7/8+owJkJZaX1iijrYYmsgEYff/KuDhd51F+tn1XQDgEoUNPwRcnrAHrl gIGDuyFNAvrDN1RbyDfOJAEvZPHr07cipN38JjlJ4z6KSzMmVVZauCebvVNzBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706303487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n/Evg1IeKMGhgLJ6QLIVR1NIRbIKjgeZBeGox/TQKBs=; b=d9YAg8Fcmemc2cbVPMkvjHd8lsMhbmKpe+NHCdidvNbC/jgzc09I3guv+Y9DhkHdVCGUi5 UY914bFtuMrUCf4ajbZJAeyoE/2+JeV9waDaPrezML2l7hPiimPzoRE3jhUiGVcZt8q0Dy kwSqknG1TLjiTE2j+zgNsNqaITZkFEaRA8ZthB7503cs2uIvGrRp6aB1BFOh08MKplM98F S/lltIJyWsjIlid2WRyd13ey+95atzwynlD6tMbjohYXixJijFblyFynamQqRSncxIIvMA Ea2UqE8qTN3Rae/neWWz1CZ+0tRFIDl5bx3LM79mSQyi+rnfVsQW2e+GQJlwDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706303487; a=rsa-sha256; cv=none; b=GVF935jeQi6gExhJdt4DNF2bum+LSCp+FLuRWmLD/LqqGuyxwmDbGLodQGH+hc6w3oNN0z 99TfHRYXnyR/zyVjVnpJy1JzTYkaF2UZt2yPQK/FNmDTW04aQ/SoYUqKQv+IsNBsAtBBaz v+7qsyCzaXWoP1ULJKDr5NId3lMizC2ubexPC6ZNWiV4wZB6k/ZsYChU1qz0Nn7/a1XsIv 5nudtTdPUXDManqjU7DLCgjvesKoIIrrlXErj5yKIn05vLmOeXlrHYpAbAGTVzXLTWWhd0 YKPFgBD0SiRD2ZlafD0gZfEq7VJfZmvlJ1luZA67akpa38dejXo6MAjdGdhLmw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TM9Nb1mXdzxVB; Fri, 26 Jan 2024 21:11:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40QLBR9B093984; Fri, 26 Jan 2024 21:11:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40QLBROv093981; Fri, 26 Jan 2024 21:11:27 GMT (envelope-from git) Date: Fri, 26 Jan 2024 21:11:27 GMT Message-Id: <202401262111.40QLBROv093981@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: eaed922eda58 - main - panic()/KERNEL_PANICKED(): Move back to using 'panicstr' as a flag List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: eaed922eda584da7306e7c371ff6adf3fc4dc4c3 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=eaed922eda584da7306e7c371ff6adf3fc4dc4c3 commit eaed922eda584da7306e7c371ff6adf3fc4dc4c3 Author: Olivier Certner AuthorDate: 2024-01-18 10:15:18 +0000 Commit: Olivier Certner CommitDate: 2024-01-26 21:07:56 +0000 panic()/KERNEL_PANICKED(): Move back to using 'panicstr' as a flag Currently, no performance-critical path tests for a panic. Moreover, we today have KERNEL_PANICKED() which wraps the test into __predict_false(), already catering to those (potential) use cases. Also, in practice we don't support 64-bit architectures without caches, so reading an 'int' instead of a pointer doesn't (directly) save any memory access. Finally, 'panicked' is redundant with 'panicstr' (and wastes a tiny amount of memory). Consequently: 1. Use again 'panicstr' as a flag indicating that the system is panicking. To this end: - Modify panic() so that it ensures this pointer is set to some non-NULL value even if the caller didn't pass any panic string. - Modify KERNEL_PANICKED() to test for 'panicstr'. - Remove 'panicked'. 2. Annotate 'panicstr' with '__read_mostly' (instead of using '__read_frequently' as for 'panicked'). This may have to be changed if, in the future, some performance-intensive path needs to test it. 3. Convert a few more direct tests of 'panicstr' to using KERNEL_PANICKED(). Reviewed by: kib, markj, emaste Approved by: markj (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D43569 --- sys/kern/kern_shutdown.c | 15 +++++++++++---- sys/sys/kassert.h | 3 +-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index 3b0e3997c852..d66c7ba0d344 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -224,8 +224,7 @@ SYSCTL_INT(_kern, OID_AUTO, kerneldump_gzlevel, CTLFLAG_RWTUN, * 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 @@ vpanic(const char *fmt, va_list ap) 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 @@ vpanic(const char *fmt, va_list ap) * 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 @@ vpanic(const char *fmt, va_list ap) else { bootopt |= RB_DUMP; panicstr = fmt; - panicked = true; newpanic = 1; } diff --git a/sys/sys/kassert.h b/sys/sys/kassert.h index 7b54ac6ae519..da8701ce3858 100644 --- 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