[PATCH] btrfs: reject zoned RW mount if sectorsize is smaller than page size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[BUG]
There is a bug report that with zoned device and sectorsize is smaller
than page size (aka, subpage), btrfs would crash with a very basic
workload:

 # getconfig PAGESIZE
 16384
 # mkfs.btrfs -f $dev -s 4k
 # mount $dev $mnt
 # $fsstress -w -n 8 -s 1707820327 -v -d $mnt
 # umount $mnt

The crash would look like this (with CONFIG_BTRFS_ASSERT enabled):

 assertion failed: block_start != EXTENT_MAP_HOLE, in fs/btrfs/extent_io.c:1384
 ------------[ cut here ]------------
 kernel BUG at fs/btrfs/extent_io.c:1384!
 CPU: 0 PID: 872 Comm: kworker/u9:2 Tainted: G           OE      6.8.0-rc3-custom+ #7
 Hardware name: QEMU KVM Virtual Machine, BIOS edk2-20231122-12.fc39 11/22/2023
 Workqueue: writeback wb_workfn (flush-btrfs-8)
 pc : __extent_writepage_io+0x404/0x460 [btrfs]
 lr : __extent_writepage_io+0x404/0x460 [btrfs]
 Call trace:
  __extent_writepage_io+0x404/0x460 [btrfs]
  extent_write_locked_range+0x16c/0x460 [btrfs]
  run_delalloc_cow+0x88/0x118 [btrfs]
  btrfs_run_delalloc_range+0x128/0x228 [btrfs]
  writepage_delalloc+0xb8/0x178 [btrfs]
  __extent_writepage+0xc8/0x3a0 [btrfs]
  extent_write_cache_pages+0x1cc/0x460 [btrfs]
  extent_writepages+0x8c/0x120 [btrfs]
  btrfs_writepages+0x18/0x30 [btrfs]
  do_writepages+0x94/0x1f8
  __writeback_single_inode+0x4c/0x388
  writeback_sb_inodes+0x208/0x4b0
  wb_writeback+0x118/0x3c0
  wb_do_writeback+0xbc/0x388
  wb_workfn+0x80/0x240
  process_one_work+0x154/0x3c8
  worker_thread+0x2bc/0x3e0
  kthread+0xf4/0x108
  ret_from_fork+0x10/0x20
 Code: 9102c021 90000be0 91378000 9402bf53 (d4210000)
 ---[ end trace 0000000000000000 ]---

[CAUSE]
There are several factors causing the problem:

1. __extent_writepage_io() requires all dirty ranges to have delalloc
   executed
   This can be solved by adding @start and @len parameter to only submit
   IO for a subset of the page, and update several involved helpers to
   do subpage checks.

   So this is not a big deal.

2. Subpage only accepts for full page aligned ranges for
   extent_write_locked_range()
   For zoned device, regular COW is switched to utilize
   extent_write_locked_range() to submit the IO.

   But the caller, run_delalloc_cow() can be called to run on a subpage
   range, e.g.

   0     4K     8K    12K     16K
   |/////|      |/////|

   Where |///| is the dirtied range.

   In that case, btrfs_run_delalloc_range() would call run_delalloc_cow(),
   which would call extent_write_locked_range() for [0, 4K), and unlock
   the whole [0, 16K) page.

   But btrfs_run_delalloc_range() would again be called for range [8K,
   12K), as there are still dirty range left.
   In that case, since the whole page is already unlocked by previous
   iteration, and would cause different ASSERT()s inside
   extent_write_locked_range().

   That's also why compression for subpage cases require fully page
   aligned range.

[WORKAROUND]
A proper fix requires some big changes to delalloc workload, to allow
extent_write_locked_range() to handle multiple different entries with
the same @locked_page.

So for now, disable read-write support for subpage zoned btrfs.

The problem can only be solved if subpage btrfs can handle subpage
compression, which need quite some work on the delalloc procedure for
the @locked_page handling.

Reported-by: HAN Yuwei <hrx@xxxxxxxx>
Link: https://lore.kernel.org/all/1ACD2E3643008A17+da260584-2c7f-432a-9e22-9d390aae84cc@xxxxxxxx/
CC: stable@xxxxxxxxxxxxxxx # 5.10+
Signed-off-by: Qu Wenruo <wqu@xxxxxxxx>
---
 fs/btrfs/disk-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index c3ab268533ca..85cd23aebdd6 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3193,7 +3193,8 @@ int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount)
 	 * part of @locked_page.
 	 * That's also why compression for subpage only work for page aligned ranges.
 	 */
-	if (fs_info->sectorsize < PAGE_SIZE && btrfs_is_zoned(fs_info) && is_rw_mount) {
+	if (fs_info->sectorsize < PAGE_SIZE &&
+	    btrfs_fs_incompat(fs_info, ZONED) && is_rw_mount) {
 		btrfs_warn(fs_info,
 	"no zoned read-write support for page size %lu with sectorsize %u",
 			   PAGE_SIZE, fs_info->sectorsize);
-- 
2.43.0





[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux