[PATCH] btrfs: remove unnecessary RCU protection in clear_incompat_bg_bits

Jiasheng Jiang posted 1 patch 3 weeks ago
fs/btrfs/block-group.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] btrfs: remove unnecessary RCU protection in clear_incompat_bg_bits
Posted by Jiasheng Jiang 3 weeks ago
The function clear_incompat_bg_bits() currently uses
list_for_each_entry_rcu() to iterate over the fs_info->space_info list
without holding the RCU read lock.

When CONFIG_PROVE_RCU_LIST is enabled, this triggers a false positive
lockdep warning because the internal check inside the RCU iterator fails:

  WARNING: suspicious RCU usage
  -----------------------------
  fs/btrfs/block-group.c:1014 suspicious rcu_dereference_check() usage!

  other info that might help us debug this:

  rcu_scheduler_active = 2, debug_locks = 1
  1 lock held by ...:
   #0: ... (sb_internal_sem){.+.+}-{0:0}, at: start_transaction+0x...

As established in commit 728049050012 ("btrfs: kill the RCU protection
for fs_info->space_info"), the space_info list is stable (initialized
upon mount and destroyed during unmount). RCU protection is unnecessary.

Fix this by switching to the standard list_for_each_entry() iterator,
which silences the warning.

Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 fs/btrfs/block-group.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 08b14449fabe..d2cb26f130eb 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1011,7 +1011,7 @@ static void clear_incompat_bg_bits(struct btrfs_fs_info *fs_info, u64 flags)
 		struct list_head *head = &fs_info->space_info;
 		struct btrfs_space_info *sinfo;
 
-		list_for_each_entry_rcu(sinfo, head, list) {
+		list_for_each_entry(sinfo, head, list) {
 			down_read(&sinfo->groups_sem);
 			if (!list_empty(&sinfo->block_groups[BTRFS_RAID_RAID5]))
 				found_raid56 = true;
-- 
2.25.1
Re: [PATCH] btrfs: remove unnecessary RCU protection in clear_incompat_bg_bits
Posted by Boris Burkov 3 weeks ago
On Fri, Jan 16, 2026 at 04:02:56PM +0000, Jiasheng Jiang wrote:
> The function clear_incompat_bg_bits() currently uses
> list_for_each_entry_rcu() to iterate over the fs_info->space_info list
> without holding the RCU read lock.
> 
> When CONFIG_PROVE_RCU_LIST is enabled, this triggers a false positive
> lockdep warning because the internal check inside the RCU iterator fails:
> 
>   WARNING: suspicious RCU usage
>   -----------------------------
>   fs/btrfs/block-group.c:1014 suspicious rcu_dereference_check() usage!
> 
>   other info that might help us debug this:
> 
>   rcu_scheduler_active = 2, debug_locks = 1
>   1 lock held by ...:
>    #0: ... (sb_internal_sem){.+.+}-{0:0}, at: start_transaction+0x...
> 
> As established in commit 728049050012 ("btrfs: kill the RCU protection
> for fs_info->space_info"), the space_info list is stable (initialized
> upon mount and destroyed during unmount). RCU protection is unnecessary.
> 
> Fix this by switching to the standard list_for_each_entry() iterator,
> which silences the warning.
> 

This version looks good to me, thanks.
Reviewed-by: Boris Burkov <boris@bur.io>

> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
> ---
>  fs/btrfs/block-group.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 08b14449fabe..d2cb26f130eb 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -1011,7 +1011,7 @@ static void clear_incompat_bg_bits(struct btrfs_fs_info *fs_info, u64 flags)
>  		struct list_head *head = &fs_info->space_info;
>  		struct btrfs_space_info *sinfo;
>  
> -		list_for_each_entry_rcu(sinfo, head, list) {
> +		list_for_each_entry(sinfo, head, list) {
>  			down_read(&sinfo->groups_sem);
>  			if (!list_empty(&sinfo->block_groups[BTRFS_RAID_RAID5]))
>  				found_raid56 = true;
> -- 
> 2.25.1
>