Skip to contentSkip to conversation

btrfs: do not call synchronize_srcu() in inode_tree_del

PATCH In review Josef Bacik 2 participants 2 messages Nov 19, 2019 – Nov 22, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: do not call synchronize_srcu() in inode_tree_del

Testing with the new fsstress uncovered a pretty nasty deadlock with lookup and snapshot deletion.

Process A
unlink
-> final iput
-> inode_tree_del

     -> synchronize_srcu(subvol_srcu)

Process B
btrfs_lookup <- srcu_read_lock() acquired here
-> btrfs_iget

    -> find inode that has I_FREEING set
      -> __wait_on_freeing_inode()

We're holding the srcu_read_lock() while doing the iget in order to make sure our fs root doesn't go away, and then we are waiting for the inode to finish freeing. However because the free'ing process is doing a synchronize_srcu() we deadlock.

Fix this by dropping the synchronize_srcu() in inode_tree_del(). We don't need people to stop accessing the fs root at this point, we're only adding our empty root to the dead roots list.

A larger much more invasive fix is forthcoming to address how we deal with fs roots, but this fixes the immediate problem.

Fixes 76dda93c6ae2 ("Btrfs: add snapshot/subvolume destroy ioctl")
---
 fs/btrfs/inode.c | 2 --
 1 file changed, 2 deletions(-)
fs/btrfs/inode.c +0 -2
index 8db7455fee38..fc0624fbe387 100644
@@ -5729,7 +5729,6 @@ static void inode_tree_add(struct inode *inode)
 
 static void inode_tree_del(struct inode *inode)
 {
-	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	struct btrfs_root *root = BTRFS_I(inode)->root;
 	int empty = 0;
 
@@ -5742,7 +5741,6 @@ static void inode_tree_del(struct inode *inode)
 	spin_unlock(&root->inode_lock);
 
 	if (empty && btrfs_root_refs(&root->root_item) == 0) {
-		synchronize_srcu(&fs_info->subvol_srcu);
 		spin_lock(&root->inode_lock);
 		empty = RB_EMPTY_ROOT(&root->inode_tree);
 		spin_unlock(&root->inode_lock);
Signature · 1 line
2.23.0
#1 lore raw
Quoted 24 lines · Josef Bacik

Testing with the new fsstress uncovered a pretty nasty deadlock with lookup and snapshot deletion.

Process A
unlink
-> final iput
-> inode_tree_del

     -> synchronize_srcu(subvol_srcu)

Process B
btrfs_lookup <- srcu_read_lock() acquired here
-> btrfs_iget

    -> find inode that has I_FREEING set
      -> __wait_on_freeing_inode()

We're holding the srcu_read_lock() while doing the iget in order to make sure our fs root doesn't go away, and then we are waiting for the inode to finish freeing. However because the free'ing process is doing a synchronize_srcu() we deadlock.

Fix this by dropping the synchronize_srcu() in inode_tree_del(). We don't need people to stop accessing the fs root at this point, we're only adding our empty root to the dead roots list.

Quoted 5 lines

A larger much more invasive fix is forthcoming to address how we deal with fs roots, but this fixes the immediate problem.

Fixes 76dda93c6ae2 ("Btrfs: add snapshot/subvolume destroy ioctl")

Added to misc-next, thanks.