Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp457852imi; Fri, 22 Jul 2022 02:49:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1swUIaovgcBtj48pQD5dg/9/wRXrgYGjqm+aVG8jYihK8RvaRbz45ODUqsHeq2Q3f8z5pUB X-Received: by 2002:a63:cf0e:0:b0:41a:63d7:66f3 with SMTP id j14-20020a63cf0e000000b0041a63d766f3mr2584702pgg.50.1658483361055; Fri, 22 Jul 2022 02:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658483361; cv=none; d=google.com; s=arc-20160816; b=LK+GDDve7r++Cr7dg/9kQBLdqMLVWrjp/kEpj0zQq61Hke0uqFT3gbg4w28FIvMbnY qyvhbR6+iNnm7Eznv/OzJ/HwU7Y1zJKnB7e8ypCTFDQI6iXOovCE3QZwVLurcQ5amIUE QteAmmvx7hugkd2NjONB4YVVETw+oG9TFItasbn3WsgAXjT+Guux0+Ey5CIl3raZMEZA 9AwkYZa1S+UeHOW4vo2H7bUKVD8IHRZ30bTHG1jv/I9ESJQ5RyB9aIpc6hAdxOdMyJI4 48TXLKRGjbQyxTv/+vy5FsFWwUaqggTpU3LAvXru13FnGtzQxcodIQA1Xnp5uVT6Ksfe NQZw== 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=4zQux9ecsOun20QGvkiKJXXQE8ehz1insWep44pF72Q=; b=sxhZVHK285m5KO923aYDHAFZJTatbjrsnL/6UhnHGnPnApzTN6dvsvZQhHsyyxh7ek bIcLDAiLqzPJYhUNO+3/DvsxhkjoED5UhVph6kLGBAwjNdyqx7h1MvU5hn5FM9m3D1uO 79/Aiv4MUTP8gkI1JROjTejVYbfeR+vmv4flRhFHk6MQdkmU8C58hMWCcDQhsSnTLh5w fJR6uw6FlEuxKKfNCtixUTW7zQ6hFX+XiV2tpIcMUiUq5la9NP3PPJtl4PNLpQBv8qR4 75vOvMk1sUyQHAHHxD59+gszQCq9J7TZ8mH6aUHJD/UP0BVRmJWsW4MtZa1zAor0cR+p ldHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pd9AGi++; 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 p14-20020a170902780e00b0016be96cf31bsi4878502pll.273.2022.07.22.02.49.06; Fri, 22 Jul 2022 02:49:21 -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=Pd9AGi++; 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 S236339AbiGVJ0X (ORCPT + 99 others); Fri, 22 Jul 2022 05:26:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236336AbiGVJZ5 (ORCPT ); Fri, 22 Jul 2022 05:25:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38CC9AFB70; Fri, 22 Jul 2022 02:16:25 -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 DC59F61FC3; Fri, 22 Jul 2022 09:16:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7F31C341C6; Fri, 22 Jul 2022 09:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481384; bh=FvMTOIgEJ/F9Sx4tLyEeltEoAwGGywAYye6RJJqo0P4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pd9AGi++y5Jx34zNrZhLIXpgv5KttB4+oBM5rh3VKW90Yg0gAafQeEHsUV+48iM0l kafiRC9/6BptGaxwowNw9686aDY+B6WORXcRBvK8QAjMoBJGHrY2gPZ9L5sYV74GoR nrF63cTJ3W79RFbAhQFQBIvt5DDNYnSmJP82uDBE= 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.15 58/89] x86/cpu/amd: Add Spectral Chicken Date: Fri, 22 Jul 2022 11:11:32 +0200 Message-Id: <20220722091136.606167464@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722091133.320803732@linuxfoundation.org> References: <20220722091133.320803732@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 @@ -515,6 +515,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 @@ -886,6 +886,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); @@ -931,7 +951,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);