* [RFC PATCH 0/1] dm-table: dm-zoned refuses md RAID1/RAID0 as its regular device
@ 2026-12-01 12:10 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
0 siblings, 1 reply; 2+ messages in thread
From: Kyrylo Biryuk @ 2026-12-01 12:10 UTC (permalink / raw)
To: dm-devel
Cc: agk, snitzer, mpatocka, bmarzins, dlemoal, shinichiro.kawasaki,
hare, hare, song, yukuai, magiclinan, xiao, john.garry,
abd.masalkhi, linux-block, linux-raid, linux-kernel
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
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
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* [RFC PATCH 1/1] dm-table: take the zone size from the zoned devices of a target
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 ` Kyrylo Biryuk
0 siblings, 0 replies; 2+ messages in thread
From: Kyrylo Biryuk @ 2026-12-01 12:10 UTC (permalink / raw)
To: dm-devel
Cc: agk, snitzer, mpatocka, bmarzins, dlemoal, shinichiro.kawasaki,
hare, hare, song, yukuai, magiclinan, xiao, john.garry,
abd.masalkhi, linux-block, linux-raid, linux-kernel
dm_calculate_queue_limits() stacks the queue limits of all devices of a
target and, for the first target whose stacked limits are zoned, records
the stacked chunk_sectors as the zone size. validate_hardware_zoned()
then requires every zoned device of the table to have that zone size.
A target with DM_TARGET_MIXED_ZONED_MODEL (dm-zoned) can also map a
regular device, and blk_stack_limits() combines chunk_sectors with
gcd(). On a regular device chunk_sectors is an I/O boundary, not a zone
size. If it is not zero and not a multiple of the zone size, the
recorded zone size is smaller than the zone size of the zoned devices,
and the check fails on the zoned device itself:
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.
dm-zoned's .io_hints sets chunk_sectors back to the zone size and clears
BLK_FEAT_ZONED, so the zone size taken from the final table limits at
the end of dm_calculate_queue_limits() does not replace the wrong value.
Such regular devices have become common. md RAID0 arrays report their
chunk size since commit 4b8beba60d32 ("md/raid0: set chunk_sectors
limit"), md RAID10 arrays since commit 7ef50c4c6a9c ("md/raid10: set
chunk_sectors limit"), and md RAID1 arrays start from
BARRIER_UNIT_SECTOR_SIZE (131072 sectors) before stacking the limits of
their members since commit 86d801e895b8 ("md/raid1: restrict atomic
write limits and handle runtime constraints"). With a host-managed drive
with 256 MiB zones, dm-zoned can no longer use an md RAID1 array, an md
RAID0 array whose chunk size is not a multiple of the zone size, or a
dm-linear mapping on top of one, as its regular device. md RAID5,
dm-stripe and NVMe namespaces that report an I/O boundary set
chunk_sectors as well.
Take the zone size from the first zoned device of the target instead.
Every zoned device of the table must still have that zone size, and
tables whose final limits are zoned (dm-linear, dm-crypt, dm-flakey and
similar targets on zoned devices, where every device must be zoned)
still take the zone size from the final limits, as before. The stacked
limits of a target are only zoned if one of its devices is zoned, so the
iteration always finds one.
Reproducer: a zoned null_blk device (256 MiB zones) as the zoned device
and an md RAID1 of two loop devices as the regular device; "dmzadm
--format" succeeds and "dmzadm --start" fails as above.
Tested on v7.4-rc5 with lockdep, KASAN and DEBUG_ATOMIC_SLEEP: dm-zoned
now starts with md RAID1, md RAID0 (512 KiB chunk) and dm-linear on md
RAID1 as the regular device. Tables whose zoned devices have different
zone sizes are still refused: by the dm-zoned constructor before
dm-table checks them, and for dm-linear by the check against the final
limits, which this patch does not change.
LLM coding assistants (Claude Code, with reviews by OpenAI, Google
Gemini and GitHub Copilot models) were used for the root cause analysis
and for drafts of the code, this changelog and the tests; the cover
letter has the details.
Fixes: 2d669ceb69c2 ("dm table: Fix zoned model check and zone sectors check")
Cc: stable@vger.kernel.org # 6.18.x
Signed-off-by: Kyrylo Biryuk <illofspeed@gmail.com>
---
drivers/md/dm-table.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 48f25ab6b..aba085f8f 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1742,6 +1742,17 @@ static int device_not_matches_zone_sectors(struct dm_target *ti, struct dm_dev *
return bdev_zone_sectors(dev->bdev) != *zone_sectors;
}
+static int device_get_zone_sectors(struct dm_target *ti, struct dm_dev *dev,
+ sector_t start, sector_t len, void *data)
+{
+ unsigned int *zone_sectors = data;
+
+ if (!bdev_is_zoned(dev->bdev))
+ return 0;
+ *zone_sectors = bdev_zone_sectors(dev->bdev);
+ return 1;
+}
+
/*
* Check consistency of zoned model and zone sectors across all targets. For
* zone sectors, if the destination device is a zoned block device, it shall
@@ -1816,7 +1827,14 @@ int dm_calculate_queue_limits(struct dm_table *t,
* in table support this zoned model and zone sectors.
*/
zoned = (ti_limits.features & BLK_FEAT_ZONED);
- zone_sectors = ti_limits.chunk_sectors;
+ /*
+ * Take the zone size from the first zoned device: the
+ * stacked chunk_sectors is the gcd() with the I/O
+ * boundary of any regular device that a mixed zoned
+ * model target (dm-zoned) maps.
+ */
+ ti->type->iterate_devices(ti, device_get_zone_sectors,
+ &zone_sectors);
}
/* Set I/O hints portion of queue limits */
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 12:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox