* [PATCH hci-8.2 v7 1/7] vhost-backend: add vhost_set_fork_from_owner op
2026-11-20 12:38 [PATCH hci-8.2 v7 0/7] vhost-blk: switch from VHOST_SET_NWORKERS to the mainstream worker ioctls Alexander Ivanov
@ 2026-11-20 12:38 ` Alexander Ivanov
2026-11-20 12:40 ` no-reply
2026-11-20 12:38 ` [PATCH hci-8.2 v7 2/7] vhost-blk: reject num-queues above VHOST_BLK_MAX_QUEUES Alexander Ivanov
` (5 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Alexander Ivanov @ 2026-11-20 12:38 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
Wrap VHOST_SET_FORK_FROM_OWNER for the kernel backend next to the
worker ops, so devices switch the vhost worker mode the same way they
create and attach workers.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
hw/virtio/vhost-backend.c | 7 +++++++
include/hw/virtio/vhost-backend.h | 3 +++
2 files changed, 10 insertions(+)
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 1447d129630..7f8c731a607 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -187,6 +187,12 @@ static int vhost_kernel_get_vring_worker(struct vhost_dev *dev,
return vhost_kernel_call(dev, VHOST_GET_VRING_WORKER, worker);
}
+static int vhost_kernel_set_fork_from_owner(struct vhost_dev *dev,
+ uint8_t fork_owner)
+{
+ return vhost_kernel_call(dev, VHOST_SET_FORK_FROM_OWNER, &fork_owner);
+}
+
static int vhost_kernel_set_backend_cap(struct vhost_dev *dev)
{
uint64_t features;
@@ -386,6 +392,7 @@ const VhostOps kernel_ops = {
.vhost_attach_vring_worker = vhost_kernel_attach_vring_worker,
.vhost_new_worker = vhost_kernel_new_worker,
.vhost_free_worker = vhost_kernel_free_worker,
+ .vhost_set_fork_from_owner = vhost_kernel_set_fork_from_owner,
.vhost_set_features_ex = vhost_kernel_set_features,
.vhost_get_features_ex = vhost_kernel_get_features,
.vhost_set_backend_cap = vhost_kernel_set_backend_cap,
diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
index 18ce5ea9a07..78cd66378ef 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -95,6 +95,8 @@ typedef int (*vhost_new_worker_op)(struct vhost_dev *dev,
struct vhost_worker_state *worker);
typedef int (*vhost_free_worker_op)(struct vhost_dev *dev,
struct vhost_worker_state *worker);
+typedef int (*vhost_set_fork_from_owner_op)(struct vhost_dev *dev,
+ uint8_t fork_owner);
typedef int (*vhost_set_features_ex_op)(struct vhost_dev *dev,
const uint64_t *features);
typedef int (*vhost_get_features_ex_op)(struct vhost_dev *dev,
@@ -190,6 +192,7 @@ typedef struct VhostOps {
vhost_free_worker_op vhost_free_worker;
vhost_get_vring_worker_op vhost_get_vring_worker;
vhost_attach_vring_worker_op vhost_attach_vring_worker;
+ vhost_set_fork_from_owner_op vhost_set_fork_from_owner;
vhost_set_features_ex_op vhost_set_features_ex;
vhost_get_features_ex_op vhost_get_features_ex;
vhost_set_features_op vhost_set_features;
--
2.53.0
^ permalink raw reply [flat|nested] 19+ messages in thread* [PATCH hci-8.2 v7 2/7] vhost-blk: reject num-queues above VHOST_BLK_MAX_QUEUES
2026-11-20 12:38 [PATCH hci-8.2 v7 0/7] vhost-blk: switch from VHOST_SET_NWORKERS to the mainstream worker ioctls Alexander Ivanov
2026-11-20 12:38 ` [PATCH hci-8.2 v7 1/7] vhost-backend: add vhost_set_fork_from_owner op Alexander Ivanov
@ 2026-11-20 12:38 ` Alexander Ivanov
2026-11-20 12:41 ` no-reply
2026-11-20 12:38 ` [PATCH hci-8.2 v7 3/7] vhost-blk: use a local vhost_dev pointer in start and stop Alexander Ivanov
` (4 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Alexander Ivanov @ 2026-11-20 12:38 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
Only the automatic num-queues value is capped at VHOST_BLK_MAX_QUEUES,
an explicit one is taken as is. The kernel vhost-blk device has that
many virtqueues and rejects any vq beyond them, so realize fails with
an error that does not point at num-queues:
qemu-system-x86_64: vhost_set_vring_call failed: No buffer space available (105)
qemu-system-x86_64: vhost-blk: vhost initialization failed: No buffer space available
Check num-queues against the limit up front instead.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Fixes: 0ff3cb5ff28f ("block: add vhost-blk backend")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
hw/block/vhost-blk.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index d8bbfcaff86..6c99de89120 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -599,8 +599,9 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
VHOST_BLK_MAX_QUEUES);
}
- if (!conf->num_queues) {
- error_setg(errp, "vhost-blk: num-queues property must be larger than 0");
+ if (!conf->num_queues || conf->num_queues > VHOST_BLK_MAX_QUEUES) {
+ error_setg(errp, "vhost-blk: invalid num-queues property (%" PRIu16 "), "
+ "must be 1-%d", conf->num_queues, VHOST_BLK_MAX_QUEUES);
return;
}
--
2.53.0
^ permalink raw reply [flat|nested] 19+ messages in thread* [PATCH hci-8.2 v7 3/7] vhost-blk: use a local vhost_dev pointer in start and stop
2026-11-20 12:38 [PATCH hci-8.2 v7 0/7] vhost-blk: switch from VHOST_SET_NWORKERS to the mainstream worker ioctls Alexander Ivanov
2026-11-20 12:38 ` [PATCH hci-8.2 v7 1/7] vhost-backend: add vhost_set_fork_from_owner op Alexander Ivanov
2026-11-20 12:38 ` [PATCH hci-8.2 v7 2/7] vhost-blk: reject num-queues above VHOST_BLK_MAX_QUEUES Alexander Ivanov
@ 2026-11-20 12:38 ` Alexander Ivanov
2026-11-20 12:41 ` no-reply
2026-11-20 13:07 ` Andrey Drobyshev
2026-11-20 12:38 ` [PATCH hci-8.2 v7 4/7] vhost-blk: fix vhost_blk_start() returning 0 on failure Alexander Ivanov
` (3 subsequent siblings)
6 siblings, 2 replies; 19+ messages in thread
From: Alexander Ivanov @ 2026-11-20 12:38 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
Take &s->dev once into hdev in vhost_blk_start() and vhost_blk_stop()
instead of spelling it out at every use. No functional change.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Fixes: 0ff3cb5ff28f ("block: add vhost-blk backend")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
hw/block/vhost-blk.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 6c99de89120..bbd24fa94b1 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -36,6 +36,7 @@
static int vhost_blk_start(VirtIODevice *vdev)
{
VHostBlk *s = VHOST_BLK(vdev);
+ struct vhost_dev *hdev = &s->dev;
struct vhost_vring_file backend;
int ret, i, nworkers;
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
@@ -71,22 +72,22 @@ static int vhost_blk_start(VirtIODevice *vdev)
}
}
- ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true);
+ ret = k->set_guest_notifiers(qbus->parent, hdev->nvqs, true);
if (ret < 0) {
error_report("vhost-blk: unable to bind guest notifiers");
return ret;
}
- ret = vhost_dev_enable_notifiers(&s->dev, vdev);
+ ret = vhost_dev_enable_notifiers(hdev, vdev);
if (ret < 0) {
error_report("vhost-blk: unable to enable dev notifiers: %s",
strerror(errno));
goto err_set;
}
- s->dev.acked_features = vdev->guest_features & s->dev.features;
+ hdev->acked_features = vdev->guest_features & hdev->features;
- ret = vhost_dev_start(&s->dev, vdev, false);
+ ret = vhost_dev_start(hdev, vdev, false);
if (ret < 0) {
error_report("vhost-blk: unable to start vhost dev");
goto err_disable;
@@ -101,11 +102,11 @@ static int vhost_blk_start(VirtIODevice *vdev)
goto err_stop;
}
- for (i = 0; i < s->dev.nvqs; i++) {
- vhost_virtqueue_mask(&s->dev, vdev, i, false);
+ for (i = 0; i < hdev->nvqs; i++) {
+ vhost_virtqueue_mask(hdev, vdev, i, false);
}
- for (i = 0; i < s->dev.nvqs; i++) {
+ for (i = 0; i < hdev->nvqs; i++) {
event_notifier_set(virtio_queue_get_host_notifier(virtio_get_queue(vdev, i)));
}
@@ -114,11 +115,11 @@ static int vhost_blk_start(VirtIODevice *vdev)
return 0;
err_stop:
- vhost_dev_stop(&s->dev, vdev, false);
+ vhost_dev_stop(hdev, vdev, false);
err_disable:
- vhost_dev_disable_notifiers(&s->dev, vdev);
+ vhost_dev_disable_notifiers(hdev, vdev);
err_set:
- ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
+ ret = k->set_guest_notifiers(qbus->parent, hdev->nvqs, false);
if (ret < 0) {
error_report("vhost-blk: unable to unbind guest notifiers");
}
@@ -132,6 +133,7 @@ static void vhost_blk_stop(VirtIODevice *vdev)
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
VHostBlk *s = VHOST_BLK(vdev);
+ struct vhost_dev *hdev = &s->dev;
struct vhost_vring_file backend;
int ret;
@@ -151,13 +153,13 @@ static void vhost_blk_stop(VirtIODevice *vdev)
ret = ioctl(s->vhostfd, VHOST_BLK_SET_BACKEND, &backend);
assert(ret == 0);
- vhost_dev_stop(&s->dev, vdev, false);
+ vhost_dev_stop(hdev, vdev, false);
- ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
+ ret = k->set_guest_notifiers(qbus->parent, hdev->nvqs, false);
if (ret < 0) {
error_report("vhost-blk: unable to unbind guest notifiers");
}
- vhost_dev_disable_notifiers(&s->dev, vdev);
+ vhost_dev_disable_notifiers(hdev, vdev);
s->vhost_started = false;
}
--
2.53.0
^ permalink raw reply [flat|nested] 19+ messages in thread* [PATCH hci-8.2 v7 4/7] vhost-blk: fix vhost_blk_start() returning 0 on failure
2026-11-20 12:38 [PATCH hci-8.2 v7 0/7] vhost-blk: switch from VHOST_SET_NWORKERS to the mainstream worker ioctls Alexander Ivanov
` (2 preceding siblings ...)
2026-11-20 12:38 ` [PATCH hci-8.2 v7 3/7] vhost-blk: use a local vhost_dev pointer in start and stop Alexander Ivanov
@ 2026-11-20 12:38 ` Alexander Ivanov
2026-11-20 12:42 ` no-reply
2026-11-20 12:38 ` [PATCH hci-8.2 v7 5/7] vhost-blk: reset the owner when vhost_blk_start() fails Alexander Ivanov
` (2 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Alexander Ivanov @ 2026-11-20 12:38 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
The error path stores the result of unbinding the guest notifiers in
ret, so a failure after binding them is reported as success once the
unbind succeeds: vhost_blk_set_status() logs nothing and the device
stays dead. Keep the original error in ret.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Fixes: 0ff3cb5ff28f ("block: add vhost-blk backend")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
hw/block/vhost-blk.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index bbd24fa94b1..fab79da5a38 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -119,8 +119,7 @@ err_stop:
err_disable:
vhost_dev_disable_notifiers(hdev, vdev);
err_set:
- ret = k->set_guest_notifiers(qbus->parent, hdev->nvqs, false);
- if (ret < 0) {
+ if (k->set_guest_notifiers(qbus->parent, hdev->nvqs, false) < 0) {
error_report("vhost-blk: unable to unbind guest notifiers");
}
--
2.53.0
^ permalink raw reply [flat|nested] 19+ messages in thread* [PATCH hci-8.2 v7 5/7] vhost-blk: reset the owner when vhost_blk_start() fails
2026-11-20 12:38 [PATCH hci-8.2 v7 0/7] vhost-blk: switch from VHOST_SET_NWORKERS to the mainstream worker ioctls Alexander Ivanov
` (3 preceding siblings ...)
2026-11-20 12:38 ` [PATCH hci-8.2 v7 4/7] vhost-blk: fix vhost_blk_start() returning 0 on failure Alexander Ivanov
@ 2026-11-20 12:38 ` Alexander Ivanov
2026-11-20 12:42 ` no-reply
2026-11-20 13:07 ` Andrey Drobyshev
2026-11-20 12:38 ` [PATCH hci-8.2 v7 6/7] vhost-blk: create kernel threads with the mainstream worker ioctls Alexander Ivanov
2026-11-20 12:38 ` [PATCH hci-8.2 v7 7/7] linux-headers: drop VHOST_SET_NWORKERS Alexander Ivanov
6 siblings, 2 replies; 19+ messages in thread
From: Alexander Ivanov @ 2026-11-20 12:38 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
Every failure after VHOST_SET_OWNER leaves QEMU the owner of the vhost
device with its worker threads running. The next start attempt then
fails on VHOST_SET_OWNER with -EBUSY until the guest resets the device.
Undo VHOST_SET_OWNER on these paths, as vhost_blk_reset() does.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Fixes: 0ff3cb5ff28f ("block: add vhost-blk backend")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
hw/block/vhost-blk.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index fab79da5a38..0be51a10dbc 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -60,7 +60,8 @@ static int vhost_blk_start(VirtIODevice *vdev)
nworkers = s->conf.num_threads;
if (nworkers != 1 && ioctl(s->vhostfd, VHOST_SET_NWORKERS, &nworkers)) {
error_report("vhost-blk: unable to set number of kernel threads");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_reset_owner;
}
if (s->conf.serial) {
@@ -68,14 +69,15 @@ static int vhost_blk_start(VirtIODevice *vdev)
if (ioctl(s->vhostfd, VHOST_BLK_SET_SERIAL, serial)) {
error_report("vhost-blk: unable to set drive serial %s",
s->conf.serial);
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_reset_owner;
}
}
ret = k->set_guest_notifiers(qbus->parent, hdev->nvqs, true);
if (ret < 0) {
error_report("vhost-blk: unable to bind guest notifiers");
- return ret;
+ goto err_reset_owner;
}
ret = vhost_dev_enable_notifiers(hdev, vdev);
@@ -122,6 +124,10 @@ err_set:
if (k->set_guest_notifiers(qbus->parent, hdev->nvqs, false) < 0) {
error_report("vhost-blk: unable to unbind guest notifiers");
}
+err_reset_owner:
+ if (ioctl(s->vhostfd, VHOST_RESET_OWNER, NULL)) {
+ error_report("vhost-blk: unable to reset owner: %s", strerror(errno));
+ }
return ret;
--
2.53.0
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH hci-8.2 v7 5/7] vhost-blk: reset the owner when vhost_blk_start() fails
2026-11-20 12:38 ` [PATCH hci-8.2 v7 5/7] vhost-blk: reset the owner when vhost_blk_start() fails Alexander Ivanov
@ 2026-11-20 12:42 ` no-reply
2026-11-20 13:07 ` Andrey Drobyshev
1 sibling, 0 replies; 19+ messages in thread
From: no-reply @ 2026-11-20 12:42 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
> Every failure after VHOST_SET_OWNER leaves QEMU the owner of the vhost
> device with its worker threads running. The next start attempt then
> fails on VHOST_SET_OWNER with -EBUSY until the guest resets the device.
> Undo VHOST_SET_OWNER on these paths, as vhost_blk_reset() does.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-107537
>
> Fixes: 0ff3cb5ff28f ("block: add vhost-blk backend")
> 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/20261120123840.3852526-1-alexander.ivanov@virtuozzo.com?part=5
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH hci-8.2 v7 5/7] vhost-blk: reset the owner when vhost_blk_start() fails
2026-11-20 12:38 ` [PATCH hci-8.2 v7 5/7] vhost-blk: reset the owner when vhost_blk_start() fails Alexander Ivanov
2026-11-20 12:42 ` no-reply
@ 2026-11-20 13:07 ` Andrey Drobyshev
1 sibling, 0 replies; 19+ messages in thread
From: Andrey Drobyshev @ 2026-11-20 13:07 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: andrey.zhadchenko, andrey.drobyshev, svt-core
On Fri, 20 Nov 2026 13:38:38 +0100, Alexander Ivanov <alexander.ivanov@virtuozzo.com> wrote:
> Every failure after VHOST_SET_OWNER leaves QEMU the owner of the vhost
> device with its worker threads running. The next start attempt then
> fails on VHOST_SET_OWNER with -EBUSY until the guest resets the device.
> Undo VHOST_SET_OWNER on these paths, as vhost_blk_reset() does.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-107537
>
> [...]
Reviewed-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
--
Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH hci-8.2 v7 6/7] vhost-blk: create kernel threads with the mainstream worker ioctls
2026-11-20 12:38 [PATCH hci-8.2 v7 0/7] vhost-blk: switch from VHOST_SET_NWORKERS to the mainstream worker ioctls Alexander Ivanov
` (4 preceding siblings ...)
2026-11-20 12:38 ` [PATCH hci-8.2 v7 5/7] vhost-blk: reset the owner when vhost_blk_start() fails Alexander Ivanov
@ 2026-11-20 12:38 ` Alexander Ivanov
2026-11-20 12:44 ` no-reply
2026-11-20 13:07 ` Andrey Drobyshev
2026-11-20 12:38 ` [PATCH hci-8.2 v7 7/7] linux-headers: drop VHOST_SET_NWORKERS Alexander Ivanov
6 siblings, 2 replies; 19+ messages in thread
From: Alexander Ivanov @ 2026-11-20 12:38 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
num-threads was passed to our own VHOST_SET_NWORKERS kernel ioctl. The
kernel drops it with the revert of "drivers/vhost: add ioctl to
increase the number of workers" in favour of the mainstream worker
ioctls, which vhost-blk now supports. Create num-threads - 1 workers
with VHOST_NEW_WORKER and attach them to the virtqueues round-robin
with VHOST_ATTACH_VRING_WORKER, the layout VHOST_SET_NWORKERS produced.
num-threads of 0 still means one thread and a value above num-queues
is clamped to it, as VHOST_SET_NWORKERS did.
Our kernel, unlike mainline, defaults to kthread mode, where
VHOST_NEW_WORKER fails with -EFAULT rather than -ENOTTY. So switch the
device to vhost_task mode with VHOST_SET_FORK_FROM_OWNER before
VHOST_SET_OWNER. Do it for num-threads=1 as well, so the default
thread is of the same kind whatever the number of workers, but ignore
its failure there: a single thread works in either mode. A kernel
without the ioctl fails it with -EPERM from the owner check rather
than -ENOTTY, so the error code cannot tell it apart.
Fail to start vhost-blk if any of the worker ioctls fails rather than
silently run on fewer threads than requested. num-threads above 1 now
requires a kernel whose vhost-blk handles them.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
hw/block/vhost-blk.c | 64 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 59 insertions(+), 5 deletions(-)
diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 0be51a10dbc..b678378cb9b 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -33,6 +33,50 @@
#include "migration/cpr.h"
#include "system/runstate.h"
+/*
+ * Spread the virtqueues round-robin over nworkers kernel threads. Thread 0 is
+ * the default worker VHOST_SET_OWNER created; vq 0 and every nworkers-th vq
+ * after it stay on it.
+ */
+static int vhost_blk_set_workers(struct vhost_dev *hdev, int nworkers)
+{
+ uint32_t ids[VHOST_BLK_MAX_QUEUES];
+ int i, ret;
+
+ assert(nworkers <= ARRAY_SIZE(ids));
+
+ for (i = 1; i < hdev->nvqs; i++) {
+ int w = i % nworkers;
+ struct vhost_vring_worker vq_worker = { .index = i };
+
+ if (w == 0) {
+ continue;
+ }
+
+ if (i < nworkers) {
+ struct vhost_worker_state worker = { };
+
+ ret = hdev->vhost_ops->vhost_new_worker(hdev, &worker);
+ if (ret < 0) {
+ error_report("vhost-blk: unable to create kernel thread: %s",
+ strerror(-ret));
+ return ret;
+ }
+ ids[w] = worker.worker_id;
+ }
+
+ vq_worker.worker_id = ids[w];
+ ret = hdev->vhost_ops->vhost_attach_vring_worker(hdev, &vq_worker);
+ if (ret < 0) {
+ error_report("vhost-blk: unable to attach kernel thread to "
+ "queue %d: %s", i, strerror(-ret));
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static int vhost_blk_start(VirtIODevice *vdev)
{
VHostBlk *s = VHOST_BLK(vdev);
@@ -52,16 +96,26 @@ static int vhost_blk_start(VirtIODevice *vdev)
return 0;
}
+ nworkers = MIN(s->conf.num_threads, hdev->nvqs);
+
+ ret = hdev->vhost_ops->vhost_set_fork_from_owner(hdev,
+ VHOST_FORK_OWNER_TASK);
+ if (ret < 0 && nworkers > 1) {
+ error_report("vhost-blk: unable to set vhost_task mode: %s",
+ strerror(-ret));
+ return ret;
+ }
+
if (ioctl(s->vhostfd, VHOST_SET_OWNER, NULL)) {
error_report("vhost-blk: unable to set owner");
return -ENOSYS;
}
- nworkers = s->conf.num_threads;
- if (nworkers != 1 && ioctl(s->vhostfd, VHOST_SET_NWORKERS, &nworkers)) {
- error_report("vhost-blk: unable to set number of kernel threads");
- ret = -EINVAL;
- goto err_reset_owner;
+ if (nworkers > 1) {
+ ret = vhost_blk_set_workers(hdev, nworkers);
+ if (ret < 0) {
+ goto err_reset_owner;
+ }
}
if (s->conf.serial) {
--
2.53.0
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH hci-8.2 v7 6/7] vhost-blk: create kernel threads with the mainstream worker ioctls
2026-11-20 12:38 ` [PATCH hci-8.2 v7 6/7] vhost-blk: create kernel threads with the mainstream worker ioctls Alexander Ivanov
@ 2026-11-20 12:44 ` no-reply
2026-11-20 13:07 ` Andrey Drobyshev
1 sibling, 0 replies; 19+ messages in thread
From: no-reply @ 2026-11-20 12:44 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
> num-threads was passed to our own VHOST_SET_NWORKERS kernel ioctl. The
> kernel drops it with the revert of "drivers/vhost: add ioctl to
> increase the number of workers" in favour of the mainstream worker
> ioctls, which vhost-blk now supports. Create num-threads - 1 workers
> with VHOST_NEW_WORKER and attach them to the virtqueues round-robin
> with VHOST_ATTACH_VRING_WORKER, the layout VHOST_SET_NWORKERS produced.
> num-threads of 0 still means one thread and a value above num-queues
> is clamped to it, as VHOST_SET_NWORKERS did.
>
> Our kernel, unlike mainline, defaults to kthread mode, where
> VHOST_NEW_WORKER fails with -EFAULT rather than -ENOTTY. So switch the
> device to vhost_task mode with VHOST_SET_FORK_FROM_OWNER before
> VHOST_SET_OWNER. Do it for num-threads=1 as well, so the default
> thread is of the same kind whatever the number of workers, but ignore
> its failure there: a single thread works in either mode. A kernel
> without the ioctl fails it with -EPERM from the owner check rather
> than -ENOTTY, so the error code cannot tell it apart.
>
> Fail to start vhost-blk if any of the worker ioctls fails rather than
> silently run on fewer threads than requested. num-threads above 1 now
> requires a kernel whose vhost-blk handles them.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-107537
>
> 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/20261120123840.3852526-1-alexander.ivanov@virtuozzo.com?part=6
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH hci-8.2 v7 6/7] vhost-blk: create kernel threads with the mainstream worker ioctls
2026-11-20 12:38 ` [PATCH hci-8.2 v7 6/7] vhost-blk: create kernel threads with the mainstream worker ioctls Alexander Ivanov
2026-11-20 12:44 ` no-reply
@ 2026-11-20 13:07 ` Andrey Drobyshev
2026-11-20 13:47 ` Alexander Ivanov
1 sibling, 1 reply; 19+ messages in thread
From: Andrey Drobyshev @ 2026-11-20 13:07 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: andrey.zhadchenko, andrey.drobyshev, svt-core
> num-threads was passed to our own VHOST_SET_NWORKERS kernel ioctl. The
> kernel drops it with the revert of "drivers/vhost: add ioctl to
> increase the number of workers" in favour of the mainstream worker
> ioctls, which vhost-blk now supports. Create num-threads - 1 workers
> with VHOST_NEW_WORKER and attach them to the virtqueues round-robin
> with VHOST_ATTACH_VRING_WORKER, the layout VHOST_SET_NWORKERS produced.
> num-threads of 0 still means one thread and a value above num-queues
> is clamped to it, as VHOST_SET_NWORKERS did.
>
> Our kernel, unlike mainline, defaults to kthread mode, where
> VHOST_NEW_WORKER fails with -EFAULT rather than -ENOTTY. So switch the
> device to vhost_task mode with VHOST_SET_FORK_FROM_OWNER before
> VHOST_SET_OWNER. Do it for num-threads=1 as well, so the default
> thread is of the same kind whatever the number of workers, but ignore
> its failure there: a single thread works in either mode. A kernel
> without the ioctl fails it with -EPERM from the owner check rather
> than -ENOTTY, so the error code cannot tell it apart.
>
> Fail to start vhost-blk if any of the worker ioctls fails rather than
> silently run on fewer threads than requested. num-threads above 1 now
> requires a kernel whose vhost-blk handles them.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-107537
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
>
> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index ffd647bfef2..6639f3958bf 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c
> @@ -33,6 +33,50 @@
> #include "migration/cpr.h"
> #include "system/runstate.h"
>
> +/*
> + * Spread the virtqueues round-robin over nworkers kernel threads. Thread 0 is
> + * the default worker VHOST_SET_OWNER created; vq 0 and every nworkers-th vq
> + * after it stay on it.
> + */
> +static int vhost_blk_set_workers(struct vhost_dev *hdev, int nworkers)
> +{
> + uint32_t ids[VHOST_BLK_MAX_QUEUES];
> + int i, ret;
> +
> + assert(nworkers <= ARRAY_SIZE(ids));
> +
> + for (i = 1; i < hdev->nvqs; i++) {
> + int w = i % nworkers;
> + struct vhost_vring_worker vq_worker = { .index = i };
> +
> + if (w == 0) {
> + continue;
> + }
> +
> + if (i < nworkers) {
> + struct vhost_worker_state worker = { };
> +
> + ret = hdev->vhost_ops->vhost_new_worker(hdev, &worker);
> + if (ret < 0) {
> + error_report("vhost-blk: unable to create kernel thread: %s",
> + strerror(-ret));
> + return ret;
> + }
> + ids[w] = worker.worker_id;
> + }
> +
> + vq_worker.worker_id = ids[w];
> + ret = hdev->vhost_ops->vhost_attach_vring_worker(hdev, &vq_worker);
> + if (ret < 0) {
> + error_report("vhost-blk: unable to attach kernel thread to "
> + "queue %d: %s", i, strerror(-ret));
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
> +
> static int vhost_blk_start(VirtIODevice *vdev)
> {
> VHostBlk *s = VHOST_BLK(vdev);
> @@ -52,16 +96,26 @@ static int vhost_blk_start(VirtIODevice *vdev)
> return 0;
> }
>
> + nworkers = MIN(s->conf.num_threads, hdev->nvqs);
> +
> + ret = hdev->vhost_ops->vhost_set_fork_from_owner(hdev,
> + VHOST_FORK_OWNER_TASK);
> + if (ret < 0 && nworkers > 1) {
> + error_report("vhost-blk: unable to set vhost_task mode: %s",
> + strerror(-ret));
> + return ret;
> + }
This look alright. The only real objective I have left is that with
nworkers=1 VHOST_FORK_OWNER_TASK goes silently. How about smth like:
ret = hdev->vhost_ops->vhost_set_fork_from_owner(hdev, VHOST_FORK_OWNER_TASK);
if (ret < 0) {
if (nworkers > 1) {
error_report("vhost-blk: unable to set vhost_task mode: %s",
strerror(-ret));
return ret;
}
warn_report_once("vhost-blk: unable to set vhost_task mode, "
"using a kthread worker: %s", strerror(-ret));
}
This way we error out on nworkers>1 and leave a warning in the log with
nworkers=1, but keep working.
What do you think?
Andrey
--
Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH hci-8.2 v7 6/7] vhost-blk: create kernel threads with the mainstream worker ioctls
2026-11-20 13:07 ` Andrey Drobyshev
@ 2026-11-20 13:47 ` Alexander Ivanov
0 siblings, 0 replies; 19+ messages in thread
From: Alexander Ivanov @ 2026-11-20 13:47 UTC (permalink / raw)
To: Andrey Drobyshev; +Cc: andrey.zhadchenko, svt-core
>> + nworkers = MIN(s->conf.num_threads, hdev->nvqs);
>> +
>> + ret = hdev->vhost_ops->vhost_set_fork_from_owner(hdev,
>> + VHOST_FORK_OWNER_TASK);
>> + if (ret < 0 && nworkers > 1) {
>> + error_report("vhost-blk: unable to set vhost_task mode: %s",
>> + strerror(-ret));
>> + return ret;
>> + }
> This look alright. The only real objective I have left is that with
> nworkers=1 VHOST_FORK_OWNER_TASK goes silently. How about smth like:
>
> ret = hdev->vhost_ops->vhost_set_fork_from_owner(hdev, VHOST_FORK_OWNER_TASK);
> if (ret < 0) {
> if (nworkers > 1) {
> error_report("vhost-blk: unable to set vhost_task mode: %s",
> strerror(-ret));
> return ret;
> }
> warn_report_once("vhost-blk: unable to set vhost_task mode, "
> "using a kthread worker: %s", strerror(-ret));
> }
>
> This way we error out on nworkers>1 and leave a warning in the log with
> nworkers=1, but keep working.
>
> What do you think?
Agree, fixed.
>
> Andrey
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH hci-8.2 v7 7/7] linux-headers: drop VHOST_SET_NWORKERS
2026-11-20 12:38 [PATCH hci-8.2 v7 0/7] vhost-blk: switch from VHOST_SET_NWORKERS to the mainstream worker ioctls Alexander Ivanov
` (5 preceding siblings ...)
2026-11-20 12:38 ` [PATCH hci-8.2 v7 6/7] vhost-blk: create kernel threads with the mainstream worker ioctls Alexander Ivanov
@ 2026-11-20 12:38 ` Alexander Ivanov
2026-11-20 12:43 ` no-reply
6 siblings, 1 reply; 19+ messages in thread
From: Alexander Ivanov @ 2026-11-20 12:38 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core
vhost-blk no longer uses it, and the kernel drops the ioctl.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
linux-headers/linux/vhost.h | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h
index baad06412d4..b6eb628d973 100644
--- a/linux-headers/linux/vhost.h
+++ b/linux-headers/linux/vhost.h
@@ -102,15 +102,6 @@
#define VHOST_GET_VRING_WORKER _IOWR(VHOST_VIRTIO, 0x16, \
struct vhost_vring_worker)
-/* Set number of vhost workers
- * Currently number of vhost workers can only be increased.
- * All workers are freed upon reset.
- * If the value is too big it is silently truncated to the maximum number of
- * supported vhost workers
- * Even if the error is returned it is possible that some workers were created
- */
-#define VHOST_SET_NWORKERS _IOW(VHOST_VIRTIO, 0x1F, int)
-
/* The following ioctls use eventfd file descriptors to signal and poll
* for events. */
--
2.53.0
^ permalink raw reply [flat|nested] 19+ messages in thread