* [PATCH] nvmet: bound zone append to BIO_MAX_VECS segments
@ 2026-12-01 8:34 Guixin Liu
2026-12-02 6:35 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Guixin Liu @ 2026-12-01 8:34 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
nvmet_bdev_execute_zone_append() builds a single bio with req->sg_cnt
entries. A fabric host can submit a zone append whose data length
exceeds BIO_MAX_VECS pages, and bio_alloc() then hits the BUG() in
biovec_slab(), killing the target. Unlike the read/write path, zone
append cannot be split into multiple bios.
The ZASL advertised to the host is derived from the backend device
limit without accounting for this, so even a host that respects the
advertised limit can trigger the BUG.
Cap the advertised ZASL at BIO_MAX_VECS pages, mirroring the passthru
mdts cap, and reject commands with more segments than a single bio
can hold with Invalid Field.
Fixes: aaf2e048af27 ("nvmet: add ZBD over ZNS backend support")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Found by code inspection, reproduced and verified on a QEMU loopback
nvmet-tcp target (7.3.0, KASAN) with a zoned null_blk namespace
(max_sectors 8 MiB) and port mdts 9.
Reproduction: a 2 MiB Zone Append passthru (512 pages) hits
"kernel BUG at block/bio.c:64" in biovec_slab(), called from
bio_alloc_bioset() via nvmet_bdev_execute_zone_append(); the target
I/O work dies and the command times out on the host. With this patch
the same command completes with Invalid Field (DNR) and the target
stays alive.
With the ZASL cap the controller advertises zasl 8 (1 MiB) instead of
9 (2 MiB), and a 1 MiB append through the host block layer succeeds.
A 257-page passthru append is rejected with Invalid Field; zone reset
and report zones keep working.
Note: the null_blk backend defaults to max_segments 128, so a 1 MiB
append whose receive pages are fragmented (> 128 segments) is rejected
by the block layer with Internal status on both the base and the
patched target; this is pre-existing device-limit behavior, unchanged
by this patch.
drivers/nvme/target/zns.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c
index cea05b4bc740..3575047dd0c2 100644
--- a/drivers/nvme/target/zns.c
+++ b/drivers/nvme/target/zns.c
@@ -34,7 +34,12 @@ static int validate_conv_zones_cb(struct blk_zone *z,
bool nvmet_bdev_zns_enable(struct nvmet_ns *ns)
{
- u8 zasl = nvmet_zasl(bdev_max_zone_append_sectors(ns->bdev));
+ /*
+ * Zone append is submitted as a single bio, so limit the ZASL
+ * based on BIO_MAX_VECS as well.
+ */
+ u8 zasl = nvmet_zasl(min_t(u32, bdev_max_zone_append_sectors(ns->bdev),
+ BIO_MAX_VECS << PAGE_SECTORS_SHIFT));
struct gendisk *bd_disk = ns->bdev->bd_disk;
int ret;
@@ -565,6 +570,12 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req)
if (!nvmet_check_transfer_len(req, nvmet_rw_data_len(req)))
return;
+ if (req->sg_cnt > BIO_MAX_VECS) {
+ req->error_loc = offsetof(struct nvme_rw_command, length);
+ status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
+ goto out;
+ }
+
if (data_len >
bdev_max_zone_append_sectors(req->ns->bdev) << SECTOR_SHIFT) {
req->error_loc = offsetof(struct nvme_rw_command, length);
--
2.43.7
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 6:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 8:34 [PATCH] nvmet: bound zone append to BIO_MAX_VECS segments Guixin Liu
2026-12-02 6:35 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.