This is a note to let you know that I've just added the patch titled btrfs: do not BUG_ON() on tree mod log failure at __btrfs_cow_block() to the 6.1-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-do-not-bug_on-on-tree-mod-log-failure-at-__btrfs_cow_block.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 40b0a749388517de244643c09bdbb98f7dcb6ef1 Mon Sep 17 00:00:00 2001 From: Filipe Manana <fdmanana@xxxxxxxx> Date: Thu, 8 Jun 2023 11:27:40 +0100 Subject: btrfs: do not BUG_ON() on tree mod log failure at __btrfs_cow_block() From: Filipe Manana <fdmanana@xxxxxxxx> commit 40b0a749388517de244643c09bdbb98f7dcb6ef1 upstream. At __btrfs_cow_block(), instead of doing a BUG_ON() in case we fail to record a tree mod log root insertion operation, do a transaction abort instead. There's really no need for the BUG_ON(), we can properly release all resources in this context and turn the filesystem to RO mode and in an error state instead. CC: stable@xxxxxxxxxxxxxxx # 5.4+ Reviewed-by: Qu Wenruo <wqu@xxxxxxxx> 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/ctree.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -475,9 +475,14 @@ static noinline int __btrfs_cow_block(st btrfs_header_backref_rev(buf) < BTRFS_MIXED_BACKREF_REV) parent_start = buf->start; - atomic_inc(&cow->refs); ret = btrfs_tree_mod_log_insert_root(root->node, cow, true); - BUG_ON(ret < 0); + if (ret < 0) { + btrfs_tree_unlock(cow); + free_extent_buffer(cow); + btrfs_abort_transaction(trans, ret); + return ret; + } + atomic_inc(&cow->refs); rcu_assign_pointer(root->node, cow); btrfs_free_tree_block(trans, btrfs_root_id(root), buf, Patches currently in stable-queue which might be from fdmanana@xxxxxxxx are queue-6.1/btrfs-bail-out-reclaim-process-if-filesystem-is-read-only.patch queue-6.1/btrfs-do-not-bug_on-on-tree-mod-log-failure-at-balan.patch queue-6.1/btrfs-fix-extent-buffer-leak-after-tree-mod-log-failure-at-split_node.patch queue-6.1/btrfs-fix-race-when-deleting-free-space-root-from-the-dirty-cow-roots-list.patch queue-6.1/btrfs-move-out-now-unused-bg-from-the-reclaim-list.patch queue-6.1/btrfs-fix-race-when-deleting-quota-root-from-the-dirty-cow-roots-list.patch queue-6.1/btrfs-delete-unused-bgs-while-reclaiming-bgs.patch queue-6.1/btrfs-do-not-bug_on-on-tree-mod-log-failure-at-__btrfs_cow_block.patch