Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1730438rda; Tue, 24 Oct 2023 01:09:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqZtLVnysjIOJdjXhTKrMbJXqJ71NqOcQ3H+x9RACeiAOEdyG0qmO4M00HLtBJ2srz6saI X-Received: by 2002:a05:6a21:788a:b0:17b:c254:a6a9 with SMTP id bf10-20020a056a21788a00b0017bc254a6a9mr2026986pzc.50.1698134962757; Tue, 24 Oct 2023 01:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698134962; cv=none; d=google.com; s=arc-20160816; b=ZWCLOfDJs+I/gA2PWRItHWTPq8yamffP7XRt13d4sNygGA/4xurqn8GzOrFr10c5ph lKrbpx9QVxSAA3Yl2OQi1GEPfJ8VPgaP6H/Gwq4pxged73MMRtYSVuoVXfyOV9HcFDhQ PekwdSmYNiLQkTFGVfvX/VSBzBOD3c7KKkki5RH5zj0DFtkkcP7V+Hkelq5gej/gW3xp pHk6KEDU0r7gQ9O8T/KJ4xV781GP3JWTQZEOR5Sii/rsknVr4yNHIrwkI++IS2dQq+Yq vrNBV9yM/vFEkOV++GxPUSRlVAfbAxFPLxev067TneRkGLUNxDurnUPtV3KRifB+vDW1 wUzA== 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=gYcBfgOwqZF4YkuQn6ALLKqSUnPNQohF+3zYsdZYN2A=; fh=lbJsPO+ZRDN9baDq/BZnnNH6CGOpZtNT0YCi3hapTHQ=; b=LEsxOmV/gZjy4aosf7iE6jh8fbz+nXtAGP6FuSn1R6br1YVCenbt05aR2oGPwnA+FR 0126ZlnxJ+AY7gt4O3KsLOfyoLkWoZiUhmeH+WJ9tai2XN5fdn+oiKC7bhPKXX3UlM+1 IXUtBPUdH+FR+ngTeoCERLbCYGvvv8dZBa2oJ+vy0NyRqQZv1cjMoo9zOikiCwlhoxZM XsYQLGdPO3JSXxBxnopbYTGg0YQlfZJD7OZxdgW8whiteDF+9SnJ/AMFAKIT09t6vSwK xErrpFujFHEQ+6IcU78jc0D+gFU/ho8/E1yFhifB3dBzQY+w+oOsHQlZ0S4LqFVNJGYB c5dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JpTsNdCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id lk3-20020a17090b33c300b0027d60ad5caesi8536929pjb.110.2023.10.24.01.09.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 01:09:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JpTsNdCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0C2AB803BED7; Tue, 24 Oct 2023 01:09:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233886AbjJXIJI (ORCPT + 99 others); Tue, 24 Oct 2023 04:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233884AbjJXIJD (ORCPT ); Tue, 24 Oct 2023 04:09:03 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D6071715; Tue, 24 Oct 2023 01:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698134931; x=1729670931; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=k32NnM8Fkd0yvRNKNvnewSnprEfXkGUcczhNS5Dhj/Y=; b=JpTsNdCeE3zU/NVpUNFRty6aoYoRXUY1vLUBzYsE32PajC+iz0nhZthl PK0DTPkCjeZSK+sqbK43WcNWyb6rAko/HV2LCzF9ZqpI3YZVuvKU7OUVa A/89p4LOrU6QHC2sJF7b+QpNdnmLfVjXLAinaXEN5AOgFrFes+z7R31jq bWKAq2DJpE35UprGl9cuzmHodr9SrZtPRQUO0HyR8wqbBH6pbSbjsElcn dfU271Z/4ysdm6erNdQtHQ+MZkCHOGQYFgHE+Ta8D06e+loJ/HOnUYjkf ZxnAArAkRtVPkP5r6BHkNx+3MM+iCvscI+W/9luUnIGfPjAA7PjP+utSh Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="366353003" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="366353003" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 01:08:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="874990513" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="874990513" Received: from zijianw1-mobl.amr.corp.intel.com (HELO desk) ([10.209.109.187]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 01:08:47 -0700 Date: Tue, 24 Oct 2023 01:08:46 -0700 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 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 v2 5/6] KVM: VMX: Use BT+JNC, i.e. EFLAGS.CF to select VMRESUME vs. VMLAUNCH Message-ID: <20231024-delay-verw-v2-5-f1881340c807@linux.intel.com> X-Mailer: b4 0.12.3 References: <20231024-delay-verw-v2-0-f1881340c807@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231024-delay-verw-v2-0-f1881340c807@linux.intel.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 01:09:20 -0700 (PDT) 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. 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