* FAILED: patch "[PATCH] btrfs: reject refs=0 subvolume without DEAD in" failed to apply to 6.18-stable tree
@ 2026-11-24 15:43 gregkh
2026-11-24 22:45 ` [PATCH 6.18.y 1/3] btrfs: check type flags in alloc_ordered_extent() Sasha Levin
0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2026-11-24 15:43 UTC (permalink / raw)
To: teel4res, dsterba, quwenruo.btrfs, wqu; +Cc: stable
The patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 9a58e56e70f610e29b53821e9c706600e529cca3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026112428-spearmint-famished-4675@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 9a58e56e70f610e29b53821e9c706600e529cca3 Mon Sep 17 00:00:00 2001
From: Cheng Yongkang <teel4res@gmail.com>
Date: Sat, 31 Oct 2026 23:25:39 -0700
Subject: [PATCH] btrfs: reject refs=0 subvolume without DEAD in
SUBVOL_SYNC_WAIT
btrfs_ioctl_subvol_sync() assumes that a cached root with zero
references has BTRFS_ROOT_SUBVOL_DEAD set, and asserts that before
waiting for the cleaner. Two states break the assumption:
- A corrupt ROOT_ITEM with zero references and a matching orphan item,
on a writable filesystem.
- A failed subvolume deletion. btrfs_delete_subvolume() zeroes the
root references, aborts the transaction, which forces the filesystem
read-only, and then clears DEAD again. No on-disk metadata is
corrupted in this case.
With CONFIG_BTRFS_ASSERT=y, both reach a BUG().
Change the ASSERT() into a proper rejection to avoid triggering a BUG().
Fixes: 6c83d153ed86 ("btrfs: add new ioctl to wait for cleaned subvolumes")
CC: stable@vger.kernel.org
Suggested-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Link: https://lore.kernel.org/linux-btrfs/dd97efe9-91ec-495b-b698-acff1447421c@gmx.com/
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
[ Rework the commit message, drop the ad-hoc RW check. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 847fdc19bd40..000276bb49ad 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -5161,8 +5161,12 @@ static int btrfs_ioctl_subvol_sync(struct btrfs_fs_info *fs_info, void __user *a
return -ENOENT;
wait_for_deletion = true;
- ASSERT(root_flags & BTRFS_ROOT_SUBVOL_DEAD, "root_flags=0x%llx",
- root_flags);
+ if (unlikely(!(root_flags & BTRFS_ROOT_SUBVOL_DEAD))) {
+ btrfs_err(fs_info,
+ "subvol %llu has refs 0 without DEAD flag",
+ args.subvolid);
+ return -EUCLEAN;
+ }
sched_ret = schedule_timeout_interruptible(HZ);
/* Early wake up or error. */
if (sched_ret != 0)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 6.18.y 1/3] btrfs: check type flags in alloc_ordered_extent()
2026-11-24 15:43 FAILED: patch "[PATCH] btrfs: reject refs=0 subvolume without DEAD in" failed to apply to 6.18-stable tree gregkh
@ 2026-11-24 22:45 ` Sasha Levin
2026-11-24 22:45 ` [PATCH 6.18.y 2/3] btrfs: make more ASSERTs verbose, part 3 Sasha Levin
2026-11-24 22:45 ` [PATCH 6.18.y 3/3] btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT Sasha Levin
0 siblings, 2 replies; 4+ messages in thread
From: Sasha Levin @ 2026-11-24 22:45 UTC (permalink / raw)
To: stable; +Cc: Qu Wenruo, David Sterba, Sasha Levin
From: Qu Wenruo <wqu@suse.com>
[ Upstream commit 232770bcf3aa65ae83fd7389961fa651f09f7b3a ]
Unlike other flags used in btrfs, BTRFS_ORDERED_* macros are different as
they cannot be directly used as flags.
They are defined as bit values, thus they should be utilized with
bit operations, not directly with logical operations.
Unfortunately sometimes I forgot this and passed the incorrect flags
to alloc_ordered_extent() and hit weird bugs.
Enhance the type checks in alloc_ordered_extent():
- Make sure there is one and only one bit set for exclusive type flags
There are four exclusive type flags, REGULAR, NOCOW, PREALLOC and
COMPRESSED.
So introduce a new macro, BTRFS_ORDERED_EXCLUSIVE_FLAGS, to cover
above flags.
Add an ASSERT() to check one and only one of those exclusive flags can
be set for alloc_ordered_extent().
- Re-order the type bit numbers to the end of the enum
This is make it much harder to get a valid false negative.
E.g., with the old code BTRFS_ORDERED_REGULAR starts at zero, we can
have the following flags passing the bit uniqueness check:
* BTRFS_ORDERED_NOCOW
Be treated as BTRFS_ORDERED_REGULAR (1 == 1UL << 0).
* BTRFS_ORDERED_PREALLOC
Be treated as BTRFS_ORDERED_NOCOW (2 == 1UL << 1).
* BTRFS_ORDERED_DIRECT
Be treated as BTRFS_ORDERED_PREALLOC (4 == 1UL << 2).
Now all those types start at 8, passing any of those bit numbers as
flags directly will not pass the ASSERT().
- Add a static assert to avoid overflow
To make sure all BTRFS_ORDERED_* flags can fit into an unsigned long.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Stable-dep-of: 9a58e56e70f6 ("btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/btrfs/ordered-data.c | 13 ++++++++++
fs/btrfs/ordered-data.h | 55 +++++++++++++++++++++++------------------
2 files changed, 44 insertions(+), 24 deletions(-)
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index b3ed4212bfecd..03b1d1e28cfec 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -156,6 +156,19 @@ static struct btrfs_ordered_extent *alloc_ordered_extent(
const bool is_nocow = (flags &
((1U << BTRFS_ORDERED_NOCOW) | (1U << BTRFS_ORDERED_PREALLOC)));
+ /* Only one type flag can be set. */
+ ASSERT(has_single_bit_set(flags & BTRFS_ORDERED_EXCLUSIVE_FLAGS));
+
+ /* DIRECT cannot be set with COMPRESSED nor ENCODED. */
+ if (test_bit(BTRFS_ORDERED_DIRECT, &flags)) {
+ ASSERT(!test_bit(BTRFS_ORDERED_COMPRESSED, &flags));
+ ASSERT(!test_bit(BTRFS_ORDERED_ENCODED, &flags));
+ }
+
+ /* ENCODED must be set with COMPRESSED. */
+ if (test_bit(BTRFS_ORDERED_ENCODED, &flags))
+ ASSERT(test_bit(BTRFS_ORDERED_COMPRESSED, &flags));
+
/*
* For a NOCOW write we can free the qgroup reserve right now. For a COW
* one we transfer the reserved space from the inode's iotree into the
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 2e7879c6cbc77..96486c4015c45 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -47,8 +47,25 @@ struct btrfs_ordered_sum {
* IO is done and any metadata is inserted into the tree.
*/
enum {
+ /* Extra status bits for ordered extents */
+
+ /* Set when all the pages are written. */
+ BTRFS_ORDERED_IO_DONE,
+ /* Set when removed from the tree. */
+ BTRFS_ORDERED_COMPLETE,
+ /* We had an io error when writing this out. */
+ BTRFS_ORDERED_IOERR,
+ /* Set when we have to truncate an extent. */
+ BTRFS_ORDERED_TRUNCATED,
+ /* Used during fsync to track already logged extents. */
+ BTRFS_ORDERED_LOGGED,
+ /* We have already logged all the csums of the ordered extent. */
+ BTRFS_ORDERED_LOGGED_CSUM,
+ /* We wait for this extent to complete in the current transaction. */
+ BTRFS_ORDERED_PENDING,
+
/*
- * Different types for ordered extents, one and only one of the 4 types
+ * Different types for ordered extents, one and only one of these types
* need to be set when creating ordered extent.
*
* REGULAR: For regular non-compressed COW write
@@ -61,37 +78,27 @@ enum {
BTRFS_ORDERED_PREALLOC,
BTRFS_ORDERED_COMPRESSED,
+ /* Extra bit for encoded write, must be set with COMPRESSED. */
+ BTRFS_ORDERED_ENCODED,
+
/*
* Extra bit for direct io, can only be set for
- * REGULAR/NOCOW/PREALLOC. No direct io for compressed extent.
+ * REGULAR/NOCOW/PREALLOC. Must not be set for COMPRESSED nor ENCODED.
*/
BTRFS_ORDERED_DIRECT,
- /* Extra status bits for ordered extents */
-
- /* set when all the pages are written */
- BTRFS_ORDERED_IO_DONE,
- /* set when removed from the tree */
- BTRFS_ORDERED_COMPLETE,
- /* We had an io error when writing this out */
- BTRFS_ORDERED_IOERR,
- /* Set when we have to truncate an extent */
- BTRFS_ORDERED_TRUNCATED,
- /* Used during fsync to track already logged extents */
- BTRFS_ORDERED_LOGGED,
- /* We have already logged all the csums of the ordered extent */
- BTRFS_ORDERED_LOGGED_CSUM,
- /* We wait for this extent to complete in the current transaction */
- BTRFS_ORDERED_PENDING,
- /* BTRFS_IOC_ENCODED_WRITE */
- BTRFS_ORDERED_ENCODED,
+ BTRFS_ORDERED_NR_FLAGS,
};
+static_assert(BTRFS_ORDERED_NR_FLAGS <= BITS_PER_LONG);
+
+/* One and only one flag can be set. */
+#define BTRFS_ORDERED_EXCLUSIVE_FLAGS ((1UL << BTRFS_ORDERED_REGULAR) | \
+ (1UL << BTRFS_ORDERED_NOCOW) | \
+ (1UL << BTRFS_ORDERED_PREALLOC) | \
+ (1UL << BTRFS_ORDERED_COMPRESSED))
/* BTRFS_ORDERED_* flags that specify the type of the extent. */
-#define BTRFS_ORDERED_TYPE_FLAGS ((1UL << BTRFS_ORDERED_REGULAR) | \
- (1UL << BTRFS_ORDERED_NOCOW) | \
- (1UL << BTRFS_ORDERED_PREALLOC) | \
- (1UL << BTRFS_ORDERED_COMPRESSED) | \
+#define BTRFS_ORDERED_TYPE_FLAGS (BTRFS_ORDERED_EXCLUSIVE_FLAGS | \
(1UL << BTRFS_ORDERED_DIRECT) | \
(1UL << BTRFS_ORDERED_ENCODED))
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 6.18.y 2/3] btrfs: make more ASSERTs verbose, part 3
2026-11-24 22:45 ` [PATCH 6.18.y 1/3] btrfs: check type flags in alloc_ordered_extent() Sasha Levin
@ 2026-11-24 22:45 ` Sasha Levin
2026-11-24 22:45 ` [PATCH 6.18.y 3/3] btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT Sasha Levin
1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-11-24 22:45 UTC (permalink / raw)
To: stable; +Cc: David Sterba, Sasha Levin
From: David Sterba <dsterba@suse.com>
[ Upstream commit 3fc0803f1c644e60b24cdb175109fcae83b2849a ]
We have support for optional string to be printed in ASSERT() (added in
19468a623a9109 ("btrfs: enhance ASSERT() to take optional format
string")), it's not yet everywhere it could be so add a few more files.
Try to finish what was left after 1c094e6ccead7a ("btrfs: make a few
more ASSERTs verbose").
Signed-off-by: David Sterba <dsterba@suse.com>
Stable-dep-of: 9a58e56e70f6 ("btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/btrfs/backref.c | 4 ++--
fs/btrfs/extent-tree.c | 15 ++++++++++-----
fs/btrfs/extent_map.c | 6 +++---
fs/btrfs/fiemap.c | 2 +-
fs/btrfs/file-item.c | 4 +++-
fs/btrfs/file.c | 7 +++++--
fs/btrfs/ioctl.c | 3 ++-
fs/btrfs/ordered-data.c | 12 +++++++-----
fs/btrfs/raid-stripe-tree.c | 4 +++-
fs/btrfs/reflink.c | 5 +++--
10 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 0c47b4570a7bf..ac6aaef57cf1c 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2363,7 +2363,7 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
info = (struct btrfs_tree_block_info *)(ei + 1);
*out_level = btrfs_tree_block_level(eb, info);
} else {
- ASSERT(key->type == BTRFS_METADATA_ITEM_KEY);
+ ASSERT(key->type == BTRFS_METADATA_ITEM_KEY, "key->type=%hhu", key->type);
*out_level = (u8)key->offset;
}
@@ -3189,7 +3189,7 @@ static int handle_direct_tree_backref(struct btrfs_backref_cache *cache,
struct btrfs_backref_node *upper;
struct rb_node *rb_node;
- ASSERT(ref_key->type == BTRFS_SHARED_BLOCK_REF_KEY);
+ ASSERT(ref_key->type == BTRFS_SHARED_BLOCK_REF_KEY, "ref_key->type=%hhu", ref_key->type);
/* Only reloc root uses backref pointing to itself */
if (ref_key->objectid == ref_key->offset) {
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 2f207bca62720..b53319023d76a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -372,7 +372,7 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
return type;
}
} else {
- ASSERT(is_data == BTRFS_REF_TYPE_ANY);
+ ASSERT(is_data == BTRFS_REF_TYPE_ANY, "is_data=%d", is_data);
return type;
}
}
@@ -2444,8 +2444,11 @@ int btrfs_cross_ref_exist(struct btrfs_inode *inode, u64 offset,
struct btrfs_key key;
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
- ASSERT(key.objectid == bytenr);
- ASSERT(key.type == BTRFS_EXTENT_ITEM_KEY);
+ ASSERT(key.objectid == bytenr,
+ "key.objectid=%llu bytenr=%llu",
+ key.objectid, bytenr);
+ ASSERT(key.type == BTRFS_EXTENT_ITEM_KEY, "key.type=%u",
+ key.type);
}
}
@@ -4407,10 +4410,12 @@ static noinline int find_free_extent(struct btrfs_root *root,
/* Use dedicated sub-space_info for dedicated block group users. */
if (ffe_ctl->for_data_reloc) {
space_info = space_info->sub_group[0];
- ASSERT(space_info->subgroup_id == BTRFS_SUB_GROUP_DATA_RELOC);
+ ASSERT(space_info->subgroup_id == BTRFS_SUB_GROUP_DATA_RELOC,
+ "space_info->subgroup_id=%d", space_info->subgroup_id);
} else if (ffe_ctl->for_treelog) {
space_info = space_info->sub_group[0];
- ASSERT(space_info->subgroup_id == BTRFS_SUB_GROUP_TREELOG);
+ ASSERT(space_info->subgroup_id == BTRFS_SUB_GROUP_TREELOG,
+ "space_info->subgroup_id=%d", space_info->subgroup_id);
}
}
if (!space_info) {
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 21eb104ee2aef..23610d7ebb305 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -705,7 +705,7 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode,
* file offset. Here just do a sanity check.
*/
if (em->disk_bytenr == EXTENT_MAP_INLINE)
- ASSERT(em->start == 0);
+ ASSERT(em->start == 0, "em->start=%llu", em->start);
ret = add_extent_mapping(inode, em, false);
/* it is possible that someone inserted the extent into the tree
@@ -749,7 +749,7 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode,
}
}
- ASSERT(ret == 0 || ret == -EEXIST);
+ ASSERT(ret == 0 || ret == -EEXIST, "ret=%d", ret);
return ret;
}
@@ -931,7 +931,7 @@ void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end,
ret = add_extent_mapping(inode, split, modified);
/* Logic error, shouldn't happen. */
- ASSERT(ret == 0);
+ ASSERT(ret == 0, "ret=%d", ret);
if (WARN_ON(ret != 0) && modified)
btrfs_set_inode_full_sync(inode);
}
diff --git a/fs/btrfs/fiemap.c b/fs/btrfs/fiemap.c
index 5fb7342a616d1..385c68bfd0dc1 100644
--- a/fs/btrfs/fiemap.c
+++ b/fs/btrfs/fiemap.c
@@ -112,7 +112,7 @@ static int emit_fiemap_extent(struct fiemap_extent_info *fieinfo,
u64 cache_end;
/* Set at the end of extent_fiemap(). */
- ASSERT((flags & FIEMAP_EXTENT_LAST) == 0);
+ ASSERT((flags & FIEMAP_EXTENT_LAST) == 0, "flags=0x%u", flags);
if (!cache->cached)
goto assign;
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 9b19b33e85b68..e4918ee92a52a 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -319,7 +319,9 @@ static int search_csum_tree(struct btrfs_fs_info *fs_info,
csum_start = key.offset;
csum_len = (itemsize / csum_size) * sectorsize;
- ASSERT(in_range(disk_bytenr, csum_start, csum_len));
+ ASSERT(in_range(disk_bytenr, csum_start, csum_len),
+ "disk_bytenr=%llu csum_start=%llu csum_len=%llu",
+ disk_bytenr, csum_start, csum_len);
found:
ret = (min(csum_start + csum_len, disk_bytenr + len) -
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 19f0f9df038cc..e12426c4dc272 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1214,8 +1214,11 @@ static int copy_one_range(struct btrfs_inode *inode, struct iov_iter *iter,
return ret;
reserved_len = ret;
/* Write range must be inside the reserved range. */
- ASSERT(reserved_start <= start);
- ASSERT(start + write_bytes <= reserved_start + reserved_len);
+ ASSERT(reserved_start <= start, "reserved_start=%llu start=%llu",
+ reserved_start, start);
+ ASSERT(start + write_bytes <= reserved_start + reserved_len,
+ "start=%llu write_bytes=%zu reserved_start=%llu reserved_len=%llu",
+ start, write_bytes, reserved_start, reserved_len);
again:
ret = balance_dirty_pages_ratelimited_flags(inode->vfs_inode.i_mapping,
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 84305ed0dc70e..091d090b650e0 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -5224,7 +5224,8 @@ static int btrfs_ioctl_subvol_sync(struct btrfs_fs_info *fs_info, void __user *a
return -ENOENT;
wait_for_deletion = true;
- ASSERT(root_flags & BTRFS_ROOT_SUBVOL_DEAD);
+ ASSERT(root_flags & BTRFS_ROOT_SUBVOL_DEAD, "root_flags=0x%llx",
+ root_flags);
sched_ret = schedule_timeout_interruptible(HZ);
/* Early wake up or error. */
if (sched_ret != 0)
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 03b1d1e28cfec..cfceb39c0fdcd 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -157,7 +157,8 @@ static struct btrfs_ordered_extent *alloc_ordered_extent(
((1U << BTRFS_ORDERED_NOCOW) | (1U << BTRFS_ORDERED_PREALLOC)));
/* Only one type flag can be set. */
- ASSERT(has_single_bit_set(flags & BTRFS_ORDERED_EXCLUSIVE_FLAGS));
+ ASSERT(has_single_bit_set(flags & BTRFS_ORDERED_EXCLUSIVE_FLAGS),
+ "flags=0x%lx", flags);
/* DIRECT cannot be set with COMPRESSED nor ENCODED. */
if (test_bit(BTRFS_ORDERED_DIRECT, &flags)) {
@@ -297,7 +298,7 @@ struct btrfs_ordered_extent *btrfs_alloc_ordered_extent(
{
struct btrfs_ordered_extent *entry;
- ASSERT((flags & ~BTRFS_ORDERED_TYPE_FLAGS) == 0);
+ ASSERT((flags & ~BTRFS_ORDERED_TYPE_FLAGS) == 0, "flags=0x%lx", flags);
/*
* For regular writes, we just use the members in @file_extent.
@@ -1252,7 +1253,7 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
trace_btrfs_ordered_extent_split(inode, ordered);
- ASSERT(!(flags & (1U << BTRFS_ORDERED_COMPRESSED)));
+ ASSERT(!(flags & (1U << BTRFS_ORDERED_COMPRESSED)), "flags=0x%lx", flags);
/*
* The entire bio must be covered by the ordered extent, but we can't
@@ -1274,7 +1275,7 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
}
/* We cannot split partially completed ordered extents. */
if (ordered->bytes_left) {
- ASSERT(!(flags & ~BTRFS_ORDERED_TYPE_FLAGS));
+ ASSERT(!(flags & ~BTRFS_ORDERED_TYPE_FLAGS), "flags=0x%lx", flags);
if (WARN_ON_ONCE(ordered->bytes_left != ordered->disk_num_bytes))
return ERR_PTR(-EINVAL);
}
@@ -1323,7 +1324,8 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
ordered->ram_bytes -= len;
if (test_bit(BTRFS_ORDERED_IO_DONE, &ordered->flags)) {
- ASSERT(ordered->bytes_left == 0);
+ ASSERT(ordered->bytes_left == 0, "ordered->bytes_left=%llu",
+ ordered->bytes_left);
new->bytes_left = 0;
} else {
ordered->bytes_left -= len;
diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c
index 707fe664b0771..6763114588c95 100644
--- a/fs/btrfs/raid-stripe-tree.c
+++ b/fs/btrfs/raid-stripe-tree.c
@@ -239,7 +239,9 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
btrfs_partially_delete_raid_extent(trans, path, &key,
key.offset - length,
length);
- ASSERT(key.offset - diff_end == length);
+ ASSERT(key.offset - diff_end == length,
+ "key.offset=%llu diff_end=%llu length=%llu",
+ key.offset, diff_end, length);
break;
}
diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c
index c6f8db5027a42..fec41636b540e 100644
--- a/fs/btrfs/reflink.c
+++ b/fs/btrfs/reflink.c
@@ -68,7 +68,8 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
struct address_space *mapping = inode->vfs_inode.i_mapping;
int ret;
- ASSERT(IS_ALIGNED(file_offset, block_size));
+ ASSERT(IS_ALIGNED(file_offset, block_size), "file_offset=%llu block_size=%u",
+ file_offset, block_size);
/*
* We have flushed and locked the ranges of the source and destination
@@ -469,7 +470,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
key.objectid != btrfs_ino(BTRFS_I(src)))
break;
- ASSERT(key.type == BTRFS_EXTENT_DATA_KEY);
+ ASSERT(key.type == BTRFS_EXTENT_DATA_KEY, "key.type=%u", key.type);
extent = btrfs_item_ptr(leaf, slot,
struct btrfs_file_extent_item);
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 6.18.y 3/3] btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT
2026-11-24 22:45 ` [PATCH 6.18.y 1/3] btrfs: check type flags in alloc_ordered_extent() Sasha Levin
2026-11-24 22:45 ` [PATCH 6.18.y 2/3] btrfs: make more ASSERTs verbose, part 3 Sasha Levin
@ 2026-11-24 22:45 ` Sasha Levin
1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-11-24 22:45 UTC (permalink / raw)
To: stable; +Cc: Cheng Yongkang, Qu Wenruo, Qu Wenruo, David Sterba, Sasha Levin
From: Cheng Yongkang <teel4res@gmail.com>
[ Upstream commit 9a58e56e70f610e29b53821e9c706600e529cca3 ]
btrfs_ioctl_subvol_sync() assumes that a cached root with zero
references has BTRFS_ROOT_SUBVOL_DEAD set, and asserts that before
waiting for the cleaner. Two states break the assumption:
- A corrupt ROOT_ITEM with zero references and a matching orphan item,
on a writable filesystem.
- A failed subvolume deletion. btrfs_delete_subvolume() zeroes the
root references, aborts the transaction, which forces the filesystem
read-only, and then clears DEAD again. No on-disk metadata is
corrupted in this case.
With CONFIG_BTRFS_ASSERT=y, both reach a BUG().
Change the ASSERT() into a proper rejection to avoid triggering a BUG().
Fixes: 6c83d153ed86 ("btrfs: add new ioctl to wait for cleaned subvolumes")
CC: stable@vger.kernel.org
Suggested-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Link: https://lore.kernel.org/linux-btrfs/dd97efe9-91ec-495b-b698-acff1447421c@gmx.com/
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
[ Rework the commit message, drop the ad-hoc RW check. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/btrfs/ioctl.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 091d090b650e0..2bf61cf1fd6bb 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -5224,8 +5224,12 @@ static int btrfs_ioctl_subvol_sync(struct btrfs_fs_info *fs_info, void __user *a
return -ENOENT;
wait_for_deletion = true;
- ASSERT(root_flags & BTRFS_ROOT_SUBVOL_DEAD, "root_flags=0x%llx",
- root_flags);
+ if (unlikely(!(root_flags & BTRFS_ROOT_SUBVOL_DEAD))) {
+ btrfs_err(fs_info,
+ "subvol %llu has refs 0 without DEAD flag",
+ args.subvolid);
+ return -EUCLEAN;
+ }
sched_ret = schedule_timeout_interruptible(HZ);
/* Early wake up or error. */
if (sched_ret != 0)
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 22:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 15:43 FAILED: patch "[PATCH] btrfs: reject refs=0 subvolume without DEAD in" failed to apply to 6.18-stable tree gregkh
2026-11-24 22:45 ` [PATCH 6.18.y 1/3] btrfs: check type flags in alloc_ordered_extent() Sasha Levin
2026-11-24 22:45 ` [PATCH 6.18.y 2/3] btrfs: make more ASSERTs verbose, part 3 Sasha Levin
2026-11-24 22:45 ` [PATCH 6.18.y 3/3] btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox