]> xenbits.xensource.com Git - xen.git/commit
sched: fix race between sched_move_domain() and vcpu_wake()
authorDavid Vrabel <david.vrabel@citrix.com>
Mon, 14 Oct 2013 06:58:31 +0000 (08:58 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 14 Oct 2013 06:58:31 +0000 (08:58 +0200)
commitef55257bc81204e34691f1c2aa9e01f2d0768bdd
treed969d28a0616e81cbfc240c07eeee998ebde2c6a
parenteedd60391610629b4e8a2e8278b857ff884f750d
sched: fix race between sched_move_domain() and vcpu_wake()

From: David Vrabel <david.vrabel@citrix.com>

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@citrix.com>
Acked-by: Juergen Gross <juergen.gross@ts.fujitsu.com>
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@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
xen/common/schedule.c