Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp155098ybh; Tue, 14 Jul 2020 21:20:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqTkSmWtvoswI2/LTJf5cpfOw9pq5QbOWWq5bcKyarXHJCErNv0CQOFu7dQwtaoeYUKspt X-Received: by 2002:a17:906:2bc7:: with SMTP id n7mr7695192ejg.96.1594786835693; Tue, 14 Jul 2020 21:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594786835; cv=none; d=google.com; s=arc-20160816; b=bMA+wopUfQbB8JbFRnT6U4SPdsKF4fhzGSq0Hl6y0aVVMJOGRU+LdRE7mDiOxz/yll eMwsxrRGY2Yek/K9dEHbD8N0iMQi8TrO5dcDbSHHZP9+sXMh3jJvIsAtgBg9lrWBy3D0 SoSQ3YQ3nRKX71N0rM/IQdx/BFFg6eopDK7BsYH8CotZUpPxmn99uXoP+GDTeRFc1X7y zN2fghYFTf6myj9x+S8kxeAqNzN5R9CtPk49+zh7vZWcDsm2yL7srP282MyPLXgNX/9w SsR61ijjMHALyPzv+gILo1d1ihfQoz+rBrYZ4rX4klBqIBsye3KpAeoJkiAxMUzbMtxe My2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=cxwcXeeFiOoJmIFvc1aJADE5w4Hd+SSKXCkliHXHoqw=; b=HPruN7rI42Q9CP1awJYWNgHdxN37l4vIKUsQrRgxV72WxcomGFqTpz4Jp5DcDATM7A fRziJed25/8uOVckbnU+RWRzL+s69OgDLtKN4TQILmlbXeABpxi0TxqRKEP67XCSALvI 10ogSfwzP6D29WJeq35qkJZUyTIPxAV7esVejHW8n7Djzhpe4XU0Izqz1xazaKg+y6dF f8cnYDyc/FslgvOiCcFMnHBwhEc5IfBXyhCQSEYn19p+VFfEqhIYXqjuhDLCJAEkrQa9 9tiNraDNC8m7R8nVvcN1jK3RIuvzAX/RofbBplEwKsp0nSuboHp5wcz2tOQkvz/aFKSt WRDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d23si510052edz.176.2020.07.14.21.20.13; Tue, 14 Jul 2020 21:20:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728301AbgGOEGW (ORCPT + 99 others); Wed, 15 Jul 2020 00:06:22 -0400 Received: from mga17.intel.com ([192.55.52.151]:16671 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbgGOEGD (ORCPT ); Wed, 15 Jul 2020 00:06:03 -0400 IronPort-SDR: aipBzOJaBJz0bNzeZDTaUcoYiBrOu0MFfNLR8ngP1sEChmv2H93zE3cyxvUjZwi/0Ss8w2Od4X mydyhdB/uf9g== X-IronPort-AV: E=McAfee;i="6000,8403,9682"; a="129167483" X-IronPort-AV: E=Sophos;i="5.75,353,1589266800"; d="scan'208";a="129167483" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 21:06:02 -0700 IronPort-SDR: 3/tSJsbV1kth+vL90NuOXt0MSE1ewk2QrNAiCMgDJC3UycF1FqgaDyB7SVNU0XISNwRPML4NPA e3DxAv+fqbiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,353,1589266800"; d="scan'208";a="485587020" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by fmsmga006.fm.intel.com with ESMTP; 14 Jul 2020 21:06:02 -0700 From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Cross , Peter Shier Subject: [PATCH 4/7] KVM: nVMX: Move free_nested() below vmx_switch_vmcs() Date: Tue, 14 Jul 2020 21:05:54 -0700 Message-Id: <20200715040557.5889-5-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200715040557.5889-1-sean.j.christopherson@intel.com> References: <20200715040557.5889-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move free_nested() down below vmx_switch_vmcs() so that a future patch can do an "emergency" invocation of vmx_switch_vmcs() if vmcs01 is not the loaded VMCS when freeing nested resources. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 88 +++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 7d4457aaab2ef..e9b27c6478da3 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -233,50 +233,6 @@ static inline void nested_release_evmcs(struct kvm_vcpu *vcpu) vmx->nested.hv_evmcs = NULL; } -/* - * Free whatever needs to be freed from vmx->nested when L1 goes down, or - * just stops using VMX. - */ -static void free_nested(struct kvm_vcpu *vcpu) -{ - struct vcpu_vmx *vmx = to_vmx(vcpu); - - if (!vmx->nested.vmxon && !vmx->nested.smm.vmxon) - return; - - kvm_clear_request(KVM_REQ_GET_VMCS12_PAGES, vcpu); - - vmx->nested.vmxon = false; - vmx->nested.smm.vmxon = false; - free_vpid(vmx->nested.vpid02); - vmx->nested.posted_intr_nv = -1; - vmx->nested.current_vmptr = -1ull; - if (enable_shadow_vmcs) { - vmx_disable_shadow_vmcs(vmx); - vmcs_clear(vmx->vmcs01.shadow_vmcs); - free_vmcs(vmx->vmcs01.shadow_vmcs); - vmx->vmcs01.shadow_vmcs = NULL; - } - kfree(vmx->nested.cached_vmcs12); - vmx->nested.cached_vmcs12 = NULL; - kfree(vmx->nested.cached_shadow_vmcs12); - vmx->nested.cached_shadow_vmcs12 = NULL; - /* Unpin physical memory we referred to in the vmcs02 */ - if (vmx->nested.apic_access_page) { - kvm_release_page_clean(vmx->nested.apic_access_page); - vmx->nested.apic_access_page = NULL; - } - kvm_vcpu_unmap(vcpu, &vmx->nested.virtual_apic_map, true); - kvm_vcpu_unmap(vcpu, &vmx->nested.pi_desc_map, true); - vmx->nested.pi_desc = NULL; - - kvm_mmu_free_roots(vcpu, &vcpu->arch.guest_mmu, KVM_MMU_ROOTS_ALL); - - nested_release_evmcs(vcpu); - - free_loaded_vmcs(&vmx->nested.vmcs02); -} - static void vmx_sync_vmcs_host_state(struct vcpu_vmx *vmx, struct loaded_vmcs *prev) { @@ -315,6 +271,50 @@ static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs) vmx_register_cache_reset(vcpu); } +/* + * Free whatever needs to be freed from vmx->nested when L1 goes down, or + * just stops using VMX. + */ +static void free_nested(struct kvm_vcpu *vcpu) +{ + struct vcpu_vmx *vmx = to_vmx(vcpu); + + if (!vmx->nested.vmxon && !vmx->nested.smm.vmxon) + return; + + kvm_clear_request(KVM_REQ_GET_VMCS12_PAGES, vcpu); + + vmx->nested.vmxon = false; + vmx->nested.smm.vmxon = false; + free_vpid(vmx->nested.vpid02); + vmx->nested.posted_intr_nv = -1; + vmx->nested.current_vmptr = -1ull; + if (enable_shadow_vmcs) { + vmx_disable_shadow_vmcs(vmx); + vmcs_clear(vmx->vmcs01.shadow_vmcs); + free_vmcs(vmx->vmcs01.shadow_vmcs); + vmx->vmcs01.shadow_vmcs = NULL; + } + kfree(vmx->nested.cached_vmcs12); + vmx->nested.cached_vmcs12 = NULL; + kfree(vmx->nested.cached_shadow_vmcs12); + vmx->nested.cached_shadow_vmcs12 = NULL; + /* Unpin physical memory we referred to in the vmcs02 */ + if (vmx->nested.apic_access_page) { + kvm_release_page_clean(vmx->nested.apic_access_page); + vmx->nested.apic_access_page = NULL; + } + kvm_vcpu_unmap(vcpu, &vmx->nested.virtual_apic_map, true); + kvm_vcpu_unmap(vcpu, &vmx->nested.pi_desc_map, true); + vmx->nested.pi_desc = NULL; + + kvm_mmu_free_roots(vcpu, &vcpu->arch.guest_mmu, KVM_MMU_ROOTS_ALL); + + nested_release_evmcs(vcpu); + + free_loaded_vmcs(&vmx->nested.vmcs02); +} + /* * Ensure that the current vmcs of the logical processor is the * vmcs01 of the vcpu before calling free_nested(). -- 2.26.0