debuggers.hg
changeset 17922:926a366ca82f
Clean up domain_create() interface.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Fri Jun 20 15:21:26 2008 +0100 (2008-06-20) |
parents | ad156e312aef |
children | 2483923066dd |
files | xen/arch/ia64/xen/mm.c xen/arch/x86/mm.c xen/common/domain.c xen/include/xen/domain.h xen/include/xen/sched.h |
line diff
1.1 --- a/xen/arch/ia64/xen/mm.c Fri Jun 20 15:21:04 2008 +0100 1.2 +++ b/xen/arch/ia64/xen/mm.c Fri Jun 20 15:21:26 2008 +0100 1.3 @@ -207,7 +207,7 @@ alloc_dom_xen_and_dom_io(void) 1.4 * Any Xen-heap pages that we will allow to be mapped will have 1.5 * their domain field set to dom_xen. 1.6 */ 1.7 - dom_xen = alloc_domain(DOMID_XEN); 1.8 + dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0); 1.9 BUG_ON(dom_xen == NULL); 1.10 1.11 /* 1.12 @@ -215,7 +215,7 @@ alloc_dom_xen_and_dom_io(void) 1.13 * This domain owns I/O pages that are within the range of the page_info 1.14 * array. Mappings occur at the priv of the caller. 1.15 */ 1.16 - dom_io = alloc_domain(DOMID_IO); 1.17 + dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0); 1.18 BUG_ON(dom_io == NULL); 1.19 } 1.20 1.21 @@ -1553,7 +1553,7 @@ expose_p2m_init(void) 1.22 * Initialise our DOMID_P2M domain. 1.23 * This domain owns m2p table pages. 1.24 */ 1.25 - dom_p2m = alloc_domain(DOMID_P2M); 1.26 + dom_p2m = domain_create(DOMID_P2M, DOMCRF_dummy, 0); 1.27 BUG_ON(dom_p2m == NULL); 1.28 dom_p2m->max_pages = ~0U; 1.29
2.1 --- a/xen/arch/x86/mm.c Fri Jun 20 15:21:04 2008 +0100 2.2 +++ b/xen/arch/x86/mm.c Fri Jun 20 15:21:26 2008 +0100 2.3 @@ -219,7 +219,7 @@ void __init arch_init_memory(void) 2.4 * Any Xen-heap pages that we will allow to be mapped will have 2.5 * their domain field set to dom_xen. 2.6 */ 2.7 - dom_xen = alloc_domain(DOMID_XEN); 2.8 + dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0); 2.9 BUG_ON(dom_xen == NULL); 2.10 2.11 /* 2.12 @@ -227,7 +227,7 @@ void __init arch_init_memory(void) 2.13 * This domain owns I/O pages that are within the range of the page_info 2.14 * array. Mappings occur at the priv of the caller. 2.15 */ 2.16 - dom_io = alloc_domain(DOMID_IO); 2.17 + dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0); 2.18 BUG_ON(dom_io == NULL); 2.19 2.20 /* First 1MB of RAM is historically marked as I/O. */
3.1 --- a/xen/common/domain.c Fri Jun 20 15:21:04 2008 +0100 3.2 +++ b/xen/common/domain.c Fri Jun 20 15:21:26 2008 +0100 3.3 @@ -73,36 +73,13 @@ int current_domain_id(void) 3.4 return current->domain->domain_id; 3.5 } 3.6 3.7 -struct domain *alloc_domain(domid_t domid) 3.8 +static struct domain *alloc_domain_struct(void) 3.9 { 3.10 - struct domain *d; 3.11 - 3.12 - if ( (d = xmalloc(struct domain)) == NULL ) 3.13 - return NULL; 3.14 - 3.15 - memset(d, 0, sizeof(*d)); 3.16 - d->domain_id = domid; 3.17 - 3.18 - if ( xsm_alloc_security_domain(d) != 0 ) 3.19 - { 3.20 - free_domain(d); 3.21 - return NULL; 3.22 - } 3.23 - 3.24 - atomic_set(&d->refcnt, 1); 3.25 - spin_lock_init(&d->domain_lock); 3.26 - spin_lock_init(&d->page_alloc_lock); 3.27 - spin_lock_init(&d->shutdown_lock); 3.28 - spin_lock_init(&d->hypercall_deadlock_mutex); 3.29 - INIT_LIST_HEAD(&d->page_list); 3.30 - INIT_LIST_HEAD(&d->xenpage_list); 3.31 - 3.32 - return d; 3.33 + return xmalloc(struct domain); 3.34 } 3.35 3.36 -void free_domain(struct domain *d) 3.37 +static void free_domain_struct(struct domain *d) 3.38 { 3.39 - xsm_free_security_domain(d); 3.40 xfree(d); 3.41 } 3.42 3.43 @@ -210,19 +187,39 @@ struct domain *domain_create( 3.44 domid_t domid, unsigned int domcr_flags, ssidref_t ssidref) 3.45 { 3.46 struct domain *d, **pd; 3.47 - enum { INIT_evtchn = 1, INIT_gnttab = 2, INIT_arch = 8 }; 3.48 + enum { INIT_xsm = 1u<<0, INIT_rangeset = 1u<<1, INIT_evtchn = 1u<<2, 3.49 + INIT_gnttab = 1u<<3, INIT_arch = 1u<<4 }; 3.50 int init_status = 0; 3.51 3.52 - if ( (d = alloc_domain(domid)) == NULL ) 3.53 + if ( (d = alloc_domain_struct()) == NULL ) 3.54 return NULL; 3.55 3.56 + memset(d, 0, sizeof(*d)); 3.57 + d->domain_id = domid; 3.58 + 3.59 + if ( xsm_alloc_security_domain(d) != 0 ) 3.60 + goto fail; 3.61 + init_status |= INIT_xsm; 3.62 + 3.63 + atomic_set(&d->refcnt, 1); 3.64 + spin_lock_init(&d->domain_lock); 3.65 + spin_lock_init(&d->page_alloc_lock); 3.66 + spin_lock_init(&d->shutdown_lock); 3.67 + spin_lock_init(&d->hypercall_deadlock_mutex); 3.68 + INIT_LIST_HEAD(&d->page_list); 3.69 + INIT_LIST_HEAD(&d->xenpage_list); 3.70 + 3.71 if ( domcr_flags & DOMCRF_hvm ) 3.72 d->is_hvm = 1; 3.73 3.74 if ( (domid == 0) && opt_dom0_vcpus_pin ) 3.75 d->is_pinned = 1; 3.76 3.77 + if ( domcr_flags & DOMCRF_dummy ) 3.78 + return d; 3.79 + 3.80 rangeset_domain_initialise(d); 3.81 + init_status |= INIT_rangeset; 3.82 3.83 if ( !is_idle_domain(d) ) 3.84 { 3.85 @@ -278,8 +275,11 @@ struct domain *domain_create( 3.86 grant_table_destroy(d); 3.87 if ( init_status & INIT_evtchn ) 3.88 evtchn_destroy(d); 3.89 - rangeset_domain_destroy(d); 3.90 - free_domain(d); 3.91 + if ( init_status & INIT_rangeset ) 3.92 + rangeset_domain_destroy(d); 3.93 + if ( init_status & INIT_xsm ) 3.94 + xsm_free_security_domain(d); 3.95 + free_domain_struct(d); 3.96 return NULL; 3.97 } 3.98 3.99 @@ -535,7 +535,8 @@ static void complete_domain_destroy(stru 3.100 if ( d->target != NULL ) 3.101 put_domain(d->target); 3.102 3.103 - free_domain(d); 3.104 + xsm_free_security_domain(d); 3.105 + free_domain_struct(d); 3.106 3.107 send_guest_global_virq(dom0, VIRQ_DOM_EXC); 3.108 }
4.1 --- a/xen/include/xen/domain.h Fri Jun 20 15:21:04 2008 +0100 4.2 +++ b/xen/include/xen/domain.h Fri Jun 20 15:21:26 2008 +0100 4.3 @@ -16,9 +16,6 @@ int boot_vcpu( 4.4 struct vcpu *alloc_idle_vcpu(unsigned int cpu_id); 4.5 void vcpu_reset(struct vcpu *v); 4.6 4.7 -struct domain *alloc_domain(domid_t domid); 4.8 -void free_domain(struct domain *d); 4.9 - 4.10 struct xen_domctl_getdomaininfo; 4.11 void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info); 4.12
5.1 --- a/xen/include/xen/sched.h Fri Jun 20 15:21:04 2008 +0100 5.2 +++ b/xen/include/xen/sched.h Fri Jun 20 15:21:26 2008 +0100 5.3 @@ -315,10 +315,14 @@ static inline struct domain *get_current 5.4 struct domain *domain_create( 5.5 domid_t domid, unsigned int domcr_flags, ssidref_t ssidref); 5.6 /* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */ 5.7 -#define _DOMCRF_hvm 0 5.8 -#define DOMCRF_hvm (1U<<_DOMCRF_hvm) 5.9 -#define _DOMCRF_hap 1 5.10 -#define DOMCRF_hap (1U<<_DOMCRF_hap) 5.11 +#define _DOMCRF_hvm 0 5.12 +#define DOMCRF_hvm (1U<<_DOMCRF_hvm) 5.13 + /* DOMCRF_hap: Create a domain with hardware-assisted paging. */ 5.14 +#define _DOMCRF_hap 1 5.15 +#define DOMCRF_hap (1U<<_DOMCRF_hap) 5.16 + /* DOMCRF_dummy: Create a dummy domain (not scheduled; not on domain list) */ 5.17 +#define _DOMCRF_dummy 2 5.18 +#define DOMCRF_dummy (1U<<_DOMCRF_dummy) 5.19 5.20 int construct_dom0( 5.21 struct domain *d,