From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 1/2] Revert "drivers/vhost: add ioctl to increase the number of workers"
Date: Tue, 27 Oct 2026 12:38:28 +0100 [thread overview]
Message-ID: <20261027113830.2927925-2-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261027113830.2927925-1-alexander.ivanov@virtuozzo.com>
This reverts commit 1491588e71dafc934c8d450ba36cc33bb0f990bd.
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.
It is also unsafe next to those ioctls. vhost_set_workers() installs
its workers into vq->worker bypassing __vhost_vq_attach_worker(), so
their attachment_cnt stays 0. VHOST_FREE_WORKER then destroys such a
worker while a virtqueue still points at it, and the next
vhost_vq_work_queue() on that vq is a use-after-free. vhost-scsi
exposes this to the device owner.
The 0x1F ioctl number is freed: VHOST_SET_NWORKERS now fails with
-ENOTTY, so userspace that still issues it has to be updated
together with this kernel.
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 | 52 +-------------------------------------
drivers/vhost/vhost.h | 1 -
include/uapi/linux/vhost.h | 8 ------
3 files changed, 1 insertion(+), 60 deletions(-)
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 1057ba7e3fc7..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,42 +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++) {
- dev->vqs[i]->worker = dev->vqs[j]->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;
- }
- dev->vqs[i]->worker = worker;
- }
-
- vhost_propagate_workers(dev, i);
-
- return ret;
-}
-
/* Caller should have device mutex */
long vhost_dev_set_owner(struct vhost_dev *dev)
{
@@ -1259,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);
@@ -2345,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) {
@@ -2441,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->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
next prev parent reply other threads:[~2026-10-27 11:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 11:38 [Devel] [PATCH hci-8.1 0/2] vhost: replace VHOST_SET_NWORKERS with the mainstream worker ioctls Alexander Ivanov
2026-10-27 11:38 ` Alexander Ivanov [this message]
2026-10-27 11:42 ` [Devel] [PATCH hci-8.1 1/2] Revert "drivers/vhost: add ioctl to increase the number of workers" no-reply
2026-10-27 11:38 ` [Devel] [PATCH hci-8.1 2/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
2026-10-27 11:44 ` no-reply
2026-10-29 10:48 ` [Devel] [PATCH hci-8.1 0/2] vhost: replace VHOST_SET_NWORKERS with the mainstream " Alexander Ivanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261027113830.2927925-2-alexander.ivanov@virtuozzo.com \
--to=alexander.ivanov@virtuozzo.com \
--cc=andrey.zhadchenko@virtuozzo.com \
--cc=devel@openvz.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox