The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Borislav Petkov <bp@alien8.de>, Rong Zhang <i@rong.moe>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Fenghua Yu <fenghuay@nvidia.com>,
	linux-kernel@vger.kernel.org, Tony Luck <tony.luck@intel.com>
Subject: Re: [PATCH] x86/split_lock: Zap the unwieldy switch-case in sld_state_show()
Date: Wed, 7 Jan 2026 13:38:41 +0800	[thread overview]
Message-ID: <aa2407e5-d012-4bc7-917e-017c31e7dc08@intel.com> (raw)
In-Reply-To: <20260104191726.GEaVq8xqi0OhsIs284@fat_crate.local>

+ Tony

On 1/5/2026 3:17 AM, Borislav Petkov wrote:
>  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.

If I understand correctly, the CPU offline callback was added to avoid 
the case where a CPU is taken offline when split lock detection is 
disabled temporarily and before the delayed work to re-enable it being 
called. Since the MSR_TEST_CTRL is per-core scope, the sibling CPU on 
the same core may then be left running with split lock detection 
disabled without the delayed work to re-enable it.

For fatal mode, there is no such handling of temporarily disabling the 
feature and we don't need the CPU offline callback.

> 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


  reply	other threads:[~2026-01-07  5:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15 18:11 [PATCH] x86/split_lock: Remove dead kmsg formatting when split_lock_detect=fatal Rong Zhang
2026-01-04 19:17 ` [PATCH] x86/split_lock: Zap the unwieldy switch-case in sld_state_show() Borislav Petkov
2026-01-07  5:38   ` Xiaoyao Li [this message]
2026-01-07 11:28     ` Borislav Petkov
2026-01-07 16:41       ` Luck, Tony
2026-01-08 10:38         ` Borislav Petkov
2026-02-26 14:50           ` [PATCH -v2] x86/split_lock: Restructure " Borislav Petkov
2026-02-26 21:01             ` Luck, Tony
2026-02-27 16:32               ` Borislav Petkov
2026-03-06  2:57             ` Xiaoyao Li
2026-03-13 15:25               ` Borislav Petkov
2026-03-13 20:22             ` [tip: x86/cleanups] " tip-bot2 for Borislav Petkov
2026-01-04 19:18 ` [tip: x86/cleanups] x86/split_lock: Remove dead string when split_lock_detect=fatal tip-bot2 for Rong Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa2407e5-d012-4bc7-917e-017c31e7dc08@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=fenghuay@nvidia.com \
    --cc=hpa@zytor.com \
    --cc=i@rong.moe \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox