Skip to contentSkip to conversation

btrfs: hold space_info->lock when clearing periodic reclaim ready

PATCH In review Sun YangKai 3 participants 4 messages Feb 9 – Feb 26 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: hold space_info->lock when clearing periodic reclaim ready

btrfs_set_periodic_reclaim_ready() requires space_info->lock to be held, as enforced by lockdep_assert_held(). However, btrfs_reclaim_sweep() was calling it after do_reclaim_sweep() returns, at which point space_info->lock is no longer held.

Fix this by explicitly acquiring space_info->lock before clearing the periodic reclaim ready flag in btrfs_reclaim_sweep().

Fixes 19eff93dc738 ("btrfs: fix periodic reclaim condition")
---
 fs/btrfs/space-info.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/space-info.c +4 -1
index 1dd65fae6349..931f0dc02b95 100644
@@ -2205,8 +2205,11 @@ void btrfs_reclaim_sweep(const struct btrfs_fs_info *fs_info)
 		if (!btrfs_should_periodic_reclaim(space_info))
 			continue;
 		for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) {
-			if (do_reclaim_sweep(space_info, raid))
+			if (do_reclaim_sweep(space_info, raid)) {
+				spin_lock(&space_info->lock);
 				btrfs_set_periodic_reclaim_ready(space_info, false);
+				spin_unlock(&space_info->lock);
+			}
 		}
 	}
 }
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Sun YangKai

btrfs_set_periodic_reclaim_ready() requires space_info->lock to be held, as enforced by lockdep_assert_held(). However, btrfs_reclaim_sweep() was calling it after do_reclaim_sweep() returns, at which point space_info->lock is no longer held.

Quoted 7 lines

Fix this by explicitly acquiring space_info->lock before clearing the periodic reclaim ready flag in btrfs_reclaim_sweep().

Fixes 19eff93dc738 ("btrfs: fix periodic reclaim condition")
Quoted 24 lines
---
 fs/btrfs/space-info.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/space-info.c +4 -1
index 1dd65fae6349..931f0dc02b95 100644
@@ -2205,8 +2205,11 @@ void btrfs_reclaim_sweep(const struct btrfs_fs_info *fs_info)
 		if (!btrfs_should_periodic_reclaim(space_info))
 			continue;
 		for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) {
-			if (do_reclaim_sweep(space_info, raid))
+			if (do_reclaim_sweep(space_info, raid)) {
+				spin_lock(&space_info->lock);
 				btrfs_set_periodic_reclaim_ready(space_info, false);
+				spin_unlock(&space_info->lock);
+			}
 		}
 	}
 }
Signature · 1 line
2.52.0
#2 lore raw
In reply to Sun YangKai
Quoted 11 lines · Sun YangKai

btrfs_set_periodic_reclaim_ready() requires space_info->lock to be held, as enforced by lockdep_assert_held(). However, btrfs_reclaim_sweep() was calling it after do_reclaim_sweep() returns, at which point space_info->lock is no longer held.

Fix this by explicitly acquiring space_info->lock before clearing the periodic reclaim ready flag in btrfs_reclaim_sweep().

Fixes 19eff93dc738 ("btrfs: fix periodic reclaim condition")

Please use Link: for the original report unless the tag is known to be used for some sort of automation, e.g. what syzbot does.

Quoted 1 line

Added to for-next, thanks.

#3 lore raw
Quoted 9 lines · David Sterba
Quoted 8 lines · Sun YangKai

btrfs_set_periodic_reclaim_ready() requires space_info->lock to be held, as enforced by lockdep_assert_held(). However, btrfs_reclaim_sweep() was calling it after do_reclaim_sweep() returns, at which point space_info->lock is no longer held.

Fix this by explicitly acquiring space_info->lock before clearing the periodic reclaim ready flag in btrfs_reclaim_sweep().

Quoted 6 lines
Quoted 3 lines
Fixes 19eff93dc738 ("btrfs: fix periodic reclaim condition")

Please use Link: for the original report unless the tag is known to be used for some sort of automation, e.g. what syzbot does.

Got it. Thanks a lot :)

Quoted 4 lines
Quoted 2 lines

Added to for-next, thanks.