Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp415109rwb; Tue, 4 Oct 2022 05:59:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM531pM2Ssvk9TRpKBNcCqtCMtQ9IZXuHs6hOX0EMBy4VNFtmzyl8KS73MBC4BnsJAm4ZHLk X-Received: by 2002:a62:1e83:0:b0:545:6896:188 with SMTP id e125-20020a621e83000000b0054568960188mr27435972pfe.51.1664888364376; Tue, 04 Oct 2022 05:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664888364; cv=none; d=google.com; s=arc-20160816; b=Teujg2TlVoaZWZtJpw00ihcSfkxsTfWGZujk+YRjDkJkBFrIFTJBqq1fiBq/c39qyx l/FH3W/5FgcV+3o9OsWp7qd+7EIyyOLJnOhs8wrlWjqgY5Xl1PKebZkaNA47tx3OfQGm tpbFhIKJUf2GregBKSfMjP9oZMdCayyiwA3rRWckf/TvJMYeSHXhSSQjKHeuZdTIsxuT SwfHRFJll7RzXqy7HN9GVmk5Uan/s5VnDb1QNJuGO8dCOLOakKb94UVQwHyGNdKTnKYX esjjkvELsWvD5JYrpbISFZSDCeRXRWTHUSQQGmuMiGfR8LCdblkmx5S4kYL73M3nF0ff pKVg== 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=jloN3SIxD7ene/zBvWHc8pRvuYBGWThxLxnFXgF+iiY=; b=c9h8gqerpBB6ya1ZY2I6x6KLiWuw1Sq3BXTpiDKsQgez9j0hUHzRSepsFsjc5sBNf2 WqcY5XeQc3U5Pc2hIyaNSUPfCjrqIZ2mh4efcqtFimN886SExM+wbaQnNP6WYbTdDcWC IaWzuae5y2GB+IhROpdu8wsdOoPAwg/I+TdTe2nQnTE4D1IBWmH1ZhedIeli2WebdL5i 9XKX6VzRz8LRRFfc1ocz0/2wayaRtXw9yQzf9AI9VIJc1YkXLa4wMBfmUXkqkTkwCzLU N9rLgeZQ0lDz6UPpG8xHq3BzC/hgPltDn2J06ojZGL6yCysXpcwngMi/AcAHo+is+fhv 9ZGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A9psh4qr; 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 q3-20020aa79823000000b0056194c5518fsi4193647pfl.322.2022.10.04.05.59.11; Tue, 04 Oct 2022 05:59:24 -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=A9psh4qr; 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 S229930AbiJDMnG (ORCPT + 99 others); Tue, 4 Oct 2022 08:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbiJDMmk (ORCPT ); Tue, 4 Oct 2022 08:42:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A9475E300 for ; Tue, 4 Oct 2022 05:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664887250; 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=jloN3SIxD7ene/zBvWHc8pRvuYBGWThxLxnFXgF+iiY=; b=A9psh4qrNh0DnqSUvkbMgO50X8xUab+CtXm8IN+OSaZzNR9K8DzkoeJIujOjbKccfcvXkF Q8tEvFoEVSEqsNwGFHegMIhymPOsZwBvoXp70xQH510o9JJT6t4vPBUm1Noc3AHSeybJSN CJIC1vl3k9xhCVt8AA0kGcTYK4ItF7Y= 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-326-Ji0CIm7RMpKOiYo0-C_pSQ-1; Tue, 04 Oct 2022 08:40:47 -0400 X-MC-Unique: Ji0CIm7RMpKOiYo0-C_pSQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC779101CC6F; Tue, 4 Oct 2022 12:40:46 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5BD07AE5; Tue, 4 Oct 2022 12:40: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 v11 19/46] KVM: nVMX: Keep track of hv_vm_id/hv_vp_id when eVMCS is in use Date: Tue, 4 Oct 2022 14:39:29 +0200 Message-Id: <20221004123956.188909-20-vkuznets@redhat.com> In-Reply-To: <20221004123956.188909-1-vkuznets@redhat.com> References: <20221004123956.188909-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 025c0d6cda69..b2413f58b919 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -649,6 +649,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 292591e93286..bc421de19816 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -224,6 +224,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)) { @@ -232,6 +233,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, @@ -1556,11 +1563,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.37.3