All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them
@ 2026-12-01  8:50 Alexander Ivanov
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc() Alexander Ivanov
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Alexander Ivanov @ 2026-12-01  8:50 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: devel

With report_enospc, dm-qcow2 and dm-ploop fail a request with ENOSPC
at once, and vhost-blk passes it to the guest as VIRTIO_BLK_S_IOERR.
The guest gets a write error, where QEMU with werror=enospc would
pause the VM until space is freed.

This series lets QEMU hold such requests in vhost-blk:
- VHOST_BLK_SET_ERROR_POLICY selects the requests to hold on ENOSPC:
  writes (with flushes, write zeroes and discards) and reads
- VHOST_BLK_SET_ERROR_FD sets the eventfd signalled when a request is
  held
- VHOST_BLK_GET_HELD_REQS returns the vq and head of each held request
- VHOST_BLK_RESUBMIT submits held requests again by vq and head, on
  resume or on the destination of a migration

A held request stays out of the used ring and is not counted as
inflight, so stopping vhost-blk to pause the VM does not wait for it.

QEMU uses them as follows:
- when it starts vhost-blk: VHOST_BLK_SET_ERROR_POLICY and
  VHOST_BLK_SET_ERROR_FD, before the backend is set
- on the eventfd: stops the VM and vhost-blk, then reads the list
  with VHOST_BLK_GET_HELD_REQS
- on the next start, or on the destination of a migration:
  VHOST_BLK_RESUBMIT with the saved vq and head pairs, after
  VHOST_BLK_SET_BACKEND, which empties the list

Patches 1-2 move the descriptor chain walk and the request parsing out
of the avail ring path, so that a head taken earlier can be parsed
again. Patch 3 holds the requests and reports them, patch 4 resubmits
them.

The series goes on top of "dm-qcow2, dm-ploop: report ENOSPC at once
for vhost-blk disks" v3, which lets the ENOSPC reach vhost-blk. The
other parts:
- QEMU: "[PATCH hci-8.2 v3 0/5] vhost-blk: support the werror/rerror
  policies"
- libvirt: https://bitbucket.org/openvz/libvirt.ovz/pull-requests/403
- ploop.ovz: https://bitbucket.org/openvz/ploop.ovz/pull-requests/530

v3:
- patch 3: copy the held list to userspace in VHOST_BLK_GET_HELD_REQS
  without held_mutex, so that a faulting user buffer does not stall
  the completion path
- patch 4: say in the uapi which VHOST_BLK_RESUBMIT errors fail the
  rest of the entries and which concern only the failed one
- rebase on top of rh10-6.12.0-211.75.1.26.6.vz10 and the dm-qcow2,
  dm-ploop series v3

v2:
- cover letter: say how QEMU uses the ioctls and name the QEMU,
  libvirt and ploop.ovz series
- patch 3: hold a request split into several bios only if none of
  them failed with an error other than ENOSPC
- patch 3: say that a guest reusing a held head after a backend
  restart gets it accepted
- patch 4: fail a head out of range with -EINVAL and a head in flight
  with -EBUSY before the descriptor chain is walked
- patch 4: on error, set nr to the index of the entry that failed
- rebase on top of the dm-qcow2, dm-ploop series v2 and the
  VIRTIO_BLK_F_DISCARD series v4
- patch 3: say that a discard is held as a write, as werror covers it
  in QEMU
- patch 4: say in the uapi that VHOST_BLK_RESUBMIT needs the backend
  set

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Alexander Ivanov (4):
  drivers/vhost: split the descriptor chain walk out of
    vhost_get_vq_desc()
  drivers/vhost/blk: split request parsing out of the guest kick handler
  drivers/vhost/blk: hold requests failed with ENOSPC
  drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl

 drivers/vhost/blk.c              | 304 ++++++++++++++++++++++++++++---
 drivers/vhost/vhost.c            |  91 +++++----
 drivers/vhost/vhost.h            |   4 +
 include/uapi/linux/vhost.h       |  35 ++++
 include/uapi/linux/vhost_types.h |  21 +++
 5 files changed, 392 insertions(+), 63 deletions(-)

