From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl
Date: Fri, 27 Nov 2026 12:16:03 +0100 [thread overview]
Message-ID: <20261127111604.1151696-5-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261127111604.1151696-1-alexander.ivanov@virtuozzo.com>
QEMU stops vhost-blk to pause the VM on a held request, and the list of
held requests is emptied when the device starts again. The heads of
these requests are already taken from the avail ring, so the kick
handler never sees them, and the guest waits for them forever.
VHOST_BLK_RESUBMIT parses the descriptor chain of each given head and
submits the request as if it were just taken from the avail ring. The
request data stays in guest memory, so QEMU needs only the vq and head
pairs it read with VHOST_BLK_GET_HELD_REQS, also after a migration. A
request that fails with ENOSPC again is held again.
Only the owner may resubmit, as the descriptors are walked and the data
pages are pinned through the mm of the caller.
A head still in flight fails with -EBUSY before it reaches the request
parser, which would report it as a guest error on the vring error
eventfd: here the caller is at fault, and the errno already says so.
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 | 63 ++++++++++++++++++++++++++++++++++++++
include/uapi/linux/vhost.h | 11 +++++++
2 files changed, 74 insertions(+)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index e1e39b361b68..614b8c68f576 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -19,6 +19,7 @@
#include <linux/mutex.h>
#include <linux/file.h>
#include <linux/kthread.h>
+#include <linux/sched/signal.h>
#include <linux/blkdev.h>
#include <linux/llist.h>
@@ -1165,6 +1166,65 @@ static long vhost_blk_get_held_reqs(struct vhost_blk *blk,
return ret;
}
+static int vhost_blk_resubmit_one(struct vhost_blk *blk,
+ const struct vhost_blk_held_req *r)
+{
+ struct vhost_virtqueue *vq;
+ unsigned int out, in;
+ int ret;
+
+ if (r->vq >= VHOST_BLK_VQ_MAX || r->reserved)
+ return -EINVAL;
+
+ vq = &blk->vqs[r->vq].vq;
+ mutex_lock(&vq->mutex);
+ if (!vhost_vq_get_backend(vq)) {
+ ret = -ENODEV;
+ goto out;
+ }
+
+ ret = vhost_get_desc_chain(vq, r->head, vq->iov, ARRAY_SIZE(vq->iov),
+ &out, &in, NULL, NULL);
+ if (!ret && blk->vqs[r->vq].req[r->head].inflight)
+ ret = -EBUSY;
+ if (!ret)
+ ret = vhost_blk_handle_desc(vq, r->head, out, in);
+out:
+ mutex_unlock(&vq->mutex);
+ return ret;
+}
+
+static long vhost_blk_resubmit(struct vhost_blk *blk,
+ struct vhost_blk_held_reqs __user *argp)
+{
+ struct vhost_blk_held_req r;
+ u32 nr, i;
+ int ret;
+
+ ret = vhost_blk_get_held_nr(argp, &nr);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < nr; i++) {
+ if (fatal_signal_pending(current)) {
+ ret = -EINTR;
+ break;
+ }
+ cond_resched();
+ if (copy_from_user(&r, &argp->reqs[i], sizeof(r))) {
+ ret = -EFAULT;
+ break;
+ }
+ ret = vhost_blk_resubmit_one(blk, &r);
+ if (ret)
+ break;
+ }
+
+ if (ret && put_user(i, &argp->nr))
+ ret = -EFAULT;
+ return ret;
+}
+
static long vhost_blk_error_ioctl(struct vhost_blk *blk, unsigned int ioctl,
void __user *argp)
{
@@ -1182,6 +1242,8 @@ static long vhost_blk_error_ioctl(struct vhost_blk *blk, unsigned int ioctl,
return vhost_blk_set_error_fd(blk, argp);
case VHOST_BLK_GET_HELD_REQS:
return vhost_blk_get_held_reqs(blk, argp);
+ case VHOST_BLK_RESUBMIT:
+ return vhost_blk_resubmit(blk, argp);
}
return -ENOIOCTLCMD;
}
@@ -1208,6 +1270,7 @@ static long vhost_blk_ioctl(struct file *f, unsigned int ioctl,
case VHOST_BLK_SET_ERROR_POLICY:
case VHOST_BLK_SET_ERROR_FD:
case VHOST_BLK_GET_HELD_REQS:
+ case VHOST_BLK_RESUBMIT:
mutex_lock(&blk->dev.mutex);
ret = vhost_dev_check_owner(&blk->dev);
if (!ret)
diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
index 4dee1b53e97e..9581c9840750 100644
--- a/include/uapi/linux/vhost.h
+++ b/include/uapi/linux/vhost.h
@@ -304,4 +304,15 @@
*/
#define VHOST_BLK_GET_HELD_REQS _IOWR(VHOST_VIRTIO, 0xFB, \
struct vhost_blk_held_reqs)
+
+/*
+ * Resubmit requests by vq and head, as if they were just taken from the avail
+ * ring. Only heads read with VHOST_BLK_GET_HELD_REQS after the last stop may be
+ * passed: the kernel does not track them, and a head passed again after its
+ * request completed, or still owned by the guest, is completed twice. A head
+ * still in flight fails with -EBUSY. error and type are ignored, reserved
+ * must be 0. On error, nr is set to the number of requests resubmitted.
+ */
+#define VHOST_BLK_RESUBMIT _IOWR(VHOST_VIRTIO, 0xFA, \
+ struct vhost_blk_held_reqs)
#endif
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev 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 ` [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 ` Alexander Ivanov [this message]
2026-11-27 11:51 ` [Devel] [PATCH hci-8.2 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl 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-5-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