direct-io.hg
changeset 14186:9d36026b1b43
xen: Cleanups and bug fixes after the rcu_lock_domain patch.
Signed-off-by: Keir Fraser <keir@xensource.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kfraser@localhost.localdomain |
---|---|
date | Thu Mar 01 11:38:55 2007 +0000 (2007-03-01) |
parents | 3fb02f56c19f |
children | 0de2f7d8d89f |
files | xen/arch/ia64/vmx/vmx_hypercall.c xen/arch/ia64/xen/mm.c xen/arch/powerpc/mm.c xen/arch/x86/hvm/hvm.c xen/arch/x86/mm.c xen/common/domain.c xen/common/domctl.c xen/common/event_channel.c xen/common/grant_table.c xen/common/schedule.c xen/common/sysctl.c xen/include/xen/sched.h |
line diff
1.1 --- a/xen/arch/ia64/vmx/vmx_hypercall.c Thu Mar 01 11:08:49 2007 +0000 1.2 +++ b/xen/arch/ia64/vmx/vmx_hypercall.c Thu Mar 01 11:38:55 2007 +0000 1.3 @@ -122,8 +122,7 @@ do_hvm_op(unsigned long op, XEN_GUEST_HA 1.4 return -EINVAL; 1.5 1.6 if (a.domid == DOMID_SELF) { 1.7 - get_knownalive_domain(current->domain); 1.8 - d = current->domain; 1.9 + d = get_current_domain(); 1.10 } 1.11 else if (IS_PRIV(current->domain)) { 1.12 d = get_domain_by_id(a.domid);
2.1 --- a/xen/arch/ia64/xen/mm.c Thu Mar 01 11:08:49 2007 +0000 2.2 +++ b/xen/arch/ia64/xen/mm.c Thu Mar 01 11:38:55 2007 +0000 2.3 @@ -435,11 +435,15 @@ share_xen_page_with_guest(struct page_in 2.4 page_set_owner(page, d); 2.5 wmb(); /* install valid domain ptr before updating refcnt. */ 2.6 ASSERT(page->count_info == 0); 2.7 - page->count_info |= PGC_allocated | 1; 2.8 2.9 - if ( unlikely(d->xenheap_pages++ == 0) ) 2.10 - get_knownalive_domain(d); 2.11 - list_add_tail(&page->list, &d->xenpage_list); 2.12 + /* Only add to the allocation list if the domain isn't dying. */ 2.13 + if ( !test_bit(_DOMF_dying, &d->domain_flags) ) 2.14 + { 2.15 + page->count_info |= PGC_allocated | 1; 2.16 + if ( unlikely(d->xenheap_pages++ == 0) ) 2.17 + get_knownalive_domain(d); 2.18 + list_add_tail(&page->list, &d->xenpage_list); 2.19 + } 2.20 2.21 // grant_table_destroy() releases these pages. 2.22 // but it doesn't clear their m2p entry. So there might remain stale 2.23 @@ -2057,8 +2061,7 @@ arch_memory_op(int op, XEN_GUEST_HANDLE( 2.24 return -EFAULT; 2.25 2.26 if (xatp.domid == DOMID_SELF) { 2.27 - d = current->domain; 2.28 - get_knownalive_domain(d); 2.29 + d = get_current_domain(); 2.30 } 2.31 else if (!IS_PRIV(current->domain)) 2.32 return -EPERM;
3.1 --- a/xen/arch/powerpc/mm.c Thu Mar 01 11:08:49 2007 +0000 3.2 +++ b/xen/arch/powerpc/mm.c Thu Mar 01 11:38:55 2007 +0000 3.3 @@ -80,11 +80,15 @@ void share_xen_page_with_guest( 3.4 page_set_owner(page, d); 3.5 wmb(); /* install valid domain ptr before updating refcnt. */ 3.6 ASSERT(page->count_info == 0); 3.7 - page->count_info |= PGC_allocated | 1; 3.8 3.9 - if ( unlikely(d->xenheap_pages++ == 0) ) 3.10 - get_knownalive_domain(d); 3.11 - list_add_tail(&page->list, &d->xenpage_list); 3.12 + /* Only add to the allocation list if the domain isn't dying. */ 3.13 + if ( !test_bit(_DOMF_dying, &d->domain_flags) ) 3.14 + { 3.15 + page->count_info |= PGC_allocated | 1; 3.16 + if ( unlikely(d->xenheap_pages++ == 0) ) 3.17 + get_knownalive_domain(d); 3.18 + list_add_tail(&page->list, &d->xenpage_list); 3.19 + } 3.20 3.21 spin_unlock(&d->page_alloc_lock); 3.22 }
4.1 --- a/xen/arch/x86/hvm/hvm.c Thu Mar 01 11:08:49 2007 +0000 4.2 +++ b/xen/arch/x86/hvm/hvm.c Thu Mar 01 11:38:55 2007 +0000 4.3 @@ -836,20 +836,14 @@ long do_hvm_op(unsigned long op, XEN_GUE 4.4 return -EINVAL; 4.5 4.6 if ( a.domid == DOMID_SELF ) 4.7 - { 4.8 - get_knownalive_domain(current->domain); 4.9 - d = current->domain; 4.10 - } 4.11 + d = rcu_lock_current_domain(); 4.12 else if ( IS_PRIV(current->domain) ) 4.13 - { 4.14 d = rcu_lock_domain_by_id(a.domid); 4.15 - if ( d == NULL ) 4.16 - return -ESRCH; 4.17 - } 4.18 else 4.19 - { 4.20 return -EPERM; 4.21 - } 4.22 + 4.23 + if ( d == NULL ) 4.24 + return -ESRCH; 4.25 4.26 rc = -EINVAL; 4.27 if ( !is_hvm_domain(d) )
5.1 --- a/xen/arch/x86/mm.c Thu Mar 01 11:08:49 2007 +0000 5.2 +++ b/xen/arch/x86/mm.c Thu Mar 01 11:38:55 2007 +0000 5.3 @@ -263,11 +263,15 @@ void share_xen_page_with_guest( 5.4 page_set_owner(page, d); 5.5 wmb(); /* install valid domain ptr before updating refcnt. */ 5.6 ASSERT(page->count_info == 0); 5.7 - page->count_info |= PGC_allocated | 1; 5.8 - 5.9 - if ( unlikely(d->xenheap_pages++ == 0) ) 5.10 - get_knownalive_domain(d); 5.11 - list_add_tail(&page->list, &d->xenpage_list); 5.12 + 5.13 + /* Only add to the allocation list if the domain isn't dying. */ 5.14 + if ( !test_bit(_DOMF_dying, &d->domain_flags) ) 5.15 + { 5.16 + page->count_info |= PGC_allocated | 1; 5.17 + if ( unlikely(d->xenheap_pages++ == 0) ) 5.18 + get_knownalive_domain(d); 5.19 + list_add_tail(&page->list, &d->xenpage_list); 5.20 + } 5.21 5.22 spin_unlock(&d->page_alloc_lock); 5.23 } 5.24 @@ -2960,10 +2964,7 @@ long arch_memory_op(int op, XEN_GUEST_HA 5.25 return -EFAULT; 5.26 5.27 if ( xatp.domid == DOMID_SELF ) 5.28 - { 5.29 - d = current->domain; 5.30 - get_knownalive_domain(d); 5.31 - } 5.32 + d = rcu_lock_current_domain(); 5.33 else if ( !IS_PRIV(current->domain) ) 5.34 return -EPERM; 5.35 else if ( (d = rcu_lock_domain_by_id(xatp.domid)) == NULL ) 5.36 @@ -3039,10 +3040,7 @@ long arch_memory_op(int op, XEN_GUEST_HA 5.37 return -EINVAL; 5.38 5.39 if ( fmap.domid == DOMID_SELF ) 5.40 - { 5.41 - d = current->domain; 5.42 - get_knownalive_domain(d); 5.43 - } 5.44 + d = rcu_lock_current_domain(); 5.45 else if ( !IS_PRIV(current->domain) ) 5.46 return -EPERM; 5.47 else if ( (d = rcu_lock_domain_by_id(fmap.domid)) == NULL )
6.1 --- a/xen/common/domain.c Thu Mar 01 11:08:49 2007 +0000 6.2 +++ b/xen/common/domain.c Thu Mar 01 11:38:55 2007 +0000 6.3 @@ -345,8 +345,7 @@ void domain_pause_for_debugger(void) 6.4 send_guest_global_virq(dom0, VIRQ_DEBUGGER); 6.5 } 6.6 6.7 -/* Complete domain destroy after RCU readers are not holding 6.8 - old references */ 6.9 +/* Complete domain destroy after RCU readers are not holding old references. */ 6.10 static void complete_domain_destroy(struct rcu_head *head) 6.11 { 6.12 struct domain *d = container_of(head, struct domain, rcu); 6.13 @@ -390,7 +389,7 @@ void domain_destroy(struct domain *d) 6.14 rcu_assign_pointer(*pd, d->next_in_hashbucket); 6.15 spin_unlock(&domlist_update_lock); 6.16 6.17 - /* schedule RCU asynchronous completion of domain destroy */ 6.18 + /* Schedule RCU asynchronous completion of domain destroy. */ 6.19 call_rcu(&d->rcu, complete_domain_destroy); 6.20 } 6.21
7.1 --- a/xen/common/domctl.c Thu Mar 01 11:08:49 2007 +0000 7.2 +++ b/xen/common/domctl.c Thu Mar 01 11:38:55 2007 +0000 7.3 @@ -484,22 +484,20 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc 7.4 break; 7.5 } 7.6 7.7 - if ( (d == NULL) || !get_domain(d) ) 7.8 + if ( d == NULL ) 7.9 { 7.10 rcu_read_unlock(&domlist_read_lock); 7.11 ret = -ESRCH; 7.12 break; 7.13 } 7.14 7.15 - rcu_read_unlock(&domlist_read_lock); 7.16 - 7.17 getdomaininfo(d, &op->u.getdomaininfo); 7.18 7.19 op->domain = op->u.getdomaininfo.domain; 7.20 if ( copy_to_guest(u_domctl, op, 1) ) 7.21 ret = -EFAULT; 7.22 7.23 - put_domain(d); 7.24 + rcu_read_unlock(&domlist_read_lock); 7.25 } 7.26 break; 7.27
8.1 --- a/xen/common/event_channel.c Thu Mar 01 11:08:49 2007 +0000 8.2 +++ b/xen/common/event_channel.c Thu Mar 01 11:38:55 2007 +0000 8.3 @@ -434,7 +434,7 @@ static long __evtchn_close(struct domain 8.4 spin_unlock(&d2->evtchn_lock); 8.5 put_domain(d2); 8.6 } 8.7 - 8.8 + 8.9 spin_unlock(&d1->evtchn_lock); 8.10 8.11 return rc;
9.1 --- a/xen/common/grant_table.c Thu Mar 01 11:08:49 2007 +0000 9.2 +++ b/xen/common/grant_table.c Thu Mar 01 11:38:55 2007 +0000 9.3 @@ -1086,26 +1086,16 @@ static void 9.4 "only allow copy-by-mfn for DOMID_SELF.\n"); 9.5 9.6 if ( op->source.domid == DOMID_SELF ) 9.7 - { 9.8 - sd = current->domain; 9.9 - get_knownalive_domain(sd); 9.10 - } 9.11 + sd = rcu_lock_current_domain(); 9.12 else if ( (sd = rcu_lock_domain_by_id(op->source.domid)) == NULL ) 9.13 - { 9.14 PIN_FAIL(error_out, GNTST_bad_domain, 9.15 "couldn't find %d\n", op->source.domid); 9.16 - } 9.17 9.18 if ( op->dest.domid == DOMID_SELF ) 9.19 - { 9.20 - dd = current->domain; 9.21 - get_knownalive_domain(dd); 9.22 - } 9.23 + dd = rcu_lock_current_domain(); 9.24 else if ( (dd = rcu_lock_domain_by_id(op->dest.domid)) == NULL ) 9.25 - { 9.26 PIN_FAIL(error_out, GNTST_bad_domain, 9.27 "couldn't find %d\n", op->dest.domid); 9.28 - } 9.29 9.30 if ( src_is_gref ) 9.31 {
10.1 --- a/xen/common/schedule.c Thu Mar 01 11:08:49 2007 +0000 10.2 +++ b/xen/common/schedule.c Thu Mar 01 11:38:55 2007 +0000 10.3 @@ -430,12 +430,12 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN 10.4 break; 10.5 10.6 ret = -ESRCH; 10.7 - d = get_domain_by_id(sched_remote_shutdown.domain_id); 10.8 + d = rcu_lock_domain_by_id(sched_remote_shutdown.domain_id); 10.9 if ( d == NULL ) 10.10 break; 10.11 10.12 domain_shutdown(d, (u8)sched_remote_shutdown.reason); 10.13 - put_domain(d); 10.14 + rcu_unlock_domain(d); 10.15 ret = 0; 10.16 10.17 break;
11.1 --- a/xen/common/sysctl.c Thu Mar 01 11:08:49 2007 +0000 11.2 +++ b/xen/common/sysctl.c Thu Mar 01 11:38:55 2007 +0000 11.3 @@ -86,16 +86,9 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc 11.4 continue; 11.5 if ( num_domains == op->u.getdomaininfolist.max_domains ) 11.6 break; 11.7 - if ( (d == NULL) || !get_domain(d) ) 11.8 - { 11.9 - ret = -ESRCH; 11.10 - break; 11.11 - } 11.12 11.13 getdomaininfo(d, &info); 11.14 11.15 - put_domain(d); 11.16 - 11.17 if ( copy_to_guest_offset(op->u.getdomaininfolist.buffer, 11.18 num_domains, &info, 1) ) 11.19 {
12.1 --- a/xen/include/xen/sched.h Thu Mar 01 11:08:49 2007 +0000 12.2 +++ b/xen/include/xen/sched.h Thu Mar 01 11:38:55 2007 +0000 12.3 @@ -258,6 +258,14 @@ static inline void get_knownalive_domain 12.4 ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTROYED)); 12.5 } 12.6 12.7 +/* Obtain a reference to the currently-running domain. */ 12.8 +static inline struct domain *get_current_domain(void) 12.9 +{ 12.10 + struct domain *d = current->domain; 12.11 + get_knownalive_domain(d); 12.12 + return d; 12.13 +} 12.14 + 12.15 struct domain *domain_create(domid_t domid, unsigned int domcr_flags); 12.16 /* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */ 12.17 #define _DOMCRF_hvm 0 12.18 @@ -284,6 +292,12 @@ static inline void rcu_unlock_domain(str 12.19 rcu_read_unlock(&domlist_read_lock); 12.20 } 12.21 12.22 +static inline struct domain *rcu_lock_current_domain(void) 12.23 +{ 12.24 + rcu_read_lock(&domlist_read_lock); 12.25 + return current->domain; 12.26 +} 12.27 + 12.28 struct domain *get_domain_by_id(domid_t dom); 12.29 void domain_destroy(struct domain *d); 12.30 void domain_kill(struct domain *d);