-- 
2.53.0

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Devel] [PATCH hci-8.2 v3 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc()
  2026-12-01  8:50 [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
@ 2026-12-01  8:50 ` Alexander Ivanov
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler Alexander Ivanov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Alexander Ivanov @ 2026-12-01  8:50 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: devel

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Devel] [PATCH hci-8.2 v3 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler
  2026-12-01  8:50 [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc() Alexander Ivanov
@ 2026-12-01  8:50 ` Alexander Ivanov
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC Alexander Ivanov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Alexander Ivanov @ 2026-12-01  8:50 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: devel

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>
Reviewed-by: Sashiko <no-reply@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

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC
  2026-12-01  8:50 [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc() Alexander Ivanov
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler Alexander Ivanov
@ 2026-12-01  8:50 ` Alexander Ivanov
  2026-12-01  8:56   ` no-reply
  2026-12-01  9:19   ` Konstantin Khorenko
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl Alexander Ivanov
  2026-12-01  9:19 ` [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Konstantin Khorenko
  4 siblings, 2 replies; 13+ messages in thread
From: Alexander Ivanov @ 2026-12-01  8:50 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: devel

When the image of a vhost-blk disk runs out of space, dm-qcow2 or
dm-ploop with report_enospc fails the bio with ENOSPC, and vhost-blk
passes it to the guest as VIRTIO_BLK_S_IOERR. The guest gets a write
error, where QEMU with werror=enospc would pause the VM until the space
is freed.

Let QEMU choose with VHOST_BLK_SET_ERROR_POLICY the requests to hold
on ENOSPC: writes (with flushes, write zeroes and discards, as werror
covers them in QEMU) and reads. A held request is not put to the used
ring, the eventfd set with VHOST_BLK_SET_ERROR_FD is signalled, and
QEMU reads the list of held requests with VHOST_BLK_GET_HELD_REQS to
pause the VM and resubmit them on resume. A request split into several
bios is held only if none of them failed with an error other than
ENOSPC.

A held request is not counted as inflight, so that unsetting the
backend does not wait for it. Until then its head stays taken, so a
guest reusing it gets the same error as for a head in flight. The
request slots are freed with the backend, so after a restart a guest
reusing the head gets it accepted; only that guest is hurt.

The list is kept when the backend is unset, as the stop path of QEMU
must read it after all requests in flight are completed. It is emptied
by setting a new backend, when the vrings and their heads may be
different, and by VHOST_RESET_OWNER together with the policy and the
eventfd.

The new ioctls are allowed only to the owner and run under dev.mutex,
so that they do not race with VHOST_RESET_OWNER dropping the eventfd.

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              | 173 ++++++++++++++++++++++++++++++-
 include/uapi/linux/vhost.h       |  20 ++++
 include/uapi/linux/vhost_types.h |  21 ++++
 3 files changed, 211 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index d8ea714f71ae..c11b5be5d6bf 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -51,6 +51,9 @@ enum {
 
 #define NR_INLINE 16
 
+#define VHOST_BLK_HOLD_ALL (VHOST_BLK_HOLD_ENOSPC_WRITE | \
+			    VHOST_BLK_HOLD_ENOSPC_READ)
+
 #define vhostblk_vq_err(blk, vq, fmt, ...) do {				\
 		pr_warn_ratelimited(KBUILD_MODNAME "(%d) : " fmt,	\
 				    blk->owner_pid, ##__VA_ARGS__);	\
@@ -76,6 +79,7 @@ struct vhost_blk_req {
 
 	sector_t sector;
 	int bi_opf;
+	u32 type;
 	u16 head;
 	size_t len;
 	int bio_err;
@@ -105,6 +109,11 @@ struct vhost_blk {
 	struct file *backend;
 	char serial[VIRTIO_BLK_ID_BYTES];
 	pid_t owner_pid;
+	u64 error_policy;
+	struct mutex held_mutex;
+	struct eventfd_ctx *error_ctx;
+	struct vhost_blk_held_req *held;
+	unsigned int nr_held;
 };
 
 static int move_iovec(struct iovec *from, struct iovec *to,
@@ -162,9 +171,11 @@ static void vhost_blk_req_done(struct bio *bio)
 		else if ((req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES &&
 			 !bdev_write_zeroes_sectors(bdev))
 			err = -EOPNOTSUPP;
-		if (err)
-			req->bio_err = err;
 	}
+	if (err == -ENOSPC)
+		cmpxchg(&req->bio_err, 0, err);
+	else if (err)
+		WRITE_ONCE(req->bio_err, err);
 
 	/*
 	 * Bounce buffer adds kvec to bio (instead of user backed memory),
@@ -587,8 +598,9 @@ static int vhost_blk_req_handle(struct vhost_virtqueue *vq,
 	req->sector	= vhost64_to_cpu(vq, hdr->sector);
 	req->iov	= blk_vq->iov;
 	req->bio_err	= 0;
+	req->type	= vhost32_to_cpu(vq, hdr->type);
 	in_len		= iov_length(vq->iov + out, in);
-	type		= vhost32_to_cpu(vq, hdr->type);
+	type		= req->type;
 
 	if (in_len < sizeof(status) || in_len > INT_MAX)
 		return -EINVAL;
@@ -770,6 +782,29 @@ static void vhost_blk_handle_guest_kick(struct vhost_work *work)
 	mutex_unlock(&vq->mutex);
 }
 
+static bool vhost_blk_hold_req(struct vhost_blk_req *req)
+{
+	struct vhost_blk *blk = req->blk;
+	u64 flag = req->bi_opf == REQ_OP_READ ? VHOST_BLK_HOLD_ENOSPC_READ :
+						VHOST_BLK_HOLD_ENOSPC_WRITE;
+
+	if (req->bio_err != -ENOSPC || !(READ_ONCE(blk->error_policy) & flag))
+		return false;
+
+	mutex_lock(&blk->held_mutex);
+	blk->held[blk->nr_held++] = (struct vhost_blk_held_req) {
+		.vq	= req->blk_vq - blk->vqs,
+		.head	= req->head,
+		.error	= -req->bio_err,
+		.type	= req->type,
+	};
+	if (blk->error_ctx)
+		eventfd_signal(blk->error_ctx);
+	mutex_unlock(&blk->held_mutex);
+
+	return true;
+}
+
 static void vhost_blk_handle_host_kick(struct vhost_work *work)
 {
 	struct vhost_blk_vq *blk_vq;
@@ -799,6 +834,12 @@ static void vhost_blk_handle_host_kick(struct vhost_work *work)
 		}
 		vhost_blk_req_cleanup(req);
 
+		/* req->inflight stays set: the guest must not reuse the head */
+		if (vhost_blk_hold_req(req)) {
+			forget_request(req);
+			continue;
+		}
+
 		if (!req->bio_err)
 			status = VIRTIO_BLK_S_OK;
 		else if (req->bio_err == -EOPNOTSUPP &&
@@ -905,11 +946,34 @@ static void vhost_blk_drop_backend(struct vhost_blk *blk)
 	blk->backend = NULL;
 }
 
+static void vhost_blk_reset_held(struct vhost_blk *blk,
+				 struct vhost_blk_held_req *held)
+{
+	mutex_lock(&blk->held_mutex);
+	kvfree(blk->held);
+	blk->held = held;
+	blk->nr_held = 0;
+	mutex_unlock(&blk->held_mutex);
+}
+
 static int vhost_blk_setup_vqs(struct vhost_blk *blk)
 {
+	struct vhost_blk_held_req *held;
 	struct vhost_virtqueue *vq;
+	unsigned int nr = 0;
 	int ret, i;
 
+	for (i = 0; i < VHOST_BLK_VQ_MAX; i++) {
+		vq = &blk->vqs[i].vq;
+		if (vhost_vq_is_setup(vq))
+			nr += vq->num;
+	}
+
+	held = kvcalloc(nr, sizeof(*held), GFP_KERNEL);
+	if (!held)
+		return -ENOMEM;
+	vhost_blk_reset_held(blk, held);
+
 	for (i = 0; i < VHOST_BLK_VQ_MAX; i++) {
 		vq = &blk->vqs[i].vq;
 
@@ -962,6 +1026,7 @@ static int vhost_blk_open(struct inode *inode, struct file *file)
 	blk->during_flush = 0;
 	blk->new_req_bin = 0;
 	spin_lock_init(&blk->flush_lock);
+	mutex_init(&blk->held_mutex);
 	init_waitqueue_head(&blk->flush_wait);
 	blk->owner_pid = current->pid;
 
@@ -981,11 +1046,21 @@ static int vhost_blk_open(struct inode *inode, struct file *file)
 	return ret;
 }
 
+static void vhost_blk_reset_errors(struct vhost_blk *blk)
+{
+	vhost_blk_reset_held(blk, NULL);
+	WRITE_ONCE(blk->error_policy, 0);
+	if (blk->error_ctx)
+		eventfd_ctx_put(blk->error_ctx);
+	blk->error_ctx = NULL;
+}
+
 static int vhost_blk_release(struct inode *inode, struct file *f)
 {
 	struct vhost_blk *blk = f->private_data;
 
 	vhost_blk_drop_backend(blk);
+	vhost_blk_reset_errors(blk);
 	vhost_dev_stop(&blk->dev);
 	vhost_dev_cleanup(&blk->dev);
 	kfree(blk->dev.vqs);
@@ -1084,6 +1159,7 @@ static long vhost_blk_reset_owner(struct vhost_blk *blk)
 		goto done;
 	}
 	vhost_blk_drop_backend(blk);
+	vhost_blk_reset_errors(blk);
 	vhost_dev_stop(&blk->dev);
 	vhost_dev_reset_owner(&blk->dev, umem);
 
@@ -1092,6 +1168,88 @@ static long vhost_blk_reset_owner(struct vhost_blk *blk)
 	return err;
 }
 
+static long vhost_blk_set_error_fd(struct vhost_blk *blk, int __user *argp)
+{
+	struct eventfd_ctx *ctx = NULL;
+	int fd;
+
+	if (get_user(fd, argp))
+		return -EFAULT;
+
+	if (fd != -1) {
+		ctx = eventfd_ctx_fdget(fd);
+		if (IS_ERR(ctx))
+			return PTR_ERR(ctx);
+	}
+
+	mutex_lock(&blk->held_mutex);
+	swap(ctx, blk->error_ctx);
+	mutex_unlock(&blk->held_mutex);
+
+	if (ctx)
+		eventfd_ctx_put(ctx);
+	return 0;
+}
+
+static int vhost_blk_get_held_nr(struct vhost_blk_held_reqs __user *argp,
+				 u32 *nr)
+{
+	struct vhost_blk_held_reqs hdr;
+
+	if (copy_from_user(&hdr, argp, sizeof(hdr)))
+		return -EFAULT;
+	if (hdr.reserved)
+		return -EINVAL;
+	*nr = hdr.nr;
+	return 0;
+}
+
+static long vhost_blk_get_held_reqs(struct vhost_blk *blk,
+				    struct vhost_blk_held_reqs __user *argp)
+{
+	u32 nr, nr_held;
+	long ret;
+
+	ret = vhost_blk_get_held_nr(argp, &nr);
+	if (ret)
+		return ret;
+
+	mutex_lock(&blk->held_mutex);
+	nr_held = blk->nr_held;
+	mutex_unlock(&blk->held_mutex);
+
+	if (nr < nr_held)
+		ret = -E2BIG;
+	else if (copy_to_user(argp->reqs, blk->held,
+			      nr_held * sizeof(*blk->held)))
+		return -EFAULT;
+
+	if (put_user(nr_held, &argp->nr))
+		return -EFAULT;
+	return ret;
+}
+
+static long vhost_blk_error_ioctl(struct vhost_blk *blk, unsigned int ioctl,
+				  void __user *argp)
+{
+	u64 policy;
+
+	switch (ioctl) {
+	case VHOST_BLK_SET_ERROR_POLICY:
+		if (get_user(policy, (u64 __user *)argp))
+			return -EFAULT;
+		if (policy & ~VHOST_BLK_HOLD_ALL)
+			return -EOPNOTSUPP;
+		WRITE_ONCE(blk->error_policy, policy);
+		return 0;
+	case VHOST_BLK_SET_ERROR_FD:
+		return vhost_blk_set_error_fd(blk, argp);
+	case VHOST_BLK_GET_HELD_REQS:
+		return vhost_blk_get_held_reqs(blk, argp);
+	}
+	return -ENOIOCTLCMD;
+}
+
 static long vhost_blk_ioctl(struct file *f, unsigned int ioctl,
 			    unsigned long arg)
 {
@@ -1111,6 +1269,15 @@ static long vhost_blk_ioctl(struct file *f, unsigned int ioctl,
 		if (copy_from_user(blk->serial, argp, VIRTIO_BLK_ID_BYTES))
 			return -EFAULT;
 		return 0;
+	case VHOST_BLK_SET_ERROR_POLICY:
+	case VHOST_BLK_SET_ERROR_FD:
+	case VHOST_BLK_GET_HELD_REQS:
+		mutex_lock(&blk->dev.mutex);
+		ret = vhost_dev_check_owner(&blk->dev);
+		if (!ret)
+			ret = vhost_blk_error_ioctl(blk, ioctl, argp);
+		mutex_unlock(&blk->dev.mutex);
+		return ret;
 	case VHOST_GET_FEATURES:
 		features = VHOST_BLK_FEATURES;
 		if (copy_to_user(featurep, &features, sizeof(features)))
diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
index 4371703948b9..21bf6e39a85a 100644
--- a/include/uapi/linux/vhost.h
+++ b/include/uapi/linux/vhost.h
@@ -276,4 +276,24 @@
 
 #define VHOST_BLK_SET_BACKEND		_IOW(VHOST_VIRTIO, 0xFF, \
 					     struct vhost_vring_file)
+
+/*
+ * Hold a request failing with an error selected by VHOST_BLK_HOLD_* flags
+ * instead of completing it. The guest gets its head back only through
+ * VHOST_BLK_RESUBMIT.
+ */
+#define VHOST_BLK_SET_ERROR_POLICY	_IOW(VHOST_VIRTIO, 0xFD, __u64)
+
+/* An eventfd signalled on every held request, -1 to unset */
+#define VHOST_BLK_SET_ERROR_FD		_IOW(VHOST_VIRTIO, 0xFC, int)
+
+/*
+ * nr is the capacity of reqs on input and the number of held requests on
+ * output; -E2BIG if they do not fit. reserved must be 0. The list is final
+ * once the backend is unset, and is emptied by VHOST_RESET_OWNER and by a
+ * successful VHOST_BLK_SET_BACKEND with fd >= 0. A failing one may empty it
+ * too.
+ */
+#define VHOST_BLK_GET_HELD_REQS		_IOWR(VHOST_VIRTIO, 0xFB, \
+					      struct vhost_blk_held_reqs)
 #endif
diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.h
index 1c39cc5f5a31..c0fbdfd29e1d 100644
--- a/include/uapi/linux/vhost_types.h
+++ b/include/uapi/linux/vhost_types.h
@@ -198,4 +198,25 @@ struct vhost_vdpa_iova_range {
 /* IOTLB don't flush memory mapping across device reset */
 #define VHOST_BACKEND_F_IOTLB_PERSIST  0x8
 
+/*
+ * VHOST_BLK_SET_ERROR_POLICY flags. ENOSPC_WRITE covers every request but a
+ * read: writes, flushes, write zeroes and discards, as werror does in QEMU.
+ */
+#define VHOST_BLK_HOLD_ENOSPC_WRITE	(1ULL << 0)
+#define VHOST_BLK_HOLD_ENOSPC_READ	(1ULL << 1)
+
+struct vhost_blk_held_req {
+	__u16 vq;
+	__u16 head;
+	__s32 error;		/* positive errno */
+	__u32 type;		/* VIRTIO_BLK_T_* */
+	__u32 reserved;
+};
+
+struct vhost_blk_held_reqs {
+	__u32 nr;
+	__u32 reserved;
+	struct vhost_blk_held_req reqs[];
+};
+
 #endif
-- 
2.53.0

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl
  2026-12-01  8:50 [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
                   ` (2 preceding siblings ...)
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC Alexander Ivanov
@ 2026-12-01  8:50 ` Alexander Ivanov
  2026-12-01  9:01   ` no-reply
  2026-12-01  9:19   ` Konstantin Khorenko
  2026-12-01  9:19 ` [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Konstantin Khorenko
  4 siblings, 2 replies; 13+ messages in thread
From: Alexander Ivanov @ 2026-12-01  8:50 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: devel

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 out of range or still in flight fails with -EINVAL or -EBUSY
before the descriptor chain is walked, as the walk and the request
parser 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        | 70 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/vhost.h | 15 ++++++++
 2 files changed, 85 insertions(+)

diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index c11b5be5d6bf..fcf51aab4203 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>
 
@@ -1229,6 +1230,72 @@ 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;
+	}
+
+	if (r->head >= vq->num) {
+		ret = -EINVAL;
+		goto out;
+	}
+	if (blk->vqs[r->vq].req[r->head].inflight) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	ret = vhost_get_desc_chain(vq, r->head, vq->iov, ARRAY_SIZE(vq->iov),
+				   &out, &in, NULL, NULL);
+	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)
 {
@@ -1246,6 +1313,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;
 }
@@ -1272,6 +1341,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 21bf6e39a85a..f024c8784974 100644
--- a/include/uapi/linux/vhost.h
+++ b/include/uapi/linux/vhost.h
@@ -296,4 +296,19 @@
  */
 #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. A head passed again after its request
+ * completed, still owned by the guest, or reused by the guest since the backend
+ * was set, is completed twice, or fails with -EBUSY while still in flight.
+ * error and type are ignored, reserved must be 0. On error, nr is set to the
+ * index of the entry that failed; the entries before it were resubmitted.
+ * On -ENOMEM pass the same entry again; -ENODEV and -EINTR fail the rest as
+ * well. Any other error concerns only that entry: the ones after it may still
+ * be passed from nr + 1. Fails with -ENODEV until the backend is set.
+ */
+#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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC Alexander Ivanov
@ 2026-12-01  8:56   ` no-reply
  2026-12-01  9:19   ` Konstantin Khorenko
  1 sibling, 0 replies; 13+ messages in thread
From: no-reply @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel

> When the image of a vhost-blk disk runs out of space, dm-qcow2 or
> dm-ploop with report_enospc fails the bio with ENOSPC, and vhost-blk
> passes it to the guest as VIRTIO_BLK_S_IOERR. The guest gets a write
> error, where QEMU with werror=enospc would pause the VM until the space
> is freed.
> 
> Let QEMU choose with VHOST_BLK_SET_ERROR_POLICY the requests to hold
> on ENOSPC: writes (with flushes, write zeroes and discards, as werror
> covers them in QEMU) and reads. A held request is not put to the used
> ring, the eventfd set with VHOST_BLK_SET_ERROR_FD is signalled, and
> QEMU reads the list of held requests with VHOST_BLK_GET_HELD_REQS to
> pause the VM and resubmit them on resume. A request split into several
> bios is held only if none of them failed with an error other than
> ENOSPC.
> 
> [ ... ]
> so that they do not race with VHOST_RESET_OWNER dropping the eventfd.
> 
> 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>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261201085020.1884923-1-alexander.ivanov@virtuozzo.com?part=3


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl Alexander Ivanov
@ 2026-12-01  9:01   ` no-reply
  2026-12-01 11:14     ` Alexander Ivanov
  2026-12-01  9:19   ` Konstantin Khorenko
  1 sibling, 1 reply; 13+ messages in thread
From: no-reply @ 2026-12-01  9:01 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] vhost-blk: RESUBMIT UAPI error contract does not match the code
- [Low] vhost-blk: RESUBMIT passes -EAGAIN through, undocumented, and
  put_user() can mask errno
--

commit 53438eeba5481f2e3e53873a8e09498dc7a3b381
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl

This adds an owner-only ioctl that takes vq and head pairs, such as those
read with VHOST_BLK_GET_HELD_REQS. For each pair it parses the descriptor
chain and submits the request as if it had just been taken from the avail
ring.

> diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
> index c11b5be5d6bf..fcf51aab4203 100644
> --- a/drivers/vhost/blk.c
> +++ b/drivers/vhost/blk.c

[ ... ]

> +static int vhost_blk_resubmit_one(struct vhost_blk *blk,
> +				  const struct vhost_blk_held_req *r)
> +{

[ ... ]

> +	ret = vhost_get_desc_chain(vq, r->head, vq->iov, ARRAY_SIZE(vq->iov),
> +				   &out, &in, NULL, NULL);
> +	if (!ret)
> +		ret = vhost_blk_handle_desc(vq, r->head, out, in);

[Severity: Low]
Can -EAGAIN reach userspace here and cause a request to be lost?
vhost_get_desc_chain() returns -EAGAIN on an IOTLB miss, and
vhost_blk_req_submit() returns it when no backend file is found. The kick
handler answers -EAGAIN with vhost_discard_vq_desc() and a requeue. Here
the head is already off the avail ring, so nothing retries it. The UAPI
comment lists -EAGAIN under "any other error", so userspace that follows
it skips to nr + 1 and the guest never gets that head back. Should -EAGAIN
be documented, or handled in the kernel?

> +out:
> +	mutex_unlock(&vq->mutex);
> +	return ret;
> +}
> +
> +static long vhost_blk_resubmit(struct vhost_blk *blk,
> +			       struct vhost_blk_held_reqs __user *argp)
> +{

[ ... ]

> +	if (ret && put_user(i, &argp->nr))
> +		ret = -EFAULT;
> +	return ret;
> +}

[Severity: Low]
Also, when put_user() fails here, the real errno is replaced by -EFAULT.
Userspace can then no longer tell why the loop stopped, and it also
loses the index of the failing entry.

[ ... ]

> diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
> index 21bf6e39a85a..f024c8784974 100644
> --- a/include/uapi/linux/vhost.h
> +++ b/include/uapi/linux/vhost.h

[ ... ]

> + * error and type are ignored, reserved must be 0. On error, nr is set to the
> + * index of the entry that failed; the entries before it were resubmitted.
> + * On -ENOMEM pass the same entry again; -ENODEV and -EINTR fail the rest as
> + * well. Any other error concerns only that entry: the ones after it may still
> + * be passed from nr + 1. Fails with -ENODEV until the backend is set.

[Severity: Low]
As reported by Konstantin Khorenko on v1 [1], does this error contract
match the code? It says -ENODEV fails the rest as well, but
vhost_blk_resubmit_one() checks vhost_vq_get_backend(vq) per virtqueue.
On a multiqueue device where one vq has no backend, entries for the other
vqs can still be resubmitted.

The "any other error concerns only that entry" rule also does not hold
for -EFAULT from copy_from_user() on reqs[i]. The buffer is unreadable,
so continuing from nr + 1 makes no sense. Could the comment state the
real per-errno behaviour?

[1] https://lore.kernel.org/r/179578030084.10258.14556640974201502480.b4-review@b4

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261201085020.1884923-1-alexander.ivanov@virtuozzo.com?part=4

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC Alexander Ivanov
  2026-12-01  8:56   ` no-reply
@ 2026-12-01  9:19   ` Konstantin Khorenko
  2026-12-01 11:25     ` Alexander Ivanov
  1 sibling, 1 reply; 13+ messages in thread
From: Konstantin Khorenko @ 2026-12-01  9:19 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: devel

Items 1 and 2 of the cover letter reply.

On Tue, 1 Dec 2026 09:50:19 +0100, Alexander Ivanov wrote:
> backend does not wait for it. Until then its head stays taken, so a

"Until then" has nothing to refer to; "while the backend is set".

> + * once the backend is unset, and is emptied by VHOST_RESET_OWNER and by a
> + * successful VHOST_BLK_SET_BACKEND with fd >= 0. A failing one may empty it
> + * too.

A failing one may also leave requests in it: the vqs set up before
the failure are live and hold requests on the new list. Say that QEMU
reads the list again after a failing SET_BACKEND.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them
  2026-12-01  8:50 [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
                   ` (3 preceding siblings ...)
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl Alexander Ivanov
@ 2026-12-01  9:19 ` Konstantin Khorenko
  4 siblings, 0 replies; 13+ messages in thread
From: Konstantin Khorenko @ 2026-12-01  9:19 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: devel

I won't apply this version, please send v4 with the changes below.
The code is fine; only the uapi comments and one sentence change.

On Tue, 1 Dec 2026 09:50:16 +0100, Alexander Ivanov wrote:
> - patch 4: say in the uapi which VHOST_BLK_RESUBMIT errors fail the
>   rest of the entries and which concern only the failed one

My v2 reply never went out, sorry: items 1, 2, 3 and 5 are from it.

1. Patch 3: the VHOST_BLK_GET_HELD_REQS comment: after a failing
   VHOST_BLK_SET_BACKEND the list may also hold requests held during
   it, so QEMU reads it again.
2. Patch 3 message: "Until then its head stays taken" - say "while
   the backend is set".
3. Patch 4: the VHOST_BLK_RESUBMIT comment: nr when the call fails
   before the first entry (-EPERM, a fault on the header, reserved
   not 0). Set it to 0, or say these errors leave it unchanged.
4. Patch 4: the same comment: an -EFAULT on reading an entry fails
   the rest, like -ENODEV and -EINTR, not only that entry.
5. Patch 4: the same comment: say that the guest request of a
   skipped entry is never completed.

The v3 copy of the held list outside held_mutex is fine: blk->held
changes only under dev.mutex, which the ioctl holds, and new entries
go past nr_held.

Separate patches, not needed for this series. I created a task:

1. vhost-blk: vhost_blk_req_cleanup() frees a kmalloc'ed req->bio
   array but leaves the pointer set, and nothing resets it for the
   next request on that head. If that request needs a bounce buffer
   and its kvmalloc or the copy into it fails, err_req frees the old
   array again. A guest can steer it, and the -ENOMEM retry of
   RESUBMIT takes the same path.
   https://virtuozzo.atlassian.net/browse/VSTOR-158259

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl
  2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl Alexander Ivanov
  2026-12-01  9:01   ` no-reply
@ 2026-12-01  9:19   ` Konstantin Khorenko
  2026-12-01 11:16     ` Alexander Ivanov
  1 sibling, 1 reply; 13+ messages in thread
From: Konstantin Khorenko @ 2026-12-01  9:19 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: devel

Items 3, 4 and 5 of the cover letter reply.

On Tue, 1 Dec 2026 09:50:20 +0100, Alexander Ivanov wrote:
> + * error and type are ignored, reserved must be 0. On error, nr is set to the
> + * index of the entry that failed; the entries before it were resubmitted.
> + * On -ENOMEM pass the same entry again; -ENODEV and -EINTR fail the rest as
> + * well. Any other error concerns only that entry: the ones after it may still
> + * be passed from nr + 1. Fails with -ENODEV until the backend is set.

- -EPERM, -EFAULT on the header and -EINVAL for reserved fail before
  the loop and leave nr as passed in. By this rule QEMU goes on from
  nr + 1, past the end, and resubmits nothing.
- -EFAULT from copy_from_user() of reqs[i] is not about that entry:
  it was never read. Put it with -ENODEV and -EINTR.
- Say that a skipped entry's guest request is never completed, so
  QEMU knows what skipping costs.

-ENODEV is named twice; one mention is enough.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl
  2026-12-01  9:01   ` no-reply
@ 2026-12-01 11:14     ` Alexander Ivanov
  0 siblings, 0 replies; 13+ messages in thread
From: Alexander Ivanov @ 2026-12-01 11:14 UTC (permalink / raw)
  To: no-reply, andrey.zhadchenko; +Cc: devel

>> +	ret = vhost_get_desc_chain(vq, r->head, vq->iov, ARRAY_SIZE(vq->iov),
>> +				   &out, &in, NULL, NULL);
>> +	if (!ret)
>> +		ret = vhost_blk_handle_desc(vq, r->head, out, in);
> [Severity: Low]
> Can -EAGAIN reach userspace here and cause a request to be lost?
> vhost_get_desc_chain() returns -EAGAIN on an IOTLB miss, and
> vhost_blk_req_submit() returns it when no backend file is found. The kick
> handler answers -EAGAIN with vhost_discard_vq_desc() and a requeue. Here
> the head is already off the avail ring, so nothing retries it. The UAPI
> comment lists -EAGAIN under "any other error", so userspace that follows
> it skips to nr + 1 and the guest never gets that head back. Should -EAGAIN
> be documented, or handled in the kernel?
-EAGAIN cannot reach userspace here. vhost_blk_resubmit_one() checks the
backend under vq->mutex and fails with -ENODEV without one; the backend
is only changed under the same mutex, so the !f path of
vhost_blk_req_submit() is not taken. translate_desc() returns -EAGAIN
only when dev->iotlb is set, and vhost-blk never calls
vhost_init_device_iotlb() nor offers VIRTIO_F_ACCESS_PLATFORM, so a
missing mapping fails with -EFAULT instead.
>> +	if (ret && put_user(i, &argp->nr))
>> +		ret = -EFAULT;
>> +	return ret;
>> +}
> [Severity: Low]
> Also, when put_user() fails here, the real errno is replaced by -EFAULT.
> Userspace can then no longer tell why the loop stopped, and it also
> loses the index of the failing entry.
put_user() failing means nr still holds the input count; returning the
original errno would make the caller act on that stale index. -EFAULT
tells it the output is not valid, which is the usual convention.
>> + * error and type are ignored, reserved must be 0. On error, nr is set to the
>> + * index of the entry that failed; the entries before it were resubmitted.
>> + * On -ENOMEM pass the same entry again; -ENODEV and -EINTR fail the rest as
>> + * well. Any other error concerns only that entry: the ones after it may still
>> + * be passed from nr + 1. Fails with -ENODEV until the backend is set.
> [Severity: Low]
> As reported by Konstantin Khorenko on v1 [1], does this error contract
> match the code? It says -ENODEV fails the rest as well, but
> vhost_blk_resubmit_one() checks vhost_vq_get_backend(vq) per virtqueue.
> On a multiqueue device where one vq has no backend, entries for the other
> vqs can still be resubmitted.
>
> The "any other error concerns only that entry" rule also does not hold
> for -EFAULT from copy_from_user() on reqs[i]. The buffer is unreadable,
> so continuing from nr + 1 makes no sense. Could the comment state the
> real per-errno behaviour?
>
> [1] https://lore.kernel.org/r/179578030084.10258.14556640974201502480.b4-review@b4
Fixed the comment.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl
  2026-12-01  9:19   ` Konstantin Khorenko
@ 2026-12-01 11:16     ` Alexander Ivanov
  0 siblings, 0 replies; 13+ messages in thread
From: Alexander Ivanov @ 2026-12-01 11:16 UTC (permalink / raw)
  To: Konstantin Khorenko; +Cc: devel

On 12/1/26 10:19, Konstantin Khorenko wrote:
> Items 3, 4 and 5 of the cover letter reply.
>
> On Tue, 1 Dec 2026 09:50:20 +0100, Alexander Ivanov wrote:
>> + * error and type are ignored, reserved must be 0. On error, nr is set to the
>> + * index of the entry that failed; the entries before it were resubmitted.
>> + * On -ENOMEM pass the same entry again; -ENODEV and -EINTR fail the rest as
>> + * well. Any other error concerns only that entry: the ones after it may still
>> + * be passed from nr + 1. Fails with -ENODEV until the backend is set.
> - -EPERM, -EFAULT on the header and -EINVAL for reserved fail before
>    the loop and leave nr as passed in. By this rule QEMU goes on from
>    nr + 1, past the end, and resubmits nothing.
> - -EFAULT from copy_from_user() of reqs[i] is not about that entry:
>    it was never read. Put it with -ENODEV and -EINTR.
> - Say that a skipped entry's guest request is never completed, so
>    QEMU knows what skipping costs.
>
> -ENODEV is named twice; one mention is enough.
All fixed in v4. A guest-memory -EFAULT now stops the call too:
the errno cannot tell it from an unreadable reqs.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC
  2026-12-01  9:19   ` Konstantin Khorenko
@ 2026-12-01 11:25     ` Alexander Ivanov
  0 siblings, 0 replies; 13+ messages in thread
From: Alexander Ivanov @ 2026-12-01 11:25 UTC (permalink / raw)
  To: Konstantin Khorenko; +Cc: devel

On 12/1/26 10:19, Konstantin Khorenko wrote:
> Items 1 and 2 of the cover letter reply.
>
> On Tue, 1 Dec 2026 09:50:19 +0100, Alexander Ivanov wrote:
>> backend does not wait for it. Until then its head stays taken, so a
> "Until then" has nothing to refer to; "while the backend is set".
>
>> + * once the backend is unset, and is emptied by VHOST_RESET_OWNER and by a
>> + * successful VHOST_BLK_SET_BACKEND with fd >= 0. A failing one may empty it
>> + * too.
> A failing one may also leave requests in it: the vqs set up before
> the failure are live and hold requests on the new list. Say that QEMU
> reads the list again after a failing SET_BACKEND.
Reworded.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-12-01 11:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01  8:50 [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc() Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 3/4] drivers/vhost/blk: hold requests failed with ENOSPC Alexander Ivanov
2026-12-01  8:56   ` no-reply
2026-12-01  9:19   ` Konstantin Khorenko
2026-12-01 11:25     ` Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl Alexander Ivanov
2026-12-01  9:01   ` no-reply
2026-12-01 11:14     ` Alexander Ivanov
2026-12-01  9:19   ` Konstantin Khorenko
2026-12-01 11:16     ` Alexander Ivanov
2026-12-01  9:19 ` [Devel] [PATCH hci-8.2 v3 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Konstantin Khorenko

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.