From patchwork Fri Mar 10 16:22:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 67551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp973159wrd; Fri, 10 Mar 2023 08:38:23 -0800 (PST) X-Google-Smtp-Source: AK7set9gbjIv8aYVAkkJXfqwFcDMnNaV+Z2GRjqi9mkVJ/JS4JbOzfWY28iDfNSjj0eXq0Fn74v7 X-Received: by 2002:a17:903:41d0:b0:19e:3b41:1826 with SMTP id u16-20020a17090341d000b0019e3b411826mr30248257ple.54.1678466303337; Fri, 10 Mar 2023 08:38:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678466303; cv=none; d=google.com; s=arc-20160816; b=hk7j0NFHuf9prsqQX7lDb3yZTscwX4ffes/dWmwTC653/s0LxvM5jk6vhXTMc8a8Gy A5q+wYqvJCYndMUiZAl8tdezgEC2pPw06cfitae2XM3V/J34d59AFSnmF1dzsHvzUyUj I5O8/QlbrKfR5DT4uqC0Jrqew0/9gs2Rr8rbiiRwbQX8W5wQGlUUaL3nF0gBIjweN0He vgyKTjLfCaPCbsXgv0mAPn7+P1EA8JLNIx5MB6WaZNwql94CB35gGR6my9n3fA294B+O x2VmH1lk/SURkIE2wOEKEi0POgWTRVC3RnVMLKEgvO807Ir+xiikQ9U0iORViVNHFUls xTIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Zn3O1Wv8hkpbU9xlZEacvI/7IhPFKYjF4Rh+Ru4Qd7o=; b=POms/zg/St4oPK84EVoIbmhgWpNeyQl7X5cnV5PvCh7szdzWflTpOZU6xB/1Vx0Gh7 lOmRaL/kD22liTuzyndkBpujKCS1bAMc5dKx38zLh5n8dsSvsa140Mc0wq74VwKFPsMC 3n21CWxPhX1AOaFmEhptN0+6NZRjdJwRhTH1Gj+lVsPu6QxZrEdmkzyXlSRS0ACrKkSM 7AIDFHjyq/ngJxnhwFlpGq+nXLhKQTDrvjZAkEDOGcykitQBrhnLdYWPaJkZv507sFYA snxGDhx/zl2NxqLXeFieeOGtya2R3TAEXH7lTEZ6s0+gEp51AlqHdS3ukOfF3b8XHLHi NB9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=i4X5Mit4; 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=alien8.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kd5-20020a17090313c500b00194819b340dsi294356plb.351.2023.03.10.08.38.10; Fri, 10 Mar 2023 08:38:23 -0800 (PST) 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=@alien8.de header.s=dkim header.b=i4X5Mit4; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbjCJQ1e (ORCPT + 99 others); Fri, 10 Mar 2023 11:27:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230373AbjCJQ0n (ORCPT ); Fri, 10 Mar 2023 11:26:43 -0500 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D4E164B20; Fri, 10 Mar 2023 08:23:12 -0800 (PST) Received: from zn.tnic (p5de8e9fe.dip0.t-ipconnect.de [93.232.233.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 5C3E11EC0554; Fri, 10 Mar 2023 17:22:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1678465377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=Zn3O1Wv8hkpbU9xlZEacvI/7IhPFKYjF4Rh+Ru4Qd7o=; b=i4X5Mit4U8kl9v7iGgYtOKUsx1Wd68zbYF2p6kNYzqJ7GiZu/mWyCs3+mmgXDho/tsy1Uq c4NTudr4144eQrYalak0XGyKKhUqr4axXIMb0VupXDBjeddRqYLAsrfsBXdMlD8Tpvm5Mn eKKNGx344acXzkCNqDR2ES0jFJr0XuE= Date: Fri, 10 Mar 2023 17:22:53 +0100 From: Borislav Petkov To: Dave Hansen Cc: Josh Poimboeuf , Pawan Gupta , Kim Phillips , x86@kernel.org, Boris Ostrovsky , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Joao Martins , Jonathan Corbet , Konrad Rzeszutek Wilk , Paolo Bonzini , Sean Christopherson , Thomas Gleixner , David Woodhouse , Greg Kroah-Hartman , Juergen Gross , Peter Zijlstra , Tony Luck , Tom Lendacky , Alexey Kardashevskiy , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH -v2] x86/CPU/AMD: Make sure EFER[AIBRSE] is set Message-ID: <20230310162253.GCZAtZXcpK2JK0cFkZ@fat_crate.local> References: <20230225000931.wrednfun4jifkqau@treble> <20230225005221.425yahqvxb57c43x@desk> <20230225013202.g7tibykvylprsxs5@treble> <445daef5-8417-ddbb-abbf-3c5ab38e1c9c@intel.com> <3f80e71f-a995-8ad6-b7f2-2b80fefdbd46@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <3f80e71f-a995-8ad6-b7f2-2b80fefdbd46@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758760709797500317?= X-GMAIL-MSGID: =?utf-8?q?1759999482269258058?= v2, with feedback addressed, and rediffed ontop of 6.3-rc1: Acked-by: Dave Hansen --- From: "Borislav Petkov (AMD)" The AutoIBRS bit gets set only on the BSP as part of determining which mitigation to enable on AMD. Setting on the APs relies on the circumstance that the APs get booted through the trampoline and EFER - the MSR which contains that bit - gets replicated on every AP from the BSP. However, this can change in the future and considering the security implications of this bit not being set on every CPU, make sure it is set by verifying EFER later in the boot process and on every AP. Reported-by: Josh Poimboeuf Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20230224185257.o3mcmloei5zqu7wa@treble --- arch/x86/kernel/cpu/amd.c | 11 +++++++++++ arch/x86/kernel/cpu/bugs.c | 10 +--------- arch/x86/kernel/cpu/cpu.h | 8 ++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 380753b14cab..dd32dbc7c33e 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -996,6 +996,17 @@ static void init_amd(struct cpuinfo_x86 *c) msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT); check_null_seg_clears_base(c); + + /* + * Make sure EFER[AIBRSE - Automatic IBRS Enable] is set. The APs are brought up + * using the trampoline code and as part of it, MSR_EFER gets prepared there in + * order to be replicated onto them. Regardless, set it here again, if not set, + * to protect against any future refactoring/code reorganization which might + * miss setting this important bit. + */ + if (spectre_v2_in_eibrs_mode(spectre_v2_enabled) && + cpu_has(c, X86_FEATURE_AUTOIBRS)) + WARN_ON_ONCE(msr_set_bit(MSR_EFER, _EFER_AUTOIBRS)); } #ifdef CONFIG_X86_32 diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index f9d060e71c3e..182af64387d0 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -784,8 +784,7 @@ static int __init nospectre_v1_cmdline(char *str) } early_param("nospectre_v1", nospectre_v1_cmdline); -static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init = - SPECTRE_V2_NONE; +enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init = SPECTRE_V2_NONE; #undef pr_fmt #define pr_fmt(fmt) "RETBleed: " fmt @@ -1133,13 +1132,6 @@ spectre_v2_parse_user_cmdline(void) return SPECTRE_V2_USER_CMD_AUTO; } -static inline bool spectre_v2_in_eibrs_mode(enum spectre_v2_mitigation mode) -{ - return mode == SPECTRE_V2_EIBRS || - mode == SPECTRE_V2_EIBRS_RETPOLINE || - mode == SPECTRE_V2_EIBRS_LFENCE; -} - static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode) { return spectre_v2_in_eibrs_mode(mode) || mode == SPECTRE_V2_IBRS; diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h index 57a5349e6954..f97b0fe13da8 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -83,4 +83,12 @@ unsigned int aperfmperf_get_khz(int cpu); extern void x86_spec_ctrl_setup_ap(void); extern void update_srbds_msr(void); +extern enum spectre_v2_mitigation spectre_v2_enabled; + +static inline bool spectre_v2_in_eibrs_mode(enum spectre_v2_mitigation mode) +{ + return mode == SPECTRE_V2_EIBRS || + mode == SPECTRE_V2_EIBRS_RETPOLINE || + mode == SPECTRE_V2_EIBRS_LFENCE; +} #endif /* ARCH_X86_CPU_H */