From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: no-reply@sashiko.virtuozzo.com, andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.2 2/2] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD
Date: Mon, 23 Nov 2026 09:57:28 +0100 [thread overview]
Message-ID: <bd38e4c8-f714-4ea8-a5b1-e810fda5a21c@virtuozzo.com> (raw)
In-Reply-To: <010701a207953b9f-3e153367-d6dd-495b-a422-9b5c2e47e6eb-000000@eu-central-1.amazonses.com>
>> @@ -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@sashiko.virtuozzo.com>
A Linux guest cannot send a discard of 4 GiB or more:
blk_queue_get_max_sectors()
caps discard requests at UINT_MAX >> SECTOR_SHIFT, whatever
max_discard_sectors says,
so fstrim/blkdiscard will not hit IOERR. QEMU never advertises 0 there
either, and it fails a
discard above its advertised limit with VIRTIO_BLK_S_IOERR too.
Splitting is not worth the
complexity.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-23 8:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 8:40 [Devel] [PATCH hci-8.2 0/2] " Alexander Ivanov
2026-11-23 8:40 ` [Devel] [PATCH hci-8.2 1/2] drivers/vhost/blk: drop ring features already in VHOST_FEATURES Alexander Ivanov
2026-11-23 8:43 ` no-reply
2026-11-23 8:40 ` [Devel] [PATCH hci-8.2 2/2] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD Alexander Ivanov
2026-11-23 8:45 ` no-reply
2026-11-23 8:57 ` Alexander Ivanov [this message]
2026-11-23 13:36 ` Andrey Zhadchenko
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=bd38e4c8-f714-4ea8-a5b1-e810fda5a21c@virtuozzo.com \
--to=alexander.ivanov@virtuozzo.com \
--cc=andrey.zhadchenko@virtuozzo.com \
--cc=devel@openvz.org \
--cc=no-reply@sashiko.virtuozzo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox