This is a note to let you know that I've just added the patch titled btrfs: unlock extents in btrfs_zero_range in case of quota reservation errors to the 5.11-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: btrfs-unlock-extents-in-btrfs_zero_range-in-case-of-quota-reservation-errors.patch and it can be found in the queue-5.11 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 4f6a49de64fd1b1dba5229c02047376da7cf24fd Mon Sep 17 00:00:00 2001 From: Nikolay Borisov <nborisov@xxxxxxxx> Date: Tue, 23 Feb 2021 15:20:42 +0200 Subject: btrfs: unlock extents in btrfs_zero_range in case of quota reservation errors From: Nikolay Borisov <nborisov@xxxxxxxx> commit 4f6a49de64fd1b1dba5229c02047376da7cf24fd upstream. If btrfs_qgroup_reserve_data returns an error (i.e quota limit reached) the handling logic directly goes to the 'out' label without first unlocking the extent range between lockstart, lockend. This results in deadlocks as other processes try to lock the same extent. Fixes: a7f8b1c2ac21 ("btrfs: file: reserve qgroup space after the hole punch range is locked") CC: stable@xxxxxxxxxxxxxxx # 5.10+ Reviewed-by: Qu Wenruo <wqu@xxxxxxxx> Signed-off-by: Nikolay Borisov <nborisov@xxxxxxxx> Reviewed-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/btrfs/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3264,8 +3264,11 @@ reserve_space: goto out; ret = btrfs_qgroup_reserve_data(BTRFS_I(inode), &data_reserved, alloc_start, bytes_to_reserve); - if (ret) + if (ret) { + unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, + lockend, &cached_state); goto out; + } ret = btrfs_prealloc_file_range(inode, mode, alloc_start, alloc_end - alloc_start, i_blocksize(inode), Patches currently in stable-queue which might be from nborisov@xxxxxxxx are queue-5.11/btrfs-fix-race-between-extent-freeing-allocation-when-using-bitmaps.patch queue-5.11/btrfs-free-correct-amount-of-space-in-btrfs_delayed_inode_reserve_metadata.patch queue-5.11/btrfs-unlock-extents-in-btrfs_zero_range-in-case-of-quota-reservation-errors.patch