From nobody Sat Feb 7 21:05:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B7547224AF1 for ; Tue, 30 Dec 2025 11:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767092855; cv=none; b=FsyeGWh7i4umKHOv5HZgbCVrXxxbnjV5t9rH8PiswPazLCueU0Lqa/Xv92TBQOP06xbRaf9nl4VfsV83lS+kNRH+DsYHE6WAbJg64R2eyybUzoKryECP/1RfMrw9rGPshAPQjK/YulMRKUIN0g18mvh01E2zSV3OHl+f9//JIXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767092855; c=relaxed/simple; bh=37FjOjUa/yk7EO3VnEA6ONG/v4SeTyga63RYGfnQjSg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ebCqH8nH59PEnX7eCW9iSmAnkaTve/S0RExYVfT0ULt58jLh28pvc30po0PvFV9kR8400OrHC/gYQVkOdlEPSwFkrmNfSu0S3qs0jCU5K303PJDGJexddqcV0EO3468DABSQ+7XqBbQGDzWRhg08ZnPPo2ZImhx5B668I8uen7o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BQ+DxJEc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BQ+DxJEc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48FB3C4CEFB; Tue, 30 Dec 2025 11:07:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767092855; bh=37FjOjUa/yk7EO3VnEA6ONG/v4SeTyga63RYGfnQjSg=; h=From:To:Cc:Subject:Date:From; b=BQ+DxJEc/pevX/+1mTC2BB/VGalM9mJeWVU5lFvzIDjJ3l30X/1e07IAUtimdqXRJ fcj282dW7MD7IZQTfS02HjwO55p24DS2FDEQHSBQwT4Ux2t4GOEhU80YP4MVgeJHVL B4XyqBCimY7EbUfkPbRfmef8KtXd1lqnelqYXAjdWY6BqfzYud25e85+4P9vb3mc17 G9f9H4aEHAgUuf9yEyEHy3vW/hrNDfI3amwbtNIe3ZWP79Mn3qYtIm2UAreGQ5Ou0V uQIsEi1iv65DqQjAMRqinDOCwzWGYDOsI1JJd6r6gdfvoyp150qoo5wRv2u+oP+T1r oEKaKpFrs2DEQ== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH] x86/CPU/AMD: Simplify the spectral chicken fix Date: Tue, 30 Dec 2025 12:07:31 +0100 Message-ID: <20251230110731.28108-1-bp@kernel.org> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" msr_set_bit() takes a bit number to set but MSR_ZEN2_SPECTRAL_CHICKEN_BIT is a bit mask. The usual pattern that code uses is a _BIT-named type macro instead of a mask. So convert it to a bit number to reflect that. Also, msr_set_bit() already does the reading and checking whether the bit needs to be set so use that instead of a local variable. Fixup tabbing while at it. No functional changes. Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Nikolay Borisov --- arch/x86/include/asm/msr-index.h | 4 ++-- arch/x86/kernel/cpu/amd.c | 10 ++-------- tools/arch/x86/include/asm/msr-index.h | 4 ++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index 3d0a0950d20a..43adc38d31d5 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -794,8 +794,8 @@ #define MSR_F19H_UMC_PERF_CTR 0xc0010801 =20 /* Zen 2 */ -#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3 -#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1) +#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3 +#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT 1 =20 /* Fam 17h MSRs */ #define MSR_F17H_IRPERF 0xc00000e9 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index c792c2afd849..09de584e4c8f 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -900,20 +900,14 @@ static void fix_erratum_1386(struct cpuinfo_x86 *c) void init_spectral_chicken(struct cpuinfo_x86 *c) { #ifdef CONFIG_MITIGATION_UNRET_ENTRY - u64 value; - /* * On Zen2 we offer this chicken (bit) on the altar of Speculation. * * This suppresses speculation from the middle of a basic block, i.e. it * suppresses non-branch predictions. */ - if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) { - if (!rdmsrq_safe(MSR_ZEN2_SPECTRAL_CHICKEN, &value)) { - value |=3D MSR_ZEN2_SPECTRAL_CHICKEN_BIT; - wrmsrq_safe(MSR_ZEN2_SPECTRAL_CHICKEN, value); - } - } + if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) + msr_set_bit(MSR_ZEN2_SPECTRAL_CHICKEN, MSR_ZEN2_SPECTRAL_CHICKEN_BIT); #endif } =20 diff --git a/tools/arch/x86/include/asm/msr-index.h b/tools/arch/x86/includ= e/asm/msr-index.h index 9e1720d73244..d4137a302793 100644 --- a/tools/arch/x86/include/asm/msr-index.h +++ b/tools/arch/x86/include/asm/msr-index.h @@ -770,8 +770,8 @@ #define MSR_F19H_UMC_PERF_CTR 0xc0010801 =20 /* Zen 2 */ -#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3 -#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1) +#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3 +#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT 1 =20 /* Fam 17h MSRs */ #define MSR_F17H_IRPERF 0xc00000e9 --=20 2.51.0