From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 3/3] drivers/vhost/blk: take req->len from one side of the descriptor chain
Date: Wed, 21 Oct 2026 10:46:10 +0200 [thread overview]
Message-ID: <20261021084610.1476738-4-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261021084610.1476738-1-alexander.ivanov@virtuozzo.com>
req->len covered the whole descriptor chain, so both readable and
writable data buffers became the payload. A read wrote disk data into
device-readable buffers and reported them as used, a write sent the
guest's writable buffers to disk.
Take write data only from the readable part and the payload of other
requests only from the writable part, as QEMU does. Read the status
byte from the end of the writable part.
Complete a read or write with VIRTIO_BLK_S_IOERR if its payload is
empty, above ALIGN_DOWN(INT_MAX, SECTOR_SIZE) or, for a write, not a
multiple of SECTOR_SIZE. Such requests used to fail in bio setup or
hit a WARN_ONCE() and leave the guest request hanging. Drop the now
unreachable WARN_ONCE().
https://virtuozzo.atlassian.net/browse/VSTOR-142755
Fixes: 1629db092dd7 ("drivers/vhost: vhost-blk accelerator for virtio-blk guests")
Fixes: 02ce37f62707 ("vhost-blk: add bounce-buffer for non-aligned requests")
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/vhost/blk.c | 43 ++++++++++++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index 94317a5f2cb6..3448910f9046 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -277,12 +277,6 @@ 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_WRITE && !IS_ALIGNED(req->len, SECTOR_SIZE)) {
- WARN_ONCE(1, "vhost-blk: write requests with unaligned len"
- " are not supported, len = %zu", req->len);
- return -EINVAL;
- }
-
/*
* Requests with unaligned io vectors are not supported by underlined
* block device, let's use an aligned intermediary "bounce buffer" to
@@ -450,10 +444,10 @@ static int vhost_blk_req_handle(struct vhost_virtqueue *vq,
struct vhost_blk *blk = container_of(vq->dev, struct vhost_blk, dev);
struct vhost_blk_vq *blk_vq = container_of(vq, struct vhost_blk_vq, vq);
struct vhost_blk_req *req;
- u16 total_iov_nr = out + in;
+ struct iovec *data_iov, *st;
struct iov_iter iter;
size_t in_len;
- int ret, len;
+ int ret, len, data_nr;
u32 type;
u8 status;
@@ -470,14 +464,37 @@ static int vhost_blk_req_handle(struct vhost_virtqueue *vq,
if (in_len < sizeof(status) || in_len > INT_MAX)
return -EINVAL;
- req->len = iov_length(vq->iov, total_iov_nr) - sizeof(status);
- req->iov_nr = move_iovec(vq->iov, req->iov, req->len, total_iov_nr,
+ /* The status is the last byte of the device-writable part */
+ for (st = vq->iov + out + in - 1; !st->iov_len; st--)
+ ;
+ st->iov_len -= sizeof(status);
+ req->status[0].iov_base = st->iov_base + st->iov_len;
+ req->status[0].iov_len = sizeof(status);
+
+ if (type == VIRTIO_BLK_T_OUT) {
+ data_iov = vq->iov;
+ data_nr = out;
+ } else {
+ data_iov = vq->iov + out;
+ data_nr = in;
+ }
+
+ req->len = iov_length(data_iov, data_nr);
+
+ if ((type == VIRTIO_BLK_T_IN || type == VIRTIO_BLK_T_OUT) &&
+ (!req->len || req->len > ALIGN_DOWN(INT_MAX, SECTOR_SIZE) ||
+ (type == VIRTIO_BLK_T_OUT && !IS_ALIGNED(req->len, SECTOR_SIZE)))) {
+ ret = vhost_blk_set_status(req, VIRTIO_BLK_S_IOERR);
+ if (!ret)
+ vhost_add_used_and_signal(&blk->dev, vq, head, sizeof(status));
+ return ret;
+ }
+
+ req->iov_nr = move_iovec(data_iov, req->iov, req->len, data_nr,
ARRAY_SIZE(blk_vq->iov));
req->bb = NULL;
- ret = move_iovec(vq->iov, req->status, sizeof(status), total_iov_nr,
- ARRAY_SIZE(req->status));
- if (ret < 0 || req->iov_nr < 0)
+ if (req->iov_nr < 0)
return -EINVAL;
switch (type) {
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-10-21 8:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 8:46 [Devel] [PATCH hci-8.1 0/3] drivers/vhost/blk: fix virtio-blk request header and payload parsing Alexander Ivanov
2026-10-21 8:46 ` [Devel] [PATCH hci-8.1 1/3] drivers/vhost/blk: convert virtio_blk_outhdr fields to CPU byte order Alexander Ivanov
2026-10-21 8:49 ` no-reply
2026-10-21 8:46 ` [Devel] [PATCH hci-8.1 2/3] drivers/vhost/blk: take virtio_blk_outhdr only from the readable part Alexander Ivanov
2026-10-21 8:49 ` no-reply
2026-10-21 8:46 ` Alexander Ivanov [this message]
2026-10-21 8:50 ` [Devel] [PATCH hci-8.1 3/3] drivers/vhost/blk: take req->len from one side of the descriptor chain no-reply
2026-10-25 21:54 ` [Devel] [PATCH hci-8.1 0/3] drivers/vhost/blk: fix virtio-blk request header and payload parsing Andrey Zhadchenko
2026-10-29 11:26 ` Konstantin Khorenko
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=20261021084610.1476738-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