[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen stable-4.2] sched: fix race between sched_move_domain() and vcpu_wake()



commit 2d6e9bf5201d9b662a04d9f007f22f06fb9c9981
Author:     David Vrabel <david.vrabel@xxxxxxxxxx>
AuthorDate: Fri Nov 15 11:34:43 2013 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri Nov 15 11:34:43 2013 +0100

    sched: fix race between sched_move_domain() and vcpu_wake()
    
    From: David Vrabel <david.vrabel@xxxxxxxxxx>
    
    sched_move_domain() changes v->processor for all the domain's VCPUs.
    If another domain, softirq etc. triggers a simultaneous call to
    vcpu_wake() (e.g., by setting an event channel as pending), then
    vcpu_wake() may lock one schedule lock and try to unlock another.
    
    vcpu_schedule_lock() attempts to handle this but only does so for the
    window between reading the schedule_lock from the per-CPU data and the
    spin_lock() call.  This does not help with sched_move_domain()
    changing v->processor between the calls to vcpu_schedule_lock() and
    vcpu_schedule_unlock().
    
    Fix the race by taking the schedule_lock for v->processor in
    sched_move_domain().
    
    Signed-off-by: David Vrabel <david.vrabel@xxxxxxxxxx>
    Acked-by: Juergen Gross <juergen.gross@xxxxxxxxxxxxxx>
    
    Use vcpu_schedule_lock_irq() (which now returns the lock) to properly
    retry the locking should the to be used lock have changed in the course
    of acquiring it (issue pointed out by George Dunlap).
    
    Add a comment explaining the state after the v->processor adjustment.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Keir Fraser <keir@xxxxxxx>
    master commit: ef55257bc81204e34691f1c2aa9e01f2d0768bdd
    master date: 2013-10-14 08:58:31 +0200
---
 xen/common/schedule.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index 3d516e6..e2c6ce7 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -275,6 +275,8 @@ int sched_move_domain(struct domain *d, struct cpupool *c)
     new_p = cpumask_first(c->cpu_valid);
     for_each_vcpu ( d, v )
     {
+        spinlock_t *lock;
+
         vcpudata = v->sched_priv;
 
         migrate_timer(&v->periodic_timer, new_p);
@@ -282,7 +284,16 @@ int sched_move_domain(struct domain *d, struct cpupool *c)
         migrate_timer(&v->poll_timer, new_p);
 
         cpumask_setall(v->cpu_affinity);
+
+        lock = vcpu_schedule_lock_irq(v);
         v->processor = new_p;
+        /*
+         * With v->processor modified we must not
+         * - make any further changes assuming we hold the scheduler lock,
+         * - use vcpu_schedule_unlock_irq().
+         */
+        spin_unlock_irq(lock);
+
         v->sched_priv = vcpu_priv[v->vcpu_id];
         evtchn_move_pirqs(v);
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.2

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.