Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1820841rwb; Wed, 5 Oct 2022 05:25:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6at4yr96bSez/e12QY0NXoRRO/MY8QnllhW85xo8qxOT+PjPPPb1PS60KRDyyfYZrvYix3 X-Received: by 2002:a17:90b:3a88:b0:209:f55a:962e with SMTP id om8-20020a17090b3a8800b00209f55a962emr5054793pjb.28.1664972757246; Wed, 05 Oct 2022 05:25:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664972757; cv=none; d=google.com; s=arc-20160816; b=fKgCaxrJEIwbAjRECttaDZ48s6MtCDJlePkNNB+16COvFQN2vo9ZL8ZkcFnjMlZ6QH Vjb77kPet9bwZiUblQskMeVqr15u5ZjwI9PwvaqsJeiWUhrulLWnCXrI747GUIJBmB1R t9I3hjpiU2kl7DjnRPloQszQTti1UIqL8CeB8pMOXu95lZj24iy98svIyqTkCZUSs732 RzmKLXQNZAYU7wHVn8pCAyFULQvvnXagHqz0G+actiDHkev5SOvOQbHHwJswcMSoSvOr HtAVS/VnFrpUR9STmDAb50W4lL1rqbAgIOCAztMw9vhuwujDH1QKoovPjEhhReXFiZfX V/iQ== 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=L45iqvCTn6VwIKT4dZEs0rNM1P+9a5/kwB8MOj9uTYk=; b=Un77S2SkyqihlYYhF0rz+4dbi53igUQpQID1ont68SEXK3fify1nN5lalGqwtg7Bh5 V3mc4eHonEsJqV9+GcJWz+eG8gw/5P8sf8oSUN9+j+Y/+J+kQnK7dFhzMEhv952S6p1b xY+TdFHstTqlf8HFKQSGn9Is1tlhsmVY08JteYW8J8YPLNMV/WQB1lDTuzPkk8uxcKKy cqz9XoTJJcK2uIg4bAeHq5BVD+nW9qm4juisKhb5sQizO63zaCUly7fGP5aeROyoxqiL 7mpKw4JY8s/XcXwMIkaQc6NSotprqmUPbPNheweuOO6+4phBcGYpZqK5zZan+TWyL9/V EEIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KjFwDRb6; 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 b1-20020a636701000000b0045a3e1d1a77si82800pgc.111.2022.10.05.05.25.44; Wed, 05 Oct 2022 05:25:57 -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=KjFwDRb6; 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 S230163AbiJELgG (ORCPT + 99 others); Wed, 5 Oct 2022 07:36:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbiJELfa (ORCPT ); Wed, 5 Oct 2022 07:35:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C835786CE; Wed, 5 Oct 2022 04:34:09 -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 2A59CB81DB2; Wed, 5 Oct 2022 11:33:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CADBC433C1; Wed, 5 Oct 2022 11:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664969635; bh=46VLJu9YyPc9gZ9l+X0jmicASSTF3QF8dJGDhZN+hIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KjFwDRb6p+8gs/k4OqjjzhfJPPVIpCB1PtCwKQ96fu76CeM9iMjh/igoXCaCjsLm9 /40DLbe6FuvhDrju63q368zqmu3+rUq+pxBpjy7VN8G0mhYtV+o6QWrEhHjA6egnjm K78eC9s3E0ftkYk4A5+EmedyVihyG9zRa+CHB0Sg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Andrew Cooper , Borislav Petkov , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.4 32/51] x86/cpu/amd: Enumerate BTC_NO Date: Wed, 5 Oct 2022 13:32:20 +0200 Message-Id: <20221005113211.771085542@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221005113210.255710920@linuxfoundation.org> References: <20221005113210.255710920@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 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 @@ -304,6 +304,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 @@ -894,12 +894,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 @@ -1259,8 +1259,10 @@ static void __init cpu_set_bug_bits(stru setup_force_cpu_bug(X86_BUG_MMIO_UNKNOWN); } - 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;