[Devel] [PATCH hci-8.2 2/2] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Mon Nov 23 11:45:50 MSK 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] vhost-blk: discard of 4 GiB or more fails with IOERR, unlike
  QEMU
--

commit 585dad915e7dad27e7f9cee3c2459ab7642245e2
Author: Alexander Ivanov <alexander.ivanov at virtuozzo.com>

drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD

This commit makes vhost-blk offer VIRTIO_BLK_F_DISCARD. A discard request is handled like write-zeroes: it takes a single segment, passes the same checks, and goes to the backend as one REQ_OP_DISCARD bio. A backend with no discard support, or an -EOPNOTSUPP from the bio, completes with VIRTIO_BLK_S_OK.

> diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
> index 816ce4cb77a2..811349b19500 100644
> --- a/drivers/vhost/blk.c
> +++ b/drivers/vhost/blk.c

[ ... ]

> @@ -478,13 +485,14 @@ static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status)
> -	if (vhost_blk_backend_ro(f) || !max_sects ||
> -	    nr_sects > UINT_MAX >> SECTOR_SHIFT || nr_sects > max_sects ||
> +	if (vhost_blk_backend_ro(f) ||
> +	    (!discard && (!max_sects || nr_sects > max_sects)) ||
> +	    nr_sects > UINT_MAX >> SECTOR_SHIFT ||
>  	    (sector | nr_sects) & bs_mask ||
>  	    sector > bdev_nr_sectors(bdev) ||
>  	    nr_sects > bdev_nr_sectors(bdev) - sector) {
>  		*status = VIRTIO_BLK_S_IOERR;

[Severity: Low]
Can a valid discard of 4 GiB or more fail with VIRTIO_BLK_S_IOERR here? The commit message treats discard as a hint that is not checked against backend limits. For discard, though, the nr_sects > UINT_MAX >> SECTOR_SHIFT check still returns IOERR.

If the VMM leaves max_discard_sectors at 0, drivers/block/virtio_blk.c sets max_hw_discard_sectors to UINT_MAX. The guest can then merge discards well past this cap. With max_discard_seg = 1, the merged range goes out as a single segment. fstrim or blkdiscard on a large range would then report errors. QEMU does not fail these requests.

Should vhost_blk_bio_make() split a large discard across several bios? Alternatively, the commit message could tell the VMM to cap max_discard_sectors, as the write-zeroes commit did for its limit.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply at sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261123084014.176824-1-alexander.ivanov@virtuozzo.com?part=2



More information about the Devel mailing list