x86/domain: factor out pv_domain_destroy
authorWei Liu <wei.liu2@citrix.com>
Fri, 7 Apr 2017 14:49:42 +0000 (15:49 +0100)
committerWei Liu <wei.liu2@citrix.com>
Wed, 7 Jun 2017 11:15:56 +0000 (12:15 +0100)
Now this function also frees the perdomain mapping. It is safe to do so
because destroy_perdomain_mapping is idempotent.

Move free_perdomain_mappings after pv_domain_destroy. It is safe to do
so because both destroy_perdomain_mapping and free_perdomain_mappings
are idempotent.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/domain.c

index 0f9222487f0a94c43978c6fc149c7953ec64a41a..0046661b6f220d2a9fad47b65754a3b90001b817 100644 (file)
@@ -538,6 +538,18 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
     return true;
 }
 
+static void pv_domain_destroy(struct domain *d)
+{
+    destroy_perdomain_mapping(d, GDT_LDT_VIRT_START,
+                              GDT_LDT_MBYTES << (20 - PAGE_SHIFT));
+
+    xfree(d->arch.pv_domain.cpuidmasks);
+    d->arch.pv_domain.cpuidmasks = NULL;
+
+    free_xenheap_page(d->arch.pv_domain.gdt_ldt_l1tab);
+    d->arch.pv_domain.gdt_ldt_l1tab = NULL;
+}
+
 int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
@@ -717,12 +729,10 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     xfree(d->arch.cpuid);
     if ( paging_initialised )
         paging_final_teardown(d);
-    free_perdomain_mappings(d);
     if ( is_pv_domain(d) )
-    {
-        xfree(d->arch.pv_domain.cpuidmasks);
-        free_xenheap_page(d->arch.pv_domain.gdt_ldt_l1tab);
-    }
+        pv_domain_destroy(d);
+    free_perdomain_mappings(d);
+
     return rc;
 }
 
@@ -740,12 +750,9 @@ void arch_domain_destroy(struct domain *d)
 
     paging_final_teardown(d);
 
-    free_perdomain_mappings(d);
     if ( is_pv_domain(d) )
-    {
-        free_xenheap_page(d->arch.pv_domain.gdt_ldt_l1tab);
-        xfree(d->arch.pv_domain.cpuidmasks);
-    }
+        pv_domain_destroy(d);
+    free_perdomain_mappings(d);
 
     free_xenheap_page(d->shared_info);
     cleanup_domain_irq_mapping(d);