From: Niklas Cassel <cassel@kernel.org>
To: Stefan Hajnoczi <stefanha@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Hanna Reitz <hreitz@redhat.com>
Cc: Sam Li <faithilikerun@gmail.com>,
Damien Le Moal <dlemoal@kernel.org>,
Niklas Cassel <cassel@kernel.org>,
qemu-block@nongnu.org, qemu-devel@nongnu.org
Subject: [PATCH v5 09/15] block: reject a zone append that is larger than a zone
Date: Fri, 18 Sep 2026 19:29:17 +0200 [thread overview]
Message-ID: <20260918172925.2640888-10-cassel@kernel.org> (raw)
In-Reply-To: <20260918172925.2640888-1-cassel@kernel.org>
A zone append cannot cross a zone boundary, so a request larger than a
zone can never be carried out.
Nothing rejects one. The block layer does not look at the length at all,
and raw_co_zone_append() writes qiov->size bytes at the write pointer
once it has validated the offset, so the write runs past the end of the
zone: on a disk with 8 MiB zones, an append of 8 MiB plus one block
fills the zone and advances the write pointer of the zone after it.
virtio-blk does compare the length, but against
BlockLimits.max_append_sectors, which is how much the backend takes in
one command and not how large a zone is. For a Linux block device that
value is never larger than a zone, so virtio-blk is protected by what
the backend happens to report rather than by the check it makes.
Check the length in bdrv_co_zone_append(), next to the check that an
append is a multiple of the sector size. Both are conditions of the
operation rather than of a medium, so the block layer is where they hold
for every caller and where no driver has to repeat them.
The exact bound is tighter: a request also has to fit in the part of the
zone that is still writable, which depends on the write pointer and so
stays with the drivers.
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
block/io.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/block/io.c b/block/io.c
index b9d0b3fd7b..d7c403bc08 100644
--- a/block/io.c
+++ b/block/io.c
@@ -3365,6 +3365,18 @@ int coroutine_fn bdrv_co_zone_append(BlockDriverState *bs, int64_t *offset,
return -EINVAL;
}
+ /*
+ * An append cannot cross a zone boundary, so one that is larger than a
+ * zone can never be carried out, wherever the write pointer of the zone
+ * is. The exact bound is the part of the zone that is still writable,
+ * which only a driver can check, as only it holds the write pointer.
+ * zone_size is zero when the device is not zoned, which is reported as
+ * unsupported below.
+ */
+ if (bs->bl.zone_size && qiov->size > bs->bl.zone_size) {
+ return -EINVAL;
+ }
+
bdrv_inc_in_flight(bs);
if (!drv || !drv->bdrv_co_zone_append || bs->bl.zoned == BLK_Z_NONE) {
co.ret = -ENOTSUP;
--
2.55.0
next prev parent reply other threads:[~2026-09-18 17:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 17:29 [PATCH v5 00/15] block: fix the zone write granularity and the zone append limit Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 01/15] block: widen BlockLimits.zone_size to uint64_t Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 02/15] virtio-blk: do not merge requests across a zone boundary Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 03/15] block: add a helper for the index of the zone an offset falls in Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 04/15] block: add a helper to check if a zone is conventional Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 05/15] hw/block: derive the zone write granularity from the block sizes Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 06/15] virtio-blk: check the write granularity of writes to sequential zones Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 07/15] hw/block: reject a zoned device that the block sizes cannot address Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 08/15] block: reject zone appends that are not a multiple of the sector size Niklas Cassel
2026-09-18 17:29 ` Niklas Cassel [this message]
2026-09-18 17:29 ` [PATCH v5 10/15] file-posix: remove the zone append write granularity check Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 11/15] virtio-blk: add a max-append-sectors property Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 12/15] block: remove BlockLimits.max_append_sectors Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 13/15] file-posix: reject a zone append past the device capacity Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 14/15] file-posix: reject a zone append to a full or conventional zone Niklas Cassel
2026-09-18 17:29 ` [PATCH v5 15/15] block: do not use CoroutineIOCompletion to hold a return value Niklas Cassel
2026-09-18 18:09 ` [PATCH v5 00/15] block: fix the zone write granularity and the zone append limit Niklas Cassel
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=20260918172925.2640888-10-cassel@kernel.org \
--to=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=faithilikerun@gmail.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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 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.