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

Alexander Ivanov alexander.ivanov at virtuozzo.com
Tue Dec 1 11:16:44 MSK 2026


>> +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?
Agreed, the copy will go out of held_mutex in the next revision.

No snapshot is needed though: only nr_held is read under held_mutex.
blk->held is freed or replaced only by SET_BACKEND and RESET_OWNER,
both under dev.mutex, which this ioctl holds too, and the kick handler
only appends past nr_held, so the entries below it do not change while
they are copied.


More information about the Devel mailing list