Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4094imw; Tue, 12 Jul 2022 13:21:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ss1YX6ae8oZ+8gjeXF06EMp4DexXHPXAebWUL5Fk/LBObWAehgw9y/Nl/wP6faYwC7+7r9 X-Received: by 2002:a17:907:96a8:b0:72b:40b0:658 with SMTP id hd40-20020a17090796a800b0072b40b00658mr18182393ejc.3.1657657314736; Tue, 12 Jul 2022 13:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657657314; cv=none; d=google.com; s=arc-20160816; b=szaSE0nIAJeG9qtPSpEcNispoR/lckgFmTnKWHtF/QesYXi2uWHXkkwiycD/jqBhTI kk1bgjEsnrtO56aLXkgNl1Drptwvndgpnicow43JyzRkj7amu8FqQ7ZqTIO33B6XPEZT ufuuihy6YaX2y0od3XzyOwZ5JBV9r4lTZvct1ljr3Nh+tKV7rayPemnhP64rXyxYQOeJ q2+i4nEF6o7F/A/ngSkAFScyOXgkqkzPErqIcT7LHrUjq7YBBmnIlVuFG5FWFQ/uKnY6 E5VZpioPE9vCZG2+vS0rxV/N9o8YuU0nPNuIO4nVq+6b+Q/wk21/k7zbbERfTpkIeey9 i0YA== 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=TqYz9J1aVXiVJkS0mbxtghmvDqAMGYQGk0165TRTOjQ=; b=YZhmQU8TiIlChOOyV961fms+povJtE0KQiYZM4zrSioZwYzlk3Bbb/Vbi+AlmI/BdM Vq7tflxj+6i2vWgJBrls5XfmCT1/Sh02n7T/6aIr++mgSHOuPbrZHXGhs9cyRp0zWWZZ vbxLz2uPgRuqtxSV2ZgaNRT70BcXAf53rTyuRAEfVuP9V8qcycF8YXLrCIefzN3SNzxo Ic+ocpYSrJxIPppUw5j9pwD/ofWn6MJU7E7QGW+2ETFpOBud448PwoOk4yA3xIeHYDTx em5Z0EJaBLjFTLlFhKSIGtOeZnXGzfzu7iagUWQHwZCRLM5VqFYphzkCJ53b70vo1Ojh wGyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="U/qjLTwC"; 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 e7-20020a056402190700b0043ae0bf81ddsi7401630edz.326.2022.07.12.13.21.25; Tue, 12 Jul 2022 13:21:54 -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="U/qjLTwC"; 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 S234965AbiGLS41 (ORCPT + 99 others); Tue, 12 Jul 2022 14:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234744AbiGLSz6 (ORCPT ); Tue, 12 Jul 2022 14:55:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE812DB2F4; Tue, 12 Jul 2022 11:46:32 -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 ams.source.kernel.org (Postfix) with ESMTPS id 77D42B81BAB; Tue, 12 Jul 2022 18:46:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9F96C3411C; Tue, 12 Jul 2022 18:46:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651590; bh=27eIWJulyqSRKoMB+Qg9COgotQ0OI5jj3NKghFqH9oY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U/qjLTwCdaTYlw2q/3bCVBHYZFhiWEEfL0ytipwomuBgWnL8WtZNMhTcwbcBo33sS o8o83bugskX0hgxmuuSl+q/jV6zdrn5b9bOfaTLpBUbuhyBwW0KR0S+WvS/fJ1RZ+R avDy2AV96vGZijr8KIW5t1TNkjzshe3b+5S6zwXE= 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 , Ben Hutchings Subject: [PATCH 5.10 124/130] x86/cpu/amd: Enumerate BTC_NO Date: Tue, 12 Jul 2022 20:39:30 +0200 Message-Id: <20220712183252.194478286@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183246.394947160@linuxfoundation.org> References: <20220712183246.394947160@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] [cascardo: no X86_FEATURE_CPPC] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Ben Hutchings 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 @@ -316,6 +316,7 @@ #define X86_FEATURE_AMD_SSBD (13*32+24) /* "" Speculative Store Bypass Disable */ #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_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 @@ -942,12 +942,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 @@ -1246,8 +1246,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;