From nobody Thu Jan 8 00:27:22 2026 Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1865A4C92 for ; Sun, 4 Jan 2026 19:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767554276; cv=none; b=jmaV/6cNhklmz1clYu0KVnnnIsfbw65W6FuljkbWdP0r45pD+seqnFNPY+BVqysE8jvg4NwojIZj3zPrSH40Q9NOVmEhNjtKYPNWdBKJTK6REXuZlG6BckXCtkstTxQjcejT+gUkwfW1F/hdXGwB0+/wZvh9sDQOAlyd3OcAyEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767554276; c=relaxed/simple; bh=6Ed+8WeA/wR8iBsiIbCDK9WbeL8s3b0/2lpox5Fg3GY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tB6HbBzK45/1lqs5qOpz1s8k1ZaR5RM3bY8MMxGK7hzBFrwjuPuflN7ty1GBpog2eTfhLG6EGcWjNcb3oLBJb7WDmcCMx8MFB37NXf/RALKiH9SuJz/kDDMRsC4SKMmH1ulfq91naRfCWuVr6v0pVkYcaIM/2mTKjUStklQBBfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de; spf=pass smtp.mailfrom=alien8.de; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b=F7PbJhsl; arc=none smtp.client-ip=65.109.113.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="F7PbJhsl" Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id B275C40E01A9; Sun, 4 Jan 2026 19:17:49 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=pass (4096-bit key) header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 9WH-_eTUfKhj; Sun, 4 Jan 2026 19:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1767554263; bh=27DQUgKNLCmkk4wqq8ZXHR+btyBqVmjDf/y9POHSnp8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F7PbJhsleWWMlF0mWH4I0eWuUm+SXqJP42tHvcqmWH3YPmCZe3wSueYsrduZkCM6h pDI2phmoPFh5yuWl6ZaCb6I4dBe851NufshTmytwMxkqWJIoPVtdeiGvuZLhih+qNF c7ezs/t+2lVZcG+HvenruANyKJkOp5/ZuETX0fKYM7KBTuuMW70DKK+XFW+B3fLl49 cNtkN9kZ+5D1cS6Wp1fWNxuQlRMzcx6HPV8JYG29TPRptFO9vfFV6B2ow0+xG4X8Ih DPfj3DJJXOrRi9LtnFdcCtO7E/HULoY5XCU40XgRXSJ9rfW/a/6/VCufomdmpGFHC0 A/3HTGuCFLTlEsTjLwRWkvrZhz59JH51vHkMUlIR7rTqL4jpxqfYYyZW6bnqhLVXEP glCaOkXiqBkwK+JzJIruE4lGaCBm+cqDAlxdUpL7lLF1ujfzQ1hCxkw7hz4gvuWCgk 0yPfya+KLMEszXU3M5/mzbSv1gvJ7kYxwGDc0lzcg/04LCB0KNi2ZbYhkBxJ69Moic KhEmBVC1C4KOrXDPf0j754v1Tfje+P0R95+Flc+313vzjSDWb8FaGGQkGWlIOaiL33 IJUmz60I4mf3125XkIHuvnNoYl48H2jfMmeD4cTdNb04uHWj/ydMzOCvn2k7e0dud+ qUSybMBfR1DvM4h0U5Uw1/0s= Received: from zn.tnic (pd953023b.dip0.t-ipconnect.de [217.83.2.59]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with UTF8SMTPSA id 5810240E0140; Sun, 4 Jan 2026 19:17:35 +0000 (UTC) Date: Sun, 4 Jan 2026 20:17:26 +0100 From: Borislav Petkov To: Rong Zhang Cc: Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Fenghua Yu , linux-kernel@vger.kernel.org Subject: [PATCH] x86/split_lock: Zap the unwieldy switch-case in sld_state_show() Message-ID: <20260104191726.GEaVq8xqi0OhsIs284@fat_crate.local> References: <20251215182907.152881-1-i@rong.moe> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20251215182907.152881-1-i@rong.moe> Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On Tue, Dec 16, 2025 at 02:11:51AM +0800, Rong Zhang wrote: > sld_state_show() has a dead kmsg formatting: >=20 > if (A) { > ... > } else if (B) { > pr_info(... A ? str1 : str2 ...); > } >=20 > where A is always false in the second block, implied by the "if (A) > else" pattern. Hence, str2 is always used. >=20 > 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=3Dfatal, but that's no > longer true in the merged revision. >=20 > Remove it and translate the pr_info() into its equivalent form. >=20 > [1]: https://lore.kernel.org/r/20201121023624.3604415-3-fenghua.yu@intel.= com/ >=20 > Signed-off-by: Rong Zhang > --- > 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)" 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) --- 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_x8= 6 *c) =20 static void sld_state_show(void) { + const char *action =3D "warning"; + if (!boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT) && !boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT)) return; =20 - switch (sld_state) { - case sld_off: + if (sld_state =3D=3D 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 SIG= BUS 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 =3D=3D 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 =3D=3D sld_fatal) + action =3D "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-s= pace 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); } } =20 --=20 2.51.0 --=20 Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette