Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp458544imi; Fri, 22 Jul 2022 02:50:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLSfhc4GqPLzB1VwSF0q+TzXXrnCTRU2zkz2EzivJzLAEu0lXcDLZpiKrlIwrRl9BRVH+c X-Received: by 2002:a17:902:74c5:b0:16d:4417:8c02 with SMTP id f5-20020a17090274c500b0016d44178c02mr889214plt.121.1658483426508; Fri, 22 Jul 2022 02:50:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658483426; cv=none; d=google.com; s=arc-20160816; b=llwuOOiwV1dGZ+oMS+zd6yTN5O3rzTmw+ucUqy3/Q23bqsdEHGZFoUp3jlnP4G8xfU lFcWcydW+BhBf17yRxJwWnU+3uiooo68s4nBLKCGBhrmja8xdFv0ZhsxMaTrUCr5Axay xWOPBtnGuwBJHggGBkTrkfbDQ82LjnFfCgVxBGwCA1UxmBO2go/yfFzMvdco7BCZjWuY IQGPwTTYkVtNOEf/fETUZHo5sJ2xriqysvpo/PZTQb92kpi+GA/1Z4yxHaZBH5yV/2nC sjFwj72nZFwQHBgf8lIvVFAbdfr5nENENfXENnCKkEpZaFTs0Vbw3rDMtyfiPa7C9Wtb M0iA== 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=yKQmg+8OtUod5T9nL3PIqHub8zxmA7SdZhKJIs9UArw=; b=mc9XcXqK4033DOZJWXXqRF4ImeXxy5Ew0ZRTqBquvufwOYfyH3ATbq0XFyvs7Ket6C 3+d/gEPrg/6QJNAdHf3GJDQuF6Ar1TatBpJz7ZZgr1YRzJcwxSydK8e409rf0aziwIBa s7eQN0vNtv8ipNErCqUKzHdt4vfBQnOPx3cObAwkcpInx3B4Ll+g3+wg437yZ+HzqZob HcpUr/t3xnetQdVpC1DLf8B3epgmB4POnHm6n5GSI4QN4iob6YgrwYiObIe8eHLXJSB3 WT/uMZ3NPDD43YH965FoQh3RKlSIq6qpDpcl5vM1MJrQxZFwzPZ0PDj2VrvzwFIaMI5E 23XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WZ2+OVZ1; 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 x77-20020a633150000000b003fd60345d13si5511208pgx.693.2022.07.22.02.50.11; Fri, 22 Jul 2022 02:50:26 -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=WZ2+OVZ1; 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 S235242AbiGVJMb (ORCPT + 99 others); Fri, 22 Jul 2022 05:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235087AbiGVJL6 (ORCPT ); Fri, 22 Jul 2022 05:11:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54EC9A0B91; Fri, 22 Jul 2022 02:09:53 -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 E4F77B827C8; Fri, 22 Jul 2022 09:09:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54DE3C341C7; Fri, 22 Jul 2022 09:09:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658480990; bh=2MIJbf8TXQQVuRBlejKSL9UpaG5j6tBin2fze29fTlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WZ2+OVZ1jDwOXmJ4ecLIywCNGtTobmzXzLE/WghUfWxnS2wLZ8OXdiUDuuu32FgKM 9plf8d/5Qhc0lIkbKsYJAe3v+G4WvdvEeIuZx7Bz95myQ64jiS4dbvwFRQ7qS/Ze6f NSiNp9uhfNQjbGgBpRa5HYM1JbT0HyfE/NF5a12k= 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 Subject: [PATCH 5.18 40/70] x86/cpu/amd: Add Spectral Chicken Date: Fri, 22 Jul 2022 11:07:35 +0200 Message-Id: <20220722090652.962971847@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: 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: 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 @@ -553,6 +553,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 @@ -862,6 +862,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); @@ -907,7 +927,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 @@ -61,6 +61,8 @@ static inline void tsx_init(void) { } static inline void tsx_ap_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 @@ -302,6 +302,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);