From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59CD3C433F5 for ; Mon, 7 Mar 2022 14:51:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243558AbiCGOwJ (ORCPT ); Mon, 7 Mar 2022 09:52:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243478AbiCGOv4 (ORCPT ); Mon, 7 Mar 2022 09:51:56 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 434C385BEA for ; Mon, 7 Mar 2022 06:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646664655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LoSIusgLjJaqwxYyszOop3hSo5cVEixY4wGXy+fz2xw=; b=M4dade8faI3L37dmpqFe3b1ciCzvPqPpKG1JMMgokZIndMWPQAxOYezKsT2pMQUpko2B59 B0GxKQPAqEh39bc/jzOz3/L7ehR6kKzJ5sz0ExSJIsYqXAQGxDN+iB13qdTmU1h0VJTW4E rOilDFBc6IknxmbCrOa9QRHCwQknqnU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-14-AUvqjo2-PKy3bZDCRvkVwg-1; Mon, 07 Mar 2022 09:50:52 -0500 X-MC-Unique: AUvqjo2-PKy3bZDCRvkVwg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 084E91854E26; Mon, 7 Mar 2022 14:50:51 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.193.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id DACFF7F0D6; Mon, 7 Mar 2022 14:50:48 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson , linux-hyperv@vger.kernel.org, Siddharth Chandrasekaran , linux-kernel@vger.kernel.org Subject: [PATCH RFC 09/19] KVM: nVMX: Keep track of hv_vm_id/hv_vp_id when eVMCS is in use Date: Mon, 7 Mar 2022 15:50:13 +0100 Message-Id: <20220307145023.1913205-10-vkuznets@redhat.com> In-Reply-To: <20220307145023.1913205-1-vkuznets@redhat.com> References: <20220307145023.1913205-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To handle Direct TLB flush requests from L2, KVM needs to keep track of L2's VM_ID/VP_IDs which are set by L1 hypervisor. 'Partition assist page' address is also needed to handle post-flush exit to L1 (upon request). Assume vm_id/vp_id/partition_assist_page don't change while eVMCS is active. Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/kvm_host.h | 6 ++++++ arch/x86/kvm/vmx/nested.c | 24 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 1fce8232a2e9..21b502aa9655 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -618,6 +618,12 @@ struct kvm_vcpu_hv { /* Preallocated buffer for handling hypercalls passing sparse vCPU set */ u64 sparse_banks[64]; + + struct { + u64 pa_page_gpa; + u64 vm_id; + u32 vp_id; + } nested; }; /* Xen HVM per vcpu emulation context */ diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index f18744f7ff82..dd3054c3291c 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -225,6 +225,7 @@ static void vmx_disable_shadow_vmcs(struct vcpu_vmx *vmx) static inline void nested_release_evmcs(struct kvm_vcpu *vcpu) { + struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu); if (evmptr_is_valid(vmx->nested.hv_evmcs_vmptr)) { @@ -233,6 +234,9 @@ static inline void nested_release_evmcs(struct kvm_vcpu *vcpu) } vmx->nested.hv_evmcs_vmptr = EVMPTR_INVALID; + hv_vcpu->nested.pa_page_gpa = INVALID_GPA; + hv_vcpu->nested.vm_id = 0; + hv_vcpu->nested.vp_id = 0; } static void vmx_sync_vmcs_host_state(struct vcpu_vmx *vmx, @@ -2042,15 +2046,27 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld( } - /* - * Clean fields data can't be used on VMLAUNCH and when we switch - * between different L2 guests as KVM keeps a single VMCS12 per L1. - */ if (from_launch || evmcs_gpa_changed) { + struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(&vmx->vcpu); + struct hv_enlightened_vmcs *evmcs = vmx->nested.hv_evmcs; + + /* + * Clean fields data can't be used on VMLAUNCH and when we + * switch between different L2 guests as KVM keeps a single + * VMCS12 per L1. + */ vmx->nested.hv_evmcs->hv_clean_fields &= ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL; vmx->nested.force_msr_bitmap_recalc = true; + + /* + * Assume vm_id/vp_id/partition_assist_page don't change while + * eVMCS is active. + */ + hv_vcpu->nested.pa_page_gpa = evmcs->partition_assist_page; + hv_vcpu->nested.vm_id = evmcs->hv_vm_id; + hv_vcpu->nested.vp_id = evmcs->hv_vp_id; } return EVMPTRLD_SUCCEEDED; -- 2.35.1