From patchwork Fri Jan 28 13:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 12728563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34B11C433FE for ; Fri, 28 Jan 2022 13:30:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.262002.454026 (Exim 4.92) (envelope-from ) id 1nDRKE-0004yZ-U6; Fri, 28 Jan 2022 13:30:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 262002.454026; Fri, 28 Jan 2022 13:30:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDRKE-0004w9-CI; Fri, 28 Jan 2022 13:30:02 +0000 Received: by outflank-mailman (input) for mailman id 262002; Fri, 28 Jan 2022 13:30:01 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDRKD-0003aP-3m for xen-devel@lists.xenproject.org; Fri, 28 Jan 2022 13:30:01 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 64259e89-803e-11ec-8f75-fffcc8bd4f1a; Fri, 28 Jan 2022 14:30:00 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 64259e89-803e-11ec-8f75-fffcc8bd4f1a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1643376600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gHfpIZlajUaP6cGdkiuSguv/j1zSvd9zDfBvEzVBPh8=; b=VcTK6SFso4R6xTRh8ky2XPYt5O6mVf6Pqj/+J6U24yUPvtzgLdPDEHHZ ud70B4xxvXk6VEyKY+rqi1w9BJ/pl7lOdMTPp3pfQ+plFt85N9Psqy9KL JRTIQqAyJfQunMzj4dxFLFqXu8HRTWN/B5/xPNQQbSwGv+CXGJJ7iJHVn w=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: xFsr5l5z5y/D9EoB3ZQVgrJPfyV9kXFMZpXxUAhrWB7N5x7vh8FwwNpBa1LR4L88Nva269NoTD gRadX/pU4CRSM1iTbxfzQP2LE9mcAvdHsKT+pGGC5hRdzuncfdDJ9f9uXnS1BbHHMKA0hcvGEi r7T8RHAw3C6thv/y2wEhbtwKB4lPeaelCcN+pvqfR5XFtnpTJhkAPaX7AnLTdecl1Q5eGTNSjG crgeRLOqsBGzKFnwjv7QxzUh3pi7Idc4EvTQrYc24Jt87DJ/bI+roNhhknP9fhWJO3Lgt68TtK lvkODKRs07CBOEJgOS6aVOrt X-SBRS: 5.2 X-MesageID: 62981611 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:Y0ZiWanVl3PN+mBmO7h1XTPo5gxVIURdPkR7XQ2eYbSJt1+Wr1Gzt xIZXWzTb/fcNDb1ftwna9/npElTvZOBy4cwQQNspX0xFSMWpZLJC+rCIxarNUt+DCFioGGLT Sk6QoOdRCzhZiaE/n9BClVlxJVF/fngqoDUUYYoAQgsA180IMsdoUg7wbRh29Q42YTR7z6l4 rseneWOYDdJ5BYsWo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;i="5.88,324,1635220800"; d="scan'208";a="62981611" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH v2 2/9] x86/spec-ctrl: Drop use_spec_ctrl boolean Date: Fri, 28 Jan 2022 13:29:20 +0000 Message-ID: <20220128132927.14997-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220128132927.14997-1-andrew.cooper3@citrix.com> References: <20220128132927.14997-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Several bugfixes have reduced the utility of this variable from it's original purpose, and now all it does is aid in the setup of SCF_ist_wrmsr. Simplify the logic by drop the variable, and doubling up the setting of SCF_ist_wrmsr for the PV and HVM blocks, which will make the AMD SPEC_CTRL support easier to follow. Leave a comment explaining why SCF_ist_wrmsr is still necessary for the VMExit case. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu --- xen/arch/x86/spec_ctrl.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/spec_ctrl.c b/xen/arch/x86/spec_ctrl.c index c18cc8aa493a..8a550d0a0902 100644 --- a/xen/arch/x86/spec_ctrl.c +++ b/xen/arch/x86/spec_ctrl.c @@ -927,7 +927,7 @@ static __init void mds_calculations(uint64_t caps) void __init init_speculation_mitigations(void) { enum ind_thunk thunk = THUNK_DEFAULT; - bool use_spec_ctrl = false, ibrs = false, hw_smt_enabled; + bool ibrs = false, hw_smt_enabled; bool cpu_has_bug_taa; uint64_t caps = 0; @@ -1016,19 +1016,21 @@ void __init init_speculation_mitigations(void) { if ( opt_msr_sc_pv ) { - use_spec_ctrl = true; + default_spec_ctrl_flags |= SCF_ist_wrmsr; setup_force_cpu_cap(X86_FEATURE_SC_MSR_PV); } if ( opt_msr_sc_hvm ) { - use_spec_ctrl = true; + /* + * While the guest MSR_SPEC_CTRL value is loaded/saved atomically, + * Xen's value is not restored atomically. An early NMI hitting + * the VMExit path needs to restore Xen's value for safety. + */ + default_spec_ctrl_flags |= SCF_ist_wrmsr; setup_force_cpu_cap(X86_FEATURE_SC_MSR_HVM); } - if ( use_spec_ctrl ) - default_spec_ctrl_flags |= SCF_ist_wrmsr; - if ( ibrs ) default_xen_spec_ctrl |= SPEC_CTRL_IBRS; }