* [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD
@ 2026-11-25 14:21 Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 1/4] drivers/vhost/blk: drop ring features already in VHOST_FEATURES Alexander Ivanov
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Alexander Ivanov @ 2026-11-25 14:21 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
vhost-blk does not offer VIRTIO_BLK_F_DISCARD, so a guest on vhost-blk
cannot release unused blocks of its disk, while virtio-blk in QEMU can.
vhost-blk also fails WRITE ZEROES with VIRTIO_BLK_S_IOERR when the range
is above the backend limit, which the guest does not know, and once the
backend loses WRITE ZEROES support, e.g. on a dm table reload. In the
latter case the guest gets -EIO instead of falling back to writing
zeroes itself.
Patch 1 drops the ring features that are already part of VHOST_FEATURES.
Patch 2 stops checking WRITE ZEROES ranges against the backend limit.
Patch 3 answers VIRTIO_BLK_S_UNSUPP to WRITE ZEROES when the backend has
no WRITE ZEROES support. Patch 4 handles VIRTIO_BLK_T_DISCARD as a
single-segment request sent to the backend as one REQ_OP_DISCARD bio.
The QEMU side is sent separately.
v4:
- patch 2: say a backend without WRITE ZEROES still gets
VIRTIO_BLK_S_IOERR and the VMM still has to cap
max_write_zeroes_sectors
- patch 3: look up the backend bdev in vhost_blk_req_done() only when
the bio failed
- patch 4: pass the backend file to vhost_blk_parse_segment() instead of
bdev; test for REQ_OP_DISCARD instead of op_is_discard(); say the VMM
rounds the limit down to the logical block size and must not offer
discard for a drive with discard=ignore
v3:
- merge with "drivers/vhost/blk: return UNSUPP for write zeroes on a
backend without it", split into patches 2 and 3 and put before the
discard patch, so the WRITE ZEROES fixes apply without it
- patch 3: test the op in vhost_blk_req_done() through req->bi_opf;
treat any failure as unsupported once the backend limit is 0; say this
replaces the contract of 3b2e28a4f6b7 and add its Fixes: line
- patch 4: count any discard failure as success once the backend
discard limit is 0; pass bdev to vhost_blk_parse_segment() instead of
a size limit; complete both request types through
vhost_blk_req_submit_or_complete(); say which limits the VMM must set
v2:
- discard patch: keep vhost_blk_parse_write_zeroes() and add
vhost_blk_parse_discard(), both on top of vhost_blk_parse_segment()
that reads and checks the segment, instead of one parser full of
per-type conditions
https://virtuozzo.atlassian.net/browse/VSTOR-141683
https://virtuozzo.atlassian.net/browse/VSTOR-141684
Assisted-by: LLM
Alexander Ivanov (4):
drivers/vhost/blk: drop ring features already in VHOST_FEATURES
drivers/vhost/blk: stop failing write zeroes above the backend limit
drivers/vhost/blk: return UNSUPP for write zeroes on a backend without
it
drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD
drivers/vhost/blk.c | 115 +++++++++++++++++++++++++++++++++-----------
1 file changed, 88 insertions(+), 27 deletions(-)
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Devel] [PATCH hci-8.2 v4 1/4] drivers/vhost/blk: drop ring features already in VHOST_FEATURES
2026-11-25 14:21 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
@ 2026-11-25 14:21 ` Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 2/4] drivers/vhost/blk: stop failing write zeroes above the backend limit Alexander Ivanov
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Alexander Ivanov @ 2026-11-25 14:21 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
VIRTIO_RING_F_INDIRECT_DESC and VIRTIO_RING_F_EVENT_IDX are part of
VHOST_FEATURES, there is no need to list them again.
https://virtuozzo.atlassian.net/browse/VSTOR-141683
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
---
drivers/vhost/blk.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index d6917f0e662e..816ce4cb77a2 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -26,8 +26,6 @@
enum {
VHOST_BLK_FEATURES = VHOST_FEATURES |
- (1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
- (1ULL << VIRTIO_RING_F_EVENT_IDX) |
(1ULL << VIRTIO_BLK_F_MQ) |
(1ULL << VIRTIO_BLK_F_FLUSH) |
(1ULL << VIRTIO_BLK_F_WRITE_ZEROES),
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Devel] [PATCH hci-8.2 v4 2/4] drivers/vhost/blk: stop failing write zeroes above the backend limit
2026-11-25 14:21 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 1/4] drivers/vhost/blk: drop ring features already in VHOST_FEATURES Alexander Ivanov
@ 2026-11-25 14:21 ` Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Alexander Ivanov
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Alexander Ivanov @ 2026-11-25 14:21 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
vhost_blk_parse_write_zeroes() answers VIRTIO_BLK_S_IOERR to a range
above the WRITE ZEROES limit of the backend. The guest does not know
that limit: it sees UINT_MAX when the VMM leaves
max_write_zeroes_sectors 0, and a dm table reload can lower the limit of
the backend below the one the VMM sampled.
Every request above the limit of the backend then fails, while the block
layer splits a WRITE ZEROES bio by that limit anyway.
Drop the check. A backend without WRITE ZEROES still gets
VIRTIO_BLK_S_IOERR: submit_bio_noacct() fails the bio with
BLK_STS_NOTSUPP once the limit is 0. The VMM then need not set
max_write_zeroes_sectors from the limit of the backend, only cap it at
8388607 rounded down to the logical block size, so that the range fits
in one bio.
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 | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index 816ce4cb77a2..86b526c3f571 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -462,7 +462,6 @@ static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status)
struct file *f = vhost_vq_get_backend(&req->blk_vq->vq);
struct block_device *bdev = I_BDEV(f->f_mapping->host);
sector_t bs_mask = (bdev_logical_block_size(bdev) >> SECTOR_SHIFT) - 1;
- unsigned int max_sects = bdev_write_zeroes_sectors(bdev);
struct virtio_blk_discard_write_zeroes seg;
struct iov_iter iter;
u32 flags, nr_sects;
@@ -483,8 +482,8 @@ static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status)
sector = le64_to_cpu(seg.sector);
nr_sects = le32_to_cpu(seg.num_sectors);
- if (vhost_blk_backend_ro(f) || !max_sects ||
- nr_sects > UINT_MAX >> SECTOR_SHIFT || nr_sects > max_sects ||
+ if (vhost_blk_backend_ro(f) ||
+ nr_sects > UINT_MAX >> SECTOR_SHIFT ||
(sector | nr_sects) & bs_mask ||
sector > bdev_nr_sectors(bdev) ||
nr_sects > bdev_nr_sectors(bdev) - sector) {
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Devel] [PATCH hci-8.2 v4 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it
2026-11-25 14:21 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 1/4] drivers/vhost/blk: drop ring features already in VHOST_FEATURES Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 2/4] drivers/vhost/blk: stop failing write zeroes above the backend limit Alexander Ivanov
@ 2026-11-25 14:21 ` Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD Alexander Ivanov
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Alexander Ivanov @ 2026-11-25 14:21 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
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 | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index 86b526c3f571..5b8522729d18 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -149,11 +149,17 @@ 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;
int err;
err = blk_status_to_errno(bio->bi_status);
- if (err)
+ if (err) {
+ bdev = I_BDEV(req->blk->backend->f_mapping->host);
+ if ((req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES &&
+ !bdev_write_zeroes_sectors(bdev))
+ err = -EOPNOTSUPP;
req->bio_err = err;
+ }
/*
* Bounce buffer adds kvec to bio (instead of user backed memory),
@@ -730,7 +736,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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Devel] [PATCH hci-8.2 v4 4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD
2026-11-25 14:21 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
` (2 preceding siblings ...)
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Alexander Ivanov
@ 2026-11-25 14:21 ` Alexander Ivanov
2026-11-26 11:31 ` [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, " Andrey Zhadchenko
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Alexander Ivanov @ 2026-11-25 14:21 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
virtio-blk in QEMU supports discard, while vhost-blk does not offer
VIRTIO_BLK_F_DISCARD, so a guest on vhost-blk cannot release unused
blocks of its disk.
Handle VIRTIO_BLK_T_DISCARD like a write-zeroes request: a single
segment taken from the device-readable part, the same read-only,
alignment and capacity checks, and the range sent to the backend as a
single REQ_OP_DISCARD bio. Any flag set in a discard segment completes
the request with VIRTIO_BLK_S_UNSUPP, as the spec requires for UNMAP.
The VMM must set max_discard_seg to 1: a request with more than one
segment is unsupported, and a Linux guest reads zero there as seg_max and
merges discards into multi-range requests. It must also cap
max_discard_sectors at 8388607 rounded down to the logical block size, so
that the range fits in one bio. QEMU with the discard property on reports
zero for both until "vhost-blk: advertise discard limits in the config
space", so it needs that change. Nor may the VMM offer
VIRTIO_BLK_F_DISCARD for a drive whose discards are to be ignored (QEMU
discard=ignore): vhost-blk sends every discard to the backend.
The guest takes the limits from the VMM, not from the backend, so the
range is not checked against the backend discard limit: the block layer
splits the bio by it. A discard is a hint, so, as QEMU does, complete
the request with VIRTIO_BLK_S_OK without issuing it when the backend has
no discard support, and treat -EOPNOTSUPP from the bio as success: the
limit can drop to zero after the check, e.g. on a dm table reload, and a
stacked driver may reject a discard while still advertising one.
A discard in flight while support is lost may fail with BLK_STS_TARGET
instead, when dm or sd drop the limit on a target error. So any failure
of a discard counts as success once the backend discard limit is 0.
https://virtuozzo.atlassian.net/browse/VSTOR-141683
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/vhost/blk.c | 96 ++++++++++++++++++++++++++++++++++-----------
1 file changed, 74 insertions(+), 22 deletions(-)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index 5b8522729d18..bfd4bde0bcff 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -28,6 +28,7 @@ enum {
VHOST_BLK_FEATURES = VHOST_FEATURES |
(1ULL << VIRTIO_BLK_F_MQ) |
(1ULL << VIRTIO_BLK_F_FLUSH) |
+ (1ULL << VIRTIO_BLK_F_DISCARD) |
(1ULL << VIRTIO_BLK_F_WRITE_ZEROES),
};
@@ -155,10 +156,14 @@ static void vhost_blk_req_done(struct bio *bio)
err = blk_status_to_errno(bio->bi_status);
if (err) {
bdev = I_BDEV(req->blk->backend->f_mapping->host);
- if ((req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES &&
- !bdev_write_zeroes_sectors(bdev))
+ if ((req->bi_opf & REQ_OP_MASK) == REQ_OP_DISCARD &&
+ (err == -EOPNOTSUPP || !bdev_max_discard_sectors(bdev)))
+ err = 0;
+ else if ((req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES &&
+ !bdev_write_zeroes_sectors(bdev))
err = -EOPNOTSUPP;
- req->bio_err = err;
+ if (err)
+ req->bio_err = err;
}
/*
@@ -289,7 +294,8 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req,
if (unlikely(req->bi_opf & REQ_PREFLUSH))
return vhost_blk_bio_make_simple(req, bdev);
- if ((req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES) {
+ if ((req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES ||
+ (req->bi_opf & REQ_OP_MASK) == REQ_OP_DISCARD) {
ret = vhost_blk_bio_make_simple(req, bdev);
if (!ret)
req->bio[0]->bi_iter.bi_size = req->len;
@@ -463,18 +469,19 @@ static bool vhost_blk_backend_ro(struct file *f)
bdev_read_only(I_BDEV(f->f_mapping->host));
}
-static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status)
+static int vhost_blk_parse_segment(struct vhost_blk_req *req, struct file *f,
+ unsigned int feature, u32 flags_mask,
+ u32 *flags, u8 *status)
{
- struct file *f = vhost_vq_get_backend(&req->blk_vq->vq);
struct block_device *bdev = I_BDEV(f->f_mapping->host);
sector_t bs_mask = (bdev_logical_block_size(bdev) >> SECTOR_SHIFT) - 1;
struct virtio_blk_discard_write_zeroes seg;
struct iov_iter iter;
- u32 flags, nr_sects;
+ u32 nr_sects;
sector_t sector;
*status = VIRTIO_BLK_S_UNSUPP;
- if (!vhost_has_feature(&req->blk_vq->vq, VIRTIO_BLK_F_WRITE_ZEROES) ||
+ if (!vhost_has_feature(&req->blk_vq->vq, feature) ||
req->len != sizeof(seg))
return 0;
@@ -482,8 +489,8 @@ static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status)
if (copy_from_iter(&seg, sizeof(seg), &iter) != sizeof(seg))
return -EFAULT;
- flags = le32_to_cpu(seg.flags);
- if (flags & ~VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP)
+ *flags = le32_to_cpu(seg.flags);
+ if (*flags & ~flags_mask)
return 0;
sector = le64_to_cpu(seg.sector);
@@ -499,14 +506,61 @@ static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status)
req->sector = sector;
req->len = (size_t)nr_sects << SECTOR_SHIFT;
+ *status = VIRTIO_BLK_S_OK;
+ return 0;
+}
+
+static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status)
+{
+ struct file *f = vhost_vq_get_backend(&req->blk_vq->vq);
+ u32 flags;
+ int ret;
+
+ ret = vhost_blk_parse_segment(req, f, VIRTIO_BLK_F_WRITE_ZEROES,
+ VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP,
+ &flags, status);
+ if (ret || *status != VIRTIO_BLK_S_OK)
+ return ret;
+
req->bi_opf = REQ_OP_WRITE_ZEROES;
if (!(flags & VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP))
req->bi_opf |= REQ_NOUNMAP;
+ return 0;
+}
- *status = VIRTIO_BLK_S_OK;
+static int vhost_blk_parse_discard(struct vhost_blk_req *req, u8 *status)
+{
+ struct file *f = vhost_vq_get_backend(&req->blk_vq->vq);
+ struct block_device *bdev = I_BDEV(f->f_mapping->host);
+ u32 flags;
+ int ret;
+
+ ret = vhost_blk_parse_segment(req, f, VIRTIO_BLK_F_DISCARD,
+ 0, &flags, status);
+ if (ret || *status != VIRTIO_BLK_S_OK)
+ return ret;
+
+ req->bi_opf = REQ_OP_DISCARD;
+ if (!bdev_max_discard_sectors(bdev))
+ req->len = 0;
return 0;
}
+static int vhost_blk_req_submit_or_complete(struct vhost_blk_req *req,
+ u8 status)
+{
+ int ret;
+
+ if (status == VIRTIO_BLK_S_OK && req->len)
+ return vhost_blk_req_submit(req);
+
+ ret = vhost_blk_set_status(req, status);
+ if (!ret)
+ vhost_add_used_and_signal(&req->blk->dev, &req->blk_vq->vq,
+ req->head, sizeof(status));
+ return ret;
+}
+
static int vhost_blk_req_handle(struct vhost_virtqueue *vq,
struct virtio_blk_outhdr *hdr,
u16 head, u16 out, u16 in)
@@ -546,7 +600,8 @@ static int vhost_blk_req_handle(struct vhost_virtqueue *vq,
req->status[0].iov_base = st->iov_base + st->iov_len;
req->status[0].iov_len = sizeof(status);
- if (type == VIRTIO_BLK_T_OUT || type == VIRTIO_BLK_T_WRITE_ZEROES) {
+ if (type == VIRTIO_BLK_T_OUT || type == VIRTIO_BLK_T_DISCARD ||
+ type == VIRTIO_BLK_T_WRITE_ZEROES) {
data_iov = vq->iov;
data_nr = out;
} else {
@@ -594,18 +649,15 @@ static int vhost_blk_req_handle(struct vhost_virtqueue *vq,
req->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
ret = vhost_blk_req_submit(req);
break;
+ case VIRTIO_BLK_T_DISCARD:
+ ret = vhost_blk_parse_discard(req, &status);
+ if (!ret)
+ ret = vhost_blk_req_submit_or_complete(req, status);
+ break;
case VIRTIO_BLK_T_WRITE_ZEROES:
ret = vhost_blk_parse_write_zeroes(req, &status);
- if (ret)
- break;
- if (status == VIRTIO_BLK_S_OK && req->len) {
- ret = vhost_blk_req_submit(req);
- break;
- }
- ret = vhost_blk_set_status(req, status);
- if (ret)
- break;
- vhost_add_used_and_signal(&blk->dev, vq, head, sizeof(status));
+ if (!ret)
+ ret = vhost_blk_req_submit_or_complete(req, status);
break;
case VIRTIO_BLK_T_GET_ID:
len = min_t(size_t,
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD
2026-11-25 14:21 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
` (3 preceding siblings ...)
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD Alexander Ivanov
@ 2026-11-26 11:31 ` Andrey Zhadchenko
2026-11-30 15:24 ` Konstantin Khorenko
2026-11-30 15:24 ` Konstantin Khorenko
6 siblings, 0 replies; 8+ messages in thread
From: Andrey Zhadchenko @ 2026-11-26 11:31 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: devel
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
On 11/25/26 15:21, Alexander Ivanov wrote:
> vhost-blk does not offer VIRTIO_BLK_F_DISCARD, so a guest on vhost-blk
> cannot release unused blocks of its disk, while virtio-blk in QEMU can.
>
> vhost-blk also fails WRITE ZEROES with VIRTIO_BLK_S_IOERR when the range
> is above the backend limit, which the guest does not know, and once the
> backend loses WRITE ZEROES support, e.g. on a dm table reload. In the
> latter case the guest gets -EIO instead of falling back to writing
> zeroes itself.
>
> Patch 1 drops the ring features that are already part of VHOST_FEATURES.
> Patch 2 stops checking WRITE ZEROES ranges against the backend limit.
> Patch 3 answers VIRTIO_BLK_S_UNSUPP to WRITE ZEROES when the backend has
> no WRITE ZEROES support. Patch 4 handles VIRTIO_BLK_T_DISCARD as a
> single-segment request sent to the backend as one REQ_OP_DISCARD bio.
>
> The QEMU side is sent separately.
>
> v4:
> - patch 2: say a backend without WRITE ZEROES still gets
> VIRTIO_BLK_S_IOERR and the VMM still has to cap
> max_write_zeroes_sectors
> - patch 3: look up the backend bdev in vhost_blk_req_done() only when
> the bio failed
> - patch 4: pass the backend file to vhost_blk_parse_segment() instead of
> bdev; test for REQ_OP_DISCARD instead of op_is_discard(); say the VMM
> rounds the limit down to the logical block size and must not offer
> discard for a drive with discard=ignore
>
> v3:
> - merge with "drivers/vhost/blk: return UNSUPP for write zeroes on a
> backend without it", split into patches 2 and 3 and put before the
> discard patch, so the WRITE ZEROES fixes apply without it
> - patch 3: test the op in vhost_blk_req_done() through req->bi_opf;
> treat any failure as unsupported once the backend limit is 0; say this
> replaces the contract of 3b2e28a4f6b7 and add its Fixes: line
> - patch 4: count any discard failure as success once the backend
> discard limit is 0; pass bdev to vhost_blk_parse_segment() instead of
> a size limit; complete both request types through
> vhost_blk_req_submit_or_complete(); say which limits the VMM must set
>
> v2:
> - discard patch: keep vhost_blk_parse_write_zeroes() and add
> vhost_blk_parse_discard(), both on top of vhost_blk_parse_segment()
> that reads and checks the segment, instead of one parser full of
> per-type conditions
>
> https://virtuozzo.atlassian.net/browse/VSTOR-141683
> https://virtuozzo.atlassian.net/browse/VSTOR-141684
>
> Assisted-by: LLM
>
> Alexander Ivanov (4):
> drivers/vhost/blk: drop ring features already in VHOST_FEATURES
> drivers/vhost/blk: stop failing write zeroes above the backend limit
> drivers/vhost/blk: return UNSUPP for write zeroes on a backend without
> it
> drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD
>
> drivers/vhost/blk.c | 115 +++++++++++++++++++++++++++++++++-----------
> 1 file changed, 88 insertions(+), 27 deletions(-)
>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD
2026-11-25 14:21 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
` (4 preceding siblings ...)
2026-11-26 11:31 ` [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, " Andrey Zhadchenko
@ 2026-11-30 15:24 ` Konstantin Khorenko
2026-11-30 15:24 ` Konstantin Khorenko
6 siblings, 0 replies; 8+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 15:24 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: devel
Applying as is.
On Wed, 25 Nov 2026 15:21:41 +0100, Alexander Ivanov wrote:
> v4:
> - patch 2: say a backend without WRITE ZEROES still gets
> VIRTIO_BLK_S_IOERR and the VMM still has to cap
> max_write_zeroes_sectors
All v3 items are done in the patches. Keeping the backend file in
3/4 instead of bio->bi_bdev, as I suggested, is right: md raid0
remaps the bio itself to a member disk, so bi_bdev at completion is
not the device the limit has to be read from.
Thanks.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD
2026-11-25 14:21 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
` (5 preceding siblings ...)
2026-11-30 15:24 ` Konstantin Khorenko
@ 2026-11-30 15:24 ` Konstantin Khorenko
6 siblings, 0 replies; 8+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 15:24 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
On Wed, 25 Nov 2026 15:21:41 +0100, Alexander Ivanov wrote:
> drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD
>
> vhost-blk does not offer VIRTIO_BLK_F_DISCARD, so a guest on vhost-blk
> cannot release unused blocks of its disk, while virtio-blk in QEMU can.
>
> vhost-blk also fails WRITE ZEROES with VIRTIO_BLK_S_IOERR when the range
> is above the backend limit, which the guest does not know, and once the
> backend loses WRITE ZEROES support, e.g. on a dm table reload. In the
> latter case the guest gets -EIO instead of falling back to writing
> zeroes itself.
>
> [...]
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.6.vz10, thanks!
[1/4] drivers/vhost/blk: drop ring features already in VHOST_FEATURES
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/8b799e203feb
[2/4] drivers/vhost/blk: stop failing write zeroes above the backend limit
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/eae6c95d3a96
[3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/12fc00d18d45
[4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/f7e30da4f53b
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-30 15:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 14:21 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 1/4] drivers/vhost/blk: drop ring features already in VHOST_FEATURES Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 2/4] drivers/vhost/blk: stop failing write zeroes above the backend limit Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Alexander Ivanov
2026-11-25 14:21 ` [Devel] [PATCH hci-8.2 v4 4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD Alexander Ivanov
2026-11-26 11:31 ` [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, " Andrey Zhadchenko
2026-11-30 15:24 ` Konstantin Khorenko
2026-11-30 15:24 ` Konstantin Khorenko
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.