From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 v4 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc()
Date: Tue, 1 Dec 2026 13:49:28 +0100 [thread overview]
Message-ID: <20261201124931.1969095-2-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261201124931.1969095-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>
Reviewed-by: Sashiko <no-reply@sashiko.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 56c0ecbb8352..922e588938b2 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2783,45 +2783,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",
@@ -2901,6 +2875,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 077fa4d0cf36..88c322d8462c 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -223,6 +223,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
next prev parent reply other threads:[~2026-12-01 12:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:49 [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
2026-12-01 12:49 ` Alexander Ivanov [this message]
2026-12-01 12:49 ` [Devel] [PATCH hci-8.2 v4 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler Alexander Ivanov
2026-12-01 12:49 ` [Devel] [PATCH hci-8.2 v4 3/4] drivers/vhost/blk: hold requests failed with ENOSPC Alexander Ivanov
2026-12-01 12:49 ` [Devel] [PATCH hci-8.2 v4 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl Alexander Ivanov
2026-12-01 12:57 ` no-reply
2026-12-01 15:32 ` [Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Konstantin Khorenko
2026-12-01 15:32 ` 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=20261201124931.1969095-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox