From patchwork Tue Nov 1 14:53:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 13708 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3020954wru; Tue, 1 Nov 2022 07:58:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6X0EqJwMVd6XuMd9iQ1HAo5Z6cTIIYhpBPHfHDH5c3Dhf9x96ZhZuTAHEnHWkrTUmr12V1 X-Received: by 2002:a17:906:5d10:b0:7ad:e132:bb85 with SMTP id g16-20020a1709065d1000b007ade132bb85mr7783364ejt.367.1667314718644; Tue, 01 Nov 2022 07:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667314718; cv=none; d=google.com; s=arc-20160816; b=K4+xcznOtbAgek5oQfgt3NyBVk76XcV064yHEWWUdnNXysDomPA6mfiPYwsemJvVTY vwJM9my1b01fVv3WeDm6J/gfNVY9OHxkYgZRWfgAdRVaCVXvdA2AukZ7MMHSLlxej4bo h4Jm1ux9qxWhLmy4TqGsDt2ZakpDkIQE83SoFWXFmQgoPllEqQaPY9T26L3rP4y0nR4w R9AOD7gfH2JzjhRHGnCF0NO07AywNf1Co+BQWnuVzB+K4OayCvSTXJ1QqxRRSrYA+fqW aWW7MA3ovibIj3qD4mc5H/6dM/m40jS4E9Hsy6UAlBhy2Ajhj/tmd34tcfcn8LB+y61K 3iig== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs36-20020a1709072d2400b0077d26491a9csi14406706ejc.141.2022.11.01.07.58.14; Tue, 01 Nov 2022 07:58:38 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748306198221941072?= X-GMAIL-MSGID: =?utf-8?q?1748306198221941072?= 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;