]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: nVMX: Add helper to put (unmap) vmcs12 pages
authorSean Christopherson <seanjc@google.com>
Thu, 10 Oct 2024 18:23:27 +0000 (11:23 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 25 Oct 2024 16:57:59 +0000 (12:57 -0400)
Add a helper to dedup unmapping the vmcs12 pages.  This will reduce the
amount of churn when a future patch refactors the kvm_vcpu_unmap() API.

No functional change intended.

Tested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20241010182427.1434605-26-seanjc@google.com>

arch/x86/kvm/vmx/nested.c

index fb37658b62c9156727bb93aaa3a54ef1c9c5c50b..81865db18e129b5528a9180eac28589c6def75a2 100644 (file)
@@ -314,6 +314,21 @@ static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
        vcpu->arch.regs_dirty = 0;
 }
 
+static void nested_put_vmcs12_pages(struct kvm_vcpu *vcpu)
+{
+       struct vcpu_vmx *vmx = to_vmx(vcpu);
+
+       /*
+        * Unpin physical memory we referred to in the vmcs02.  The APIC access
+        * page's backing page (yeah, confusing) shouldn't actually be accessed,
+        * and if it is written, the contents are irrelevant.
+        */
+       kvm_vcpu_unmap(vcpu, &vmx->nested.apic_access_page_map, false);
+       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;
+}
+
 /*
  * Free whatever needs to be freed from vmx->nested when L1 goes down, or
  * just stops using VMX.
@@ -346,15 +361,8 @@ static void free_nested(struct kvm_vcpu *vcpu)
        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.  The APIC access
-        * page's backing page (yeah, confusing) shouldn't actually be accessed,
-        * and if it is written, the contents are irrelevant.
-        */
-       kvm_vcpu_unmap(vcpu, &vmx->nested.apic_access_page_map, false);
-       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;
+
+       nested_put_vmcs12_pages(vcpu);
 
        kvm_mmu_free_roots(vcpu->kvm, &vcpu->arch.guest_mmu, KVM_MMU_ROOTS_ALL);
 
@@ -5010,11 +5018,7 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
                vmx_update_cpu_dirty_logging(vcpu);
        }
 
-       /* Unpin physical memory we referred to in vmcs02 */
-       kvm_vcpu_unmap(vcpu, &vmx->nested.apic_access_page_map, false);
-       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;
+       nested_put_vmcs12_pages(vcpu);
 
        if (vmx->nested.reload_vmcs01_apic_access_page) {
                vmx->nested.reload_vmcs01_apic_access_page = false;