From: Jan Beulich Date: Tue, 29 Mar 2016 15:16:23 +0000 (+0200) Subject: spinlock: improve spin_is_locked() for recursive locks X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~1477 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=bb9373a802f5413880dec591a57292a877178d17;p=xen.git spinlock: improve spin_is_locked() for recursive locks Recursive locks know their current owner, and since we use the function solely to determine whether a particular lock is being held by the current CPU (which so far has been an imprecise check), make actually check the owner for recusrively acquired locks. Signed-off-by: Jan Beulich Reviewed-by: Dario Faggioli Reviewed-by: Andrew Cooper Reviewed-by: Quan Xu Acked-by: Tim Deegan --- diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index a43fa84f5b..b377bb907b 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -188,7 +188,15 @@ void _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) int _spin_is_locked(spinlock_t *lock) { check_lock(&lock->debug); - return lock->tickets.head != lock->tickets.tail; + + /* + * Recursive locks may be locked by another CPU, yet we return + * "false" here, making this function suitable only for use in + * ASSERT()s and alike. + */ + return lock->recurse_cpu == SPINLOCK_NO_CPU + ? lock->tickets.head != lock->tickets.tail + : lock->recurse_cpu == smp_processor_id(); } int _spin_trylock(spinlock_t *lock)