Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3108imw; Tue, 12 Jul 2022 13:19:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uBHtuhqCapuA3eVXNRKr0eQPyqG6CXOyJLiPQvZtyGvLtUMTRDOXdBicucJdy3mecYWPii X-Received: by 2002:a17:906:3f02:b0:718:bdf7:790d with SMTP id c2-20020a1709063f0200b00718bdf7790dmr26378657ejj.479.1657657002328; Tue, 12 Jul 2022 13:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657657002; cv=none; d=google.com; s=arc-20160816; b=yX82qktRye7iVdq7ZFRSHsJLBFtKXMLAIxpu4b9Dzjo/feEGjnQzbVzGuyGRgu7GdW 4lncUhTeRzlQkFKEZKSgYyw+Q42keS2cQp7FRFxg3MFSnySa8aLuad+fWEtcackPm/+r SKOXcDKfhSRMte+e97X36I37MLHLnGCEE1lIzEzIBPjQ7NjNmkBrArz12Q9Ii/sjyq/g 4iRHTo5j3rCL1k1bml/Hi4B/8jIDvw/sWNiZfIlWpAV1CVu6vHHLDcyJJta9JDoVb68Z ooPO6sBlTHzbVtWuNkdDPK21oRnJqiVZZbM0FIhBZindx3A7/cNw81Fo95DgTP6KfhpP wCFg== 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=REksm1vsrPcnxUO+qKJsBbQ3eBgBoS47nxjEH4FuUIQ=; b=o/QRmdZemtRxQrGW3vmYl18ESGzLa88ahOzJxPFPTX8I1pUlT8hu30uYqco7vAWbZz MOvqOHHpkYpb3IGr2BBdWqEBDXaDAgjyosXI1AVnsCgQmokw4No4LEEE7hHjyJFntjIe Z3o0yJH7tFSqd5Na47Fx81ARg46lXlGJq5vXUtCJVm4Rw+Bp3qzORdxsJlrmN8YGaR3h Bt59iefjmSjxA44Zg8WaXkG3qs59PZkB2MY/Rqh67Q8vSk38dR+G8xwxjdHE3sQGmS4K 9qgfSC4gdK9JonaCaqHdiN/NYgRtsfTn6B1E3iEwJAcdtu20DpLKA1nWI/44CiX8suGX ol/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bXXrydcU; 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 g14-20020a056402090e00b004356a5f330fsi17676489edz.445.2022.07.12.13.16.12; Tue, 12 Jul 2022 13:16: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=bXXrydcU; 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 S235027AbiGLS5h (ORCPT + 99 others); Tue, 12 Jul 2022 14:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234785AbiGLS5K (ORCPT ); Tue, 12 Jul 2022 14:57:10 -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 39498DC88F; Tue, 12 Jul 2022 11:47:02 -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 9F09A60C93; Tue, 12 Jul 2022 18:47:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7C8EC3411C; Tue, 12 Jul 2022 18:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651621; bh=v6IcRe3m3zGjisnaOPEL/c8dPABEyZPbTJYzs5Yb47o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bXXrydcUeQfFvXVJ9glGwgaMKrLiYwIElIgbEZZLHEhi9OKEW3NJQoSzBCm51a6z/ D8b23tVzBbY8/OTh/m0Wdut+cfkHA2ZapRhYFUd3wvHl/ZNyQ6WixK28LaFCtpg6Gd 5g9zUS8Kn5XvWgm6caAt6yJkuFvLvtCmgAcmeI0E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Cooper , "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Thadeu Lima de Souza Cascardo , Ben Hutchings Subject: [PATCH 5.10 111/130] x86/cpu/amd: Add Spectral Chicken Date: Tue, 12 Jul 2022 20:39:17 +0200 Message-Id: <20220712183251.585031032@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: Peter Zijlstra commit d7caac991feeef1b871ee6988fd2c9725df09039 upstream. Zen2 uarchs have an undocumented, unnamed, MSR that contains a chicken bit for some speculation behaviour. It needs setting. Note: very belatedly AMD released naming; it's now officially called MSR_AMD64_DE_CFG2 and MSR_AMD64_DE_CFG2_SUPPRESS_NOBR_PRED_BIT but shall remain the SPECTRAL CHICKEN. Suggested-by: Andrew Cooper Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Josh Poimboeuf Signed-off-by: Borislav Petkov Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/msr-index.h | 3 +++ arch/x86/kernel/cpu/amd.c | 23 ++++++++++++++++++++++- arch/x86/kernel/cpu/cpu.h | 2 ++ arch/x86/kernel/cpu/hygon.c | 6 ++++++ 4 files changed, 33 insertions(+), 1 deletion(-) --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -508,6 +508,9 @@ /* Fam 17h MSRs */ #define MSR_F17H_IRPERF 0xc00000e9 +#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3 +#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1) + /* Fam 16h MSRs */ #define MSR_F16H_L2I_PERF_CTL 0xc0010230 #define MSR_F16H_L2I_PERF_CTR 0xc0010231 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -914,6 +914,26 @@ static void init_amd_bd(struct cpuinfo_x clear_rdrand_cpuid_bit(c); } +void init_spectral_chicken(struct cpuinfo_x86 *c) +{ + u64 value; + + /* + * On Zen2 we offer this chicken (bit) on the altar of Speculation. + * + * This suppresses speculation from the middle of a basic block, i.e. it + * suppresses non-branch predictions. + * + * We use STIBP as a heuristic to filter out Zen2 from the rest of F17H + */ + if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && cpu_has(c, X86_FEATURE_AMD_STIBP)) { + if (!rdmsrl_safe(MSR_ZEN2_SPECTRAL_CHICKEN, &value)) { + value |= MSR_ZEN2_SPECTRAL_CHICKEN_BIT; + wrmsrl_safe(MSR_ZEN2_SPECTRAL_CHICKEN, value); + } + } +} + static void init_amd_zn(struct cpuinfo_x86 *c) { set_cpu_cap(c, X86_FEATURE_ZEN); @@ -959,7 +979,8 @@ static void init_amd(struct cpuinfo_x86 case 0x12: init_amd_ln(c); break; case 0x15: init_amd_bd(c); break; case 0x16: init_amd_jg(c); break; - case 0x17: fallthrough; + case 0x17: init_spectral_chicken(c); + fallthrough; case 0x19: init_amd_zn(c); break; } --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -60,6 +60,8 @@ extern void tsx_disable(void); static inline void tsx_init(void) { } #endif /* CONFIG_CPU_SUP_INTEL */ +extern void init_spectral_chicken(struct cpuinfo_x86 *c); + extern void get_cpu_cap(struct cpuinfo_x86 *c); extern void get_cpu_address_sizes(struct cpuinfo_x86 *c); extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c); --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -318,6 +318,12 @@ static void init_hygon(struct cpuinfo_x8 /* get apicid instead of initial apic id from cpuid */ c->apicid = hard_smp_processor_id(); + /* + * XXX someone from Hygon needs to confirm this DTRT + * + init_spectral_chicken(c); + */ + set_cpu_cap(c, X86_FEATURE_ZEN); set_cpu_cap(c, X86_FEATURE_CPB);