Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp472728imi; Fri, 22 Jul 2022 03:10:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vt4mMZAAuWksY3ZF4Oh4NzJ/lrI517ZRd80AlDvM2RarrpVr4Lvy8pYF8P698jLj7UHgWD X-Received: by 2002:a05:6402:5415:b0:43b:a888:fefe with SMTP id ev21-20020a056402541500b0043ba888fefemr2786840edb.302.1658484638403; Fri, 22 Jul 2022 03:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658484638; cv=none; d=google.com; s=arc-20160816; b=SrSLUVJvn5XupQJMVcP7t1itcuY1T/f56kIzZLP7OHbVH5AdZLQv4QmzSr2qXX6DNd IYSA8VABj3lEQj2qJI+SyI0fyizQkAoM7NO0BIE6rUZUTiJ0K1T1lNUiGORGR2HTcgbF fmx4r7yYTjVOVEc/28G/lZo+F2T6IGEJdGjzQtiZp2nUO8ZGnftuDCiLvNdjAuM5Ovzg MCe9CILFEgmlOhlxMj68jSPpGA+fGjNsmg2M9fBc75nVWn7ZbO0z6B/F+zOd910mSpYx 3pDUV6NX2wX5ff58s0s8EkpNhDPb6wXzi3p5IdbHDKlT+77WtD6YzskOx4jwWX/Nvvld FzNw== 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=q9uXx+ffIn9GhH7pwhi4wjmMe04L1P0chd1Jtyjz51dTXfNg6/ax5ih6WKLIUs+rr9 gwFXC/KyzFhxEKvoC0KzvMeXFUssLx8SitxdXRlEO4/76kBsjtczIk2k5EaAxaPeyNz/ 2gRFnnCMCZvmje5ZR+ndNgKhG0BFr2BECbxWzRsiAO2GriFPxhQKNDnDwMeV5Pvq0xLd tg5M+DCNSgzrUtWXs0KcMMrQ8P+47WvfH0wyq4zPI8NQswo6Tafb75nS2CdkGzyTCTqI D3Po49l+W3i60mKDx7GlXklJu9BCwpIpUduTHRJH6MfWs7KswzDg/f9KGIrN/e1YC4PW Wjsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PnbsR9wN; 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 a11-20020a1709063a4b00b0072b978aecf9si2418681ejf.328.2022.07.22.03.10.13; Fri, 22 Jul 2022 03:10: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=PnbsR9wN; 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 S234564AbiGVJOP (ORCPT + 99 others); Fri, 22 Jul 2022 05:14:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235339AbiGVJNR (ORCPT ); Fri, 22 Jul 2022 05:13:17 -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 382D1A6FA2; Fri, 22 Jul 2022 02:10: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 ABFC661F4C; Fri, 22 Jul 2022 09:10:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4249C341CA; Fri, 22 Jul 2022 09:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481035; bh=kC8Yo+zlmSXkHVKbkmutWgRB5JaAAmyWQj1eufr2znI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PnbsR9wNCeryGJ65kVqGVN7RNGW4SNDxhFs3LztUbF+tPKJPiUl2Xy1h7StIKEE/8 aJdMhISfk5XpFKlxiBkk/RNqT/4joKj7yYsTT4YT62kfbMMgWsOPow+GvkVMUN25te O/dOp+Ptr+FMvwvkvrZyJFlpLf8xE6G9KrqjcJLU= 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/70] x86/cpu/amd: Enumerate BTC_NO Date: Fri, 22 Jul 2022 11:07:49 +0200 Message-Id: <20220722090653.770944471@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722090650.665513668@linuxfoundation.org> References: <20220722090650.665513668@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.8 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 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;