Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4705003imw; Tue, 12 Jul 2022 12:44:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vG9ahUsHyH+FgVxtgy6oS8My16mhrV3Xvu5aebBFdGdNm+7vAKm7ym2X3SfzRsCY3sjkSD X-Received: by 2002:a63:27c3:0:b0:412:99f2:e483 with SMTP id n186-20020a6327c3000000b0041299f2e483mr21205174pgn.483.1657655059910; Tue, 12 Jul 2022 12:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657655059; cv=none; d=google.com; s=arc-20160816; b=XrQ+9niJzF4WePFIrojX6397Bf5Gayzy/6rUNQrgMOYaLfOI71do5EW5ITDY4T3w0z bOXTVei1umoJJ2/np7NkUzoEOEYK4bd6oTvOOpa3vVe7GESbYNo1MGQ5k6ICaAMw98CZ UuhXsjg/gQfRsKCcWGsoMm8iHtG1b/A1pSEaJorRjrh3Ff+IkgUqbQe8CWlvC1BR6rY1 wO7r725UUS3ZPjZyUIVbkI39i4KKgnSOBTnmrC2+m2e/RA+Lk7tVcQuRW3Mz5KDWeDaA 0BY8u01dDcULkDaQs+7MI2E7chWCOAoTosTpS2LL7riYGC+z8kEaY5WI9+zIuFqo7lLj tT9A== 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=X/Q8dieg0eUcGFg6Hfhbk1bGTmJ+t95NiySfcdUt/azRM6HTfXlVpWKaGtY5RuKEiR jSz0lUGig41gg2CTeG1F6QJ+T+NKWDJ9Pcr7iEW12MivUMb62KYlrAbMVHJjDvMw3k3E f/Ux3Ws8G1dhRhOqy/28P9rMBFj9VdGF0/DtVEOyBgIVBuVcOvsGlRA0dvsci7YjEKGi se5RMzehaQttWnzEbN7wWsk/5gFmG/gLcJyFmOXd2oK5tSpKNtGAxSSXiYo78iOXvL4M ThhrYTJ5oU8wbwGKjcoI6W2yGnF+UXPnZLARCd8B/jVjlBfj9wbGhAjvpXu3I9/ugDnF hJeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IGzsXYx0; 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 b8-20020a056a0002c800b0052ae2e0afdesi3832224pft.69.2022.07.12.12.44.07; Tue, 12 Jul 2022 12:44:19 -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=IGzsXYx0; 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 S235918AbiGLTO7 (ORCPT + 99 others); Tue, 12 Jul 2022 15:14:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235959AbiGLTNs (ORCPT ); Tue, 12 Jul 2022 15:13:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1F4545068; Tue, 12 Jul 2022 11:53:50 -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 0730CB81BAC; Tue, 12 Jul 2022 18:53:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 245E4C3411C; Tue, 12 Jul 2022 18:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657652027; bh=2MIJbf8TXQQVuRBlejKSL9UpaG5j6tBin2fze29fTlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IGzsXYx0GI/vR4S2jz6Mb8+z63oc4M0TyKoZ26pME74rganWhNjeFdmSq0Mvkg2W5 8eYXjo/1Mi5hhVJinG7p+LR9x8ZlbUkilWG2Mr2PODwiRIwGehb2AkaZE4rGokgjpp uTyhpFg8r5ox4AvxxjXDxHpbcllW7ul5ILx3UO6M= 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/61] x86/cpu/amd: Add Spectral Chicken Date: Tue, 12 Jul 2022 20:39:37 +0200 Message-Id: <20220712183238.578903841@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183236.931648980@linuxfoundation.org> References: <20220712183236.931648980@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: 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);