On Wed Sep 3, 2025 at 7:40 PM JST, Johannes Thumshirn wrote: > On 9/3/25 10:36 AM, Yi Zhang wrote: >> The kernel BUG was triggered by blktests zbd/009 on v6.17-rc3, please >> help check it and let me know if you need any infor/test for it, >> thanks. > [...] >> [ 319.819821] assertion failed: bg->zone_unusable == 0 :: 0, in >> fs/btrfs/zoned.c:2587 >> [ 319.828449] ------------[ cut here ]------------ >> [ 319.833618] kernel BUG at fs/btrfs/zoned.c:2587! >> [ 319.838793] Oops: invalid opcode: 0000 [#1] SMP KASAN PTI >> [ 319.844829] CPU: 3 UID: 0 PID: 1370 Comm: mount Tainted: G W >> ------ --- >> 6.17.0-0.rc3.250826gfab1beda7597.32.fc44.x86_64+debug #1 PREEMPT(lazy) >> [ 319.860948] Tainted: [W]=WARN >> [ 319.864259] Hardware name: Dell Inc. PowerEdge R730/0WCJNT, BIOS >> 2.19.0 12/12/2023 >> [ 319.872704] RIP: 0010:btrfs_zoned_reserve_data_reloc_bg.cold+0xb2/0xb4 >> [ 319.880014] Code: ab e8 7e ab f7 ff 0f 0b 41 b8 1b 0a 00 00 48 c7 >> c1 80 9f 59 ab 31 d2 48 c7 c6 20 b8 59 ab 48 c7 c7 20 a0 59 ab e8 5a >> ab f7 ff <0f> 0b 41 b8 5f 0a 00 00 48 c7 c1 80 9f 59 ab 31 d2 48 c7 c6 >> 00 b9 >> [ 319.900977] RSP: 0018:ffffc9000c21f930 EFLAGS: 00010282 >> [ 319.906816] RAX: 0000000000000047 RBX: ffff8888d1a54000 RCX: 0000000000000000 >> [ 319.914783] RDX: 0000000000000047 RSI: 1ffffffff629cc84 RDI: fffff52001843f18 >> [ 319.922742] RBP: ffff888121b7c000 R08: ffffffffa802cbb5 R09: fffff52001843edc >> [ 319.930709] R10: 0000000000000003 R11: 0000000000000001 R12: 0000000000000000 >> [ 319.938666] R13: 0000000000000001 R14: ffff888121b7c128 R15: ffff88810f379800 >> [ 319.946625] FS: 00007fbd89e98840(0000) GS:ffff8890af8e8000(0000) >> knlGS:0000000000000000 >> [ 319.955661] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >> [ 319.962077] CR2: 0000559e0ad4b540 CR3: 00000008e14ce003 CR4: 00000000003726f0 >> [ 319.970046] Call Trace: >> [ 319.972767] <TASK> >> [ 319.975102] ? create_space_info+0x155/0x390 >> [ 319.979880] open_ctree+0x1874/0x2203 >> [ 319.983977] btrfs_fill_super.cold+0x2c/0x16d >> [ 319.988850] btrfs_get_tree_super+0x936/0xd60 >> [ 319.993725] btrfs_get_tree_subvol+0x230/0x5f0 >> > > OK the problem is, we're ASSERTing if zone_unusable is 0 and that > obviously fails, because zbd/009 configures scsi_debug with a zone_size > of 4MB and a zone_capacity of 3MB. This automatically leads to an > assertion failure as bg->zone_unusable is 1MB. > > The test in there is to check if we have an empty block-group. > @Naohiro what do you think of the following: > > diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c > index 6e66ec491181..f897f914b78e 100644 > --- a/fs/btrfs/zoned.c > +++ b/fs/btrfs/zoned.c > @@ -2590,7 +2590,8 @@ void btrfs_zoned_reserve_data_reloc_bg(struct > btrfs_fs_info *fs_info) > space_info->disk_total -= bg->length * factor; > /* There is no allocation ever happened. */ > ASSERT(bg->used == 0); > - ASSERT(bg->zone_unusable == 0); > + ASSERT(bg->zone_unusable == 0 || > + bg->length - bg->zone_unusable == > bg->zone_capacity); Nah, then, we must handle the space_info->bytes_zone_unsable properly. We need to do "space_info->disk_total -= bg->zone_unusable;" and we can just drop the ASSERT. > /* No super block in a block group on the zoned > setup. */ > ASSERT(bg->bytes_super == 0); > spin_unlock(&space_info->lock);