arch/x86/kernel/cpu/bus_lock.c | 39 ++++++++++++++++------------------ 1 file changed, 18 insertions(+), 21 deletions(-)
On Tue, Dec 16, 2025 at 02:11:51AM +0800, Rong Zhang wrote:
> sld_state_show() has a dead kmsg formatting:
>
> if (A) {
> ...
> } else if (B) {
> pr_info(... A ? str1 : str2 ...);
> }
>
> where A is always false in the second block, implied by the "if (A)
> else" pattern. Hence, str2 is always used.
>
> This seems to be some mysterious legacy inherited from the earlier patch
> revisions of commit ebb1064e7c2e ("x86/traps: Handle #DB for bus lock").
> Earlier revisions [1] did enable both sld and bld at the same time to
> detect non-WB bus_locks when split_lock_detect=fatal, but that's no
> longer true in the merged revision.
>
> Remove it and translate the pr_info() into its equivalent form.
>
> [1]: https://lore.kernel.org/r/20201121023624.3604415-3-fenghua.yu@intel.com/
>
> Signed-off-by: Rong Zhang <i@rong.moe>
> ---
> arch/x86/kernel/cpu/bus_lock.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
While staring at this, that sld_state_show() function looks like it needs
a good scrubbin'. Here's a first attempt ontop:
---
From e52fe2e2009e488c720f3e98a77963145ac9153c Mon Sep 17 00:00:00 2001
From: "Borislav Petkov (AMD)" <bp@alien8.de>
Date: Sun, 4 Jan 2026 14:40:23 +0100
Subject: [PATCH] x86/split_lock: Zap the unwieldy switch-case in sld_state_show()
Handle the easy cases first and leave the meat of the code at the end,
after having removed all possible gunk which makes it even more
unreadable than it is.
Have the CPU-going-offline check for both fatal and warning settings
because there's no point to have it only in the sld_warn case.
There should be no functional changes resulting from this cleanup.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
arch/x86/kernel/cpu/bus_lock.c | 39 ++++++++++++++++------------------
1 file changed, 18 insertions(+), 21 deletions(-)
diff --git a/arch/x86/kernel/cpu/bus_lock.c b/arch/x86/kernel/cpu/bus_lock.c
index fb166662bc0d..811f87906c1e 100644
--- a/arch/x86/kernel/cpu/bus_lock.c
+++ b/arch/x86/kernel/cpu/bus_lock.c
@@ -391,34 +391,31 @@ static void __init split_lock_setup(struct cpuinfo_x86 *c)
static void sld_state_show(void)
{
+ const char *action = "warning";
+
if (!boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT) &&
!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT))
return;
- switch (sld_state) {
- case sld_off:
+ if (sld_state == sld_off) {
pr_info("disabled\n");
- break;
- case sld_warn:
- if (boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT)) {
- pr_info("#AC: crashing the kernel on kernel split_locks and warning on user-space split_locks\n");
- if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
- "x86/splitlock", NULL, splitlock_cpu_offline) < 0)
- pr_warn("No splitlock CPU offline handler\n");
- } else if (boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT)) {
- pr_info("#DB: warning on user-space bus_locks\n");
- }
- break;
- case sld_fatal:
- if (boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT))
- pr_info("#AC: crashing the kernel on kernel split_locks and sending SIGBUS on user-space split_locks\n");
- else if (boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT))
- pr_info("#DB: sending SIGBUS on user-space bus_locks\n");
- break;
- case sld_ratelimit:
+ return;
+ } else if (sld_state == sld_ratelimit) {
if (boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT))
pr_info("#DB: setting system wide bus lock rate limit to %u/sec\n", bld_ratelimit.burst);
- break;
+ return;
+ }
+
+ if (sld_state == sld_fatal)
+ action = "sending SIGBUS";
+
+ if (boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT)) {
+ pr_info("#AC: crashing the kernel on kernel split_locks and %s on user-space split_locks\n", action);
+ if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
+ "x86/splitlock", NULL, splitlock_cpu_offline) < 0)
+ pr_warn("No splitlock CPU offline handler\n");
+ } else if (boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT)) {
+ pr_info("#DB: %s on user-space bus_locks\n", action);
}
}
--
2.51.0
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
© 2016 - 2026 Red Hat, Inc.