git: 08180f1b613b - main - witness: actually set read-only tunables in time for witness_startup

From: Ryan Libby <rlibby_at_FreeBSD.org>
Date: Thu, 18 Jun 2026 04:17:16 UTC
The branch main has been updated by rlibby:

URL: https://cgit.FreeBSD.org/src/commit/?id=08180f1b613b6fe000135efa28b7c3293cbf1683

commit 08180f1b613b6fe000135efa28b7c3293cbf1683
Author:     Ryan Libby <rlibby@FreeBSD.org>
AuthorDate: 2026-06-18 03:52:53 +0000
Commit:     Ryan Libby <rlibby@FreeBSD.org>
CommitDate: 2026-06-18 04:05:43 +0000

    witness: actually set read-only tunables in time for witness_startup
    
    SYSCTL_XXX with CTLFLAG_RDTUN and without CTLFLAG_NOFETCH should not be
    used for values that are needed before SI_SUB_KLD.  Otherwise they are
    tuned after they are needed.  Set CTLFLAG_RDTUN | CTLFLAG_NOFETCH for
    the debug.witness.witness_count and debug.witness.skipspin sysctls and
    add separate tunables for them, which run at SI_SUB_TUNABLES time, i.e.,
    in time for witness_startup.
    
    Reviewed by:    kib, markj
    Sponsored by:   Dell Inc.
    Differential Revision:  https://reviews.freebsd.org/D57613
---
 sys/kern/subr_witness.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c
index 3c192b2b0dce..2bfd8711eed7 100644
--- a/sys/kern/subr_witness.c
+++ b/sys/kern/subr_witness.c
@@ -404,17 +404,22 @@ SYSCTL_INT(_debug_witness, OID_AUTO, trace, CTLFLAG_RWTUN, &witness_trace, 0, ""
 #endif /* DDB || KDB */
 
 #ifdef WITNESS_SKIPSPIN
-int	witness_skipspin = 1;
+static bool witness_skipspin = true;
 #else
-int	witness_skipspin = 0;
+static bool witness_skipspin = false;
 #endif
-SYSCTL_INT(_debug_witness, OID_AUTO, skipspin, CTLFLAG_RDTUN, &witness_skipspin, 0, "");
+SYSCTL_BOOL(_debug_witness, OID_AUTO, skipspin,
+    CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &witness_skipspin, 0,
+    "Skip all witness checks on spin locks");
+TUNABLE_BOOL("debug.witness.skipspin", &witness_skipspin);
 
 int badstack_sbuf_size;
 
-int witness_count = WITNESS_COUNT;
-SYSCTL_INT(_debug_witness, OID_AUTO, witness_count, CTLFLAG_RDTUN,
-    &witness_count, 0, "");
+static u_long witness_count = WITNESS_COUNT;
+SYSCTL_ULONG(_debug_witness, OID_AUTO, witness_count,
+    CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &witness_count, 0,
+    "Maximum count of lock type entries");
+TUNABLE_ULONG("debug.witness.witness_count", &witness_count);
 
 /*
  * Output channel for witness messages.  By default we print to the console.
@@ -790,7 +795,8 @@ witness_startup_count(void)
 /*
  * The WITNESS-enabled diagnostic code.  Note that the witness code does
  * assume that the early boot is single-threaded at least until after this
- * routine is completed.
+ * routine is completed.  This routine runs during SI_SUB_VM.  Any read-only
+ * tunables need to have been initialized by now.
  */
 void
 witness_startup(void *mem)