nestedsvm: fix memory leak on shutdown/crash
authorChristoph Egger <Christoph.Egger@amd.com>
Tue, 23 Oct 2012 07:13:27 +0000 (09:13 +0200)
committerChristoph Egger <Christoph.Egger@amd.com>
Tue, 23 Oct 2012 07:13:27 +0000 (09:13 +0200)
Fix memory leak of l1 vmcb page when destroying a vcpu while l2 guest
is running.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Acked-by: Tim Deegan <tim@xen.org>
Committed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/svm/nestedsvm.c

index 9f69bcc70f9f89132730ab5c205c48f12d9a907b..e48db005e6b3cda32b0b764bd61eb712a4401e55 100644 (file)
@@ -122,6 +122,15 @@ void nsvm_vcpu_destroy(struct vcpu *v)
     struct nestedvcpu *nv = &vcpu_nestedhvm(v);
     struct nestedsvm *svm = &vcpu_nestedsvm(v);
 
+    /*
+     * When destroying the vcpu, it may be running on behalf of l2 guest.
+     * Therefore we need to switch the VMCB pointer back to the l1 vmcb,
+     * in order to avoid double free of l2 vmcb and the possible memory leak
+     * of l1 vmcb page.
+     */
+    if (nv->nv_n1vmcx)
+        v->arch.hvm_svm.vmcb = nv->nv_n1vmcx;
+
     if (svm->ns_cached_msrpm) {
         free_xenheap_pages(svm->ns_cached_msrpm,
                            get_order_from_bytes(MSRPM_SIZE));