* [Devel] [PATCH hci-8.1 v4 0/2] drivers/vhost/blk: add support for worker ioctls
@ 2026-11-16 8:51 Alexander Ivanov
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers Alexander Ivanov
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Alexander Ivanov @ 2026-11-16 8:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
vhost-blk gets the mainstream worker ioctls, so userspace can move from
our VHOST_SET_NWORKERS to them. Until it does, both interfaces live on
the same device, and the workers VHOST_SET_NWORKERS installs are not
counted in attachment_cnt: VHOST_FREE_WORKER can free a worker a vq
still uses.
Patch 1 attaches the VHOST_SET_NWORKERS workers with
__vhost_vq_attach_worker(), so VHOST_FREE_WORKER refuses to free them.
Patch 2 wires the worker ioctls into vhost-blk.
v4:
- rebased onto the current hci-8.1
- patch 1: update the Fixes tag to the new hash of the fixed commit
- patch 2: unchanged
v3:
- patch 1: skip a source vq whose worker was killed, reject
VHOST_SET_NWORKERS on devices that do not use workers (vhost-vdpa),
add the Fixes tag
- patch 2: unchanged
v2:
- patch 1: new, keeps VHOST_SET_NWORKERS safe next to the worker ioctls
- patch 2: unchanged
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Alexander Ivanov (2):
drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers
drivers/vhost/blk: add support for worker ioctls
drivers/vhost/blk.c | 8 ++++++++
drivers/vhost/vhost.c | 11 ++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Devel] [PATCH hci-8.1 v4 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers
2026-11-16 8:51 [Devel] [PATCH hci-8.1 v4 0/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
@ 2026-11-16 8:51 ` Alexander Ivanov
2026-11-16 8:57 ` no-reply
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 2/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Alexander Ivanov @ 2026-11-16 8:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
vhost_set_workers() and vhost_propagate_workers() store workers into
vq->worker directly, bypassing __vhost_vq_attach_worker(). The workers
they install keep attachment_cnt at 0, and the default worker keeps
counting every vq. VHOST_FREE_WORKER then destroys a worker a virtqueue
still points at, and the next vhost_vq_work_queue() on that vq is a
use-after-free. VHOST_ATTACH_VRING_WORKER on such a vq drives
attachment_cnt of its worker to -1. vhost-scsi already exposes both
interfaces to the device owner.
Attach the workers with __vhost_vq_attach_worker(), so VHOST_FREE_WORKER
fails with -EBUSY while a vq uses the worker and both interfaces can
coexist until userspace moves to the worker ioctls. Userspace issues
VHOST_SET_NWORKERS before VHOST_SET_VRING_KICK, so the attach takes the
path without synchronize_rcu() and VM startup is not slowed down.
The attach dereferences the worker, so skip a source vq whose worker
was killed, and reject VHOST_SET_NWORKERS on devices that do not use
workers. On vhost-vdpa every vq->worker is NULL, and the workers
vhost_set_workers() created there were never freed.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Fixes: 705a4b3eefde ("drivers/vhost: add ioctl to increase the number of workers")
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/vhost/vhost.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 1057ba7e3fc7..422cac6f2298 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1094,7 +1094,12 @@ 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;
+ 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;
}
@@ -1117,7 +1122,7 @@ static int vhost_set_workers(struct vhost_dev *dev, int n)
ret = -ENOMEM;
break;
}
- dev->vqs[i]->worker = worker;
+ __vhost_vq_attach_worker(dev->vqs[i], worker);
}
vhost_propagate_workers(dev, i);
@@ -2445,7 +2450,7 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
r = get_user(n, (int __user *)argp);
if (r < 0)
break;
- if (d->workers_set) {
+ if (!d->use_worker || d->workers_set) {
r = -EINVAL;
break;
}
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Devel] [PATCH hci-8.1 v4 2/2] drivers/vhost/blk: add support for worker ioctls
2026-11-16 8:51 [Devel] [PATCH hci-8.1 v4 0/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers Alexander Ivanov
@ 2026-11-16 8:51 ` Alexander Ivanov
2026-11-16 8:57 ` no-reply
2026-11-16 17:29 ` [Devel] [PATCH hci-8.1 v4 0/2] " Konstantin Khorenko
2026-11-17 14:40 ` Konstantin Khorenko
3 siblings, 1 reply; 7+ messages in thread
From: Alexander Ivanov @ 2026-11-16 8:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
Let userspace create vhost workers and bind them to vhost-blk
virtqueues with the mainstream ioctls from c1ecd8e95007 ("vhost: allow
userspace to create workers"), the same way d74b55e65502 ("vhost_scsi:
add support for worker ioctls") does it for vhost-scsi.
VHOST_NEW_WORKER needs the device in vhost_task mode, so userspace has
to issue VHOST_SET_FORK_FROM_OWNER with VHOST_FORK_OWNER_TASK before
VHOST_SET_OWNER: our fork_from_owner_default is kthread.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Suggested-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
drivers/vhost/blk.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index b95358cdf3bc..a4bd69b13b3b 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -956,6 +956,14 @@ static long vhost_blk_ioctl(struct file *f, unsigned int ioctl,
return vhost_blk_set_features(blk, features);
case VHOST_RESET_OWNER:
return vhost_blk_reset_owner(blk);
+ case VHOST_NEW_WORKER:
+ case VHOST_FREE_WORKER:
+ case VHOST_ATTACH_VRING_WORKER:
+ case VHOST_GET_VRING_WORKER:
+ mutex_lock(&blk->dev.mutex);
+ ret = vhost_worker_ioctl(&blk->dev, ioctl, argp);
+ mutex_unlock(&blk->dev.mutex);
+ return ret;
default:
mutex_lock(&blk->dev.mutex);
ret = vhost_dev_ioctl(&blk->dev, ioctl, argp);
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v4 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers Alexander Ivanov
@ 2026-11-16 8:57 ` no-reply
0 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2026-11-16 8:57 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
> vhost_set_workers() and vhost_propagate_workers() store workers into
> vq->worker directly, bypassing __vhost_vq_attach_worker(). The workers
> they install keep attachment_cnt at 0, and the default worker keeps
> counting every vq. VHOST_FREE_WORKER then destroys a worker a virtqueue
> still points at, and the next vhost_vq_work_queue() on that vq is a
> use-after-free. VHOST_ATTACH_VRING_WORKER on such a vq drives
> attachment_cnt of its worker to -1. vhost-scsi already exposes both
> interfaces to the device owner.
>
> Attach the workers with __vhost_vq_attach_worker(), so VHOST_FREE_WORKER
> fails with -EBUSY while a vq uses the worker and both interfaces can
> coexist until userspace moves to the worker ioctls. Userspace issues
> VHOST_SET_NWORKERS before VHOST_SET_VRING_KICK, so the attach takes the
> path without synchronize_rcu() and VM startup is not slowed down.
>
> The attach dereferences the worker, so skip a source vq whose worker
> was killed, and reject VHOST_SET_NWORKERS on devices that do not use
> workers. On vhost-vdpa every vq->worker is NULL, and the workers
> vhost_set_workers() created there were never freed.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-107537
> Fixes: 705a4b3eefde ("drivers/vhost: add ioctl to increase the number of workers")
> 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.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261116085139.2848797-1-alexander.ivanov@virtuozzo.com?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v4 2/2] drivers/vhost/blk: add support for worker ioctls
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 2/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
@ 2026-11-16 8:57 ` no-reply
0 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2026-11-16 8:57 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
> Let userspace create vhost workers and bind them to vhost-blk
> virtqueues with the mainstream ioctls from c1ecd8e95007 ("vhost: allow
> userspace to create workers"), the same way d74b55e65502 ("vhost_scsi:
> add support for worker ioctls") does it for vhost-scsi.
>
> VHOST_NEW_WORKER needs the device in vhost_task mode, so userspace has
> to issue VHOST_SET_FORK_FROM_OWNER with VHOST_FORK_OWNER_TASK before
> VHOST_SET_OWNER: our fork_from_owner_default is kthread.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-107537
> Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
>
> Suggested-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261116085139.2848797-1-alexander.ivanov@virtuozzo.com?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v4 0/2] drivers/vhost/blk: add support for worker ioctls
2026-11-16 8:51 [Devel] [PATCH hci-8.1 v4 0/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers Alexander Ivanov
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 2/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
@ 2026-11-16 17:29 ` Konstantin Khorenko
2026-11-17 14:40 ` Konstantin Khorenko
3 siblings, 0 replies; 7+ messages in thread
From: Konstantin Khorenko @ 2026-11-16 17:29 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: devel
I'm ready to apply this series, but only after the series
"drivers/vhost/blk: support VIRTIO_BLK_F_WRITE_ZEROES": its 1/2,
"drivers/vhost/blk: fix a flush hang on requests completed after
worker kill", is the hang fix I asked for on v1.
Then applying with these fixes on my side:
- patch 1 message: says that vhost_dev_flush() skipped these workers
(attachment_cnt 0) and now waits for them; the use-after-free is
tied to vhost-blk getting the worker ioctls in patch 2, since
CONFIG_VHOST_SCSI is off in our kernels; the first paragraph split
- patch 2 message: VHOST_SET_FORK_FROM_OWNER before every
VHOST_SET_OWNER, VHOST_RESET_OWNER goes back to kthread
On Mon, 16 Nov 2026 09:51:37 +0100, Alexander Ivanov wrote:
> Alexander Ivanov (2):
> drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers
> drivers/vhost/blk: add support for worker ioctls
The two series apply cleanly on top of each other in this order.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v4 0/2] drivers/vhost/blk: add support for worker ioctls
2026-11-16 8:51 [Devel] [PATCH hci-8.1 v4 0/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
` (2 preceding siblings ...)
2026-11-16 17:29 ` [Devel] [PATCH hci-8.1 v4 0/2] " Konstantin Khorenko
@ 2026-11-17 14:40 ` Konstantin Khorenko
3 siblings, 0 replies; 7+ messages in thread
From: Konstantin Khorenko @ 2026-11-17 14:40 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
On Mon, 16 Nov 2026 09:51:37 +0100, Alexander Ivanov wrote:
> drivers/vhost/blk: add support for worker ioctls
>
> vhost-blk gets the mainstream worker ioctls, so userspace can move from
> our VHOST_SET_NWORKERS to them. Until it does, both interfaces live on
> the same device, and the workers VHOST_SET_NWORKERS installs are not
> counted in attachment_cnt: VHOST_FREE_WORKER can free a worker a vq
> still uses.
>
> [...]
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.24.3.vz10, thanks!
[1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/b3ed783d6715
[2/2] drivers/vhost/blk: add support for worker ioctls
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/6afc2f6416c3
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-17 14:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 8:51 [Devel] [PATCH hci-8.1 v4 0/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers Alexander Ivanov
2026-11-16 8:57 ` no-reply
2026-11-16 8:51 ` [Devel] [PATCH hci-8.1 v4 2/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
2026-11-16 8:57 ` no-reply
2026-11-16 17:29 ` [Devel] [PATCH hci-8.1 v4 0/2] " Konstantin Khorenko
2026-11-17 14:40 ` Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox