Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1365890imi; Sat, 23 Jul 2022 03:47:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t/2W4jtjC0abu6I8zhSo2gqadXmMzldtV0ZJ0BnUKwCaXoyquQYY3YOs73HqfBXHQhiXMJ X-Received: by 2002:a17:906:ff48:b0:72f:10c:bb3f with SMTP id zo8-20020a170906ff4800b0072f010cbb3fmr3112275ejb.718.1658573262013; Sat, 23 Jul 2022 03:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573262; cv=none; d=google.com; s=arc-20160816; b=XxfGJnjbn+R87ODenb0/5WHWXKP6t2tlxFmTBTodScaW36Ies1zI+5lw+nHeHM+PQg qdBbLAkbzo0/bTRqLWQ8gyqWf0oyUZ79Bb12KvHJ6ZDsqlQwum7ewtI3hhX2/QOH7LJu 5N8X5v0gBw/Fno0fs9ch4dkyKiViCQMphFv19kOTGs8SZVFs9AkR6A0vwQLweTM5SFxE Bfg/QDbTNUwDFlLNlx3Z5Cn6uoMIfACfSqJUMlnXWiMEX1JPESIz+3bBDG3oS582prSh UV1k8I7fZdrb1wpSxZpARfThJJrLempol4vSlfGl/u0ilBNLi7H4H/3eEWmLOo9SqQI5 pC8Q== 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=q6gChD8L+oUNH3WC+/VYJBu1zByv0vrqNof1U95m0srjV6hSdDJweJ2sbUtVZrFns6 0lfr753qL1gYm4nez5rdP348ZJORpK5V//gltz9mdBqC8F0DOSK8zxW9cT1EQ9VWs8vK jhyq7uWMTlgIvQ7KdFCpZ+X+DdcK/N4ty2f6XmFbC1DcsqqVFKJQdbrs17QI/ESsnuix gVqJq052r8pJ13vnI6E1RfSDyjnjwgPSUH9g/bk5sK9VFtEmo1Czwd7OMizxn7G2cUfJ xQhR2XA7yuQyVWdaTCbHC64+6fcg+eeKhnUNx/o65ZnB0/aH+ZfpAw+q2m3pRM31OXBZ Ek/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RIHe02dZ; 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 f12-20020a056402354c00b0043bb671bf39si9395050edd.247.2022.07.23.03.47.16; Sat, 23 Jul 2022 03:47:42 -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=RIHe02dZ; 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 S239056AbiGWKKv (ORCPT + 99 others); Sat, 23 Jul 2022 06:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239021AbiGWKJN (ORCPT ); Sat, 23 Jul 2022 06:09:13 -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 45B617E323; Sat, 23 Jul 2022 03:02:22 -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 BCE37612B4; Sat, 23 Jul 2022 10:02:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8D24C341C0; Sat, 23 Jul 2022 10:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570539; bh=27eIWJulyqSRKoMB+Qg9COgotQ0OI5jj3NKghFqH9oY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RIHe02dZaE2Iw0upVG5h/TgCE4bX7otebXU44OBCjUgRuN3Q7/BLSaD/6FYJtTj2C Fi1RMf2zR5NqlfgpSfOJTkpM26youbVFOw0aUR9wfuWVs1mrChTFVh4XrtEj/FvTv0 Y7JK/5AFNqzNbfYAdQfJH/ftA5NCyUTh/ffP9U3s= 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/148] x86/cpu/amd: Enumerate BTC_NO Date: Sat, 23 Jul 2022 11:55:36 +0200 Message-Id: <20220723095259.044246744@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@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] [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;