Linux block layer
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Kyrylo Biryuk <illofspeed@gmail.com>, dm-devel@lists.linux.dev
Cc: agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
	bmarzins@redhat.com, shinichiro.kawasaki@wdc.com, hare@suse.de,
	hare@kernel.org, song@kernel.org, yukuai@fygo.io,
	magiclinan@didiglobal.com, xiao@kernel.org, john.garry@linux.dev,
	abd.masalkhi@gmail.com, linux-block@vger.kernel.org,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 0/1] dm-table: dm-zoned refuses md RAID1/RAID0 as its regular device
Date: Wed, 2 Dec 2026 15:49:03 +0900	[thread overview]
Message-ID: <27d958f1-4ecf-4d54-9dbc-51fd11840625@kernel.org> (raw)
In-Reply-To: <20261201121037.366367-1-illofspeed@gmail.com>

On 12/1/26 21:10, Kyrylo Biryuk wrote:
> Hi,
> 
> dm-zoned can no longer be set up with an md RAID1 array (since v7.3 and
> 7.2.y) or an md RAID0 array (since v6.17) as its regular device, next to a
> host-managed drive with 256 MiB zones. The table load fails with
> 
>   device-mapper: table: 253:0: zone sectors is not consistent across all zoned devices
>   device-mapper: core: Cannot calculate initial queue limits
>   device-mapper: ioctl: unable to set up device queue for new table.
> 
> I think the problem is in dm_calculate_queue_limits(), not in md, and
> patch 1/1 is a proposed fix. I first hit this on a 7.2.10 kernel with
> real drives (an md RAID1 of two SSD partitions as the regular device, a
> host-managed HDD with 256 MiB zones) and reproduced it on vanilla 7.3.6
> and 7.4-rc5 in a VM.
> 
> What changed in md: commit 86d801e895b8 ("md/raid1: restrict atomic
> write limits and handle runtime constraints", v7.3-rc1, also in
> linux-7.2.y) makes raid1_set_limits() start from lim.chunk_sectors =
> BARRIER_UNIT_SECTOR_SIZE (131072 sectors, 64 MiB) before it stacks the
> members' limits, so an md RAID1 of ordinary members reports 131072, and
> commit 4b8beba60d32 ("md/raid0: set chunk_sectors limit", v6.17-rc1)
> sets it to the chunk size on md RAID0. Any regular device whose
> chunk_sectors is non-zero and not a multiple of the zone size fails in
> the same way: tested md RAID1, md RAID0 with a 512 KiB chunk, and
> dm-linear on top of md RAID1; by the same mechanism, not tested, md
> RAID10 and RAID5, dm-stripe and NVMe namespaces with NOIOB.
> 
> Where it goes wrong (7.4-rc5 line numbers):
> 
>  1. dm_calculate_queue_limits() stacks all devices of the target into
>     ti_limits via dmz_iterate_devices(), regular device first.
>     blk_stack_limits() combines chunk_sectors with gcd(), so
>     gcd(131072 (md RAID1), 524288 (256 MiB zones)) = 131072.
>     BLK_FEAT_ZONED is inherited from the zoned device.
>  2. dm-table.c:1819 stores zone_sectors = ti_limits.chunk_sectors, i.e.
>     131072. This happens before the target's .io_hints runs, on purpose
>     (see the comment above dm-table.c:1866).
>  3. dmz_io_hints() (dm-zoned-target.c:1008) sets chunk_sectors back to
>     the zone size and clears BLK_FEAT_ZONED, so the assignment from the
>     final limits at dm-table.c:1872 is skipped and zone_sectors stays
>     131072.
>  4. validate_hardware_zoned() calls device_not_matches_zone_sectors(),
>     which compares bdev_zone_sectors() of the zoned device (524288) with
>     131072 and fails (dm-table.c:1767).
> 
> On a zoned device chunk_sectors is the zone size, but on a regular
> device it is only an I/O boundary, so the gcd over all devices is not a

Strictly speaking, the zone size is *also* an I/O boundary. BIOs are always
split to not go over a zone boundary.

