git: 57bc1e1c2f4c - main - amd64: make hw.splitlock_force adjustable at runtime

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Fri, 06 Nov 2026 13:31:45 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=57bc1e1c2f4c01953336bdf03743e30f4ba12cdc

commit 57bc1e1c2f4c01953336bdf03743e30f4ba12cdc
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-06 13:05:50 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-06 13:31:28 +0000

    amd64: make hw.splitlock_force adjustable at runtime
    
    The setting is only read on exec(2), so it can be safely modified.
    This is useful to adapt the system to newly discovered buggy programs
    without reboot.
    
    Note that that running processes keep their mode until they exec again.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
---
 sys/amd64/amd64/machdep.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index a714c4e52b9b..04204fa74c11 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -210,10 +210,29 @@ int ia32_splitlock = 0;
 SYSCTL_INT(_hw, OID_AUTO, splitlock, CTLFLAG_RD,
     &ia32_splitlock, 0,
     "splitlock prevention supported");
+
 int ia32_splitlock_force = 1;
-SYSCTL_INT(_hw, OID_AUTO, splitlock_force, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
-    &ia32_splitlock_force, 0,
-    "splitlock prevention enabled by default");
+
+static int
+sysctl_hw_splitlock_force_proc(SYSCTL_HANDLER_ARGS)
+{
+	int error, val;
+
+	val = ia32_splitlock_force;
+	error = sysctl_handle_int(oidp, &val, 0, req);
+	if (error != 0 || req->newptr == NULL)
+		return (error);
+	if (val != 0 && !ia32_splitlock)
+		error = ENOTSUP;
+	else
+		ia32_splitlock_force = val != 0;
+	return (error);
+}
+
+SYSCTL_PROC(_hw, OID_AUTO, splitlock_force,
+    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NOFETCH | CTLFLAG_MPSAFE, 0, 0,
+    sysctl_hw_splitlock_force_proc, "I",
+    "Splitlock prevention enabled on exec");
 
 int __read_frequently fred = 0;
 SYSCTL_INT(_hw, OID_AUTO, fred, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,