[v4,0/3] btrfs: fix sleep from invalid context bug in update_qgroup_limit_item()

Message ID 20221115171709.3774614-1-chenxiaosong2@huawei.com
Headers
Series btrfs: fix sleep from invalid context bug in update_qgroup_limit_item() |

Message

ChenXiaoSong Nov. 15, 2022, 5:17 p.m. UTC
  At least 3 places might sleep in update_qgroup_limit_item(), as shown below:

  update_qgroup_limit_item
    btrfs_alloc_path
      /* allocate memory non-atomically, might sleep */
      kmem_cache_zalloc(btrfs_path_cachep, GFP_NOFS)
    btrfs_search_slot
      setup_nodes_for_search
        reada_for_balance
          btrfs_readahead_node_child
            btrfs_readahead_tree_block
              btrfs_find_create_tree_block
                alloc_extent_buffer
                  kmem_cache_zalloc
                    /* allocate memory non-atomically, might sleep */
                    kmem_cache_alloc(GFP_NOFS|__GFP_NOFAIL|__GFP_ZERO)
              read_extent_buffer_pages
                submit_extent_page
                  /* disk IO, might sleep */
                  submit_one_bio

Fix this by delaying the limit item updates until unlock the spin lock.

By the way, add might_sleep() to some places.

ChenXiaoSong (3):
  btrfs: add might_sleep() to some places in update_qgroup_limit_item()
  btrfs: qgroup: introduce btrfs_update_quoto_limit() helper
  btrfs: qgroup: fix sleep from invalid context bug in
    update_qgroup_limit_item()

 fs/btrfs/ctree.c  |  2 ++
 fs/btrfs/qgroup.c | 45 ++++++++++++++++++++++++++-------------------
 2 files changed, 28 insertions(+), 19 deletions(-)