> zone size as soon as a regular device carries a smaller non-zero value.
> dm core already reads the zone size from the zoned device everywhere
> else (device_area_is_invalid(), device_not_matches_zone_sectors()), and
> so does dm-zoned (dmz_fixup_devices()); the patch makes this one place
> do the same: it takes the zone size from the first zoned device of the
> target. All zoned devices of the table must still have that zone size,
> and tables whose final limits are zoned (linear, crypt, flakey and the
> other DM_TARGET_ZONED_HM targets) still take it from the final limits.
> 
> Why not elsewhere: a dm-zoned .io_hints change cannot work, because the
> value is captured before .io_hints runs, and changing md alone would
> leave RAID0/10/5, dm-stripe and NVMe NOIOB. A dm-raid (LVM raid1) LV is
> not affected because raid1_run() calls raid1_set_limits() only if
> !mddev_is_dm().
> 
> Results before the patch (x86_64 KVM guest, Debian 13 userspace,
> vanilla kernels from defconfig plus md, dm-zoned and null_blk as
> modules; start of the dm-zoned target with the regular device first):
> 
>   kernel                       md     md      plain  LVM raid1  dm-linear
>                                RAID1  RAID0   loop   LV         on md RAID1
>   Debian 6.12.118 (cloud)      ok     ok (*)  ok     ok         ok
>   7.3.6 (kernel.org tarball)   FAIL   FAIL    ok     ok         FAIL
>   7.4-rc5 (torvalds snapshot)  FAIL   FAIL    ok     ok         FAIL
> 
>   (*) on 6.12.118 md RAID0 reports chunk_sectors 0.
> 
> The patch, on v7.4-rc5 with KASAN (generic, inline), PROVE_LOCKING and
> DEBUG_ATOMIC_SLEEP, same kernel with the unpatched and the patched
> dm-mod in a KVM guest; zoned devices are zoned null_blk, regular devices
> loop-backed:
> 
>   case                                          unpatched  patched
>   dm-zoned + md RAID1 (256 MiB zones)           refused    starts, I/O ok
>   dm-zoned + md RAID0, 512 KiB chunk            refused    starts, I/O ok
>   dm-zoned + dm-linear on md RAID1              refused    starts, I/O ok
>   dm-zoned + md RAID1 + two zoned devices       refused    starts
>   dm-zoned + loop, LVM raid1 LV, or md RAID1
>     with 32 MiB zones (controls)                starts     starts
>   dm-zoned on one zoned device only             starts     starts
>   dm-zoned, zoned devices of different sizes    refused    refused (a)
>   dm-linear, zoned devices of different sizes   refused    refused
>   dm-linear, zoned + regular device             refused    refused
>   dm-linear, not zone aligned                   refused    refused
>   dm-linear, dm-crypt, dm-flakey on a zoned
>     device: zoned model, zone size, nr_zones    = device   = device
> 
>   "I/O ok": ext4 on the target, 256 MiB written, suspend/resume while
>   mounted, remount, checksum equal (the controls passed this on both
>   kernels). In the cases started by the reproduction script (the first
>   three rows and the controls), the same table was then loaded again and
>   resumed; the target's limits stayed chunk_sectors = zone size, not
>   zoned. dm-crypt also wrote and read back 16 MiB
>   through the zone write pointer.
>   (a) refused by the dm-zoned constructor ("Zone nr sectors mismatch")
>   before dm-table checks anything.
> 
> No KASAN, lockdep or might_sleep reports; the kernel stayed untainted
> and lockdep stayed enabled in both runs. checkpatch --strict: one
> warning, for the quoted kernel log line.
> 
> Not tested: md RAID10/RAID5, dm-stripe or NVMe as the regular device,
> real NVMe members with atomic write limits, stable kernels at run time,
> blktests and the dm-zoned-tools tests, and a table where the changed
> line itself refuses (the dm-zoned constructor refuses mismatched zone
> sizes first).
> 
> Reproduction, on a disposable test VM (root; kernel with null_blk, md,
> loop and dm-zoned; mdadm 4.4, dm-zoned-tools 2.2.2):
> 
>   modprobe null_blk nr_devices=0; modprobe loop; modprobe dm-zoned
>   mount -t configfs none /sys/kernel/config 2>/dev/null
>   d=/sys/kernel/config/nullb/zt; mkdir $d
>   echo 32768 > $d/size; echo 4096 > $d/blocksize
>   echo 1 > $d/memory_backed; echo 1 > $d/zoned
>   echo 256 > $d/zone_size; echo 0 > $d/zone_nr_conv; echo 1 > $d/power
>   w=$(mktemp -d); truncate -s 4G $w/a.img $w/b.img
>   A=$(losetup -f --show $w/a.img); B=$(losetup -f --show $w/b.img)
>   mdadm --create /dev/md/zt --run --level=1 --raid-devices=2 \
>         --bitmap=none --assume-clean $A $B
>   M=$(readlink -f /dev/md/zt)
>   cat /sys/block/${M#/dev/}/queue/chunk_sectors  # 131072
>   dmzadm --format $M /dev/zt --force
>   dmzadm --start $M /dev/zt                      # fails as above
> 
> The script I used for all cases (RAID1, RAID0, plain loop, LVM raid1,
> dm-linear on RAID1, with cleanup) is available on request.
> 
> Workaround until then: an LVM raid1 LV (dm-raid) or a plain partition
> as the regular device, as long as it reports chunk_sectors 0 or a
> multiple of the zone size. A dm-linear over md RAID1 does not help.
> 
> Questions:
> 
>  1. Fixes: patch 1/1 names 2d669ceb69c2 ("dm table: Fix zoned model
>     check and zone sectors check"). That commit introduced
>     DM_TARGET_MIXED_ZONED_MODEL and made the zone size check skip
>     regular devices, but kept the stacked chunk_sectors as the reference
>     zone size, which is the logic the patch amends. This is from reading
>     the history, not a bisect; please say if another commit fits
>     better.
>  2. Stable: "Cc: stable # 6.18.x". The md RAID0/RAID10 and dm-stripe
>     triggers are in v6.17 and later, md RAID5 in v7.1 and later, and md
>     RAID1 in v7.3 and 7.2.y; the patch applies to 6.18.y, 7.2.y and
>     7.3.y. On 6.12.y (it applies there too) the only trigger I know of is
>     an NVMe namespace that reports NOIOB, which I have not tested, so I
>     left it out; say if you want it widened. Older trees need a separate
>     backport (different context); I can do one if wanted.
>  3. FYI for linux-raid: independently of this fix, is chunk_sectors the
>     right limit for raid1's barrier unit? It makes a mirror report a
>     64 MiB "chunk" to everything stacked on top of it. The dm fix is
>     needed either way.
> 
> Based on v7.4-rc5; the patch also applies to linux-dm for-next and to
> current mainline.
> 
> I used LLM coding assistants (Claude Code for the root-cause analysis
> and drafts of the code, the changelog, this report and the test
> harness; OpenAI, Google Gemini and GitHub Copilot models for reviews).
> I reviewed the code and changed it where needed, and I am responsible
> for this patch.
> 
> Kyrylo Biryuk (1):
>   dm-table: take the zone size from the zoned devices of a target
> 
>  drivers/md/dm-table.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> 
> base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244


-- 
Damien Le Moal
Western Digital Research

      parent reply	other threads:[~2026-12-02  6:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 12:10 [RFC PATCH 0/1] dm-table: dm-zoned refuses md RAID1/RAID0 as its regular device Kyrylo Biryuk
2026-12-01 12:10 ` [RFC PATCH 1/1] dm-table: take the zone size from the zoned devices of a target Kyrylo Biryuk
2026-12-02  7:00   ` Damien Le Moal
2026-12-02  6:49 ` Damien Le Moal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=27d958f1-4ecf-4d54-9dbc-51fd11840625@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=abd.masalkhi@gmail.com \
    --cc=agk@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=hare@kernel.org \
    --cc=hare@suse.de \
    --cc=illofspeed@gmail.com \
    --cc=john.garry@linux.dev \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=mpatocka@redhat.com \
    --cc=shinichiro.kawasaki@wdc.com \
    --cc=snitzer@kernel.org \
    --cc=song@kernel.org \
    --cc=xiao@kernel.org \
    --cc=yukuai@fygo.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox