All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler
Date: Fri, 27 Nov 2026 12:16:01 +0100	[thread overview]
Message-ID: <20261127111604.1151696-3-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261127111604.1151696-1-alexander.ivanov@virtuozzo.com>

A request resubmitted by QEMU is to go through the same header checks
and vhost_blk_req_handle() as one taken from the avail ring. Move them
into vhost_blk_handle_desc().

https://virtuozzo.atlassian.net/browse/VSTOR-152175
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 drivers/vhost/blk.c | 61 ++++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 25 deletions(-)

diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index d6917f0e662e..3089aea7dda2 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -627,14 +627,46 @@ static int vhost_blk_req_handle(struct vhost_virtqueue *vq,
 	return ret;
 }
 
-static void vhost_blk_handle_guest_kick(struct vhost_work *work)
+static int vhost_blk_handle_desc(struct vhost_virtqueue *vq, u16 head,
+				 unsigned int out, unsigned int in)
 {
+	struct vhost_blk *blk = container_of(vq->dev, struct vhost_blk, dev);
+	struct iovec hdr_iovec[VHOST_MAX_METADATA_IOV];
 	struct virtio_blk_outhdr hdr;
+	struct iov_iter iter;
+	int ret;
+
+	if (iov_length(vq->iov, out) < sizeof(hdr)) {
+		vhostblk_vq_err(blk, vq, "virtio_blk_hdr (head %d) is missing!", head);
+		return -EINVAL;
+	}
+
+	ret = move_iovec(vq->iov, hdr_iovec, sizeof(hdr), out, ARRAY_SIZE(hdr_iovec));
+	if (ret < 0) {
+		vhostblk_vq_err(blk, vq, "virtio_blk_hdr (head %d) is too split!", head);
+		return -EINVAL;
+	}
+
+	iov_iter_init(&iter, ITER_SOURCE, hdr_iovec, ARRAY_SIZE(hdr_iovec), sizeof(hdr));
+	ret = copy_from_iter(&hdr, sizeof(hdr), &iter);
+	if (ret != sizeof(hdr)) {
+		vhostblk_vq_err(blk, vq, "Failed to get read header (head %d): got %d, expected %ld!\n",
+				head, ret, sizeof(hdr));
+		return -EFAULT;
+	}
+
+	ret = vhost_blk_req_handle(vq, &hdr, head, out, in);
+	if (ret < 0 && ret != -EAGAIN && ret != -ENOMEM)
+		vhostblk_vq_err(blk, vq, "Failed to process guest request (head %d) with %d",
+				head, ret);
+	return ret;
+}
+
+static void vhost_blk_handle_guest_kick(struct vhost_work *work)
+{
 	struct vhost_blk_vq *blk_vq;
 	struct vhost_virtqueue *vq;
-	struct iovec hdr_iovec[VHOST_MAX_METADATA_IOV];
 	struct vhost_blk *blk;
-	struct iov_iter iter;
 	int in, out, ret;
 	struct file *f;
 	int head;
@@ -665,33 +697,12 @@ static void vhost_blk_handle_guest_kick(struct vhost_work *work)
 			break;
 		}
 
-		if (iov_length(vq->iov, out) < sizeof(hdr)) {
-			vhostblk_vq_err(blk, vq, "virtio_blk_hdr (head %d) is missing!", head);
-			break;
-		}
-
-		ret = move_iovec(vq->iov, hdr_iovec, sizeof(hdr), out, ARRAY_SIZE(hdr_iovec));
-		if (ret < 0) {
-			vhostblk_vq_err(blk, vq, "virtio_blk_hdr (head %d) is too split!", head);
-			break;
-		}
-
-		iov_iter_init(&iter, ITER_SOURCE, hdr_iovec, ARRAY_SIZE(hdr_iovec), sizeof(hdr));
-		ret = copy_from_iter(&hdr, sizeof(hdr), &iter);
-		if (ret != sizeof(hdr)) {
-			vhostblk_vq_err(blk, vq, "Failed to get read header (head %d): got %d, expected %ld!\n",
-					head, ret, sizeof(hdr));
-			break;
-		}
-
-		ret = vhost_blk_req_handle(vq, &hdr, head, out, in);
+		ret = vhost_blk_handle_desc(vq, head, out, in);
 		if (ret == -EAGAIN || ret == -ENOMEM) {
 			vhost_discard_vq_desc(vq, 1);
 			vhost_poll_queue(&vq->poll);
 			break;
 		} else if (ret < 0) {
-			vhostblk_vq_err(blk, vq, "Failed to process guest request (head %d) with %d",
-					head, ret);
 			break;
 		}
 
-- 
2.53.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-11-27 11:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 11:15 [Devel] [PATCH hci-8.2 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
2026-11-27 11:16 ` [Devel] [PATCH hci-8.2 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc() Alexander Ivanov
2026-11-27 11:16 ` Alexander Ivanov [this message]
2026-11-27 11:16 ` [Devel] [PATCH hci-8.2 3/4] drivers/vhost/blk: hold requests failed with ENOSPC Alexander Ivanov
2026-11-27 11:51   ` Konstantin Khorenko
2026-11-27 11:16 ` [Devel] [PATCH hci-8.2 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl Alexander Ivanov
2026-11-27 11:51   ` Konstantin Khorenko
2026-11-27 11:51 ` [Devel] [PATCH hci-8.2 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Konstantin Khorenko
2026-11-30 10:52   ` Alexander Ivanov

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=20261127111604.1151696-3-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 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.