Skip to content

Commit

Permalink
Merge tag 'locking_urgent_for_v5.12' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…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()
  • Loading branch information
Linus Torvalds committed Apr 25, 2021
2 parents 682b26b + 84a24bf commit 0146da0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kernel/locking/qrwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ EXPORT_SYMBOL(queued_read_lock_slowpath);
*/
void queued_write_lock_slowpath(struct qrwlock *lock)
{
int cnts;

/* Put the writer into the wait queue */
arch_spin_lock(&lock->wait_lock);

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

/* When no more readers or writers, set the locked flag */
do {
atomic_cond_read_acquire(&lock->cnts, VAL == _QW_WAITING);
} while (atomic_cmpxchg_relaxed(&lock->cnts, _QW_WAITING,
_QW_LOCKED) != _QW_WAITING);
cnts = atomic_cond_read_relaxed(&lock->cnts, VAL == _QW_WAITING);
} while (!atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED));
unlock:
arch_spin_unlock(&lock->wait_lock);
}
Expand Down

0 comments on commit 0146da0

Please sign in to comment.