Skip to content

Commit 7811d6f

Browse files
committed
spinlock: mark spinlock unlocked before releasing the lock
The spin_unlock()/spin_unlock_irqrestore() path cleared the holder after spin_unlock_notrace() had already released the lock value. On SMP this leaves a window in which another thread may acquire the lock (see lock == unlocked) while info->holder still refers to the previous owner, so mark_locked() misreports a relock. Reorder to match the downstream semantics: mark the spinlock as unlocked first, then release the lock value, then emit the trace note. The recursive (rspin) unlock path already used the correct order. This is a series-original fix: it restores the mark-before-release ordering of the original downstream implementation (regression against the merged debug-tools series). Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
1 parent 237f0b6 commit 7811d6f

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎include/nuttx/spinlock.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,17 @@ spin_unlock_notrace(FAR volatile spinlock_t *lock)
408408
#ifdef CONFIG_SPINLOCK
409409
static inline_function void spin_unlock(FAR volatile spinlock_t *lock)
410410
{
411+
/* Mark the spinlock has been unlocked */
412+
413+
spinlock_mark_unlocked(&lock->info);
414+
411415
/* Unlock without trace note */
412416

413417
spin_unlock_notrace(lock);
414418

415419
/* Notify that we are unlocking the spinlock */
416420

417421
sched_note_spinlock_unlock(lock);
418-
419-
/* Mark the spinlock has been unlocked */
420-
421-
spinlock_mark_unlocked(&lock->info);
422422
}
423423
#else
424424
# define spin_unlock(lock) ((void)(lock))
@@ -1033,17 +1033,17 @@ void spin_unlock_irqrestore_notrace(FAR volatile spinlock_t *lock,
10331033
static inline_function
10341034
void spin_unlock_irqrestore(FAR volatile spinlock_t *lock, irqstate_t flags)
10351035
{
1036+
/* Mark the spinlock has been unlocked */
1037+
1038+
spinlock_mark_unlocked(&lock->info);
1039+
10361040
/* Unlock without trace note */
10371041

10381042
spin_unlock_notrace(lock);
10391043

10401044
/* Notify that we are unlocking the spinlock */
10411045

10421046
sched_note_spinlock_unlock(lock);
1043-
1044-
/* Mark the spinlock has been unlocked */
1045-
1046-
spinlock_mark_unlocked(&lock->info);
10471047
irq_restore(flags);
10481048
}
10491049
#else

0 commit comments

Comments
 (0)