[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] xen: Cleanups and bug fixes after the rcu_lock_domain patch.
# HG changeset patch # User kfraser@xxxxxxxxxxxxxxxxxxxxx # Date 1172749135 0 # Node ID 9d36026b1b431990163caf09da715cacdab7cae7 # Parent 3fb02f56c19f096edc6e3b23025389c84b41ec5d xen: Cleanups and bug fixes after the rcu_lock_domain patch. Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx> --- xen/arch/ia64/vmx/vmx_hypercall.c | 3 +-- xen/arch/ia64/xen/mm.c | 17 ++++++++++------- xen/arch/powerpc/mm.c | 14 +++++++++----- xen/arch/x86/hvm/hvm.c | 14 ++++---------- xen/arch/x86/mm.c | 24 +++++++++++------------- xen/common/domain.c | 5 ++--- xen/common/domctl.c | 6 ++---- xen/common/event_channel.c | 2 +- xen/common/grant_table.c | 14 ++------------ xen/common/schedule.c | 4 ++-- xen/common/sysctl.c | 7 ------- xen/include/xen/sched.h | 14 ++++++++++++++ 12 files changed, 58 insertions(+), 66 deletions(-) diff -r 3fb02f56c19f -r 9d36026b1b43 xen/arch/ia64/vmx/vmx_hypercall.c --- a/xen/arch/ia64/vmx/vmx_hypercall.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/arch/ia64/vmx/vmx_hypercall.c Thu Mar 01 11:38:55 2007 +0000 @@ -122,8 +122,7 @@ do_hvm_op(unsigned long op, XEN_GUEST_HA return -EINVAL; if (a.domid == DOMID_SELF) { - get_knownalive_domain(current->domain); - d = current->domain; + d = get_current_domain(); } else if (IS_PRIV(current->domain)) { d = get_domain_by_id(a.domid); diff -r 3fb02f56c19f -r 9d36026b1b43 xen/arch/ia64/xen/mm.c --- a/xen/arch/ia64/xen/mm.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/arch/ia64/xen/mm.c Thu Mar 01 11:38:55 2007 +0000 @@ -435,11 +435,15 @@ share_xen_page_with_guest(struct page_in page_set_owner(page, d); wmb(); /* install valid domain ptr before updating refcnt. */ ASSERT(page->count_info == 0); - page->count_info |= PGC_allocated | 1; - - if ( unlikely(d->xenheap_pages++ == 0) ) - get_knownalive_domain(d); - list_add_tail(&page->list, &d->xenpage_list); + + /* Only add to the allocation list if the domain isn't dying. */ + if ( !test_bit(_DOMF_dying, &d->domain_flags) ) + { + page->count_info |= PGC_allocated | 1; + if ( unlikely(d->xenheap_pages++ == 0) ) + get_knownalive_domain(d); + list_add_tail(&page->list, &d->xenpage_list); + } // grant_table_destroy() releases these pages. // but it doesn't clear their m2p entry. So there might remain stale @@ -2057,8 +2061,7 @@ arch_memory_op(int op, XEN_GUEST_HANDLE( return -EFAULT; if (xatp.domid == DOMID_SELF) { - d = current->domain; - get_knownalive_domain(d); + d = get_current_domain(); } else if (!IS_PRIV(current->domain)) return -EPERM; diff -r 3fb02f56c19f -r 9d36026b1b43 xen/arch/powerpc/mm.c --- a/xen/arch/powerpc/mm.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/arch/powerpc/mm.c Thu Mar 01 11:38:55 2007 +0000 @@ -80,11 +80,15 @@ void share_xen_page_with_guest( page_set_owner(page, d); wmb(); /* install valid domain ptr before updating refcnt. */ ASSERT(page->count_info == 0); - page->count_info |= PGC_allocated | 1; - - if ( unlikely(d->xenheap_pages++ == 0) ) - get_knownalive_domain(d); - list_add_tail(&page->list, &d->xenpage_list); + + /* Only add to the allocation list if the domain isn't dying. */ + if ( !test_bit(_DOMF_dying, &d->domain_flags) ) + { + page->count_info |= PGC_allocated | 1; + if ( unlikely(d->xenheap_pages++ == 0) ) + get_knownalive_domain(d); + list_add_tail(&page->list, &d->xenpage_list); + } spin_unlock(&d->page_alloc_lock); } diff -r 3fb02f56c19f -r 9d36026b1b43 xen/arch/x86/hvm/hvm.c --- a/xen/arch/x86/hvm/hvm.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/arch/x86/hvm/hvm.c Thu Mar 01 11:38:55 2007 +0000 @@ -836,20 +836,14 @@ long do_hvm_op(unsigned long op, XEN_GUE return -EINVAL; if ( a.domid == DOMID_SELF ) - { - get_knownalive_domain(current->domain); - d = current->domain; - } + d = rcu_lock_current_domain(); else if ( IS_PRIV(current->domain) ) - { d = rcu_lock_domain_by_id(a.domid); - if ( d == NULL ) - return -ESRCH; - } else - { return -EPERM; - } + + if ( d == NULL ) + return -ESRCH; rc = -EINVAL; if ( !is_hvm_domain(d) ) diff -r 3fb02f56c19f -r 9d36026b1b43 xen/arch/x86/mm.c --- a/xen/arch/x86/mm.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/arch/x86/mm.c Thu Mar 01 11:38:55 2007 +0000 @@ -263,11 +263,15 @@ void share_xen_page_with_guest( page_set_owner(page, d); wmb(); /* install valid domain ptr before updating refcnt. */ ASSERT(page->count_info == 0); - page->count_info |= PGC_allocated | 1; - - if ( unlikely(d->xenheap_pages++ == 0) ) - get_knownalive_domain(d); - list_add_tail(&page->list, &d->xenpage_list); + + /* Only add to the allocation list if the domain isn't dying. */ + if ( !test_bit(_DOMF_dying, &d->domain_flags) ) + { + page->count_info |= PGC_allocated | 1; + if ( unlikely(d->xenheap_pages++ == 0) ) + get_knownalive_domain(d); + list_add_tail(&page->list, &d->xenpage_list); + } spin_unlock(&d->page_alloc_lock); } @@ -2960,10 +2964,7 @@ long arch_memory_op(int op, XEN_GUEST_HA return -EFAULT; if ( xatp.domid == DOMID_SELF ) - { - d = current->domain; - get_knownalive_domain(d); - } + d = rcu_lock_current_domain(); else if ( !IS_PRIV(current->domain) ) return -EPERM; else if ( (d = rcu_lock_domain_by_id(xatp.domid)) == NULL ) @@ -3039,10 +3040,7 @@ long arch_memory_op(int op, XEN_GUEST_HA return -EINVAL; if ( fmap.domid == DOMID_SELF ) - { - d = current->domain; - get_knownalive_domain(d); - } + d = rcu_lock_current_domain(); else if ( !IS_PRIV(current->domain) ) return -EPERM; else if ( (d = rcu_lock_domain_by_id(fmap.domid)) == NULL ) diff -r 3fb02f56c19f -r 9d36026b1b43 xen/common/domain.c --- a/xen/common/domain.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/common/domain.c Thu Mar 01 11:38:55 2007 +0000 @@ -345,8 +345,7 @@ void domain_pause_for_debugger(void) send_guest_global_virq(dom0, VIRQ_DEBUGGER); } -/* Complete domain destroy after RCU readers are not holding - old references */ +/* Complete domain destroy after RCU readers are not holding old references. */ static void complete_domain_destroy(struct rcu_head *head) { struct domain *d = container_of(head, struct domain, rcu); @@ -390,7 +389,7 @@ void domain_destroy(struct domain *d) rcu_assign_pointer(*pd, d->next_in_hashbucket); spin_unlock(&domlist_update_lock); - /* schedule RCU asynchronous completion of domain destroy */ + /* Schedule RCU asynchronous completion of domain destroy. */ call_rcu(&d->rcu, complete_domain_destroy); } diff -r 3fb02f56c19f -r 9d36026b1b43 xen/common/domctl.c --- a/xen/common/domctl.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/common/domctl.c Thu Mar 01 11:38:55 2007 +0000 @@ -484,14 +484,12 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc break; } - if ( (d == NULL) || !get_domain(d) ) + if ( d == NULL ) { rcu_read_unlock(&domlist_read_lock); ret = -ESRCH; break; } - - rcu_read_unlock(&domlist_read_lock); getdomaininfo(d, &op->u.getdomaininfo); @@ -499,7 +497,7 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc if ( copy_to_guest(u_domctl, op, 1) ) ret = -EFAULT; - put_domain(d); + rcu_read_unlock(&domlist_read_lock); } break; diff -r 3fb02f56c19f -r 9d36026b1b43 xen/common/event_channel.c --- a/xen/common/event_channel.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/common/event_channel.c Thu Mar 01 11:38:55 2007 +0000 @@ -434,7 +434,7 @@ static long __evtchn_close(struct domain spin_unlock(&d2->evtchn_lock); put_domain(d2); } - + spin_unlock(&d1->evtchn_lock); return rc; diff -r 3fb02f56c19f -r 9d36026b1b43 xen/common/grant_table.c --- a/xen/common/grant_table.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/common/grant_table.c Thu Mar 01 11:38:55 2007 +0000 @@ -1086,26 +1086,16 @@ __gnttab_copy( "only allow copy-by-mfn for DOMID_SELF.\n"); if ( op->source.domid == DOMID_SELF ) - { - sd = current->domain; - get_knownalive_domain(sd); - } + sd = rcu_lock_current_domain(); else if ( (sd = rcu_lock_domain_by_id(op->source.domid)) == NULL ) - { PIN_FAIL(error_out, GNTST_bad_domain, "couldn't find %d\n", op->source.domid); - } if ( op->dest.domid == DOMID_SELF ) - { - dd = current->domain; - get_knownalive_domain(dd); - } + dd = rcu_lock_current_domain(); else if ( (dd = rcu_lock_domain_by_id(op->dest.domid)) == NULL ) - { PIN_FAIL(error_out, GNTST_bad_domain, "couldn't find %d\n", op->dest.domid); - } if ( src_is_gref ) { diff -r 3fb02f56c19f -r 9d36026b1b43 xen/common/schedule.c --- a/xen/common/schedule.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/common/schedule.c Thu Mar 01 11:38:55 2007 +0000 @@ -430,12 +430,12 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN break; ret = -ESRCH; - d = get_domain_by_id(sched_remote_shutdown.domain_id); + d = rcu_lock_domain_by_id(sched_remote_shutdown.domain_id); if ( d == NULL ) break; domain_shutdown(d, (u8)sched_remote_shutdown.reason); - put_domain(d); + rcu_unlock_domain(d); ret = 0; break; diff -r 3fb02f56c19f -r 9d36026b1b43 xen/common/sysctl.c --- a/xen/common/sysctl.c Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/common/sysctl.c Thu Mar 01 11:38:55 2007 +0000 @@ -86,15 +86,8 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc continue; if ( num_domains == op->u.getdomaininfolist.max_domains ) break; - if ( (d == NULL) || !get_domain(d) ) - { - ret = -ESRCH; - break; - } getdomaininfo(d, &info); - - put_domain(d); if ( copy_to_guest_offset(op->u.getdomaininfolist.buffer, num_domains, &info, 1) ) diff -r 3fb02f56c19f -r 9d36026b1b43 xen/include/xen/sched.h --- a/xen/include/xen/sched.h Thu Mar 01 11:08:49 2007 +0000 +++ b/xen/include/xen/sched.h Thu Mar 01 11:38:55 2007 +0000 @@ -258,6 +258,14 @@ static inline void get_knownalive_domain ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTROYED)); } +/* Obtain a reference to the currently-running domain. */ +static inline struct domain *get_current_domain(void) +{ + struct domain *d = current->domain; + get_knownalive_domain(d); + return d; +} + struct domain *domain_create(domid_t domid, unsigned int domcr_flags); /* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */ #define _DOMCRF_hvm 0 @@ -282,6 +290,12 @@ static inline void rcu_unlock_domain(str static inline void rcu_unlock_domain(struct domain *d) { rcu_read_unlock(&domlist_read_lock); +} + +static inline struct domain *rcu_lock_current_domain(void) +{ + rcu_read_lock(&domlist_read_lock); + return current->domain; } struct domain *get_domain_by_id(domid_t dom); _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |