Code restructuring
PATCH 1/1 Code restructuring
This patch restructures part of the ACM code in Xen. When a domain is created, the function acm_domain_create() in domain_create() is called that does what previously the pre- and post_domain_create functions were doing. Similarly there's a function acm_domain_destroy() in domain_kill() that reverts changes to state when destroying a domain. There's no more separate initialization necessary for domain-0, but domain_create takes one more parameter, the ssidref. It is usually passed through the hypercall when a domain is created.
--- xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c | 70 +--- xen-unstable.hg/xen/acm/acm_null_hooks.c | 6 xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c | 17 - xen-unstable.hg/xen/arch/ia64/xen/xensetup.c | 4 xen-unstable.hg/xen/arch/powerpc/setup.c | 7 xen-unstable.hg/xen/arch/x86/setup.c | 8 xen-unstable.hg/xen/common/domain.c | 22 + xen-unstable.hg/xen/common/domctl.c | 12 xen-unstable.hg/xen/include/acm/acm_hooks.h | 190 +++--------- xen-unstable.hg/xen/include/xen/sched.h | 4 10 files changed, 119 insertions(+), 221 deletions(-)
xen-unstable.hg/xen/common/domctl.c +2 -10
@@ -176,7 +176,6 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc {long ret =0 ;struct xen_domctl curop, *op = &curop; -void *ssid =NULL ;/* save security ptr between pre and post/fail hooks */ static DEFINE_SPINLOCK (domctl_lock);if ( !IS_PRIV (current->domain) )
@@ -188,9 +187,6 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domcif ( op->interface_version !=XEN_DOMCTL_INTERFACE_VERSION )return -EACCES ; -if (acm_pre_domctl (op, &ssid) ) -return -EPERM ; -spin_lock (&domctl_lock); switch ( op->cmd )
@@ -333,7 +329,8 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc domcr_flags |= DOMCRF_hvm; ret = -ENOMEM ; -if ( (d =domain_create (dom, domcr_flags)) ==NULL ) +if ( (d =domain_create (dom, domcr_flags, + op->u.createdomain.ssidref)) ==NULL )break ; ret =0 ;
@@ -716,11 +713,6 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domcspin_unlock (&domctl_lock); -if ( ret ==0 ) -acm_post_domctl (op, &ssid); -else -acm_fail_domctl (op, &ssid); -return ret; }
xen-unstable.hg/xen/arch/x86/setup.c +3 -5
@@ -254,7 +254,7 @@ static void __init init_idle_domain(void/* Domain creation requires that scheduler structures are initialised. */ scheduler_init (); - idle_domain =domain_create (IDLE_DOMAIN_ID ,0 ); + idle_domain =domain_create (IDLE_DOMAIN_ID ,0 ,0 );if ( (idle_domain ==NULL ) || (alloc_vcpu (idle_domain,0 ,0 ) ==NULL ) )BUG ();
@@ -727,15 +727,13 @@ void __init __start_xen(multiboot_info_tacm_init (_policy_start, _policy_len);/* Create initial domain 0. */ - dom0 =domain_create (0 ,0 ); + dom0 =domain_create (0 ,0 ,DOM0_SSIDREF ); +if ( (dom0 ==NULL ) || (alloc_vcpu (dom0,0 ,0 ) ==NULL ) )panic ("Error creating domain 0\n" ); dom0->is_privileged =1 ; -/* Post-create hook sets security label. */ -acm_post_domain0_create (dom0->domain_id); -/* Grab the DOM0 command line. */ cmdline = (char *)(mod[0 ].string ?__va (mod[0 ].string) :NULL );if ( cmdline !=NULL )
xen-unstable.hg/xen/common/domain.c +15 -6
@@ -28,6 +28,7 @@#include <asm/debugger.h> #include <public/sched.h> #include <public/vcpu.h> +#include <acm/acm_hooks.h> /* Protect updates/reads (resp.) of domain_list and domain_hash. */ DEFINE_SPINLOCK (domlist_update_lock);
@@ -178,7 +179,7 @@ struct vcpu *alloc_idle_vcpu(unsigned inreturn v; d = (vcpu_id ==0 ) ? -domain_create (IDLE_DOMAIN_ID ,0 ) : +domain_create (IDLE_DOMAIN_ID ,0 ,0 ) : idle_vcpu[cpu_id - vcpu_id]->domain;BUG_ON (d ==NULL );
@@ -188,7 +189,8 @@ struct vcpu *alloc_idle_vcpu(unsigned inreturn v; } -struct domain *domain_create (domid_t domid,unsigned int domcr_flags) +struct domain *domain_create (domid_t domid,unsigned int domcr_flags, +ssidref_t ssidref) {struct domain *d, **pd;
@@ -210,18 +212,21 @@ struct domain *domain_create(domid_t domif (grant_table_create (d) !=0 ) goto fail2; + +if (acm_domain_create (d, ssidref) !=0 ) + goto fail3; }if (arch_domain_create (d) !=0 ) - goto fail3; + goto fail4; d->iomem_caps =rangeset_new (d,"I/O Memory" , RANGESETF_prettyprint_hex); d->irq_caps =rangeset_new (d,"Interrupts" ,0 );if ( (d->iomem_caps ==NULL ) || (d->irq_caps ==NULL ) ) - goto fail4; + goto fail5;if (sched_init_domain (d) !=0 ) - goto fail4; + goto fail5;if ( !is_idle_domain (d) ) {
@@ -243,8 +248,11 @@ struct domain *domain_create(domid_t domreturn d; - fail4: + fail5:arch_domain_destroy (d); + fail4: +if ( !is_idle_domain (d) ) +acm_domain_destroy (d); fail3:if ( !is_idle_domain (d) )grant_table_destroy (d);
@@ -313,6 +321,7 @@ void domain_kill(struct domain *d)return ; } +acm_domain_destroy (d);gnttab_release_mappings (d);domain_relinquish_resources (d);put_domain (d);
xen-unstable.hg/xen/include/acm/acm_hooks.h +54 -136
237 lines not on this page · raw message
xen-unstable.hg/xen/include/xen/sched.h +3 -1
@@ -10,6 +10,7 @@#include <public/xen.h> #include <public/domctl.h> #include <public/vcpu.h> +#include <public/acm.h> #include <xen/time.h> #include <xen/timer.h> #include <xen/grant_table.h>
@@ -296,7 +297,8 @@ static inline struct domain *get_currentreturn d; } -struct domain *domain_create (domid_t domid,unsigned int domcr_flags); +struct domain *domain_create (domid_t domid,unsigned int domcr_flags, +ssidref_t ssidref);/* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */ #define _DOMCRF_hvm 0#define DOMCRF_hvm (1U<<_DOMCRF_hvm)
xen-unstable.hg/xen/arch/ia64/xen/xensetup.c +2 -2
@@ -421,7 +421,7 @@ void start_kernel(void)scheduler_init (); idle_vcpu[0 ] = (struct vcpu *) ia64_r13; - idle_domain =domain_create (IDLE_DOMAIN_ID ,0 ); + idle_domain =domain_create (IDLE_DOMAIN_ID ,0 ,0 );if ( (idle_domain ==NULL ) || (alloc_vcpu (idle_domain,0 ,0 ) ==NULL ) )BUG ();
@@ -508,7 +508,7 @@ printk("num_online_cpus=%d, max_cpus=%d\expose_p2m_init ();/* Create initial domain 0. */ - dom0 =domain_create (0 ,0 ); + dom0 =domain_create (0 ,0 ,DOM0_SSIDREF );if (dom0 ==NULL )panic ("Error creating domain 0\n" ); dom0_vcpu0 =alloc_vcpu (dom0,0 ,0 );
xen-unstable.hg/xen/arch/powerpc/setup.c +2 -5
@@ -162,7 +162,7 @@ static void __init start_of_day(void)scheduler_init ();/* create idle domain */ - idle_domain =domain_create (IDLE_DOMAIN_ID ,0 ); + idle_domain =domain_create (IDLE_DOMAIN_ID ,0 ,0 );if ((idle_domain ==NULL ) || (alloc_vcpu (idle_domain,0 ,0 ) ==NULL ))BUG ();set_current (idle_domain->vcpu[0 ]);
@@ -370,7 +370,7 @@ static void __init __start_xen(multibootpercpu_free_unused_areas ();/* Create initial domain 0. */ - dom0 =domain_create (0 ,0 ); + dom0 =domain_create (0 ,0 ,DOM0_SSIDREF );if (dom0 ==NULL )panic ("Error creating domain 0\n" );
@@ -380,9 +380,6 @@ static void __init __start_xen(multiboot dom0->is_privileged =1 ; -/* Post-create hook sets security label. */ -acm_post_domain0_create (dom0->domain_id); - cmdline = (char *)(mod[0 ].string ?__va ((ulong )mod[0 ].string) :NULL );/* scrub_heap_pages() requires IRQs enabled, and we're post IRQ setup... */
xen-unstable.hg/xen/acm/acm_null_hooks.c +2 -4
@@ -62,10 +62,8 @@ struct acm_operations acm_null_ops = { .dump_statistics = null_dump_stats, .dump_ssid_types = null_dump_ssid_types,/* domain management control hooks */ - .pre_domain_create = NULL, - .post_domain_create = NULL, - .fail_domain_create = NULL, - .post_domain_destroy = NULL, + .domain_create = NULL, + .domain_destroy = NULL,/* event channel control hooks */ .pre_eventchannel_unbound = NULL, .fail_eventchannel_unbound = NULL,
xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c +24 -46
139 lines not on this page · raw message
xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c +11 -6
@@ -500,11 +500,18 @@ ste_pre_domain_create(void *subject_ssidreturn ACM_ACCESS_PERMITTED ; } +static int +ste_domain_create (void *subject_ssid,ssidref_t ssidref,domid_t domid) +{ +return ste_pre_domain_create (subject_ssid, ssidref); +} + +static void -ste_post_domain_destroy (void *subject_ssid,domid_t id) +ste_domain_destroy (void *subject_ssid,struct domain *d) {/* clean all cache entries for destroyed domain (might be re-used) */ -clean_id_from_cache (id); +clean_id_from_cache (d->domain_id); }/* -------- EVENTCHANNEL OPERATIONS -----------*/
@@ -685,10 +692,8 @@ struct acm_operations acm_simple_type_en .dump_ssid_types = ste_dump_ssid_types,/* domain management control hooks */ - .pre_domain_create = ste_pre_domain_create, - .post_domain_create = NULL, - .fail_domain_create = NULL, - .post_domain_destroy = ste_post_domain_destroy, + .domain_create = ste_domain_create, + .domain_destroy = ste_domain_destroy,/* event channel control hooks */ .pre_eventchannel_unbound = ste_pre_eventchannel_unbound,
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Much nicer, thank you. I've applied it for 3.0.5. However, given the effort put in to labelling a domain at the very start of its lifetime, wouldn't it be a good idea to leave that label attached until the domain is actually destroyed? This would correspond to putting the destructor call in domain_destroy() or, even better, complete_domain_destroy(). Bear in mind that a domain may still be accessible and have resources allocated to it even after domain_kill() finishes executing. So stripping its resource label at that point in time is a bit worrying.
-- Keir
Quoted 10 lines · Stefan Berger
This patch restructures part of the ACM code in Xen. When a domain is created, the function
acm_domain_create()indomain_create()is called that does what previously the pre- andpost_domain_createfunctions were doing. Similarly there's a functionacm_domain_destroy()indomain_kill()that reverts changes to state when destroying a domain. There's no more separate initialization necessary for domain-0, butdomain_createtakes one more parameter, the ssidref. It is usually passed through the hypercall when a domain is created.Signed-off-by Stefan Berger <[email protected]>
Keir Fraser <[email protected]> wrote on 04/24/2007 11:55:51 AM:
Quoted 1 line
Much nicer, thank you. I've applied it for 3.0.5. However, given the
effort
Quoted 1 line
put in to labelling a domain at the very start of its lifetime, wouldn't
it
Quoted 3 lines
be a good idea to leave that label attached until the domain is actually destroyed? This would correspond to putting the destructor call in
domain_destroy()or, even better,complete_domain_destroy(). Bear in
mind
Quoted 2 lines
that a domain may still be accessible and have resources allocated to it even after
domain_kill()finishes executing. So stripping its resource
label
Quoted 1 line
at that point in time is a bit worrying.
Right. Can you move this one call into complete_domain_destroy()?
Stefan
Quoted 8 lines
-- Keir
Quoted 3 lines · Stefan Berger
This patch restructures part of the ACM code in Xen. When a domain is created, the function
acm_domain_create()indomain_create()is called that does what previously the pre- andpost_domain_createfunctions
were
Quoted 8 lines
Quoted 7 lines
doing. Similarly there's a function
acm_domain_destroy()indomain_kill()that reverts changes to state when destroying a domain. There's no more separate initialization necessary for domain-0, butdomain_createtakes one more parameter, the ssidref. It is usually passed through the hypercall when a domain is created.Signed-off-by Stefan Berger <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 11 lines · Stefan Berger
Quoted 9 lines
Quoted 7 lines
Much nicer, thank you. I've applied it for 3.0.5. However, given the effort put in to labelling a domain at the very start of its lifetime, wouldn't it be a good idea to leave that label attached until the domain is actually destroyed? This would correspond to putting the destructor call in
domain_destroy()or, even better,complete_domain_destroy(). Bear in mind that a domain may still be accessible and have resources allocated to it even afterdomain_kill()finishes executing. So stripping its resourcelabel
Quoted 1 line
at that point in time is a bit worrying.
Right. Can you move this one call into
complete_domain_destroy()?
Will do.
K.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel