Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4704192imw; Tue, 12 Jul 2022 12:43:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1utfpL01tPtNmKVHE6FkcHYguDLPu7V/FBdBZkDXtoa6GTBTUE87BFnrY3gE5B5B80savXh X-Received: by 2002:a63:ea55:0:b0:412:290c:9694 with SMTP id l21-20020a63ea55000000b00412290c9694mr22232668pgk.39.1657655018714; Tue, 12 Jul 2022 12:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657655018; cv=none; d=google.com; s=arc-20160816; b=V1/hZSFodlv5pAyEHuKfhg5HvEfBbDBiFm7mKEVF59mOxzcAspEk4bdgVsqsRY+/R9 tuWdhmFigW2p2mkxxeI7/gQlDm8h99AwKkWd4ZKL9MFP/pLcQCcvGGxgyTHn5DCW5iBy njMLGOS1/cV2swImrRa1+j0bFOvsopNiiMrKcHfDZhZA7KdhZTz8dpnw1IfaWMyaZvS9 M7ty9dIrP9I5fNle3xTwPxf5VgVpyWh76SrjJs6mZHPFJCUTzQuKINeCwophkdJ/WURe dHDKpuGaeVv1VqKyp8Kv7VdW/Jgzgl+ahA1YqdP3Tl+j9rqBZJmOFM2bpRudLtciSCCG 0epQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NyNuYWH3IVsshoVkuOxC3jtWNx76bVo5BwczKu9qpm4=; b=nqR4Vi6xg1kAzP9ob/LP+vXVVOkg7cpq+d6gESkOoctyGvvHYz5sN9QnofT2iNB9Q4 l+qncyZ7zoSuz/6ue1qYiuIOPl84lnuALl95Njd2WM2qx3veda5SzIjZ/dOAi3Uv3ij9 cN4KQuwCvg4g+Ctes10wkIRDznvBg7vdugUsU8tjnyyweFtz8+wMmSnQKwpKgYQAm/I6 fCHCiufZl0CCYzWcYTeAmXYniBov+2jlk/sXoak7fyLeQHF4zuGllqTI1UC1MZ4LYhdq hvfqDc7xpOFdM2qnBnap01/MjH5RPLzi8QZxbYKlGCaWehX/nEDIYT7MbqvR/f57C8O4 lAuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ba5cASgE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h185-20020a636cc2000000b00415ea6aca03si11067317pgc.547.2022.07.12.12.43.26; Tue, 12 Jul 2022 12:43:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ba5cASgE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236019AbiGLTPk (ORCPT + 99 others); Tue, 12 Jul 2022 15:15:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235620AbiGLTNX (ORCPT ); Tue, 12 Jul 2022 15:13:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E446A6325; Tue, 12 Jul 2022 11:53:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B380A6157B; Tue, 12 Jul 2022 18:53:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B82DBC3411C; Tue, 12 Jul 2022 18:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657652015; bh=kC8Yo+zlmSXkHVKbkmutWgRB5JaAAmyWQj1eufr2znI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ba5cASgEz/I0y1xKYRStRFbBZljzcYWQd9pQeXwLTeSwIjcLuEjjL0fZADl884LLK GeRKESAOgQYh7Vj77Y60VlSiv0cvsQKfI5/aqFcHrB5m+vizfPnXKrP4Nalu9OhlAr EWjy+iDuHkG4Rv9hrPPrNjTKH5aV96J6NZkvK+PI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Cooper , Borislav Petkov , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.18 54/61] x86/cpu/amd: Enumerate BTC_NO Date: Tue, 12 Jul 2022 20:39:51 +0200 Message-Id: <20220712183239.052853854@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183236.931648980@linuxfoundation.org> References: <20220712183236.931648980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Cooper commit 26aae8ccbc1972233afd08fb3f368947c0314265 upstream. BTC_NO indicates that hardware is not susceptible to Branch Type Confusion. Zen3 CPUs don't suffer BTC. Hypervisors are expected to synthesise BTC_NO when it is appropriate given the migration pool, to prevent kernels using heuristics. [ bp: Massage. ] Signed-off-by: Andrew Cooper Signed-off-by: Borislav Petkov [cascardo: no X86_FEATURE_BRS] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/amd.c | 21 +++++++++++++++------ arch/x86/kernel/cpu/common.c | 6 ++++-- 3 files changed, 20 insertions(+), 8 deletions(-) --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -321,6 +321,7 @@ #define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */ #define X86_FEATURE_AMD_SSB_NO (13*32+26) /* "" Speculative Store Bypass is fixed in hardware. */ #define X86_FEATURE_CPPC (13*32+27) /* Collaborative Processor Performance Control */ +#define X86_FEATURE_BTC_NO (13*32+29) /* "" Not vulnerable to Branch Type Confusion */ /* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */ #define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */ --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -890,12 +890,21 @@ static void init_amd_zn(struct cpuinfo_x node_reclaim_distance = 32; #endif - /* - * Fix erratum 1076: CPB feature bit not being set in CPUID. - * Always set it, except when running under a hypervisor. - */ - if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && !cpu_has(c, X86_FEATURE_CPB)) - set_cpu_cap(c, X86_FEATURE_CPB); + /* Fix up CPUID bits, but only if not virtualised. */ + if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) { + + /* Erratum 1076: CPB feature bit not being set in CPUID. */ + if (!cpu_has(c, X86_FEATURE_CPB)) + set_cpu_cap(c, X86_FEATURE_CPB); + + /* + * Zen3 (Fam19 model < 0x10) parts are not susceptible to + * Branch Type Confusion, but predate the allocation of the + * BTC_NO bit. + */ + if (c->x86 == 0x19 && !cpu_has(c, X86_FEATURE_BTC_NO)) + set_cpu_cap(c, X86_FEATURE_BTC_NO); + } } static void init_amd(struct cpuinfo_x86 *c) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1385,8 +1385,10 @@ static void __init cpu_set_bug_bits(stru !arch_cap_mmio_immune(ia32_cap)) setup_force_cpu_bug(X86_BUG_MMIO_STALE_DATA); - if ((cpu_matches(cpu_vuln_blacklist, RETBLEED) || (ia32_cap & ARCH_CAP_RSBA))) - setup_force_cpu_bug(X86_BUG_RETBLEED); + if (!cpu_has(c, X86_FEATURE_BTC_NO)) { + if (cpu_matches(cpu_vuln_blacklist, RETBLEED) || (ia32_cap & ARCH_CAP_RSBA)) + setup_force_cpu_bug(X86_BUG_RETBLEED); + } if (cpu_matches(cpu_vuln_whitelist, NO_MELTDOWN)) return;