Debug helpers such as lock profiling or the invariant pCPU assertions
must strictly be performed inside the exclusive locked region, or else
races might happen.
Note the issue was not strictly introduced by the pointed commit in
the Fixes tag, since lock stats where already incremented before the
barrier, but that commit made it more apparent as manipulating the cpu
field could happen outside of the locked regions and thus trigger the
BUG_ON on rel_lock(). This is only enabled on debug builds, and thus
releases are not affected.
Fixes: 80cba391a35 ('spinlocks: in debug builds store cpu holding the lock')
Reported-by: Igor Druzhinin <igor.druzhinin@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
cb(data);
arch_lock_relax();
}
+ arch_lock_acquire_barrier();
got_lock(&lock->debug);
LOCK_PROFILE_GOT;
- arch_lock_acquire_barrier();
}
void _spin_lock(spinlock_t *lock)
void _spin_unlock(spinlock_t *lock)
{
- arch_lock_release_barrier();
LOCK_PROFILE_REL;
rel_lock(&lock->debug);
+ arch_lock_release_barrier();
add_sized(&lock->tickets.head, 1);
arch_lock_signal();
preempt_enable();
preempt_enable();
return 0;
}
+ /*
+ * cmpxchg() is a full barrier so no need for an
+ * arch_lock_acquire_barrier().
+ */
got_lock(&lock->debug);
#ifdef CONFIG_DEBUG_LOCK_PROFILE
if (lock->profile)
lock->profile->time_locked = NOW();
#endif
- /*
- * cmpxchg() is a full barrier so no need for an
- * arch_lock_acquire_barrier().
- */
return 1;
}