* [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD
@ 2026-11-25 11:56 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
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Alexander Ivanov @ 2026-11-25 11:56 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.
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 | 110 ++++++++++++++++++++++++++++++++++----------
1 file changed, 85 insertions(+), 25 deletions(-)
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread* [Devel] [PATCH hci-8.2 v3 1/4] drivers/vhost/blk: drop ring features already in VHOST_FEATURES 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 ` 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 ` (3 subsequent siblings) 4 siblings, 0 replies; 10+ messages in thread From: Alexander Ivanov @ 2026-11-25 11:57 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] 10+ messages in thread
* [Devel] [PATCH hci-8.2 v3 2/4] drivers/vhost/blk: stop failing write zeroes above the backend limit 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 ` Alexander Ivanov 2026-11-25 12:32 ` Konstantin Khorenko 2026-11-25 11:57 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Alexander Ivanov ` (2 subsequent siblings) 4 siblings, 1 reply; 10+ messages in thread From: Alexander Ivanov @ 2026-11-25 11:57 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. The VMM then need not set max_write_zeroes_sectors from the limit of the backend. 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] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v3 2/4] drivers/vhost/blk: stop failing write zeroes above the backend limit 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 0 siblings, 0 replies; 10+ messages in thread From: Konstantin Khorenko @ 2026-11-25 12:32 UTC (permalink / raw) To: Alexander Ivanov; +Cc: devel I won't apply this version, please send v4 with the changes below. - Say that the zero-limit check goes too, and keep the cap advice: item 1 of the cover letter reply. On Wed, 25 Nov 2026 12:57:01 +0100, Alexander Ivanov wrote: > - if (vhost_blk_backend_ro(f) || !max_sects || > - nr_sects > UINT_MAX >> SECTOR_SHIFT || nr_sects > max_sects || The patch drops !max_sects as well. Until 3/4 a backend without WRITE ZEROES still gets IOERR, through the BLK_STS_NOTSUPP of submit_bio_noacct(); say so, as 3/4 builds on it. > Drop the check. The VMM then need not set max_write_zeroes_sectors from > the limit of the backend. It still has to cap it at 8388607 rounded down to the logical block size: the parser keeps both checks. 4/4 gives that advice for discard; give the same here. -- Konstantin Khorenko, Virtuozzo Linux Kernel Team _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it 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 11:57 ` Alexander Ivanov 2026-11-25 12:32 ` 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 ` [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: fix write zeroes errors, " Konstantin Khorenko 4 siblings, 1 reply; 10+ messages in thread From: Alexander Ivanov @ 2026-11-25 11:57 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 | 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it 2026-11-25 11:57 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Alexander Ivanov @ 2026-11-25 12:32 ` Konstantin Khorenko 0 siblings, 0 replies; 10+ messages in thread From: Konstantin Khorenko @ 2026-11-25 12:32 UTC (permalink / raw) To: Alexander Ivanov; +Cc: devel I won't apply this version, please send v4 with the changes below. - Look up the bdev only on an error: item 2 of the cover letter reply. On Wed, 25 Nov 2026 12:57:02 +0100, Alexander Ivanov wrote: > + struct block_device *bdev = I_BDEV(req->blk->backend->f_mapping->host); This runs for every completed bio, reads and writes included, while only a failed WRITE ZEROES or discard needs it. bio->bi_bdev inside the error branch is enough. -- Konstantin Khorenko, Virtuozzo Linux Kernel Team _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD 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 ` (2 preceding siblings ...) 2026-11-25 11:57 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Alexander Ivanov @ 2026-11-25 11:57 ` 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 4 siblings, 1 reply; 10+ messages in thread From: Alexander Ivanov @ 2026-11-25 11:57 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 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. A discard is a hint, and the guest takes the limits from the VMM, not from the backend. So the range is not checked against the backend discard limit: the bio gets split by it. 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 | 91 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c index 0aee05b3f524..134f627adfe5 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), }; @@ -153,6 +154,9 @@ static void vhost_blk_req_done(struct bio *bio) int err; err = blk_status_to_errno(bio->bi_status); + if (err && op_is_discard(req->bi_opf) && + (err == -EOPNOTSUPP || !bdev_max_discard_sectors(bdev))) + err = 0; if (err && (req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES && !bdev_write_zeroes_sectors(bdev)) err = -EOPNOTSUPP; @@ -287,7 +291,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 || + op_is_discard(req->bi_opf)) { ret = vhost_blk_bio_make_simple(req, bdev); if (!ret) req->bio[0]->bi_iter.bi_size = req->len; @@ -461,18 +466,20 @@ 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 block_device *bdev, + 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; @@ -480,8 +487,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); @@ -497,14 +504,62 @@ 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); + struct block_device *bdev = I_BDEV(f->f_mapping->host); + u32 flags; + int ret; + + ret = vhost_blk_parse_segment(req, bdev, 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, bdev, 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) @@ -544,7 +599,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 { @@ -592,18 +648,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] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD 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 0 siblings, 0 replies; 10+ messages in thread From: Konstantin Khorenko @ 2026-11-25 12:32 UTC (permalink / raw) To: Alexander Ivanov; +Cc: devel I won't apply this version, please send v4 with the changes below. - One form of the op test: item 3. - Pass the backend to vhost_blk_parse_segment() once: item 4. - Message fixes: item 5 of the cover letter reply. On Wed, 25 Nov 2026 12:57:03 +0100, Alexander Ivanov wrote: > + if (err && op_is_discard(req->bi_opf) && > + (err == -EOPNOTSUPP || !bdev_max_discard_sectors(bdev))) > + err = 0; > if (err && (req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES && Item 3: two forms of the same test side by side, here and in vhost_blk_bio_make(). v1 asked for one; use (req->bi_opf & REQ_OP_MASK) == REQ_OP_DISCARD next to the WRITE_ZEROES test. > +static int vhost_blk_parse_segment(struct vhost_blk_req *req, > + struct block_device *bdev, Item 4: the function still looks up f itself, and both callers take f and bdev only to pass bdev down. Get bdev from f here and drop the parameter and the callers' locals. > A discard is a hint, and the guest takes the limits from the VMM, not > from the backend. So the range is not checked against the backend > discard limit: the bio gets split by it. As QEMU does, complete the Item 5: the block layer splitting the bio is why the limit is not checked; the hint is why the request completes with VIRTIO_BLK_S_OK without a backend discard. Keep the two reasons apart. > max_discard_sectors at 8388607 so that the range fits in one bio. QEMU Item 5: 8388607 is not a multiple of 8, so on a 4K backend a range of exactly that size fails the alignment check with IOERR: say "rounded down to the logical block size". Also say that the VMM must not 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. -- Konstantin Khorenko, Virtuozzo Linux Kernel Team _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD 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 ` (3 preceding siblings ...) 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 14:07 ` Alexander Ivanov 4 siblings, 1 reply; 10+ messages in thread From: Konstantin Khorenko @ 2026-11-25 12:32 UTC (permalink / raw) To: Alexander Ivanov; +Cc: devel I won't apply this version, please send v4 with the changes below. 1. 2/4: say that the check of a zero limit goes too, and keep the cap advice the same as in 4/4. 2. 3/4: find the backend bdev only for a failed bio. 3. 4/4: one form of the op test for both types, as asked for v1. 4. 4/4: vhost_blk_parse_segment() gets the backend once; do not look up f in it and bdev from f in both callers. 5. 4/4: the split, not the hint, is why the backend limit is not checked; a drive whose discards are to be ignored must not get the feature; the 8388607 cap rounded down to the logical block size. The code of all four patches is right, and the v1 asks of both series are done apart from items 3 and 5. On Wed, 25 Nov 2026 12:56:59 +0100, Alexander Ivanov wrote: > Patch 1 drops the ring features that are already part of VHOST_FEATURES. > Patch 2 stops checking WRITE ZEROES ranges against the backend limit. Item 1: say here too that patch 2 drops the zero-limit check, which 3/4 then relies on. -- Konstantin Khorenko, Virtuozzo Linux Kernel Team _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD 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 0 siblings, 0 replies; 10+ messages in thread From: Alexander Ivanov @ 2026-11-25 14:07 UTC (permalink / raw) To: Konstantin Khorenko; +Cc: devel On 11/25/26 13:32, Konstantin Khorenko wrote: > I won't apply this version, please send v4 with the changes below. > > 1. 2/4: say that the check of a zero limit goes too, and keep the cap > advice the same as in 4/4. > 2. 3/4: find the backend bdev only for a failed bio. > 3. 4/4: one form of the op test for both types, as asked for v1. > 4. 4/4: vhost_blk_parse_segment() gets the backend once; do not look > up f in it and bdev from f in both callers. > 5. 4/4: the split, not the hint, is why the backend limit is not > checked; a drive whose discards are to be ignored must not get the > feature; the 8388607 cap rounded down to the logical block size. Fixed. _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-25 14:09 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Alexander Ivanov 2026-11-25 12:32 ` 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
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.