Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2570964rwi; Tue, 1 Nov 2022 09:09:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM40/sWlzWutvS2CmpNgCs4jHtf4m30Kx+QvCZ1OT/3TGEx8p51ebu63WMhKeeTccF5Nj8/T X-Received: by 2002:a17:907:847:b0:77f:f489:cc25 with SMTP id ww7-20020a170907084700b0077ff489cc25mr18584950ejb.80.1667318973706; Tue, 01 Nov 2022 09:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667318973; cv=none; d=google.com; s=arc-20160816; b=UjXWH+iotYnmQQC5Qjlm9S2joInmZD6pcSSp4gLZ1I1kFZdjr8Bqil5Gks1jBz7wKX WalztCbzbI30/9eyxS6VPoVllTvc7gZ2r+60suLO6Xyglg3hTq0Q7CooSIH5BwyBpmQR 3GjWREmaSGAFvuy3iMoOwFFosw8vC26plcRqrlWNjbwLHxw4qJsTB+wWL9HE+Hc/WxvW r8i+YfV2SWcYsRB6Tld5btUDMPYB0ykQz+YoDKQlszycKQqT4ZIDr5cF9YmH5LI+meX0 PRhS7Kzrfd2A2XqsEHTflYWNVGG4EnOAwcZIpPB0wzKL4xlDWLDM38ln+hDs930bJsJD qBJA== 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=VPRegZuW8RFQJgWdrL1ZPVnD1aDzWB4g8LWboQSy57E=; b=rZeBzhkMujyb2j1GyytLQ+sCmBkt7Gw+WGQqhC2WYHaIjYzMzkE0L67Dd35BGgfakL Q4rqnZ7MkO/xALnZ5CmdZQUbJZvlmwk68ZLDuaTsX/ubZKFB2O1BXlSTwluDFGF94jmP FMWj49Eyu3mJtMndMKyGdW2ZqiCgl97To0ZV3A+Nfpaq0MK36C4VdNIAV/9F2s5p+PwA lgvcutBBEeGS+zTj8Gm/W6exR0cBMMtYnq9iwUH5BpWZ03KDRQAlzYP2TIOePKvgG5hQ 9xAowDEJb03oWUjH3HQ1oLa7xNQ4+CCY0t79LZ0JP8eqnSX7WM9/1Y2OYer3ArS8b3k9 2J7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NMdfcj+x; 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 ji4-20020a170907980400b007ad2d85d753si13524504ejc.495.2022.11.01.09.09.10; Tue, 01 Nov 2022 09:09:33 -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=NMdfcj+x; 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 S231250AbiKAO53 (ORCPT + 96 others); Tue, 1 Nov 2022 10:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231174AbiKAO4m (ORCPT ); Tue, 1 Nov 2022 10:56:42 -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 2A3771CB29 for ; Tue, 1 Nov 2022 07:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667314541; 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=VPRegZuW8RFQJgWdrL1ZPVnD1aDzWB4g8LWboQSy57E=; b=NMdfcj+xF8r2mqQcwrvqx0XOjPC0CY/ImI1Hv+Oia1VlWWzFRXZ/lS/X3qOk0GvnDrJ8PW cDitUhPLxKdKmFLASpJ7Cbdw3gOZYgZzUrq6mEWSuEIQnYtOgFXT8dDyvoP7uz4OtCfrPV VSXsfHbk+CdEecJw4X/bPGhi+WzeGEU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-602-ErHdDIX5PKS-GmqP6Vf77g-1; Tue, 01 Nov 2022 10:55:38 -0400 X-MC-Unique: ErHdDIX5PKS-GmqP6Vf77g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43BFC1C05EC7; Tue, 1 Nov 2022 14:55:28 +0000 (UTC) Received: from ovpn-194-149.brq.redhat.com (ovpn-194-149.brq.redhat.com [10.40.194.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF236C2C8D8; Tue, 1 Nov 2022 14:55:19 +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 v13 19/48] KVM: nVMX: Keep track of hv_vm_id/hv_vp_id when eVMCS is in use Date: Tue, 1 Nov 2022 15:53:57 +0100 Message-Id: <20221101145426.251680-20-vkuznets@redhat.com> In-Reply-To: <20221101145426.251680-1-vkuznets@redhat.com> References: <20221101145426.251680-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.8 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 Reviewed-by: Sean Christopherson 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 5d590157266e..ede163b6f955 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 feab88a13026..7a4260416d88 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