Following Keir suggestion, this is set of patches to add a new version
of find_domain_by_id() which does not increment the domain reference
counter. This reduces the overhead and can be used by any function which
does not need to keep a domain reference beyond its current invocation,
as the rcu mechanism prevents the domain from being removed under our
feet. Of course, this can only be applied after the RCU patch posted
earlier.
Beyond adding the function the patch also replaces most invocations to
find_domain_by_id() with the new function find_domain_by_id_noref().
Only a few places needed to continue using the old function as the
reference was kept beyond the function invocation.
I only did minor tests on x86-32. Xen and dom0 boots fine and I can
create and destroy domains. But, no more exaustive tests were done. I
carefully checked if I removed all put_domain() associated with each
modified invocation of find_domain_by_id but mistakes are always
possible. It would be good to put this to some more exhaustive tests
before pushing it to the main tree. Waiting for post 3.0.4 release is
strongly suggested.
I also decomposed the patch in multiple parts so that the mantainers of
each architecture can review changes in their subtree, test and apply
them at their convenience.
This patch:
4/6: replace find_domain_by_id on arch/x86
=======================================
Signed-off-by: Jose Renato Santos <jsantos@xxxxxxxxxx>
# HG changeset patch
# User root@xxxxxxxxxxxxxxxxxxx
# Node ID d0b80c3295f3e8329e634b7322c23b4177654957
# Parent 129de3dc1b30aa2a687819b4ebcfd9674575ed4a
Replace find_domain_by_id() with find_domain_by_id_noref() for x86 arch
files
diff -r 129de3dc1b30 -r d0b80c3295f3 xen/arch/x86/domctl.c
--- a/xen/arch/x86/domctl.c Fri Dec 8 18:15:55 2006 -0800
+++ b/xen/arch/x86/domctl.c Fri Dec 8 18:17:18 2006 -0800
@@ -37,11 +37,10 @@ long arch_do_domctl(
{
struct domain *d;
ret = -ESRCH;
- d = find_domain_by_id(domctl->domain);
+ d = find_domain_by_id_noref(domctl->domain);
if ( d != NULL )
{
ret = shadow_domctl(d, &domctl->u.shadow_op, u_domctl);
- put_domain(d);
copy_to_guest(u_domctl, domctl, 1);
}
}
@@ -58,7 +57,7 @@ long arch_do_domctl(
break;
ret = -ESRCH;
- if ( unlikely((d = find_domain_by_id(domctl->domain)) == NULL)
)
+ if ( unlikely((d = find_domain_by_id_noref(domctl->domain)) ==
NULL) )
break;
if ( np == 0 )
@@ -67,8 +66,6 @@ long arch_do_domctl(
ret = ioports_permit_access(d, fp, fp + np - 1);
else
ret = ioports_deny_access(d, fp, fp + np - 1);
-
- put_domain(d);
}
break;
@@ -82,7 +79,7 @@ long arch_do_domctl(
ret = -EINVAL;
if ( unlikely(!mfn_valid(mfn)) ||
- unlikely((d = find_domain_by_id(dom)) == NULL) )
+ unlikely((d = find_domain_by_id_noref(dom)) == NULL) )
break;
page = mfn_to_page(mfn);
@@ -115,8 +112,6 @@ long arch_do_domctl(
put_page(page);
}
- put_domain(d);
-
copy_to_guest(u_domctl, domctl, 1);
}
break;
@@ -131,13 +126,12 @@ long arch_do_domctl(
unsigned long *l_arr;
ret = -ESRCH;
- if ( unlikely((d = find_domain_by_id(dom)) == NULL) )
+ if ( unlikely((d = find_domain_by_id_noref(dom)) == NULL) )
break;
if ( unlikely(num > 1024) )
{
ret = -E2BIG;
- put_domain(d);
break;
}
@@ -205,14 +199,13 @@ long arch_do_domctl(
free_xenheap_page(l_arr);
- put_domain(d);
}
break;
case XEN_DOMCTL_getmemlist:
{
int i;
- struct domain *d = find_domain_by_id(domctl->domain);
+ struct domain *d = find_domain_by_id_noref(domctl->domain);
unsigned long max_pfns = domctl->u.getmemlist.max_pfns;
unsigned long mfn;
struct list_head *list_ent;
@@ -242,15 +235,13 @@ long arch_do_domctl(
domctl->u.getmemlist.num_pfns = i;
copy_to_guest(u_domctl, domctl, 1);
-
- put_domain(d);
}
}
break;
case XEN_DOMCTL_hypercall_init:
{
- struct domain *d = find_domain_by_id(domctl->domain);
+ struct domain *d = find_domain_by_id_noref(domctl->domain);
unsigned long gmfn = domctl->u.hypercall_init.gmfn;
unsigned long mfn;
void *hypercall_page;
@@ -264,10 +255,7 @@ long arch_do_domctl(
ret = -EACCES;
if ( !mfn_valid(mfn) ||
!get_page_and_type(mfn_to_page(mfn), d, PGT_writable_page)
)
- {
- put_domain(d);
- break;
- }
+ break;
ret = 0;
@@ -276,8 +264,6 @@ long arch_do_domctl(
unmap_domain_page(hypercall_page);
put_page_and_type(mfn_to_page(mfn));
-
- put_domain(d);
}
break;
diff -r 129de3dc1b30 -r d0b80c3295f3 xen/arch/x86/hvm/hvm.c
--- a/xen/arch/x86/hvm/hvm.c Fri Dec 8 18:15:55 2006 -0800
+++ b/xen/arch/x86/hvm/hvm.c Fri Dec 8 18:17:18 2006 -0800
@@ -621,7 +621,7 @@ static int hvmop_set_pci_intx_level(
if ( (op.domain > 0) || (op.bus > 0) || (op.device > 31) ||
(op.intx > 3) )
return -EINVAL;
- d = find_domain_by_id(op.domid);
+ d = find_domain_by_id_noref(op.domid);
if ( d == NULL )
return -ESRCH;
@@ -644,7 +644,6 @@ static int hvmop_set_pci_intx_level(
}
out:
- put_domain(d);
return rc;
}
@@ -664,7 +663,7 @@ static int hvmop_set_isa_irq_level(
if ( op.isa_irq > 15 )
return -EINVAL;
- d = find_domain_by_id(op.domid);
+ d = find_domain_by_id_noref(op.domid);
if ( d == NULL )
return -ESRCH;
@@ -687,7 +686,6 @@ static int hvmop_set_isa_irq_level(
}
out:
- put_domain(d);
return rc;
}
@@ -707,7 +705,7 @@ static int hvmop_set_pci_link_route(
if ( (op.link > 3) || (op.isa_irq > 15) )
return -EINVAL;
- d = find_domain_by_id(op.domid);
+ d = find_domain_by_id_noref(op.domid);
if ( d == NULL )
return -ESRCH;
@@ -719,7 +717,6 @@ static int hvmop_set_pci_link_route(
hvm_set_pci_link_route(d, op.link, op.isa_irq);
out:
- put_domain(d);
return rc;
}
@@ -752,7 +749,7 @@ long do_hvm_op(unsigned long op, XEN_GUE
}
else if ( IS_PRIV(current->domain) )
{
- d = find_domain_by_id(a.domid);
+ d = find_domain_by_id_noref(a.domid);
if ( d == NULL )
return -ESRCH;
}
@@ -809,7 +806,6 @@ long do_hvm_op(unsigned long op, XEN_GUE
}
param_fail:
- put_domain(d);
break;
}
diff -r 129de3dc1b30 -r d0b80c3295f3 xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Fri Dec 8 18:15:55 2006 -0800
+++ b/xen/arch/x86/mm.c Fri Dec 8 18:17:18 2006 -0800
@@ -2922,7 +2922,7 @@ long arch_memory_op(int op, XEN_GUEST_HA
}
else if ( !IS_PRIV(current->domain) )
return -EPERM;
- else if ( (d = find_domain_by_id(xatp.domid)) == NULL )
+ else if ( (d = find_domain_by_id_noref(xatp.domid)) == NULL )
return -ESRCH;
switch ( xatp.space )
@@ -2940,10 +2940,7 @@ long arch_memory_op(int op, XEN_GUEST_HA
}
if ( !shadow_mode_translate(d) || (mfn == 0) )
- {
- put_domain(d);
return -EINVAL;
- }
LOCK_BIGLOCK(d);
@@ -2969,8 +2966,6 @@ long arch_memory_op(int op, XEN_GUEST_HA
UNLOCK_BIGLOCK(d);
- put_domain(d);
-
break;
}
find_domain_by_id_noref_4.patch
Description: find_domain_by_id_noref_4.patch
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|