[Devel] [PATCH hci-8.1] drivers/vhost/blk: add support for worker ioctls

Konstantin Khorenko khorenko at virtuozzo.com
Tue Nov 3 20:08:03 MSK 2026


I won't apply this version, please send v2 with the changes below.

On 10/29/26 12:05, Alexander Ivanov wrote:
> +	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;

- Put the VHOST_SET_NWORKERS revert (your v1 1/2) in front of this
  patch again, as one series.
- Fix the stranded-completion hang Sashiko found before this patch, in
  the same series.
- Say in the message that VHOST_SET_FORK_FROM_OWNER is needed before
  every VHOST_SET_OWNER.

VHOST_SET_NWORKERS (1491588e71daf) is still in the tree. Its workers
are written straight into vq->worker, and their attachment_cnt stays
0. So VHOST_FREE_WORKER frees a worker that a vq still uses, and the
next kick or completion writes into freed memory.

Before this patch the worker ioctls were not reachable in our kernel
at all, CONFIG_VHOST_SCSI is off. And our qemu (hci-dev) still calls
VHOST_SET_NWORKERS. In v1 the revert in 1/2 closed this hole, and it
got lost in the resend.

On the hang: the code path is old, but nobody runs vhost-blk in task
mode today, and in kthread mode a kill does not clear vq->worker. This
patch makes task mode the required setup, and killing a qemu with I/O
in flight is routine, so the fix has to land first, not later.
Mainline did the same 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.

VHOST_RESET_OWNER puts fork_owner back to the default, and qemu resets
the owner on every device reset, so this is needed before every
VHOST_SET_OWNER, not only the first one.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team



More information about the Devel mailing list