]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: add RCU locks around block group initialization
authorMadhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
Fri, 6 Mar 2020 06:52:43 +0000 (12:22 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Apr 2020 08:36:34 +0000 (10:36 +0200)
[ Upstream commit 1038520766ebec0f18a9cbe3f7965e0849d85f3a ]

The space_info list is normally RCU protected and should be traversed
with rcu_read_lock held. There's a warning

  [29.104756] WARNING: suspicious RCU usage
  [29.105046] 5.6.0-rc4-next-20200305 #1 Not tainted
  [29.105231] -----------------------------
  [29.105401] fs/btrfs/block-group.c:2011 RCU-list traversed in non-reader section!!

pointing out that the locking is missing in btrfs_read_block_groups.
However this is not necessary as the list traversal happens at mount
time when there's no other thread potentially accessing the list.

To fix the warning and for consistency let's add the RCU lock/unlock,
the code won't be affected much as it's doing some lightweight
operations.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/block-group.c

index 7dcfa7d7632a16ce24bafe09e29b1c06305b788b..95330f40f998c48d025b9d2c41905e5e742d2714 100644 (file)
@@ -1829,6 +1829,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
                }
        }
 
+       rcu_read_lock();
        list_for_each_entry_rcu(space_info, &info->space_info, list) {
                if (!(btrfs_get_alloc_profile(info, space_info->flags) &
                      (BTRFS_BLOCK_GROUP_RAID10 |
@@ -1849,6 +1850,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
                                list)
                        inc_block_group_ro(cache, 1);
        }
+       rcu_read_unlock();
 
        btrfs_init_global_block_rsv(info);
        ret = check_chunk_block_group_mappings(info);