Skip to content

Commit 0146da0

Browse files
committed
Merge tag 'locking_urgent_for_v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking fix from Borislav Petkov: "Fix ordering in the queued writer lock's slowpath" * tag 'locking_urgent_for_v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: locking/qrwlock: Fix ordering in queued_write_lock_slowpath()
2 parents 682b26b + 84a24bf commit 0146da0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/locking/qrwlock.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ EXPORT_SYMBOL(queued_read_lock_slowpath);
6060
*/
6161
void queued_write_lock_slowpath(struct qrwlock *lock)
6262
{
63+
int cnts;
64+
6365
/* Put the writer into the wait queue */
6466
arch_spin_lock(&lock->wait_lock);
6567

@@ -73,9 +75,8 @@ void queued_write_lock_slowpath(struct qrwlock *lock)
7375

7476
/* When no more readers or writers, set the locked flag */
7577
do {
76-
atomic_cond_read_acquire(&lock->cnts, VAL == _QW_WAITING);
77-
} while (atomic_cmpxchg_relaxed(&lock->cnts, _QW_WAITING,
78-
_QW_LOCKED) != _QW_WAITING);
78+
cnts = atomic_cond_read_relaxed(&lock->cnts, VAL == _QW_WAITING);
79+
} while (!atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED));
7980
unlock:
8081
arch_spin_unlock(&lock->wait_lock);
8182
}

0 commit comments

Comments
 (0)