From nobody Tue Dec 16 12:38:44 2025 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 18A2814EC60 for ; Fri, 12 Apr 2024 18:10:40 +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=1712945441; cv=none; b=IPDJ+gMD+XiMTnHoIeLAz9Gg8bGrZNHte4ngiWC16K9lRZOLbNo0fUxQ1i8KssrEw3BY8uSve4pjw0AiJ4V8P6dkEi1y67zlu9JImh7Evn8uxM+c/dTC614RWLh+LBEu7WYHo8P/72N5AhvOUWG52b2pnyH8R5ZvKqlMEQYXCI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712945441; c=relaxed/simple; bh=8NZHE1tS6vfknLA1oyfYTojtWsl+OR5G87hXz6y9g5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XZa94evWT7J3q+dbcwETrF4lHO/azj7xPfn8bKAe56d6CxC7M7+VB7/uSZiIX3+OODLMP2cFaIFFDu8r1KUbpopjPTDiusZ5wTvVzdioVbOzOuFhsU5/5eVQ90RIvp06tVKUvIMVYqYNiw5NoTQAf2q/OGq4JrxsDTapt+zZ5H8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PnwENq27; 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="PnwENq27" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1F87C32786; Fri, 12 Apr 2024 18:10:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712945440; bh=8NZHE1tS6vfknLA1oyfYTojtWsl+OR5G87hXz6y9g5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PnwENq27GKTELnxMvUoZ8+jmsfhQy+Q+870u2mG+IiA2sxv9jwNwy0ZkRJfumNfzx 3d1B8SJxdFwUOsKNTKUN/uMa3pWhiedeB8rsef/NXyBB+YWDSn61LvWxfEQnC7FWEY MGBsdg8MP2ho3zIApifLmNSoqT6+Q3kwZ4adtY/BeJrtXGo4MAG29w2G854hUnYfdU uoAZ1I5wDYekZYh3wPLAD/VOIIPA1ruYqu36mHVow5EfY0MZGMicreYJyAq8KEwV8a JRRRUFUwqaZDCZCnmQcy+X8JAvrr7l7gQRLVXY+pFxc1zuCZHZEph3e02MRj5aAUkw N7SfiULmO+Jsg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Daniel Sneddon , Pawan Gupta , Thomas Gleixner , Alexandre Chartre , Konrad Rzeszutek Wilk , Peter Zijlstra , Greg Kroah-Hartman , Sean Christopherson , Andrew Cooper , Dave Hansen , Nikolay Borisov , KP Singh , Waiman Long , Borislav Petkov , Ingo Molnar Subject: [PATCH 2/3] x86/bugs: Fix BHI retpoline check Date: Fri, 12 Apr 2024 11:10:33 -0700 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: 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" Confusingly, X86_FEATURE_RETPOLINE doesn't mean retpolines are enabled, as it also includes the original "AMD retpoline" which isn't a retpoline at all. Also replace cpu_feature_enabled() with boot_cpu_has() because this is before alternatives are patched and cpu_feature_enabled()'s fallback path is slower than plain old boot_cpu_has(). Fixes: ec9404e40e8f ("x86/bhi: Add BHI mitigation knob") Signed-off-by: Josh Poimboeuf Reviewed-by: Pawan Gupta --- arch/x86/kernel/cpu/bugs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index dcb97cc2758f..e827613c9e39 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1652,7 +1652,8 @@ static void __init bhi_select_mitigation(void) return; =20 /* Retpoline mitigates against BHI unless the CPU has RRSBA behavior */ - if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) { + if (boot_cpu_has(X86_FEATURE_RETPOLINE) && + !boot_cpu_has(X86_FEATURE_RETPOLINE_LFENCE)) { spec_ctrl_disable_kernel_rrsba(); if (rrsba_disabled) return; @@ -2833,11 +2834,13 @@ static const char *spectre_bhi_state(void) { if (!boot_cpu_has_bug(X86_BUG_BHI)) return "; BHI: Not affected"; - else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_HW)) + else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_HW)) return "; BHI: BHI_DIS_S"; - else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP)) + else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP)) return "; BHI: SW loop, KVM: SW loop"; - else if (boot_cpu_has(X86_FEATURE_RETPOLINE) && rrsba_disabled) + else if (boot_cpu_has(X86_FEATURE_RETPOLINE) && + !boot_cpu_has(X86_FEATURE_RETPOLINE_LFENCE) && + rrsba_disabled) return "; BHI: Retpoline"; else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT)) return "; BHI: Vulnerable, KVM: SW loop"; --=20 2.44.0