Skip to contentSkip to conversation

btrfs: Fix a bug in try_release_subpage_extent_buffer()

PATCH In review Bart Van Assche 3 participants 3 messages Feb 25 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Fix a bug in try_release_subpage_extent_buffer()

Call rcu_read_lock() before exiting the loop in try_release_subpage_extent_buffer() because there is a rcu_read_unlock() call past the loop. This has been detected by the Clang thread-safety analyzer. Compile-tested only.

Cc Boris Burkov <[email protected]>
Cc Qu Wenruo <[email protected]>
Cc Leo Martins <[email protected]>
Cc Chris Mason <[email protected]>
Cc David Sterba <[email protected]>
Fixes ad580dfa388f ("btrfs: fix subpage deadlock in try_release_subpage_extent_buffer()")
---
 fs/btrfs/extent_io.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/extent_io.c +1 -0
index 744a1fff6eef..5f97a3d2a8d7 100644
@@ -4507,6 +4507,7 @@ static int try_release_subpage_extent_buffer(struct folio *folio)
 		 */
 		if (!test_and_clear_bit(EXTENT_BUFFER_TREE_REF, &eb->bflags)) {
 			spin_unlock(&eb->refs_lock);
+			rcu_read_lock();
 			break;
 		}
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Bart Van Assche

Call rcu_read_lock() before exiting the loop in try_release_subpage_extent_buffer() because there is a rcu_read_unlock() call past the loop. This has been detected by the Clang thread-safety analyzer. Compile-tested only.

Quoted 8 lines
Cc Boris Burkov <[email protected]>
Cc Qu Wenruo <[email protected]>
Cc Leo Martins <[email protected]>
Cc Chris Mason <[email protected]>
Cc David Sterba <[email protected]>
Fixes ad580dfa388f ("btrfs: fix subpage deadlock in try_release_subpage_extent_buffer()")

Minor modification to follow our standard (e.g. no upper case after "btrfs: ", remove overblown CCs), and pushed to for-next branch.

Thanks,
Qu

Quoted 16 lines
---
  fs/btrfs/extent_io.c | 1 +
  1 file changed, 1 insertion(+)
fs/btrfs/extent_io.c +1 -0
index 744a1fff6eef..5f97a3d2a8d7 100644
@@ -4507,6 +4507,7 @@ static int try_release_subpage_extent_buffer(struct folio *folio)
  		 */
  		if (!test_and_clear_bit(EXTENT_BUFFER_TREE_REF, &eb->bflags)) {
  			spin_unlock(&eb->refs_lock);
+			rcu_read_lock();
  			break;
  		}
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Bart Van Assche
Quoted 11 lines · Bart Van Assche

Call rcu_read_lock() before exiting the loop in try_release_subpage_extent_buffer() because there is a rcu_read_unlock() call past the loop. This has been detected by the Clang thread-safety analyzer. Compile-tested only.

Cc Boris Burkov <[email protected]>
Cc Qu Wenruo <[email protected]>
Cc Leo Martins <[email protected]>
Cc Chris Mason <[email protected]>
Cc David Sterba <[email protected]>

LGTM, thank you.

Quoted 18 lines
Fixes ad580dfa388f ("btrfs: fix subpage deadlock in try_release_subpage_extent_buffer()")
---
 fs/btrfs/extent_io.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/extent_io.c +1 -0
index 744a1fff6eef..5f97a3d2a8d7 100644
@@ -4507,6 +4507,7 @@ static int try_release_subpage_extent_buffer(struct folio *folio)
 		 */
 		if (!test_and_clear_bit(EXTENT_BUFFER_TREE_REF, &eb->bflags)) {
 			spin_unlock(&eb->refs_lock);
+			rcu_read_lock();
 			break;
 		}