* [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers"
@ 2026-11-26 8:16 Alexander Ivanov
2026-11-26 11:34 ` Andrey Zhadchenko
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Alexander Ivanov @ 2026-11-26 8:16 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
This reverts commit 705a4b3eefde336713aaa0b84b1b74e69dcdef30.
VHOST_SET_NWORKERS was a stopgap to run our userspace on the rh10
kernel unchanged. Userspace should use the mainstream worker ioctls
(VHOST_NEW_WORKER, VHOST_ATTACH_VRING_WORKER etc.) instead.
The 0x1F ioctl number is freed: VHOST_SET_NWORKERS now fails with
-ENOTTY. A QEMU that still issues it fails to start vhost-blk with
num-threads other than 1 and the guest hangs, so QEMU has to move to
the worker ioctls ("vhost-blk: create kernel threads with the
mainstream worker ioctls" in QEMU) before this kernel ships.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/vhost/vhost.c | 57 +-------------------------------------
drivers/vhost/vhost.h | 1 -
include/uapi/linux/vhost.h | 8 ------
3 files changed, 1 insertion(+), 65 deletions(-)
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 422cac6f2298..56c0ecbb8352 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -605,8 +605,6 @@ void vhost_dev_init(struct vhost_dev *dev,
spin_lock_init(&dev->iotlb_lock);
xa_init_flags(&dev->worker_xa, XA_FLAGS_ALLOC);
- dev->workers_set = false;
-
for (i = 0; i < dev->nvqs; ++i) {
vq = dev->vqs[i];
vq->log = NULL;
@@ -1089,47 +1087,6 @@ long vhost_worker_ioctl(struct vhost_dev *dev, unsigned int ioctl,
}
EXPORT_SYMBOL_GPL(vhost_worker_ioctl);
-static void vhost_propagate_workers(struct vhost_dev *dev, int nworkers)
-{
- int i, j = 0;
-
- for (i = nworkers; i < dev->nvqs; i++) {
- struct vhost_worker *worker;
-
- worker = rcu_dereference_check(dev->vqs[j]->worker,
- lockdep_is_held(&dev->mutex));
- if (worker)
- __vhost_vq_attach_worker(dev->vqs[i], worker);
- if (++j >= nworkers)
- j = 0;
- }
-}
-
-
-static int vhost_set_workers(struct vhost_dev *dev, int n)
-{
- struct vhost_worker *worker;
- int i, ret = 0;
-
- if (n > dev->nvqs)
- n = dev->nvqs;
-
- dev->workers_set = true;
-
- for (i = 1; i < n; i++) {
- worker = vhost_worker_create(dev);
- if (!worker) {
- ret = -ENOMEM;
- break;
- }
- __vhost_vq_attach_worker(dev->vqs[i], worker);
- }
-
- vhost_propagate_workers(dev, i);
-
- return ret;
-}
-
/* Caller should have device mutex */
long vhost_dev_set_owner(struct vhost_dev *dev)
{
@@ -1264,7 +1221,6 @@ void vhost_dev_cleanup(struct vhost_dev *dev)
wake_up_interruptible_poll(&dev->wait, EPOLLIN | EPOLLRDNORM);
vhost_workers_free(dev);
vhost_detach_mm(dev);
- dev->workers_set = false;
}
EXPORT_SYMBOL_GPL(vhost_dev_cleanup);
@@ -2350,7 +2306,7 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
struct eventfd_ctx *ctx;
u64 p;
long r;
- int i, fd, n;
+ int i, fd;
/* If you are not the owner, you can become one */
if (ioctl == VHOST_SET_OWNER) {
@@ -2446,17 +2402,6 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
if (ctx)
eventfd_ctx_put(ctx);
break;
- case VHOST_SET_NWORKERS:
- r = get_user(n, (int __user *)argp);
- if (r < 0)
- break;
- if (!d->use_worker || d->workers_set) {
- r = -EINVAL;
- break;
- }
-
- r = vhost_set_workers(d, n);
- break;
default:
r = -ENOIOCTLCMD;
break;
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 37ade2f1cb7d..077fa4d0cf36 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -198,7 +198,6 @@ struct vhost_dev {
* The default value is set by fork_from_owner_default
*/
bool fork_owner;
- bool workers_set;
int (*msg_handler)(struct vhost_dev *dev, u32 asid,
struct vhost_iotlb_msg *msg);
};
diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
index 5553522fbf48..4371703948b9 100644
--- a/include/uapi/linux/vhost.h
+++ b/include/uapi/linux/vhost.h
@@ -102,14 +102,6 @@
#define VHOST_GET_VRING_WORKER _IOWR(VHOST_VIRTIO, 0x16, \
struct vhost_vring_worker)
-/* Set number of vhost workers.
- * This can be done only once until reset.
- * All workers are freed upon reset.
- * If the value is too big it is silently truncated to the maximum number of
- * supported vhost workers
- */
-#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
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers"
2026-11-26 8:16 [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers" Alexander Ivanov
@ 2026-11-26 11:34 ` Andrey Zhadchenko
2026-11-30 15:30 ` Konstantin Khorenko
2026-11-30 15:45 ` Konstantin Khorenko
2 siblings, 0 replies; 5+ messages in thread
From: Andrey Zhadchenko @ 2026-11-26 11:34 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: devel
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
On 11/26/26 09:16, Alexander Ivanov wrote:
> This reverts commit 705a4b3eefde336713aaa0b84b1b74e69dcdef30.
>
> VHOST_SET_NWORKERS was a stopgap to run our userspace on the rh10
> kernel unchanged. Userspace should use the mainstream worker ioctls
> (VHOST_NEW_WORKER, VHOST_ATTACH_VRING_WORKER etc.) instead.
>
> The 0x1F ioctl number is freed: VHOST_SET_NWORKERS now fails with
> -ENOTTY. A QEMU that still issues it fails to start vhost-blk with
> num-threads other than 1 and the guest hangs, so QEMU has to move to
> the worker ioctls ("vhost-blk: create kernel threads with the
> mainstream worker ioctls" in QEMU) before this kernel ships.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-107537
> Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
> drivers/vhost/vhost.c | 57 +-------------------------------------
> drivers/vhost/vhost.h | 1 -
> include/uapi/linux/vhost.h | 8 ------
> 3 files changed, 1 insertion(+), 65 deletions(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 422cac6f2298..56c0ecbb8352 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -605,8 +605,6 @@ void vhost_dev_init(struct vhost_dev *dev,
> spin_lock_init(&dev->iotlb_lock);
> xa_init_flags(&dev->worker_xa, XA_FLAGS_ALLOC);
>
> - dev->workers_set = false;
> -
> for (i = 0; i < dev->nvqs; ++i) {
> vq = dev->vqs[i];
> vq->log = NULL;
> @@ -1089,47 +1087,6 @@ long vhost_worker_ioctl(struct vhost_dev *dev, unsigned int ioctl,
> }
> EXPORT_SYMBOL_GPL(vhost_worker_ioctl);
>
> -static void vhost_propagate_workers(struct vhost_dev *dev, int nworkers)
> -{
> - int i, j = 0;
> -
> - for (i = nworkers; i < dev->nvqs; i++) {
> - struct vhost_worker *worker;
> -
> - worker = rcu_dereference_check(dev->vqs[j]->worker,
> - lockdep_is_held(&dev->mutex));
> - if (worker)
> - __vhost_vq_attach_worker(dev->vqs[i], worker);
> - if (++j >= nworkers)
> - j = 0;
> - }
> -}
> -
> -
> -static int vhost_set_workers(struct vhost_dev *dev, int n)
> -{
> - struct vhost_worker *worker;
> - int i, ret = 0;
> -
> - if (n > dev->nvqs)
> - n = dev->nvqs;
> -
> - dev->workers_set = true;
> -
> - for (i = 1; i < n; i++) {
> - worker = vhost_worker_create(dev);
> - if (!worker) {
> - ret = -ENOMEM;
> - break;
> - }
> - __vhost_vq_attach_worker(dev->vqs[i], worker);
> - }
> -
> - vhost_propagate_workers(dev, i);
> -
> - return ret;
> -}
> -
> /* Caller should have device mutex */
> long vhost_dev_set_owner(struct vhost_dev *dev)
> {
> @@ -1264,7 +1221,6 @@ void vhost_dev_cleanup(struct vhost_dev *dev)
> wake_up_interruptible_poll(&dev->wait, EPOLLIN | EPOLLRDNORM);
> vhost_workers_free(dev);
> vhost_detach_mm(dev);
> - dev->workers_set = false;
> }
> EXPORT_SYMBOL_GPL(vhost_dev_cleanup);
>
> @@ -2350,7 +2306,7 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
> struct eventfd_ctx *ctx;
> u64 p;
> long r;
> - int i, fd, n;
> + int i, fd;
>
> /* If you are not the owner, you can become one */
> if (ioctl == VHOST_SET_OWNER) {
> @@ -2446,17 +2402,6 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
> if (ctx)
> eventfd_ctx_put(ctx);
> break;
> - case VHOST_SET_NWORKERS:
> - r = get_user(n, (int __user *)argp);
> - if (r < 0)
> - break;
> - if (!d->use_worker || d->workers_set) {
> - r = -EINVAL;
> - break;
> - }
> -
> - r = vhost_set_workers(d, n);
> - break;
> default:
> r = -ENOIOCTLCMD;
> break;
> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> index 37ade2f1cb7d..077fa4d0cf36 100644
> --- a/drivers/vhost/vhost.h
> +++ b/drivers/vhost/vhost.h
> @@ -198,7 +198,6 @@ struct vhost_dev {
> * The default value is set by fork_from_owner_default
> */
> bool fork_owner;
> - bool workers_set;
> int (*msg_handler)(struct vhost_dev *dev, u32 asid,
> struct vhost_iotlb_msg *msg);
> };
> diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
> index 5553522fbf48..4371703948b9 100644
> --- a/include/uapi/linux/vhost.h
> +++ b/include/uapi/linux/vhost.h
> @@ -102,14 +102,6 @@
> #define VHOST_GET_VRING_WORKER _IOWR(VHOST_VIRTIO, 0x16, \
> struct vhost_vring_worker)
>
> -/* Set number of vhost workers.
> - * This can be done only once until reset.
> - * All workers are freed upon reset.
> - * If the value is too big it is silently truncated to the maximum number of
> - * supported vhost workers
> - */
> -#define VHOST_SET_NWORKERS _IOW(VHOST_VIRTIO, 0x1F, int)
> -
> /* The following ioctls use eventfd file descriptors to signal and poll
> * for events. */
>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers"
2026-11-26 8:16 [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers" Alexander Ivanov
2026-11-26 11:34 ` Andrey Zhadchenko
@ 2026-11-30 15:30 ` Konstantin Khorenko
2026-11-30 15:41 ` Konstantin Khorenko
2026-11-30 15:45 ` Konstantin Khorenko
2 siblings, 1 reply; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 15:30 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: devel
Applying with these fixes on my side:
- message: name b3ed783d6715 next to 705a4b3eefde in the "This
reverts commit" line;
- message: -ENOTTY, or -ENOBUFS when the argument is not a valid vq
index;
- message: name the QEMU version that has the worker ioctls,
v10.1.0-20.vz10.33.
On Thu, 26 Nov 2026 09:16:46 +0100, Alexander Ivanov wrote:
> This reverts commit 705a4b3eefde336713aaa0b84b1b74e69dcdef30.
The diff also reverts b3ed783d6715 ("drivers/vhost: fix a
use-after-free of VHOST_SET_NWORKERS workers"): the removed lines with
__vhost_vq_attach_worker() and !d->use_worker come from it, and a plain
"git revert 705a4b3eefde" does not give this diff. Without its name a
later rebase keeps b3ed783d6715 with a Fixes: pointing to a dropped
commit.
> The 0x1F ioctl number is freed: VHOST_SET_NWORKERS now fails with
> -ENOTTY.
vhost_dev_ioctl() returns -ENOIOCTLCMD, and vhost_vring_ioctl() then
reads the int argument as a vq index: 32 or more on vhost-blk gives
-ENOBUFS. QEMU fails either way, so only the errno was off.
> mainstream worker ioctls" in QEMU) before this kernel ships.
The QEMU commit is 3b0b744f6c4 on hci-dev, first in
v10.1.0-20.vz10.33; with the version in the message packaging can
require it.
Separate patches, not needed for this patch. I created a task:
1. hci-8.1 still has 705a4b3eefde without b3ed783d6715, and its QEMU
still uses VHOST_SET_NWORKERS, so this revert does not fit there.
The owner of a vhost-scsi device can free a worker installed by
VHOST_SET_NWORKERS with VHOST_FREE_WORKER while a vq still uses
it: attachment_cnt is 0. b3ed783d6715 wants a backport to hci-8.1.
https://virtuozzo.atlassian.net/browse/VSTOR-157358
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers"
2026-11-30 15:30 ` Konstantin Khorenko
@ 2026-11-30 15:41 ` Konstantin Khorenko
0 siblings, 0 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 15:41 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: Denis V. Lunev, devel
Hi Alexander,
One more thing on this change: the new QEMU on a node that still runs
the hci-8.1 kernel.
During an hci-8.1 -> hci-8.2 update the node gets
qemu-kvm >= 10.1.0-20.vz10.33 with 3b0b744f6c4 ("vhost-blk: create
kernel threads with the mainstream worker ioctls"), but keeps running
its 24.x kernel until the reboot. 6afc2f6416c3 ("drivers/vhost/blk: add
support for worker ioctls") is in 26.x only, from 26.1 on; on 24.x
vhost_blk_ioctl() never reaches vhost_worker_ioctl(), so
VHOST_NEW_WORKER fails there.
What happens to a VM started in that window:
+----------------------------+---------------------------------------+
| VM | new QEMU on a 24.x kernel |
+----------------------------+---------------------------------------+
| no vhost-blk disks | not affected |
| vhost-blk, num-threads = 1 | starts: VHOST_SET_FORK_FROM_OWNER |
| (the QEMU default) | exists on 24.x, the worker becomes a |
| | vhost_task as on the new kernel |
| vhost-blk, num-threads > 1 | fails: VHOST_NEW_WORKER fails and |
| | there is no fallback, so start, |
| | restart and incoming migration fail |
| already running | not affected, old QEMU process |
+----------------------------+---------------------------------------+
So the window is the time between the package update and the reboot.
If the node stays in maintenance with all VMs moved away for the whole
update, nothing breaks in practice.
Questions:
1. Does our management stack (nova/libvirt with hw:use_vhostblk) ever
set num-threads > 1 for vhost-blk disks?
2. If it does, which way do we close the window: QEMU falls back to
VHOST_SET_NWORKERS when VHOST_NEW_WORKER fails, or the update
procedure guarantees that no VM starts on the node before the
reboot?
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers"
2026-11-26 8:16 [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers" Alexander Ivanov
2026-11-26 11:34 ` Andrey Zhadchenko
2026-11-30 15:30 ` Konstantin Khorenko
@ 2026-11-30 15:45 ` Konstantin Khorenko
2 siblings, 0 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 15:45 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
On Thu, 26 Nov 2026 09:16:46 +0100, Alexander Ivanov wrote:
> Revert "drivers/vhost: add ioctl to increase the number of workers"
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.6.vz10, thanks!
[1/1] Revert "drivers/vhost: add ioctl to increase the number of workers"
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/66f430970c41
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-30 15:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 8:16 [Devel] [PATCH hci-8.2] Revert "drivers/vhost: add ioctl to increase the number of workers" Alexander Ivanov
2026-11-26 11:34 ` Andrey Zhadchenko
2026-11-30 15:30 ` Konstantin Khorenko
2026-11-30 15:41 ` Konstantin Khorenko
2026-11-30 15:45 ` Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox