btrfs: hold space_info->lock when clearing periodic reclaim ready
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().
--- fs/btrfs/space-info.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/space-info.c +4 -1
@@ -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
Quoted 5 lines · Sun YangKai
btrfs_set_periodic_reclaim_ready()requiresspace_info->lockto be held, as enforced bylockdep_assert_held(). However,btrfs_reclaim_sweep()was calling it afterdo_reclaim_sweep()returns, at which pointspace_info->lockis no longer held.
Quoted 7 lines
Fix this by explicitly acquiring
space_info->lockbefore clearing the periodic reclaim ready flag inbtrfs_reclaim_sweep().Fixes 19eff93dc738 ("btrfs: fix periodic reclaim condition")Reported-by Chris Mason <[email protected]>Signed-off-by Sun YangKai <[email protected]>
Quoted 24 lines
--- fs/btrfs/space-info.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/btrfs/space-info.c +4
-1@@ -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
Quoted 11 lines · Sun YangKai
btrfs_set_periodic_reclaim_ready()requiresspace_info->lockto be held, as enforced bylockdep_assert_held(). However,btrfs_reclaim_sweep()was calling it afterdo_reclaim_sweep()returns, at which pointspace_info->lockis no longer held.Fix this by explicitly acquiring
space_info->lockbefore clearing the periodic reclaim ready flag inbtrfs_reclaim_sweep().Fixes 19eff93dc738 ("btrfs: fix periodic reclaim condition")Reported-by Chris Mason <[email protected]>
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
Signed-off-by Sun YangKai <[email protected]>
Added to for-next, thanks.
Quoted 9 lines · David Sterba
Quoted 8 lines · Sun YangKai
btrfs_set_periodic_reclaim_ready()requiresspace_info->lockto be held, as enforced bylockdep_assert_held(). However,btrfs_reclaim_sweep()was calling it afterdo_reclaim_sweep()returns, at which pointspace_info->lockis no longer held.Fix this by explicitly acquiring
space_info->lockbefore clearing the periodic reclaim ready flag inbtrfs_reclaim_sweep().
Quoted 6 lines
Quoted 3 lines
Fixes 19eff93dc738 ("btrfs: fix periodic reclaim condition")Reported-by Chris Mason <[email protected]>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
Signed-off-by Sun YangKai <[email protected]>Added to for-next, thanks.