From bb9373a802f5413880dec591a57292a877178d17 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Tue, 29 Mar 2016 17:16:23 +0200 Subject: [PATCH] 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 --- xen/common/spinlock.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) -- 2.30.2