This is a note to let you know that I've just added the patch titled btrfs: fix hang on snapshot creation after RWF_NOWAIT write to the 5.7-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-fix-hang-on-snapshot-creation-after-rwf_nowait-write.patch and it can be found in the queue-5.7 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From f2cb2f39ccc30fa13d3ac078d461031a63960e5b Mon Sep 17 00:00:00 2001 From: Filipe Manana <fdmanana@xxxxxxxx> Date: Mon, 15 Jun 2020 18:46:01 +0100 Subject: btrfs: fix hang on snapshot creation after RWF_NOWAIT write From: Filipe Manana <fdmanana@xxxxxxxx> commit f2cb2f39ccc30fa13d3ac078d461031a63960e5b upstream. If we do a successful RWF_NOWAIT write we end up locking the snapshot lock of the inode, through a call to check_can_nocow(), but we never unlock it. This means the next attempt to create a snapshot on the subvolume will hang forever. Trivial reproducer: $ mkfs.btrfs -f /dev/sdb $ mount /dev/sdb /mnt $ touch /mnt/foobar $ chattr +C /mnt/foobar $ xfs_io -d -c "pwrite -S 0xab 0 64K" /mnt/foobar $ xfs_io -d -c "pwrite -N -V 1 -S 0xfe 0 64K" /mnt/foobar $ btrfs subvolume snapshot -r /mnt /mnt/snap --> hangs Fix this by unlocking the snapshot lock if check_can_nocow() returned success. Fixes: edf064e7c6fec3 ("btrfs: nowait aio support") CC: stable@xxxxxxxxxxxxxxx # 4.14+ Signed-off-by: Filipe Manana <fdmanana@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 | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1922,6 +1922,8 @@ static ssize_t btrfs_file_write_iter(str inode_unlock(inode); return -EAGAIN; } + /* check_can_nocow() locks the snapshot lock on success */ + btrfs_drew_write_unlock(&root->snapshot_lock); } current->backing_dev_info = inode_to_bdi(inode); Patches currently in stable-queue which might be from fdmanana@xxxxxxxx are queue-5.7/btrfs-fix-bytes_may_use-underflow-when-running-balance-and-scrub-in-parallel.patch queue-5.7/btrfs-fix-rwf_nowait-write-not-failling-when-we-need-to-cow.patch queue-5.7/btrfs-fix-hang-on-snapshot-creation-after-rwf_nowait-write.patch queue-5.7/btrfs-fix-failure-of-rwf_nowait-write-into-prealloc-extent-beyond-eof.patch queue-5.7/btrfs-check-if-a-log-root-exists-before-locking-the-log_mutex-on-unlink.patch queue-5.7/btrfs-fix-data-block-group-relocation-failure-due-to-concurrent-scrub.patch queue-5.7/btrfs-fix-a-block-group-ref-counter-leak-after-failu.patch