Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp225732iof; Mon, 6 Jun 2022 02:03:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwWPlBSNUSIEKFPcHuWJDVuhQO5OIYcEU9c7ngfl01gKc5idpXVTIxrwl8kVFOiida6CZx X-Received: by 2002:a17:90a:ba15:b0:1c6:7873:b192 with SMTP id s21-20020a17090aba1500b001c67873b192mr25635041pjr.76.1654506229461; Mon, 06 Jun 2022 02:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654506229; cv=none; d=google.com; s=arc-20160816; b=H4Rh5+X6AdgTcsYPzEmRJfxD1VLiv3QvuhgLZuCahyWzggeAHNpLRRI8ZK2I9H83Ch YbdZbP5iDpu6rT7yvavS8+hqeIsko3lv4mJWScZg9kFIas43jTxCdqQyHy6hPr1oSbxh dOoQfscEG8tsWkjrnLIpcCEvgfMbuvXrjWUVgHwFLIXKbgcouR8wY/QgtDpsEO28je/l Yq8nTQ5fq1u6946ZA+QVISKPlaQRu6zThVhufCvSb/bAtQqss606ge7UMZfkXvd5IqFU cPwWBh3e5iyIsmMXp6QZYt3bL+vXYHl3q/X0USJ/dQpkCc/iHpe/8Ut3FllSF0UyPb3p aiSA== 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=GzHMZYw4NrpXOdRz/8AlgefLEtN/8vGqZNFAB8lkOgM=; b=wpvF5dcN7cMaWWfmBWzzmVdaOv8ZIp7/IvWwIO/Vdu4fl16sLA2A+Z7V6qMus06KeS Vbtdyc9/ex9I8Nc6yn8igmnRj/PbZVR1JvaHBH/li+tE4RVj/Nhu6En6s3wFvve9K1eR YZWqjOxjBdRCuqEhTRHeHroCQjW+VdwEd65WG8B1a8b/0FpWgt6kIk17WxRC0w758O9N yvC6cARX2XRJmvEnJor7PG/BwWMrGSqUc+sYBM/XWCPn9kUCwxhfIeftJiMjtCiua6ov awYwLr416GB99Ekf1GVo8ciSxzaqEYVAZJ85OuYa6XY/W62vZK0VGpJcv0Q3CbfyDA67 NIFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="DonJXMS/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id j185-20020a638bc2000000b003fcb1bb48f2si19064726pge.638.2022.06.06.02.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 02:03:49 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="DonJXMS/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 2172FDB37D; Mon, 6 Jun 2022 01:41:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232307AbiFFIjV (ORCPT + 99 others); Mon, 6 Jun 2022 04:39:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231977AbiFFIht (ORCPT ); Mon, 6 Jun 2022 04:37:49 -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 ED3D3DF1D for ; Mon, 6 Jun 2022 01:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654504654; 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=GzHMZYw4NrpXOdRz/8AlgefLEtN/8vGqZNFAB8lkOgM=; b=DonJXMS/WxM4I40efbDYsYAnkHTsJkKPW1jGMJZkX5eBEZcKZxHaPqZLaQSF2EyGH/NtF2 hxjuDZdr5cGAmPVOHaDjhWJfUuL39HW/WfXsMfbhyu4HNx2SUnVs+Xpg8tCQaRFuOCHE7o BacXzXIIzwYUUd+9ijZuowYlvaygvN8= 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-558-IezcZ8GnOSqCQv7GopHRuw-1; Mon, 06 Jun 2022 04:37:30 -0400 X-MC-Unique: IezcZ8GnOSqCQv7GopHRuw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D9B3185A79C; Mon, 6 Jun 2022 08:37:30 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.193.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 102721121314; Mon, 6 Jun 2022 08:37:27 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , Yuan Yao , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 13/38] KVM: nVMX: Keep track of hv_vm_id/hv_vp_id when eVMCS is in use Date: Mon, 6 Jun 2022 10:36:30 +0200 Message-Id: <20220606083655.2014609-14-vkuznets@redhat.com> In-Reply-To: <20220606083655.2014609-1-vkuznets@redhat.com> References: <20220606083655.2014609-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-3.1 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=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 278d8d3ee994..02bef551dafb 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -648,6 +648,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 7d8cd0ebcc75..6e264a7f205b 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.3