Wrong cpupool handling
Hi list,
When creating a cpupool, starting and destroying a guest within this pool, then removing this pool doesn't work because of EBUSY.
It seems the cause of this behavior is the commitbac6334b51d9bcfe57ecf4a4cb5288348fcf044a.
In domain_kill() the function sched_move_domain() gets called changing the d->cpupool pointer to the new cpupool without incrementing/decrementing the counters "n_dom" of the new/old cpupool.
This leads to decrementing the wrong cpupool0->n_dom counter when cpupool_rm_domain() gets called at the end and my own cpupool can't be destroyed because n_dom = 1!
I don't have a fast patch because I'am not enough familiar with the code this time but I think it should be fixed for 4.5.
Dietmar.
Signature · 1 line
Company details: http://ts.fujitsu.com/imprint.html
Hi Dietmar,
Quoted 12 lines · Dietmar Hahn
Hi list,
When creating a cpupool, starting and destroying a guest within this pool, then removing this pool doesn't work because of EBUSY.
It seems the cause of this behavior is the commit
bac6334b51d9bcfe57ecf4a4cb5288348fcf044a.In
domain_kill()the functionsched_move_domain()gets called changing thed->cpupoolpointer to the new cpupool without incrementing/decrementing the counters "n_dom" of the new/old cpupool.
Quoted 6 lines
This leads to decrementing the wrong
cpupool0->n_domcounter whencpupool_rm_domain()gets called at the end and my own cpupool can't be destroyed becausen_dom= 1!I don't have a fast patch because I'am not enough familiar with the code this time but I think it should be fixed for 4.5.
Could you try the attached (untested) patch? Should apply to HEAD.
Juergen
Quoted 1 line
From
f231f837b6dffd071c59517286562ccde7c5b5bcMon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Tue, 11 Nov 2014 15:03:33 +0100
Subject: [PATCH] Adjust number of domains in cpupools when destroying domain
Commit bac6334b51d9bcfe57ecf4a4cb5288348fcf044a (move domain to cpupool0 before destroying it) introduced an error in the accounting of cpupools regarding the number of domains. The number of domains is nor adjusted when a domain is moved to cpupool0 in kill_domain().
Correct this by introducing a cpupool function doing the move instead of open coding it by calling sched_move_domain().
--- xen/common/cpupool.c | 46 +++++++++++++++++++++++++++++++++------------- xen/common/domain.c | 2 +- xen/include/xen/sched.h | 1 + 3 files changed, 35 insertions(+), 14 deletions(-)
xen/common/cpupool.c +33 -13
@@ -225,6 +225,35 @@ static int cpupool_destroy(struct cpupool *c) }/* +* Move domain to another cpupool +*/ +static int cpupool_move_domain_unlocked (struct domain *d,struct cpupool *c) +{ +int ret; + + d->cpupool->n_dom--; + ret =sched_move_domain (d, c); +if ( ret ) + d->cpupool->n_dom++; +else + c->n_dom++; + +return ret; +} +int cpupool_move_domain (struct domain *d,struct cpupool *c) +{ +int ret; + +spin_lock (&cpupool_lock); + + ret =cpupool_move_domain_unlocked (d, c); + +spin_unlock (&cpupool_lock); + +return ret; +} + +/* * assign a specific cpu to a cpupool * cpupool_lock must be held */
@@ -338,13 +367,9 @@ static int cpupool_unassign_cpu(struct cpupool *c, unsigned int cpu) ret = -EBUSY ;break ; } - c->n_dom--; - ret =sched_move_domain (d, cpupool0); + ret =cpupool_move_domain_unlocked (d, cpupool0);if ( ret ) - { - c->n_dom++;break ; - } cpupool0->n_dom++; }rcu_read_unlock (&domlist_read_lock);
@@ -613,16 +638,11 @@ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op) d->domain_id, op->cpupool_id); ret = -ENOENT ;spin_lock (&cpupool_lock); + c =cpupool_find_by_id (op->cpupool_id);if ( (c !=NULL ) &&cpumask_weight (c->cpu_valid) ) - { - d->cpupool->n_dom--; - ret =sched_move_domain (d, c); -if ( ret ) - d->cpupool->n_dom++; -else - c->n_dom++; - } + ret =cpupool_move_domain_unlocked (d, c); +spin_unlock (&cpupool_lock);cpupool_dprintk ("cpupool move_domain(dom=%d)->pool=%d ret %d\n" , d->domain_id, op->cpupool_id, ret);
xen/common/domain.c +1 -1
@@ -621,7 +621,7 @@ int domain_kill(struct domain *d) rc = -EAGAIN ;break ; } -if (sched_move_domain (d, cpupool0) ) +if (cpupool_move_domain (d, cpupool0) )return -EAGAIN ; for_each_vcpu ( d, v )unmap_vcpu_info (v);
xen/include/xen/sched.h +1 -0
@@ -871,6 +871,7 @@ struct cpupool *cpupool_get_by_id(int poolid);void cpupool_put (struct cpupool *pool);int cpupool_add_domain (struct domain *d,int poolid);void cpupool_rm_domain (struct domain *d); +int cpupool_move_domain (struct domain *d,struct cpupool *c);int cpupool_do_sysctl (struct xen_sysctl_cpupool_op *op);void schedule_dump (struct cpupool *c);extern void dump_runq (unsigned char key);
Signature · 1 line
2.1.2
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Hi again,
Quoted 12 lines · Dietmar Hahn
Hi list,
When creating a cpupool, starting and destroying a guest within this pool, then removing this pool doesn't work because of EBUSY.
It seems the cause of this behavior is the commit
bac6334b51d9bcfe57ecf4a4cb5288348fcf044a.In
domain_kill()the functionsched_move_domain()gets called changing thed->cpupoolpointer to the new cpupool without incrementing/decrementing the counters "n_dom" of the new/old cpupool.
Quoted 6 lines
This leads to decrementing the wrong
cpupool0->n_domcounter whencpupool_rm_domain()gets called at the end and my own cpupool can't be destroyed becausen_dom= 1!I don't have a fast patch because I'am not enough familiar with the code this time but I think it should be fixed for 4.5.
Please discard previous patch, try this one.
Juergen
Quoted 1 line
From
629a7fe8ed07a13304d9378d357420ec885f59e3Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Tue, 11 Nov 2014 15:03:33 +0100
Subject: [PATCH] Adjust number of domains in cpupools when destroying domain
Commit bac6334b51d9bcfe57ecf4a4cb5288348fcf044a (move domain to cpupool0 before destroying it) introduced an error in the accounting of cpupools regarding the number of domains. The number of domains is nor adjusted when a domain is moved to cpupool0 in kill_domain().
Correct this by introducing a cpupool function doing the move instead of open coding it by calling sched_move_domain().
--- xen/common/cpupool.c | 47 +++++++++++++++++++++++++++++++++-------------- xen/common/domain.c | 2 +- xen/include/xen/sched.h | 1 + 3 files changed, 35 insertions(+), 15 deletions(-)
xen/common/cpupool.c +33 -14
@@ -225,6 +225,35 @@ static int cpupool_destroy(struct cpupool *c) }/* +* Move domain to another cpupool +*/ +static int cpupool_move_domain_unlocked (struct domain *d,struct cpupool *c) +{ +int ret; + + d->cpupool->n_dom--; + ret =sched_move_domain (d, c); +if ( ret ) + d->cpupool->n_dom++; +else + c->n_dom++; + +return ret; +} +int cpupool_move_domain (struct domain *d,struct cpupool *c) +{ +int ret; + +spin_lock (&cpupool_lock); + + ret =cpupool_move_domain_unlocked (d, c); + +spin_unlock (&cpupool_lock); + +return ret; +} + +/* * assign a specific cpu to a cpupool * cpupool_lock must be held */
@@ -338,14 +367,9 @@ static int cpupool_unassign_cpu(struct cpupool *c, unsigned int cpu) ret = -EBUSY ;break ; } - c->n_dom--; - ret =sched_move_domain (d, cpupool0); + ret =cpupool_move_domain_unlocked (d, cpupool0);if ( ret ) - { - c->n_dom++;break ; - } - cpupool0->n_dom++; }rcu_read_unlock (&domlist_read_lock);if ( ret )
@@ -613,16 +637,11 @@ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op) d->domain_id, op->cpupool_id); ret = -ENOENT ;spin_lock (&cpupool_lock); + c =cpupool_find_by_id (op->cpupool_id);if ( (c !=NULL ) &&cpumask_weight (c->cpu_valid) ) - { - d->cpupool->n_dom--; - ret =sched_move_domain (d, c); -if ( ret ) - d->cpupool->n_dom++; -else - c->n_dom++; - } + ret =cpupool_move_domain_unlocked (d, c); +spin_unlock (&cpupool_lock);cpupool_dprintk ("cpupool move_domain(dom=%d)->pool=%d ret %d\n" , d->domain_id, op->cpupool_id, ret);
xen/common/domain.c +1 -1
@@ -621,7 +621,7 @@ int domain_kill(struct domain *d) rc = -EAGAIN ;break ; } -if (sched_move_domain (d, cpupool0) ) +if (cpupool_move_domain (d, cpupool0) )return -EAGAIN ; for_each_vcpu ( d, v )unmap_vcpu_info (v);
xen/include/xen/sched.h +1 -0
@@ -871,6 +871,7 @@ struct cpupool *cpupool_get_by_id(int poolid);void cpupool_put (struct cpupool *pool);int cpupool_add_domain (struct domain *d,int poolid);void cpupool_rm_domain (struct domain *d); +int cpupool_move_domain (struct domain *d,struct cpupool *c);int cpupool_do_sysctl (struct xen_sysctl_cpupool_op *op);void schedule_dump (struct cpupool *c);extern void dump_runq (unsigned char key);
Signature · 1 line
2.1.2
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Am Dienstag 11 November 2014, 15:21:01 schrieb Juergen Gross:
Quoted 15 lines
Hi again,
Quoted 12 lines · Dietmar Hahn
Hi list,
When creating a cpupool, starting and destroying a guest within this pool, then removing this pool doesn't work because of EBUSY.
It seems the cause of this behavior is the commit
bac6334b51d9bcfe57ecf4a4cb5288348fcf044a.In
domain_kill()the functionsched_move_domain()gets called changing thed->cpupoolpointer to the new cpupool without incrementing/decrementing the counters "n_dom" of the new/old cpupool.
Quoted 8 lines
Quoted 6 lines
This leads to decrementing the wrong
cpupool0->n_domcounter whencpupool_rm_domain()gets called at the end and my own cpupool can't be destroyed becausen_dom= 1!I don't have a fast patch because I'am not enough familiar with the code this time but I think it should be fixed for 4.5.
Please discard previous patch, try this one.
Yes this patch works.
But I think in general a better solution would be to have the changing of the cpupool pointer in sched_move_domain() together with the increment/decrement of the counters but I see the locking problem.
Thanks.
Dietmar.
Quoted 3 lines
Juergen
Signature · 1 line
Company details: http://ts.fujitsu.com/imprint.html
Quoted 20 lines · Dietmar Hahn
Am Dienstag 11 November 2014, 15:21:01 schrieb Juergen Gross:
Quoted 19 lines
Hi again,
Quoted 16 lines · Dietmar Hahn
Hi list,
When creating a cpupool, starting and destroying a guest within this pool, then removing this pool doesn't work because of EBUSY.
It seems the cause of this behavior is the commit
bac6334b51d9bcfe57ecf4a4cb5288348fcf044a.In
domain_kill()the functionsched_move_domain()gets called changing thed->cpupoolpointer to the new cpupool without incrementing/decrementing the counters "n_dom" of the new/old cpupool.This leads to decrementing the wrong
cpupool0->n_domcounter whencpupool_rm_domain()gets called at the end and my own cpupool can't be destroyed becausen_dom= 1!
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I don't have a fast patch because I'am not enough familiar with the code this time but I think it should be fixed for 4.5.
Please discard previous patch, try this one.
Yes this patch works.
Thanks. Can I add your "tested-by:"?
Quoted 3 lines
But I think in general a better solution would be to have the changing of the cpupool pointer in
sched_move_domain()together with the increment/decrement of the counters but I see the locking problem.
The scheduler should never change cpupool owned data. The cpupool pointer is domain data, so changing this is okay.
Juergen
Dietmar Hahn
Tested-byAm Mittwoch 12 November 2014, 11:25:14 schrieb Juergen Gross:
Quoted 21 lines · Dietmar Hahn
Quoted 20 lines
Am Dienstag 11 November 2014, 15:21:01 schrieb Juergen Gross:
Quoted 19 lines
Hi again,
Quoted 16 lines · Dietmar Hahn
Hi list,
When creating a cpupool, starting and destroying a guest within this pool, then removing this pool doesn't work because of EBUSY.
It seems the cause of this behavior is the commit
bac6334b51d9bcfe57ecf4a4cb5288348fcf044a.In
domain_kill()the functionsched_move_domain()gets called changing thed->cpupoolpointer to the new cpupool without incrementing/decrementing the counters "n_dom" of the new/old cpupool.This leads to decrementing the wrong
cpupool0->n_domcounter whencpupool_rm_domain()gets called at the end and my own cpupool can't be destroyed becausen_dom= 1!
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I don't have a fast patch because I'am not enough familiar with the code this time but I think it should be fixed for 4.5.
Please discard previous patch, try this one.
Yes this patch works.
Thanks. Can I add your "tested-by:"?
Sorry forgot it!
Quoted 17 lines
Quoted 4 lines
But I think in general a better solution would be to have the changing of the cpupool pointer in
sched_move_domain()together with the increment/decrement of the counters but I see the locking problem.The scheduler should never change cpupool owned data. The cpupool pointer is domain data, so changing this is okay.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Signature · 1 line
Company details: http://ts.fujitsu.com/imprint.html