(V2) Avoid stale pointer when moving domain to another cpupool
PATCH 1/1 (V2) Avoid stale pointer when moving domain to another cpupool
When a domain is moved to another cpupool the scheduler private data pointers in vcpu and domain structures must never point to an already freed memory area.
While at it, simplify sched_init_vcpu() by using DOM2OP instead VCPU2OP.
Changes since V1:
- don't use an an own loop for freeing vcpu_data
- free old domain data after unpausing the domain
- simplify sched_init_vcpu (DOM2OP instead VCPU2OP)
1 file changed, 14 insertions(+), 6 deletions(-)
xen/common/schedule.c | 20 ++++++++++++++------
# HG changeset patch
# User Juergen Gross <[email protected]> # Date 1361958197 -3600
# Node ID 04071eb1f2d29de3497f88b860b0584ca25e284e
# Parent 1d8c65aee03eaf15ce8ee50deb781b4308302b77 (V2) Avoid stale pointer when moving domain to another cpupool
When a domain is moved to another cpupool the scheduler private data pointers in vcpu and domain structures must never point to an already freed memory area.
While at it, simplify sched_init_vcpu() by using DOM2OP instead VCPU2OP.
Changes since V1:
- don't use an an own loop for freeing vcpu_data
- free old domain data after unpausing the domain
- simplify sched_init_vcpu (DOM2OP instead VCPU2OP)
xen/common/schedule.c +14 -6
@@ -220,7 +220,7 @@ int sched_init_vcpu(struct vcpu *v, unsiif ( v->sched_priv ==NULL )return 1 ; -SCHED_OP (VCPU2OP (v), insert_vcpu, v); +SCHED_OP (DOM2OP (d), insert_vcpu, v);return 0 ; }
@@ -231,6 +231,9 @@ int sched_move_domain(struct domain *d,unsigned int new_p;void **vcpu_priv;void *domdata; +void *vcpudata; +struct scheduler *old_ops; +void *old_domdata; domdata =SCHED_OP (c->sched, alloc_domdata, d);if ( domdata ==NULL )
@@ -261,14 +264,13 @@ int sched_move_domain(struct domain *d,domain_pause (d); + old_ops =DOM2OP (d); + old_domdata = d->sched_priv; + for_each_vcpu ( d, v ) { -SCHED_OP (VCPU2OP (v), remove_vcpu, v); -SCHED_OP (VCPU2OP (v), free_vdata, v->sched_priv); - v->sched_priv =NULL ; +SCHED_OP (old_ops, remove_vcpu, v); } - -SCHED_OP (DOM2OP (d), free_domdata, d->sched_priv); d->cpupool = c; d->sched_priv = domdata;
@@ -276,6 +278,8 @@ int sched_move_domain(struct domain *d, new_p =cpumask_first (c->cpu_valid); for_each_vcpu ( d, v ) { + vcpudata = v->sched_priv; +migrate_timer (&v->periodic_timer, new_p);migrate_timer (&v->singleshot_timer, new_p);migrate_timer (&v->poll_timer, new_p);
@@ -288,11 +292,15 @@ int sched_move_domain(struct domain *d, new_p =cpumask_cycle (new_p, c->cpu_valid);SCHED_OP (c->sched, insert_vcpu, v); + +SCHED_OP (old_ops, free_vdata, vcpudata); }domain_update_node_affinity (d);domain_unpause (d); + +SCHED_OP (old_ops, free_domdata, old_domdata);xfree (vcpu_priv);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Juergen Gross
When a domain is moved to another cpupool the scheduler private data pointers in vcpu and domain structures must never point to an already freed memory area.
Quoted 8 lines
While at it, simplify
sched_init_vcpu()by using DOM2OP instead VCPU2OP.Changes since V1:
- don't use an an own loop for freeingvcpu_data
- free old domain data after unpausing the domain
- simplifysched_init_vcpu(DOM2OP instead VCPU2OP)Signed-off-by Juergen Gross <[email protected]>
Looks good to me now, but will want to be ack-ed by George.
Jan
George Dunlap
Acked-byQuoted 9 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 27.02.13 at 10:43, Juergen Gross <[email protected]>
Quoted 1 line · wrote:
When a domain is moved to another cpupool the scheduler private data
pointers
Quoted 5 lines
in vcpu and domain structures must never point to an already freed memory area.
While at it, simplify
sched_init_vcpu()by using DOM2OP instead VCPU2OP.
Quoted 9 lines
Quoted 6 lines
Changes since V1:
- don't use an an own loop for freeingvcpu_data
- free old domain data after unpausing the domain
- simplifysched_init_vcpu(DOM2OP instead VCPU2OP)Signed-off-by Juergen Gross <[email protected]>Looks good to me now, but will want to be ack-ed by George.
Thanks Juergen.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel