Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp367299imn; Wed, 3 Aug 2022 07:17:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR73WImFRKTrgaAP4It2qFMnJ633Hut3dFetaoYRDRIqCqyVTvtRtlWipA4LuQaH2sfftWft X-Received: by 2002:a17:90b:198d:b0:1f3:f72:cfdc with SMTP id mv13-20020a17090b198d00b001f30f72cfdcmr5146596pjb.237.1659536231466; Wed, 03 Aug 2022 07:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659536231; cv=none; d=google.com; s=arc-20160816; b=EYAU77cM5yH/SkGYVFeIo3tGRjWh/CXGY0b4V/5tMWm2b8EYjZzSKly5py4rMBagex jfXXaPw+EqKUgSk3pouA6Imd+XgXiLcNbnPiR5L0m1D2WlRp1CZF6Mcl7uZ80ogP3sWe O+1WN0wbzmtTrMnq76jtz7UXve1QlpDNTbrFF6FKso8RvHIop+DsVrKtH4FyTx4m/rUi Pu/KjOqlb43RciVY7M3ZaOEX0ACpwkL71IUz++N9sMQFuVEzeBfHRlGb1c6JUwVQlDXS 0LfyVffpwh9L9u2fAlDpdp0YT6/ldL2kGGWYGpfWvYZKcsI9qbiY0cLKqK6Rbwu1j+ea 6HFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=svnIbDkM1+S/+C8PkLXMCmtjY/qIXG0bzAs5BPRrGtY=; b=f3CXEkoU6x8yrEn+NLLl9Jo5QqggiGO19BKW9cy9eKBu0usTWX5kpuHuJr+CjvtOiP CNT2ZQ3a9/YSQZKC9GNNiQEL5NZ3+S1NX0gZ8R4Hf8MH+Y/HAnPO2mjTyck3Rj67BS+w Z0VjCehxqgWHkVCINGVYQLR/Qvo2DBNskJDQtmfZ8vEDZ3utlQ4uuUH0WXQHF82zhhLq zXv2GOHzQQmfJUn8zCkOil+J67qPeqwM1SDoVq5kg6rRQWe6CWHK3BsFHV0TwtCpDqsV RbtWpSTLEMA5KjTxi8wY3O9ffxkQs4m/PEJ3WRcd24I+SHxEuUpSD5qvAVHHUiSOi9Tt yp1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h81vO+v2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gv4-20020a17090b11c400b001f20ab3ecadsi1886324pjb.18.2022.08.03.07.16.55; Wed, 03 Aug 2022 07:17:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h81vO+v2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238201AbiHCNqA (ORCPT + 99 others); Wed, 3 Aug 2022 09:46:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238163AbiHCNp6 (ORCPT ); Wed, 3 Aug 2022 09:45:58 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3BC131C113 for ; Wed, 3 Aug 2022 06:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659534352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=svnIbDkM1+S/+C8PkLXMCmtjY/qIXG0bzAs5BPRrGtY=; b=h81vO+v25JZIBLdvp0+1C59qLMtEZn4KuliCEXWg1ixBaujncffCRrT43lAht9cnZl8Xew 3f3TeLshl0HZWQ0/Yxsahgdl+sotKxqe2NoS+1rVcVMneUE9+N0/C23F+/VVrftOIfL7Wr SAo++lCzcO+ih9vgb1VFxOGXrLtzS4I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-261-krkaT0bmMlOAJ3HqFTeCeA-1; Wed, 03 Aug 2022 09:45:48 -0400 X-MC-Unique: krkaT0bmMlOAJ3HqFTeCeA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6C8041824600; Wed, 3 Aug 2022 13:45:47 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEB494010FA2; Wed, 3 Aug 2022 13:45:44 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , Yuan Yao , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 13/40] KVM: nVMX: Keep track of hv_vm_id/hv_vp_id when eVMCS is in use Date: Wed, 3 Aug 2022 15:45:44 +0200 Message-Id: <20220803134544.399230-1-vkuznets@redhat.com> In-Reply-To: <20220803134110.397885-1-vkuznets@redhat.com> References: <20220803134110.397885-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To handle L2 TLB flush requests, 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. Reviewed-by: Maxim Levitsky Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/kvm_host.h | 6 ++++++ arch/x86/kvm/vmx/nested.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index ca8183647b6d..f5f9a4b26a55 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -647,6 +647,12 @@ struct kvm_vcpu_hv { /* Preallocated buffer for handling hypercalls passing sparse vCPU set */ u64 sparse_banks[HV_MAX_SPARSE_VCPU_BANKS]; + + 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 ddd4367d4826..925c08f4d77a 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,12 @@ static inline void nested_release_evmcs(struct kvm_vcpu *vcpu) } vmx->nested.hv_evmcs_vmptr = EVMPTR_INVALID; + + if (hv_vcpu) { + 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, @@ -1596,11 +1603,19 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields { struct vmcs12 *vmcs12 = vmx->nested.cached_vmcs12; struct hv_enlightened_vmcs *evmcs = vmx->nested.hv_evmcs; + struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(&vmx->vcpu); /* HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE */ vmcs12->tpr_threshold = evmcs->tpr_threshold; vmcs12->guest_rip = evmcs->guest_rip; + if (unlikely(!(hv_clean_fields & + HV_VMX_ENLIGHTENED_CLEAN_FIELD_ENLIGHTENMENTSCONTROL))) { + 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; + } + if (unlikely(!(hv_clean_fields & HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC))) { vmcs12->guest_rsp = evmcs->guest_rsp; -- 2.35.3