This is a note to let you know that I've just added the patch titled btrfs: zoned: fix unpaired block group unfreeze during device replace to the 5.12-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-zoned-fix-unpaired-block-group-unfreeze-during-device-replace.patch and it can be found in the queue-5.12 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 0dc16ef4f6c2708407fab6d141908d46a3b737bc Mon Sep 17 00:00:00 2001 From: Filipe Manana <fdmanana@xxxxxxxx> Date: Wed, 14 Apr 2021 14:05:26 +0100 Subject: btrfs: zoned: fix unpaired block group unfreeze during device replace From: Filipe Manana <fdmanana@xxxxxxxx> commit 0dc16ef4f6c2708407fab6d141908d46a3b737bc upstream. When doing a device replace on a zoned filesystem, if we find a block group with ->to_copy == 0, we jump to the label 'done', which will result in later calling btrfs_unfreeze_block_group(), even though at this point we never called btrfs_freeze_block_group(). Since at this point we have neither turned the block group to RO mode nor made any progress, we don't need to jump to the label 'done'. So fix this by jumping instead to the label 'skip' and dropping our reference on the block group before the jump. Fixes: 78ce9fc269af6e ("btrfs: zoned: mark block groups to copy for device-replace") CC: stable@xxxxxxxxxxxxxxx # 5.12 Reviewed-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx> 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/scrub.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -3682,8 +3682,8 @@ int scrub_enumerate_chunks(struct scrub_ spin_lock(&cache->lock); if (!cache->to_copy) { spin_unlock(&cache->lock); - ro_set = 0; - goto done; + btrfs_put_block_group(cache); + goto skip; } spin_unlock(&cache->lock); } @@ -3841,7 +3841,6 @@ int scrub_enumerate_chunks(struct scrub_ cache, found_key.offset)) ro_set = 0; -done: down_write(&dev_replace->rwsem); dev_replace->cursor_left = dev_replace->cursor_right; dev_replace->item_needs_writeback = 1; Patches currently in stable-queue which might be from fdmanana@xxxxxxxx are queue-5.12/btrfs-fix-race-between-transaction-aborts-and-fsyncs-leading-to-use-after-free.patch queue-5.12/btrfs-zoned-fix-unpaired-block-group-unfreeze-during-device-replace.patch queue-5.12/btrfs-fix-metadata-extent-leak-after-failure-to-create-subvolume.patch