git: 1d2b743784f7 - main - kmsan: Add corresponding sysctl knob for loader tunable

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Thu, 12 Oct 2023 10:15:31 UTC
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=1d2b743784f7527a6840fe35ddb7e34cd41bc17a

commit 1d2b743784f7527a6840fe35ddb7e34cd41bc17a
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-10-12 10:14:49 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-10-12 10:14:49 +0000

    kmsan: Add corresponding sysctl knob for loader tunable
    
    The loader tunable 'debug.kmsan.disabled' does not have corresponding
    sysctl MIB entry. Add it so that it can be retrieved, and `sysctl -T`
    will also report it correctly.
    
    Reviewed by:    markj
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D42138
---
 sys/kern/subr_msan.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sys/kern/subr_msan.c b/sys/kern/subr_msan.c
index 57caeb454b42..54948370a14a 100644
--- a/sys/kern/subr_msan.c
+++ b/sys/kern/subr_msan.c
@@ -108,15 +108,13 @@ static uint8_t msan_dummy_shad[PAGE_SIZE] __aligned(PAGE_SIZE);
 static uint8_t msan_dummy_write_shad[PAGE_SIZE] __aligned(PAGE_SIZE);
 static uint8_t msan_dummy_orig[PAGE_SIZE] __aligned(PAGE_SIZE);
 static msan_td_t msan_thread0;
-static bool kmsan_enabled __read_mostly;
-
 static bool kmsan_reporting = false;
 
 /*
  * Avoid clobbering any thread-local state before we panic.
  */
 #define	kmsan_panic(f, ...) do {			\
-	kmsan_enabled = false;				\
+	kmsan_disabled = true;				\
 	panic(f, __VA_ARGS__);				\
 } while (0)
 
@@ -142,6 +140,11 @@ SYSCTL_BOOL(_debug_kmsan, OID_AUTO, panic_on_violation, CTLFLAG_RWTUN,
     &panic_on_violation, 0,
     "Panic if an invalid access is detected");
 
+static bool kmsan_disabled __read_mostly = true;
+#define kmsan_enabled (!kmsan_disabled)
+SYSCTL_BOOL(_debug_kmsan, OID_AUTO, disabled, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
+    &kmsan_disabled, 0, "KMSAN is disabled");
+
 static MALLOC_DEFINE(M_KMSAN, "kmsan", "Kernel memory sanitizer");
 
 /* -------------------------------------------------------------------------- */
@@ -599,7 +602,7 @@ kmsan_init(void)
 	thread0.td_kmsan = &msan_thread0;
 
 	/* Now officially enabled. */
-	kmsan_enabled = true;
+	kmsan_disabled = false;
 }
 
 /* -------------------------------------------------------------------------- */