From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 13/21] arm: unwind allocations etc on arch_domain_create_failure
Date: Thu, 28 Jun 2012 14:48:01 +0000 [thread overview]
Message-ID: <1340894890-4369-13-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1340894890-4369-1-git-send-email-ian.campbell@citrix.com>
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@citrix.com>
Acked-by: Tim Deegan <tim@xen.org>
---
xen/arch/arm/domain.c | 42 +++++++++++++++++++++++++-----------------
xen/arch/arm/gic.h | 3 +++
xen/arch/arm/p2m.c | 15 +++++++++++++++
xen/arch/arm/vgic.c | 6 ++++++
xen/arch/arm/vpl011.c | 5 +++++
xen/arch/arm/vpl011.h | 1 +
xen/include/asm-arm/p2m.h | 3 +++
7 files changed, 58 insertions(+), 17 deletions(-)
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 2b5515d..ac6a30d 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -317,37 +317,45 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
{
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 --git a/xen/arch/arm/gic.h b/xen/arch/arm/gic.h
index 018d820..e36d6ad 100644
--- a/xen/arch/arm/gic.h
+++ b/xen/arch/arm/gic.h
@@ -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 --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 67bfeba..073216b 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -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 --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c
index a217151..f2fa927 100644
--- a/xen/arch/arm/vgic.c
+++ b/xen/arch/arm/vgic.c
@@ -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 --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
index 5dc8b28..1522667 100644
--- a/xen/arch/arm/vpl011.c
+++ b/xen/arch/arm/vpl011.c
@@ -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 = ¤t->domain->arch.uart0;
diff --git a/xen/arch/arm/vpl011.h b/xen/arch/arm/vpl011.h
index 952d812..eabd99d 100644
--- a/xen/arch/arm/vpl011.h
+++ b/xen/arch/arm/vpl011.h
@@ -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 --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index 666bb88..14e71bf 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -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.
--
1.7.9.1
next prev parent reply other threads:[~2012-06-28 14:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-28 14:47 [PATCH 0/21 V3] arm: boot a dom1 to "Calibrating delay loop" then hang Ian Campbell
2012-06-28 14:47 ` [PATCH 01/21] arm: allow p2m to be created with specific MATTR Ian Campbell
2012-06-28 14:47 ` [PATCH 02/21] arm: implement vpl011 (UART) emulator Ian Campbell
2012-06-28 14:47 ` [PATCH 03/21] arm: implement vcpu_show_execution_state Ian Campbell
2012-06-28 14:47 ` [PATCH 04/21] arm: use correct attributes for mappings in copy_from_paddr() Ian Campbell
2012-06-28 14:47 ` [PATCH 05/21] arm: split pending SPIs (global) out from pending PPIs and SGIs (per CPU) Ian Campbell
2012-06-28 14:47 ` [PATCH 06/21] arm: make vgic lock safe for use in interrupt context Ian Campbell
2012-07-02 15:42 ` Stefano Stabellini
2012-06-28 14:47 ` [PATCH 07/21] arm: map GICV in all domains, not just dom0 Ian Campbell
2012-06-28 14:47 ` [PATCH 08/21] arm: enable data-cache at the same time as enabling the MMU, not before Ian Campbell
2012-06-28 14:47 ` [PATCH 09/21] arm: Upgrade guest barriers to Outer-Shareable. Enable Protected Table Walk Ian Campbell
2012-06-28 14:47 ` [PATCH 10/21] arm: gic.lock can be taken in interrupt context, so lock appropriately Ian Campbell
2012-06-28 14:47 ` [PATCH 11/21] arm: context switch virtual timer registers Ian Campbell
2012-06-28 14:48 ` [PATCH 12/21] arm: the hyp timer seems to work in newer model versions, default to using it Ian Campbell
2012-06-28 14:48 ` Ian Campbell [this message]
2012-06-28 14:48 ` [PATCH 14/21] arm: move PSR flag definitions into interface, for tools use Ian Campbell
2012-06-28 14:48 ` [PATCH 15/21] arm: fix typo s/approprately/appropriately/g Ian Campbell
2012-06-28 14:48 ` [PATCH 16/21] HACK: arm: initial XENMAPSPACE_gmfn_foreign Ian Campbell
2012-06-28 14:48 ` [PATCH 17/21] libxc: add ARM support to xc_dom (PV domain building) Ian Campbell
2012-06-28 14:48 ` [PATCH 18/21] arm: implement VGCF_online Ian Campbell
2012-06-28 14:48 ` [PATCH 19/21] HACK: add simple xcbuild Ian Campbell
2012-06-28 14:48 ` [PATCH 20/21] HACK: arm: disable hypercall continuations Ian Campbell
2012-06-28 14:48 ` [PATCH 21/21] xen: add assertion in default_vcpu0_location to protect against broken masks Ian Campbell
2012-07-03 10:07 ` [PATCH 0/21 V3] arm: boot a dom1 to "Calibrating delay loop" then hang Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1340894890-4369-13-git-send-email-ian.campbell@citrix.com \
--to=ian.campbell@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).