static atomic_t spin_debug __read_mostly = ATOMIC_INIT(0);
-static void check_lock(union lock_debug *debug)
+static void check_lock(union lock_debug *debug, bool try)
{
bool irq_safe = !local_irq_is_enabled();
*
* To guard against this subtle bug we latch the IRQ safety of every
* spinlock in the system, on first use.
+ *
+ * A spin_trylock() with interrupts off is always fine, as this can't
+ * block and above deadlock scenario doesn't apply.
*/
+ if ( try && irq_safe )
+ return;
+
if ( unlikely(debug->irq_safe != irq_safe) )
{
union lock_debug seen, new = { 0 };
#else /* CONFIG_DEBUG_LOCKS */
-#define check_lock(l) ((void)0)
+#define check_lock(l, t) ((void)0)
#define check_barrier(l) ((void)0)
#define got_lock(l) ((void)0)
#define rel_lock(l) ((void)0)
spinlock_tickets_t tickets = SPINLOCK_TICKET_INC;
LOCK_PROFILE_VAR;
- check_lock(&lock->debug);
+ check_lock(&lock->debug, false);
preempt_disable();
tickets.head_tail = arch_fetch_and_add(&lock->tickets.head_tail,
tickets.head_tail);
int _spin_is_locked(spinlock_t *lock)
{
- check_lock(&lock->debug);
-
/*
* Recursive locks may be locked by another CPU, yet we return
* "false" here, making this function suitable only for use in
{
spinlock_tickets_t old, new;
- check_lock(&lock->debug);
+ check_lock(&lock->debug, true);
old = observe_lock(&lock->tickets);
if ( old.head != old.tail )
return 0;
BUILD_BUG_ON(NR_CPUS > SPINLOCK_NO_CPU);
BUILD_BUG_ON(SPINLOCK_RECURSE_BITS < 3);
- check_lock(&lock->debug);
+ check_lock(&lock->debug, true);
if ( likely(lock->recurse_cpu != cpu) )
{