[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] arm: unwind allocations etc on arch_domain_create_failure


  • To: xen-changelog@xxxxxxxxxxxxxxxxxxx
  • From: Xen patchbot-unstable <patchbot@xxxxxxx>
  • Date: Wed, 04 Jul 2012 04:11:41 +0000
  • Delivery-date: Wed, 04 Jul 2012 04:11:55 +0000
  • List-id: "Change log for Mercurial \(receive only\)" <xen-changelog.lists.xen.org>

# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1341309150 -3600
# Node ID 5d432081deddfe40f501ce4a1420fa126252c56e
# Parent  9faae502bb9e8a2e2eddc8368f79b1a5fc01e110
arm: unwind allocations etc on arch_domain_create_failure

This involves adding the necessary teardown/free functions for some modules.

Don't initialise full arch domain state for the idle domain, it's not needed.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Tim Deegan <tim@xxxxxxx>
Committed-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---


diff -r 9faae502bb9e -r 5d432081dedd xen/arch/arm/domain.c
--- a/xen/arch/arm/domain.c     Tue Jul 03 10:52:29 2012 +0100
+++ b/xen/arch/arm/domain.c     Tue Jul 03 10:52:30 2012 +0100
@@ -317,37 +317,45 @@ int arch_domain_create(struct domain *d,
 {
     int rc;
 
+    /* Idle domains do not need this setup */
+    if ( is_idle_domain(d) )
+        return 0;
+
     rc = -ENOMEM;
     if ( (rc = p2m_init(d)) != 0 )
         goto fail;
 
-    if ( !is_idle_domain(d) )
-    {
-        rc = -ENOMEM;
-        if ( (d->shared_info = alloc_xenheap_pages(0, 0)) == NULL )
-            goto fail;
+    if ( (d->shared_info = alloc_xenheap_pages(0, 0)) == NULL )
+        goto fail;
 
-        clear_page(d->shared_info);
-        share_xen_page_with_guest(
-                virt_to_page(d->shared_info), d, XENSHARE_writable);
+    clear_page(d->shared_info);
+    share_xen_page_with_guest(
+        virt_to_page(d->shared_info), d, XENSHARE_writable);
 
-        if ( (rc = p2m_alloc_table(d)) != 0 )
-            goto fail;
+    if ( (rc = p2m_alloc_table(d)) != 0 )
+        goto fail;
 
-        if ( (rc = gicv_setup(d)) != 0 )
-            goto fail;
+    if ( (rc = gicv_setup(d)) != 0 )
+        goto fail;
 
-        if ( (rc = domain_vgic_init(d)) != 0 )
-            goto fail;
-    }
+    if ( (rc = domain_vgic_init(d)) != 0 )
+        goto fail;
 
     /* Domain 0 gets a real UART not an emulated one */
     if ( d->domain_id && (rc = domain_uart0_init(d)) != 0 )
         goto fail;
 
-    rc = 0;
+    return 0;
+
 fail:
-    /*XXX unwind allocations etc */
+    d->is_dying = DOMDYING_dead;
+    free_xenheap_page(d->shared_info);
+
+    p2m_teardown(d);
+
+    domain_vgic_free(d);
+    domain_uart0_free(d);
+
     return rc;
 }
 
diff -r 9faae502bb9e -r 5d432081dedd xen/arch/arm/gic.h
--- a/xen/arch/arm/gic.h        Tue Jul 03 10:52:29 2012 +0100
+++ b/xen/arch/arm/gic.h        Tue Jul 03 10:52:30 2012 +0100
@@ -125,7 +125,10 @@
 #define VGIC_IRQ_EVTCHN_CALLBACK 31
 
 extern int domain_vgic_init(struct domain *d);
+extern void domain_vgic_free(struct domain *d);
+
 extern int vcpu_vgic_init(struct vcpu *v);
+
 extern void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq,int virtual);
 extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq);
 
diff -r 9faae502bb9e -r 5d432081dedd xen/arch/arm/p2m.c
--- a/xen/arch/arm/p2m.c        Tue Jul 03 10:52:29 2012 +0100
+++ b/xen/arch/arm/p2m.c        Tue Jul 03 10:52:30 2012 +0100
@@ -288,6 +288,21 @@ int p2m_alloc_table(struct domain *d)
     return 0;
 }
 
+void p2m_teardown(struct domain *d)
+{
+    struct p2m_domain *p2m = &d->arch.p2m;
+    struct page_info *pg;
+
+    spin_lock(&p2m->lock);
+
+    while ( (pg = page_list_remove_head(&p2m->pages)) )
+        free_domheap_page(pg);
+
+    p2m->first_level = NULL;
+
+    spin_unlock(&p2m->lock);
+}
+
 int p2m_init(struct domain *d)
 {
     struct p2m_domain *p2m = &d->arch.p2m;
diff -r 9faae502bb9e -r 5d432081dedd xen/arch/arm/vgic.c
--- a/xen/arch/arm/vgic.c       Tue Jul 03 10:52:29 2012 +0100
+++ b/xen/arch/arm/vgic.c       Tue Jul 03 10:52:30 2012 +0100
@@ -90,6 +90,12 @@ int domain_vgic_init(struct domain *d)
     return 0;
 }
 
+void domain_vgic_free(struct domain *d)
+{
+    xfree(d->arch.vgic.shared_irqs);
+    xfree(d->arch.vgic.pending_irqs);
+}
+
 int vcpu_vgic_init(struct vcpu *v)
 {
     int i;
diff -r 9faae502bb9e -r 5d432081dedd xen/arch/arm/vpl011.c
--- a/xen/arch/arm/vpl011.c     Tue Jul 03 10:52:29 2012 +0100
+++ b/xen/arch/arm/vpl011.c     Tue Jul 03 10:52:30 2012 +0100
@@ -56,6 +56,11 @@ int domain_uart0_init(struct domain *d)
 
 }
 
+void domain_uart0_free(struct domain *d)
+{
+    xfree(d->arch.uart0.buf);
+}
+
 static void uart0_print_char(char c)
 {
     struct vpl011 *uart = &current->domain->arch.uart0;
diff -r 9faae502bb9e -r 5d432081dedd xen/arch/arm/vpl011.h
--- a/xen/arch/arm/vpl011.h     Tue Jul 03 10:52:29 2012 +0100
+++ b/xen/arch/arm/vpl011.h     Tue Jul 03 10:52:30 2012 +0100
@@ -21,6 +21,7 @@
 #define __ARCH_ARM_VPL011_H__
 
 extern int domain_uart0_init(struct domain *d);
+extern void domain_uart0_free(struct domain *d);
 
 #endif
 
diff -r 9faae502bb9e -r 5d432081dedd xen/include/asm-arm/p2m.h
--- a/xen/include/asm-arm/p2m.h Tue Jul 03 10:52:29 2012 +0100
+++ b/xen/include/asm-arm/p2m.h Tue Jul 03 10:52:30 2012 +0100
@@ -23,6 +23,9 @@ struct p2m_domain {
 /* Init the datastructures for later use by the p2m code */
 int p2m_init(struct domain *d);
 
+/* Return all the p2m resources to Xen. */
+void p2m_teardown(struct domain *d);
+
 /* Allocate a new p2m table for a domain.
  *
  * Returns 0 for success or -errno.

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.