Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1124809rdb; Wed, 24 Jan 2024 05:47:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIgkH9rGqErrgwKUnJkfsgSr4dPBCstm8U+Bu72nlzIEGrnbmbvDfn9/x6r2jM4V8fxmTu X-Received: by 2002:aa7:9a4e:0:b0:6dd:8a25:e167 with SMTP id x14-20020aa79a4e000000b006dd8a25e167mr880045pfj.34.1706104030875; Wed, 24 Jan 2024 05:47:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706104030; cv=pass; d=google.com; s=arc-20160816; b=dKUV0c7KRpcDPpcpDsD98b21T6X4L+gjMVFzeTKtLGwllXC1scw0WJNiNaQQ5nhRCv zklMVNLBxSAjw0zLf/8PWIkQfNYjjIuI/VBCxzrVnkoAbsit5eqtSqaHW6at2nxATIXB PKgm69XnXdvq1AKKV/C0KW5otYvDHWXZgrw07wyoBNUlXTqv/P9Qi4CeuQi6NtWWrSMT YxFMBtwVWelgeGGYmDKvlWw9PmtRcWJxPF7b9mhVrKdJUuqiCfI3ktVxZdniCatEO0D3 nY33oNI8sXJDSiQSJDSxl5mBcPhyRbN36yWU+TIaPAnm0OUJC9VYofhbgRl3wzLxIw+/ 93EQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ilqGXAQjD0Zw0p+0QS0PhsqpTUKzsxY97u90wwaRZ8Y=; fh=ER2H6g+88FnZd3JyhT6ewHH56pdK2QWfWr77z0IHoNE=; b=fU4Q1z8GGoH1/CHCsF5beXo50zc8KZy0TNtRtUoIOUVWzXmBzXNiUCNNZmUJbhI6lx 0W6p7LOfUm5H6yy1mtyaQklUsDjoCwmmnY/cO4CmbYM6ypIINgGH3XTuCONwT8vnw46P bcDodUtl2e3BQCyeKPa/JPy3qe98nnTE69hNMNOQh1BiliM73QZPBIH78F08jSsw+Wr2 7GDctsu2zcXI04hNqDHmP3s2K9HdfYQAOuY0/8aMJ4u6J/NHnwwOn0Cphe7J26YTtio4 Al5e/aXbFWlQD1WFU7YIIli8oO/ys67+LEjKZZBnPAsfiF7mlnEl4ogQN4oQK91OwZO9 Sd6Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DxEim5OK; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36579-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36579-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z10-20020aa7888a000000b006db6ed782a2si14347791pfe.290.2024.01.24.05.47.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 05:47:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36579-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DxEim5OK; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36579-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36579-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5D11328EA73 for ; Wed, 24 Jan 2024 07:44:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26B0C17735; Wed, 24 Jan 2024 07:42:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DxEim5OK" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E89EC171AA; Wed, 24 Jan 2024 07:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706082141; cv=none; b=XBgQpSfZbOEunaI82rU2C0v8DfVTJ/EPRmCPG5nN0WVShpl1ePg/kCpVRyY8JJeW6oRSx2l5RxhgCqFPZ872Bubz0zzA64aBO8L5JeUWYKOXq7r3p+dwVREBbjV/xywDH4+gEPpyVluVscY9MMvBpc0ROO5i72gGMugXHiwZ8s8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706082141; c=relaxed/simple; bh=rpFgire7Svqru/HfpQ1b16RkVx0842HOL7xbgXY2vaQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f0UcyazsjAEUmn8g2uHDmiUNyZtwYLIAqf5BPJGhMr2C7kfbFttpJjfB4MTchyazvUb+a0AYa/KsyucQMMwZfTEna6nOdo/u+hPdjvQTt3Od1+PUl/3tgLaYnS9vyd8ROA4HQNdCU3fjMBR/chysWEX3c2arsCfQsF4/rWEYJQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DxEim5OK; arc=none smtp.client-ip=134.134.136.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706082139; x=1737618139; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=rpFgire7Svqru/HfpQ1b16RkVx0842HOL7xbgXY2vaQ=; b=DxEim5OKkxWhq/fmmpcb6qriPpEEMdNxTU/AWUYZDgVotvNyZ2MeOM0A tnTekbp8xiaqRMIrXmjE/GhfNom8ybwX+oBMmcFzPNPEsDnf1Bx3jk5N6 PWK0YOeKHHCkGiY1MkFlbuW0vgyTG94IqTTtiey4JRd9jQq3yvgA8tU1C x+BgE1dl5WQzfkcqg6VerSEeQ1RvY6ay6cF7d8vtMBz5YLogLA8jqWmTL Y8OulnN07dkGnSQWH8Z+2vcPd3potfsaaBj9qOs8yNiYYD2wYTNf6xNyx /BP1SFyRD1rxKnY82lehskJC2l5qxN/LQq4ReJZGpgMVnyjFGBrfxsmgm w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="392184641" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="392184641" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 23:42:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="1819150" Received: from bbaidya-mobl.amr.corp.intel.com (HELO desk) ([10.209.53.134]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 23:42:12 -0800 Date: Tue, 23 Jan 2024 23:42:11 -0800 From: Pawan Gupta To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Andy Lutomirski , Jonathan Corbet , Sean Christopherson , Paolo Bonzini , tony.luck@intel.com, ak@linux.intel.com, tim.c.chen@linux.intel.com, Andrew Cooper , Nikolay Borisov Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, Alyssa Milburn , Daniel Sneddon , antonio.gomez.iglesias@linux.intel.com, Pawan Gupta Subject: [PATCH v6 5/6] KVM: VMX: Use BT+JNC, i.e. EFLAGS.CF to select VMRESUME vs. VMLAUNCH Message-ID: <20240123-delay-verw-v6-5-a8206baca7d3@linux.intel.com> X-Mailer: b4 0.12.3 References: <20240123-delay-verw-v6-0-a8206baca7d3@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240123-delay-verw-v6-0-a8206baca7d3@linux.intel.com> From: Sean Christopherson Use EFLAGS.CF instead of EFLAGS.ZF to track whether to use VMRESUME versus VMLAUNCH. Freeing up EFLAGS.ZF will allow doing VERW, which clobbers ZF, for MDS mitigations as late as possible without needing to duplicate VERW for both paths. Reviewed-by: Nikolay Borisov Signed-off-by: Sean Christopherson Signed-off-by: Pawan Gupta --- arch/x86/kvm/vmx/run_flags.h | 7 +++++-- arch/x86/kvm/vmx/vmenter.S | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/run_flags.h b/arch/x86/kvm/vmx/run_flags.h index edc3f16cc189..6a9bfdfbb6e5 100644 --- a/arch/x86/kvm/vmx/run_flags.h +++ b/arch/x86/kvm/vmx/run_flags.h @@ -2,7 +2,10 @@ #ifndef __KVM_X86_VMX_RUN_FLAGS_H #define __KVM_X86_VMX_RUN_FLAGS_H -#define VMX_RUN_VMRESUME (1 << 0) -#define VMX_RUN_SAVE_SPEC_CTRL (1 << 1) +#define VMX_RUN_VMRESUME_SHIFT 0 +#define VMX_RUN_SAVE_SPEC_CTRL_SHIFT 1 + +#define VMX_RUN_VMRESUME BIT(VMX_RUN_VMRESUME_SHIFT) +#define VMX_RUN_SAVE_SPEC_CTRL BIT(VMX_RUN_SAVE_SPEC_CTRL_SHIFT) #endif /* __KVM_X86_VMX_RUN_FLAGS_H */ diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S index be275a0410a8..b3b13ec04bac 100644 --- a/arch/x86/kvm/vmx/vmenter.S +++ b/arch/x86/kvm/vmx/vmenter.S @@ -139,7 +139,7 @@ SYM_FUNC_START(__vmx_vcpu_run) mov (%_ASM_SP), %_ASM_AX /* Check if vmlaunch or vmresume is needed */ - test $VMX_RUN_VMRESUME, %ebx + bt $VMX_RUN_VMRESUME_SHIFT, %ebx /* Load guest registers. Don't clobber flags. */ mov VCPU_RCX(%_ASM_AX), %_ASM_CX @@ -161,8 +161,8 @@ SYM_FUNC_START(__vmx_vcpu_run) /* Load guest RAX. This kills the @regs pointer! */ mov VCPU_RAX(%_ASM_AX), %_ASM_AX - /* Check EFLAGS.ZF from 'test VMX_RUN_VMRESUME' above */ - jz .Lvmlaunch + /* Check EFLAGS.CF from the VMX_RUN_VMRESUME bit test above. */ + jnc .Lvmlaunch /* * After a successful VMRESUME/VMLAUNCH, control flow "magically" -- 2.34.1