[Devel] [PATCH hci-8.2 v2 3/4] drivers/vhost/blk: hold requests failed with ENOSPC

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Tue Dec 1 04:16:00 MSK 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] vhost-blk: copy_to_user/put_user under held_mutex in
  vhost_blk_get_held_reqs()
--

commit 62edbcac7057e5e5f630f73cc2f1f51290486cdd
Author: Alexander Ivanov <alexander.ivanov at virtuozzo.com>

drivers/vhost/blk: hold requests failed with ENOSPC

This commit lets userspace choose, through VHOST_BLK_SET_ERROR_POLICY, whether vhost-blk holds requests that fail with ENOSPC instead of completing them with VIRTIO_BLK_S_IOERR. Held requests are signalled through an eventfd, and VHOST_BLK_GET_HELD_REQS returns them to userspace.

> diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
> --- a/drivers/vhost/blk.c
> +++ b/drivers/vhost/blk.c

[ ... ]

> +static long vhost_blk_get_held_reqs(struct vhost_blk *blk,
> +				    struct vhost_blk_held_reqs __user *argp)
> +{
> +	long ret;
> +	u32 nr;
> +
> +	ret = vhost_blk_get_held_nr(argp, &nr);
> +	if (ret)
> +		return ret;
> +
> +	mutex_lock(&blk->held_mutex);
> +	if (nr < blk->nr_held)
> +		ret = -E2BIG;
> +	else if (copy_to_user(argp->reqs, blk->held,
> +			      blk->nr_held * sizeof(*blk->held)))
> +		ret = -EFAULT;
> +
> +	if (ret != -EFAULT && put_user(blk->nr_held, &argp->nr))
> +		ret = -EFAULT;
> +	mutex_unlock(&blk->held_mutex);
> +
> +	return ret;
> +}

[Severity: Low]
Can the copy_to_user() and put_user() calls here stall the vhost worker? Both can fault and sleep for an unbounded time while held_mutex is held, for example on a userfaultfd-registered or swapped-out buffer.

Meanwhile vhost_blk_handle_host_kick() -> vhost_blk_hold_req() takes the same held_mutex with vq->mutex held. The worker then blocks, and completions on that virtqueue are delayed with it.

Only the device owner can issue this ioctl, so it mostly hurts its own device. Would it be cleaner to snapshot the list under held_mutex and copy to user space after dropping it?

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply at sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261130162507.1822477-1-alexander.ivanov@virtuozzo.com?part=3



More information about the Devel mailing list