From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796194147; b=VxeXkQ5FYk+zALwz/vIZZTDmFBjbklFaSdeJ766EkjZmDfpG9TmfmFqNWWTc0WokwR5y Uy3uOd0yZc6f6moxhK3CKikHcB788PkcyFnjAaajj5pfy6LPlN3ZVwB2bZf1/6uGreoFC arEGAjpF9dA4T1s8VFL9F72djFADEDctMvogkpDaT4RLDufyooF001GqoSFz1IwwnnOou Fw/8v0t8JDs7gtMmeYVwWxEGCmvF+biMl5Opd/F7QWqHAmLr1aEPhFrCUhiUaYdMf2wSy dKRZrHFZaPHfYRd4AFyVxO32NE2qyCaJ4GEVj5X5NuTHiCXOx/8PBYWv+b4QCyFY1+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796194147; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:Organization: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=3T+h5Cw0GuNXZ0946RvrvgUvTipNbYH6so9MAyxN7oI=; b=wowleZ1wv77lDJ7Jqh/RmgkmPK4iwpCnl7GUyCH9n4HO7brw9Df1bvL7StVIGOPAxYBu Hal04QGWOtLKU8SOtsXqu9XAjrUNGJXvODHWkqwJr+D4KxTvEL//vCWNm28IE8Ldwy2xM m6ordSyObdELKGKSvSsPE4SQX4ZHvXFkIibwM/VLHe+kU3VV9yukxWN+hR8dEYJ1Oxlt+ rDV4r8fmQ8szk/xPEgET8SVE9t4Ff+qFmieBRzUX+3MOqoqdDZz8EWO5mdpfoeFWE1bfq bdiNzIosp5xI+wOMXxw+TfjWKIjAnQS7nQ9tUs6OkAsH/9hTOSlJNnP1RonFsVzlkrg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EvQBFlBF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99C91606A31A; Wed, 2 Dec 2026 06:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EvQBFlBF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 859AA1F000C1; Wed, 2 Dec 2026 06:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796194147; bh=3T+h5Cw0GuNXZ0946RvrvgUvTipNbYH6so9MAyxN7oI=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=EvQBFlBFXduHOOaywzvBlPBDpl6YKJAzDKprWuWu8hwq1lTxcg7gwkHqB5Z/XCGS9 64wSvJVYjdEGioFD1XjDWYvtBQTgqioGDtUdOYKyI1oXNIEdu3N+5vbjvC2rbI1VNO 0Ei3Ju1B7PWbFED0orngR0unyTX53/zs2SkW1vTGUieS7JEzn0cpTxxVjw/i0BYoJY gl4Ftxrig38324iT7Y1IT9Rj0z0vgMZDAwVc/XLOGAmAlVMV6sYbbNHn8bfGm1yrgo A6/Mfn0ePLFwHObSZ1ki+rkN7cwtOE6IvIrcnob5HrxGW/8GZ3hn9w8Ob+5t2fmj0O lhx2y98LZgEgw== Message-ID: <27d958f1-4ecf-4d54-9dbc-51fd11840625@kernel.org> Date: Wed, 2 Dec 2026 15:49:03 +0900 X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 0/1] dm-table: dm-zoned refuses md RAID1/RAID0 as its regular device To: Kyrylo Biryuk , 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 References: <20261201121037.366367-1-illofspeed@gmail.com> Content-Language: en-US From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20261201121037.366367-1-illofspeed@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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