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 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc()
Date: Fri, 27 Nov 2026 12:16:00 +0100	[thread overview]
Message-ID: <20261127111604.1151696-2-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261127111604.1151696-1-alexander.ivanov@virtuozzo.com>

vhost-blk is to hold a request failed with ENOSPC instead of completing
it, and resubmit it later by its head when QEMU asks. That head was
already taken from the avail ring, so vhost_get_vq_desc() cannot parse
it again.

Move the walk over the chain of a given head into
vhost_get_desc_chain(), and let vhost_get_vq_desc() call it for the
head it takes from the avail ring.

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/vhost.c | 91 ++++++++++++++++++++++++++-----------------
 drivers/vhost/vhost.h |  4 ++
 2 files changed, 60 insertions(+), 35 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 422cac6f2298..19b1e6b37654 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2838,45 +2838,19 @@ static int get_indirect(struct vhost_virtqueue *vq,
 	return 0;
 }
 
-/* This looks in the virtqueue and for the first available buffer, and converts
- * it to an iovec for convenient access.  Since descriptors consist of some
- * number of output then some number of input descriptors, it's actually two
- * iovecs, but we pack them into one and note how many of each there were.
- *
- * This function returns the descriptor number found, or vq->num (which is
- * never a valid descriptor number) if none was found.  A negative code is
- * returned on error. */
-int vhost_get_vq_desc(struct vhost_virtqueue *vq,
-		      struct iovec iov[], unsigned int iov_size,
-		      unsigned int *out_num, unsigned int *in_num,
-		      struct vhost_log *log, unsigned int *log_num)
+/*
+ * Convert the descriptor chain of @head to an iovec without consuming anything
+ * from the avail ring. Call with vq->mutex held.
+ */
+int vhost_get_desc_chain(struct vhost_virtqueue *vq, unsigned int head,
+			 struct iovec iov[], unsigned int iov_size,
+			 unsigned int *out_num, unsigned int *in_num,
+			 struct vhost_log *log, unsigned int *log_num)
 {
 	struct vring_desc desc;
-	unsigned int i, head, found = 0;
-	u16 last_avail_idx = vq->last_avail_idx;
-	__virtio16 ring_head;
+	unsigned int i, found = 0;
 	int ret, access;
 
-	if (vq->avail_idx == vq->last_avail_idx) {
-		ret = vhost_get_avail_idx(vq);
-		if (unlikely(ret < 0))
-			return ret;
-
-		if (!ret)
-			return vq->num;
-	}
-
-	/* Grab the next descriptor number they're advertising, and increment
-	 * the index we've seen. */
-	if (unlikely(vhost_get_avail_head(vq, &ring_head, last_avail_idx))) {
-		vq_err(vq, "Failed to read head: idx %d address %p\n",
-		       last_avail_idx,
-		       &vq->avail->ring[last_avail_idx % vq->num]);
-		return -EFAULT;
-	}
-
-	head = vhost16_to_cpu(vq, ring_head);
-
 	/* If their number is silly, that's an error. */
 	if (unlikely(head >= vq->num)) {
 		vq_err(vq, "Guest says index %u > %u is available",
@@ -2956,6 +2930,53 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 		}
 	} while ((i = next_desc(vq, &desc)) != -1);
 
+	return 0;
+}
+EXPORT_SYMBOL_GPL(vhost_get_desc_chain);
+
+/* This looks in the virtqueue and for the first available buffer, and converts
+ * it to an iovec for convenient access.  Since descriptors consist of some
+ * number of output then some number of input descriptors, it's actually two
+ * iovecs, but we pack them into one and note how many of each there were.
+ *
+ * This function returns the descriptor number found, or vq->num (which is
+ * never a valid descriptor number) if none was found.  A negative code is
+ * returned on error. */
+int vhost_get_vq_desc(struct vhost_virtqueue *vq,
+		      struct iovec iov[], unsigned int iov_size,
+		      unsigned int *out_num, unsigned int *in_num,
+		      struct vhost_log *log, unsigned int *log_num)
+{
+	unsigned int head;
+	u16 last_avail_idx = vq->last_avail_idx;
+	__virtio16 ring_head;
+	int ret;
+
+	if (vq->avail_idx == vq->last_avail_idx) {
+		ret = vhost_get_avail_idx(vq);
+		if (unlikely(ret < 0))
+			return ret;
+
+		if (!ret)
+			return vq->num;
+	}
+
+	/* Grab the next descriptor number they're advertising, and increment
+	 * the index we've seen. */
+	if (unlikely(vhost_get_avail_head(vq, &ring_head, last_avail_idx))) {
+		vq_err(vq, "Failed to read head: idx %d address %p\n",
+		       last_avail_idx,
+		       &vq->avail->ring[last_avail_idx % vq->num]);
+		return -EFAULT;
+	}
+
+	head = vhost16_to_cpu(vq, ring_head);
+
+	ret = vhost_get_desc_chain(vq, head, iov, iov_size, out_num, in_num,
+				   log, log_num);
+	if (unlikely(ret))
+		return ret;
+
 	/* On success, increment avail index. */
 	vq->last_avail_idx++;
 
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 37ade2f1cb7d..98ee3c438e6a 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -224,6 +224,10 @@ bool vhost_vq_access_ok(struct vhost_virtqueue *vq);
 bool vhost_log_access_ok(struct vhost_dev *);
 void vhost_clear_msg(struct vhost_dev *dev);
 
+int vhost_get_desc_chain(struct vhost_virtqueue *vq, unsigned int head,
+			 struct iovec iov[], unsigned int iov_size,
+			 unsigned int *out_num, unsigned int *in_num,
+			 struct vhost_log *log, unsigned int *log_num);
 int vhost_get_vq_desc(struct vhost_virtqueue *,
 		      struct iovec iov[], unsigned int iov_size,
 		      unsigned int *out_num, unsigned int *in_num,
-- 
2.53.0

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

  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 ` Alexander Ivanov [this message]
2026-11-27 11:16 ` [Devel] [PATCH hci-8.2 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler Alexander Ivanov
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-2-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.