From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it
Date: Wed, 25 Nov 2026 12:57:02 +0100 [thread overview]
Message-ID: <20261125115703.741517-4-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261125115703.741517-1-alexander.ivanov@virtuozzo.com>
The guest reads max_write_zeroes_sectors once at probe, but the WRITE
ZEROES limit of the backend can change while it runs: a dm table reload
with a target that does not pass WRITE ZEROES through drops it to 0.
vhost-blk then fails every WRITE ZEROES with VIRTIO_BLK_S_IOERR, and a
Linux guest since v6.11 returns -EIO to the caller instead of writing
zeroes itself. The VMM cannot work around it: the limit it samples may
already be stale, and the destination of a migration must offer the
features the guest has negotiated whatever the limit there is.
Answer VIRTIO_BLK_S_UNSUPP when a WRITE ZEROES bio fails with
BLK_STS_NOTSUPP, whatever the limit of the backend: submit_bio_noacct()
fails a WRITE ZEROES bio with BLK_STS_NOTSUPP once the limit is 0, and a
backend that rejects the command while advertising it gets UNSUPP
instead of IOERR as well. A request in flight while support is lost may
fail with BLK_STS_TARGET instead, when dm or sd drop the limit on a
target error. As blkdev_issue_write_zeroes() does, treat any failure of
a WRITE ZEROES bio as unsupported once the limit of the backend is 0.
The guest gets -EOPNOTSUPP instead of -EIO, and blkdev_issue_zeroout()
falls back to writing zeroes unless called with BLKDEV_ZERO_NOFALLBACK.
dm-kcopyd submits WRITE ZEROES without such a fallback and still fails,
now with -EOPNOTSUPP.
This replaces the contract of 3b2e28a4f6b7, which answered
VIRTIO_BLK_S_IOERR for a backend without WRITE ZEROES. The VMM must
still offer VIRTIO_BLK_F_WRITE_ZEROES only for a backend that supports
it at setup: the guest never learns that the limit is 0, and dm-kcopyd
would fail dm-thin zeroing of new blocks and dm-snapshot.
Fixes: 3b2e28a4f6b7 ("drivers/vhost/blk: support VIRTIO_BLK_F_WRITE_ZEROES")
https://virtuozzo.atlassian.net/browse/VSTOR-141684
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/vhost/blk.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index 86b526c3f571..0aee05b3f524 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -149,9 +149,13 @@ static inline int vhost_blk_set_status(struct vhost_blk_req *req, u8 status)
static void vhost_blk_req_done(struct bio *bio)
{
struct vhost_blk_req *req = bio->bi_private;
+ struct block_device *bdev = I_BDEV(req->blk->backend->f_mapping->host);
int err;
err = blk_status_to_errno(bio->bi_status);
+ if (err && (req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES &&
+ !bdev_write_zeroes_sectors(bdev))
+ err = -EOPNOTSUPP;
if (err)
req->bio_err = err;
@@ -730,7 +734,13 @@ static void vhost_blk_handle_host_kick(struct vhost_work *work)
}
vhost_blk_req_cleanup(req);
- status = req->bio_err == 0 ? VIRTIO_BLK_S_OK : VIRTIO_BLK_S_IOERR;
+ if (!req->bio_err)
+ status = VIRTIO_BLK_S_OK;
+ else if (req->bio_err == -EOPNOTSUPP &&
+ (req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES)
+ status = VIRTIO_BLK_S_UNSUPP;
+ else
+ status = VIRTIO_BLK_S_IOERR;
if (vhost_blk_set_status(req, status)) {
vhostblk_vq_err(blk, vq, "Failed to write status");
} else {
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-25 11:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 11:56 [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
2026-11-25 11:57 ` [Devel] [PATCH hci-8.2 v3 1/4] drivers/vhost/blk: drop ring features already in VHOST_FEATURES Alexander Ivanov
2026-11-25 11:57 ` [Devel] [PATCH hci-8.2 v3 2/4] drivers/vhost/blk: stop failing write zeroes above the backend limit Alexander Ivanov
2026-11-25 12:32 ` Konstantin Khorenko
2026-11-25 11:57 ` Alexander Ivanov [this message]
2026-11-25 12:32 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Konstantin Khorenko
2026-11-25 11:57 ` [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD Alexander Ivanov
2026-11-25 12:32 ` Konstantin Khorenko
2026-11-25 12:32 ` [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: fix write zeroes errors, " Konstantin Khorenko
2026-11-25 14:07 ` Alexander Ivanov
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=20261125115703.741517-4-alexander.ivanov@virtuozzo.com \
--to=alexander.ivanov@virtuozzo.com \
--cc=andrey.zhadchenko@virtuozzo.com \
--cc=devel@openvz.org \
/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