From: Dario Faggioli Date: Thu, 24 Mar 2016 14:56:56 +0000 (+0100) Subject: sched: fix locking when allocating an RTDS pCPU X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~1500 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8686d2a3f6fef8653580a649ec9c94e879eee35f;p=xen.git sched: fix locking when allocating an RTDS pCPU as doing that include changing the scheduler lock mapping for the pCPU itself, and the correct way of doing that is: - take the lock that the pCPU is using right now (which may be the lock of another scheduler); - change the mapping of the lock to the RTDS one; - release the lock (the one that has actually been taken!) Signed-off-by: Dario Faggioli Reviewed-by: Meng Xu Reviewed-by: George Dunlap --- diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index c896a6f83e..d98bfb606b 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -653,11 +653,16 @@ static void * rt_alloc_pdata(const struct scheduler *ops, int cpu) { struct rt_private *prv = rt_priv(ops); + spinlock_t *old_lock; unsigned long flags; - spin_lock_irqsave(&prv->lock, flags); + /* Move the scheduler lock to our global runqueue lock. */ + old_lock = pcpu_schedule_lock_irqsave(cpu, &flags); + per_cpu(schedule_data, cpu).schedule_lock = &prv->lock; - spin_unlock_irqrestore(&prv->lock, flags); + + /* _Not_ pcpu_schedule_unlock(): per_cpu().schedule_lock changed! */ + spin_unlock_irqrestore(old_lock, flags); if ( !alloc_cpumask_var(&_cpumask_scratch[cpu]) ) return NULL;