Skip to content

Commit b18f3b6

Browse files
naotakdave
authored andcommitted
btrfs: zoned: fix lock ordering in btrfs_zone_activate()
The btrfs CI reported a lockdep warning as follows by running generic generic/129. WARNING: possible circular locking dependency detected 6.7.0-rc5+ #1 Not tainted ------------------------------------------------------ kworker/u5:5/793427 is trying to acquire lock: ffff88813256d028 (&cache->lock){+.+.}-{2:2}, at: btrfs_zone_finish_one_bg+0x5e/0x130 but task is already holding lock: ffff88810a23a318 (&fs_info->zone_active_bgs_lock){+.+.}-{2:2}, at: btrfs_zone_finish_one_bg+0x34/0x130 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (&fs_info->zone_active_bgs_lock){+.+.}-{2:2}: ... -> #0 (&cache->lock){+.+.}-{2:2}: ... This is because we take fs_info->zone_active_bgs_lock after a block_group's lock in btrfs_zone_activate() while doing the opposite in other places. Fix the issue by expanding the fs_info->zone_active_bgs_lock's critical section and taking it before a block_group's lock. Fixes: a7e1ac7 ("btrfs: zoned: reserve zones for an active metadata/system block group") CC: stable@vger.kernel.org # 6.6 Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent d967c91 commit b18f3b6

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

fs/btrfs/zoned.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,7 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
20722072

20732073
map = block_group->physical_map;
20742074

2075+
spin_lock(&fs_info->zone_active_bgs_lock);
20752076
spin_lock(&block_group->lock);
20762077
if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags)) {
20772078
ret = true;
@@ -2084,7 +2085,6 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
20842085
goto out_unlock;
20852086
}
20862087

2087-
spin_lock(&fs_info->zone_active_bgs_lock);
20882088
for (i = 0; i < map->num_stripes; i++) {
20892089
struct btrfs_zoned_device_info *zinfo;
20902090
int reserved = 0;
@@ -2104,36 +2104,32 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
21042104
*/
21052105
if (atomic_read(&zinfo->active_zones_left) <= reserved) {
21062106
ret = false;
2107-
spin_unlock(&fs_info->zone_active_bgs_lock);
21082107
goto out_unlock;
21092108
}
21102109

21112110
if (!btrfs_dev_set_active_zone(device, physical)) {
21122111
/* Cannot activate the zone */
21132112
ret = false;
2114-
spin_unlock(&fs_info->zone_active_bgs_lock);
21152113
goto out_unlock;
21162114
}
21172115
if (!is_data)
21182116
zinfo->reserved_active_zones--;
21192117
}
2120-
spin_unlock(&fs_info->zone_active_bgs_lock);
21212118

21222119
/* Successfully activated all the zones */
21232120
set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags);
21242121
spin_unlock(&block_group->lock);
21252122

21262123
/* For the active block group list */
21272124
btrfs_get_block_group(block_group);
2128-
2129-
spin_lock(&fs_info->zone_active_bgs_lock);
21302125
list_add_tail(&block_group->active_bg_list, &fs_info->zone_active_bgs);
21312126
spin_unlock(&fs_info->zone_active_bgs_lock);
21322127

21332128
return true;
21342129

21352130
out_unlock:
21362131
spin_unlock(&block_group->lock);
2132+
spin_unlock(&fs_info->zone_active_bgs_lock);
21372133
return ret;
21382134
}
21392135

0 commit comments

Comments
 (0)