Commit 6e7ca09b authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: Fix deadlock caused by missing memory barrier

Commit 06297d8c ("btrfs: switch extent_buffer blocking_writers from
atomic to int") changed the type of blocking_writers but forgot to
adjust relevant code in btrfs_tree_unlock by converting the
smp_mb__after_atomic to smp_mb.  This opened up the possibility of a
deadlock due to re-ordering of setting blocking_writers and
checking/waking up the waiter. This particular lockup is explained in a
comment above waitqueue_active() function.

Fix it by converting the memory barrier to a full smp_mb, accounting
for the fact that blocking_writers is a simple integer.

Fixes: 06297d8c ("btrfs: switch extent_buffer blocking_writers from atomic to int")
Tested-by: default avatarJohannes Thumshirn <jthumshirn@suse.com>
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 373c3b80
...@@ -346,9 +346,12 @@ void btrfs_tree_unlock(struct extent_buffer *eb) ...@@ -346,9 +346,12 @@ void btrfs_tree_unlock(struct extent_buffer *eb)
if (blockers) { if (blockers) {
btrfs_assert_no_spinning_writers(eb); btrfs_assert_no_spinning_writers(eb);
eb->blocking_writers--; eb->blocking_writers--;
/* Use the lighter barrier after atomic */ /*
smp_mb__after_atomic(); * We need to order modifying blocking_writers above with
cond_wake_up_nomb(&eb->write_lock_wq); * actually waking up the sleepers to ensure they see the
* updated value of blocking_writers
*/
cond_wake_up(&eb->write_lock_wq);
} else { } else {
btrfs_assert_spinning_writers_put(eb); btrfs_assert_spinning_writers_put(eb);
write_unlock(&eb->lock); write_unlock(&eb->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment