Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp56025lfe; Fri, 15 Apr 2022 19:15:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxM7QYENs5jMwwOUAOjxx6R4SJNDKJgBPyEDaOi7QTAUXJY+OQJmkKy+x0NO8FwkkH3whzi X-Received: by 2002:a17:902:e885:b0:158:e564:8992 with SMTP id w5-20020a170902e88500b00158e5648992mr1550073plg.34.1650075349041; Fri, 15 Apr 2022 19:15:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650075349; cv=none; d=google.com; s=arc-20160816; b=BWhfurlvdriussDoYprLmTTOMtn+8dodvvudh5Sk74FBWClr8EtQkHlsLvUkr+Ghq3 od2HoH2FcFR8WGNZUYlKOK6CjnvUd12/it94nG3o21AC6Cz/LYUaaWfHk5Z9ifMn04D9 7iwC2WE/lCV7mlgL0tctGLUovcX/Nx71kGSDsUkzz4yBQ5j052pP+25Ev+Obl7Kf9xm6 jic8LJSbWDLj1j/CNiNV07dno9dfz7erPlDIkD757FnlKzuN4ISV8puUECv0sjCPcFG9 SjZe1H1z6+jiZsz1IAVQw/tutVNHziUtGgrG+qBCeZILsGhZRk0n4iNhaiI8z4qSEF2D rg7w== 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=50CzWrTQDY55h6HJNGeIUa1zcvA+e6RQRniRY8pLQbs=; b=FDc7TtiJvHyO3cMY488E+65u+d45aca4xYsR5x5J0dFsxaCQmCdS8gJTkKLsB2w70b 4NsKNwzmhUA0t3PcbP9Usp6FjGVFg/79pzmY+zj54NXbWnE/jNF3n+vcbFXq40f6gmfs vEZUoWC9KkE7Bh4uPRiEMiPXUVMpLAZoDjboUb2t98WeNxLW2i8KFalIGk9IZfo495CS kxlivdd7Zi+CbbaP7bZQYmXcqgRp7vE/RtH2fV1oNHxpRMfE7wFY+Pm7sWG76eiPMcqj g3RrPV7UQEFYmMUurIWTcqxBhPDTGxKhgO1+uP4Kqsm30mbCIO1TZdhMek9RbGWOYlX4 VOvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U5798atS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q5-20020a170902dac500b00153b2d16652si3069193plx.602.2022.04.15.19.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:15:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U5798atS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E7C82173AD; Fri, 15 Apr 2022 18:31:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343499AbiDNNjD (ORCPT + 99 others); Thu, 14 Apr 2022 09:39:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244775AbiDNN2G (ORCPT ); Thu, 14 Apr 2022 09:28:06 -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 ESMTP id 44141A56CE for ; Thu, 14 Apr 2022 06:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649942453; 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=50CzWrTQDY55h6HJNGeIUa1zcvA+e6RQRniRY8pLQbs=; b=U5798atSFHgCdsVzug/u5Tggdal1ReMWuY5+fnoeAJOIG5nOMoYTeGF8C4gasAszugNqPY Ek92wsDIPJ/UcUS811zOX5+LQOvc2DNNX894v3tie3kutDo0Qouh3VBiicVl33qJ0nQeh/ uNmk3ENdcWw8oFkk4hGx5BDj/kFx8YU= 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-210-9s2vFTo1NsqNRg4f7F2PjQ-1; Thu, 14 Apr 2022 09:20:52 -0400 X-MC-Unique: 9s2vFTo1NsqNRg4f7F2PjQ-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 4DB0F901865; Thu, 14 Apr 2022 13:20:41 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id B451A9D42; Thu, 14 Apr 2022 13:20:39 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 12/34] KVM: nVMX: Keep track of hv_vm_id/hv_vp_id when eVMCS is in use Date: Thu, 14 Apr 2022 15:19:51 +0200 Message-Id: <20220414132013.1588929-13-vkuznets@redhat.com> In-Reply-To: <20220414132013.1588929-1-vkuznets@redhat.com> References: <20220414132013.1588929-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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. 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 837c07e213de..8b2a52bf26c0 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -622,6 +622,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 a6688663da4d..ee88921c6156 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, @@ -1591,11 +1598,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.1