[Devel] [PATCH hci-8.2 v3 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler
Alexander Ivanov
alexander.ivanov at virtuozzo.com
Tue Dec 1 11:50:18 MSK 2026
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 at virtuozzo.com>
Reviewed-by: Sashiko <no-reply at sashiko.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 bfd4bde0bcff..d8ea714f71ae 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -682,14 +682,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;
@@ -720,33 +752,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
More information about the Devel
mailing list