Skip to content

Commit 61b85cb

Browse files
author
Kent Overstreet
committed
bcachefs: six locks: Fix lost wakeup
In percpu reader mode, trylock() for read had a lost wakeup: on failure to get the lock, we may have caused a writer to fail to get the lock, because we temporarily elevated the reader count. We need to check for waiters after decrementing the read count - not before. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 62d73df commit 61b85cb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/bcachefs/six.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ static int __do_six_trylock(struct six_lock *lock, enum six_lock_type type,
163163
this_cpu_sub(*lock->readers, !ret);
164164
preempt_enable();
165165

166-
if (!ret && (old & SIX_LOCK_WAITING_write))
167-
ret = -1 - SIX_LOCK_write;
166+
if (!ret) {
167+
smp_mb();
168+
if (atomic_read(&lock->state) & SIX_LOCK_WAITING_write)
169+
ret = -1 - SIX_LOCK_write;
170+
}
168171
} else if (type == SIX_LOCK_write && lock->readers) {
169172
if (try) {
170173
atomic_add(SIX_LOCK_HELD_write, &lock->state);

0 commit comments

Comments
 (0)