From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 B966A25CC74 for ; Wed, 7 Jan 2026 05:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767764330; cv=none; b=Cq9gPLdeOheIdhvfD+5c5Q4x0kURulQARyt1GVKbcFHKRD/0dp8yNNegEPHleZ4gJO2Pl32lyrDAC94XPOFLM+V8n/bP1lNpJmtVHupHbPjHsxSE49+07l5bRNNIoCVc9DL0AStNgbC2ofYynM/2//OmvZcAKiq6h1WjSFGrBh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767764330; c=relaxed/simple; bh=fPgwA1lTHdyrPwfmMOEjIvqfc7yj0Y6Y0PDQeGJOTaY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=b/OgF+iRKFcHTiMij0daXj5m9H7Fj/TsyfUIdfRbd8b4ActZEJOmJ3njyJkCqCcIpipIKVsoRh2KMjPLJoKGKrmHmxk+ZVy3hsGGxy35Nn6+5lda5vSk77CUZmNKLypBnRPywGPy2yAsX5mLRUXjWu8eNZSjFx6zrhs4JP1g344= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=afNkVBHO; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="afNkVBHO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1767764328; x=1799300328; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=fPgwA1lTHdyrPwfmMOEjIvqfc7yj0Y6Y0PDQeGJOTaY=; b=afNkVBHOg+UUZrOQGDegzDgRvX2Oi+CK+CNtPDTKGX48dTadZ09qOfih uZzOGwqPCKZDcdvCP+WJnrldyRqZ0LBKvZz4zHNUF+PafChs7OKTBBQSs JhUDoJoLsBY7C99GfQ6i4GIyGswIcGDq5CP1Rt36xx3hZ1vkWmwXDAXmX 17g0w6wXG2zMmJ0+GTwQ2cXL6OhdjIlVA6IqLa/IyXLW58sGG8yIKxZ4x 526iyUj8q6ViS0Fpr65g6CbENzTJQYGvC5kzdcYf1QVJ8CKwVKfNlgsyh MAP2Mg05vCUfGKs7xOMKn1L0JSC2J0eZgIbUm4CtzqAKRYBf/It4D/2bJ w==; X-CSE-ConnectionGUID: //AhQswYSXGS36OYALot9A== X-CSE-MsgGUID: 6v/ZMsEjRLKCF4J4UcENNg== X-IronPort-AV: E=McAfee;i="6800,10657,11663"; a="69179146" X-IronPort-AV: E=Sophos;i="6.21,207,1763452800"; d="scan'208";a="69179146" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2026 21:38:47 -0800 X-CSE-ConnectionGUID: +/icvT+4SxGJOdazzlXGvw== X-CSE-MsgGUID: /gvplBFYSG2XbDR1H+tUsw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,207,1763452800"; d="scan'208";a="206979547" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.124.240.173]) ([10.124.240.173]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2026 21:38:44 -0800 Message-ID: Date: Wed, 7 Jan 2026 13:38:41 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/split_lock: Zap the unwieldy switch-case in sld_state_show() To: Borislav Petkov , Rong Zhang Cc: Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Fenghua Yu , linux-kernel@vger.kernel.org, Tony Luck References: <20251215182907.152881-1-i@rong.moe> <20260104191726.GEaVq8xqi0OhsIs284@fat_crate.local> Content-Language: en-US From: Xiaoyao Li In-Reply-To: <20260104191726.GEaVq8xqi0OhsIs284@fat_crate.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit + Tony On 1/5/2026 3:17 AM, Borislav Petkov wrote: > 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. 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) > --- > 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