Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1508562rdd; Thu, 11 Jan 2024 01:00:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDUebDsaxXvrSFD1LLcEO3Cr0wyLK8P66KCHMxj/EF6QdyX2cj7qptreMnpU/9hwaX6mCC X-Received: by 2002:a05:620a:8512:b0:783:4197:f1c8 with SMTP id pe18-20020a05620a851200b007834197f1c8mr487692qkn.109.1704963620462; Thu, 11 Jan 2024 01:00:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704963620; cv=none; d=google.com; s=arc-20160816; b=pOsNZSe9yaXxzcfF07X31iBwpbftoDmVcEVESulR5Cph5KE2NTJpUnVdtg/fKTSIca F84DcnNxOVhhXqp5O3UK8AfaATh8Xe7m7ws5CNGndaqTuseETRmnLrm+OccdtLdYh+7Q wDT3kdVbPeYK9MlK58desVM3FiBGDeu+uL3RETPLS4r2Gqqa43lUH186FQlBckZZNmQ/ VI4r+lF2cu32J6rPRdqTlNi1K8xa/+M36U13qafFLmtdYewKpOUNAWLFOVzfX+yV6rK/ GkxKJCL8rtQ4iHs3ZAOOupsJU3/Z58NUAFmTZ0B3lVKFM9bfvEY/xfINfgFcTaG+y3ae zytQ== ARC-Message-Signature: i=1; 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=WcDHxcDMOPcQL1K/b5cYmAHbDL2Ctb0VBVbFhqRN/kHGrrZ5/2qR6W2TXGMql0elw7 9iWToZojQEcPVEQRbcZks/2XLVsO+iwFPTc9owwbEWmC9ToeSAkGxM8c7RpJPTENwNBm a8ESLSfy0/vaEn2Cib7xWfpRnAtS8nU/ebuz2t7ZwqXq+NC0O2Ee8zIxoENaTYBRrK22 Ev7nfzJIq6VISKEyVztGN03nU7bSMzShV7Z5piP2RNnTKYIan6Zc6KRZwtKDSxyGJoSW Ju6AeiXwXRSTxSnCzsRFDirxXbgWhFRK8URcIdZKetDgQXUli+XVJMvDGiO1E8Wt4vnq h+0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kr8xUQ7C; spf=pass (google.com: domain of linux-kernel+bounces-23266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23266-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bs10-20020a05620a470a00b0078330117dadsi508953qkb.297.2024.01.11.01.00.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 01:00:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kr8xUQ7C; spf=pass (google.com: domain of linux-kernel+bounces-23266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23266-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D23081C22D91 for ; Thu, 11 Jan 2024 09:00:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2634168C7; Thu, 11 Jan 2024 08:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kr8xUQ7C" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 C709E168B4; Thu, 11 Jan 2024 08:56:50 +0000 (UTC) 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=1704963411; x=1736499411; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=rpFgire7Svqru/HfpQ1b16RkVx0842HOL7xbgXY2vaQ=; b=kr8xUQ7C6jzdJ1hOc7IPykyiApURBUHV2KNrxu0w/RE9rPE/lcC13EM1 /jEzRe/R+JpDOcvDyPeIJ/WRQSzAu/2+1+Hxcm5iDmpdHWPa/8Q0vqDJh mPZlW83XhSWpzRk8rD80wj9XFJ7kJwaIqOOR2tLMFEiqsA6uuOxcc+bwN KSPPFJMn6tnlBK9O6b1vvhf+hHDJNe2mHHDbKPacLSizygosoFurIKo8D Up3OTcX8fg3Zk5bWpPWg82s5FxrlKpyhiN4fiWLLVbrW53kjDQV4qwAKy alatnx4c+viQbi7LR3VfCj1+9NYmFWtgeko68e87B6JtaNNe42ggmkKg+ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="6144963" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="6144963" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2024 00:56:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="905877772" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="905877772" Received: from ericwong-mobl2.amr.corp.intel.com (HELO desk) ([10.209.43.169]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2024 00:56:49 -0800 Date: Thu, 11 Jan 2024 00:56:49 -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 v5 5/6] KVM: VMX: Use BT+JNC, i.e. EFLAGS.CF to select VMRESUME vs. VMLAUNCH Message-ID: <20240111-delay-verw-v5-5-a3b234933ea6@linux.intel.com> X-Mailer: b4 0.12.3 References: <20240111-delay-verw-v5-0-a3b234933ea6@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: <20240111-delay-verw-v5-0-a3b234933ea6@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