[Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl
Alexander Ivanov
alexander.ivanov at virtuozzo.com
Tue Dec 1 14:14:02 MSK 2026
>> + ret = vhost_get_desc_chain(vq, r->head, vq->iov, ARRAY_SIZE(vq->iov),
>> + &out, &in, NULL, NULL);
>> + if (!ret)
>> + ret = vhost_blk_handle_desc(vq, r->head, out, in);
> [Severity: Low]
> Can -EAGAIN reach userspace here and cause a request to be lost?
> vhost_get_desc_chain() returns -EAGAIN on an IOTLB miss, and
> vhost_blk_req_submit() returns it when no backend file is found. The kick
> handler answers -EAGAIN with vhost_discard_vq_desc() and a requeue. Here
> the head is already off the avail ring, so nothing retries it. The UAPI
> comment lists -EAGAIN under "any other error", so userspace that follows
> it skips to nr + 1 and the guest never gets that head back. Should -EAGAIN
> be documented, or handled in the kernel?
-EAGAIN cannot reach userspace here. vhost_blk_resubmit_one() checks the
backend under vq->mutex and fails with -ENODEV without one; the backend
is only changed under the same mutex, so the !f path of
vhost_blk_req_submit() is not taken. translate_desc() returns -EAGAIN
only when dev->iotlb is set, and vhost-blk never calls
vhost_init_device_iotlb() nor offers VIRTIO_F_ACCESS_PLATFORM, so a
missing mapping fails with -EFAULT instead.
>> + if (ret && put_user(i, &argp->nr))
>> + ret = -EFAULT;
>> + return ret;
>> +}
> [Severity: Low]
> Also, when put_user() fails here, the real errno is replaced by -EFAULT.
> Userspace can then no longer tell why the loop stopped, and it also
> loses the index of the failing entry.
put_user() failing means nr still holds the input count; returning the
original errno would make the caller act on that stale index. -EFAULT
tells it the output is not valid, which is the usual convention.
>> + * error and type are ignored, reserved must be 0. On error, nr is set to the
>> + * index of the entry that failed; the entries before it were resubmitted.
>> + * On -ENOMEM pass the same entry again; -ENODEV and -EINTR fail the rest as
>> + * well. Any other error concerns only that entry: the ones after it may still
>> + * be passed from nr + 1. Fails with -ENODEV until the backend is set.
> [Severity: Low]
> As reported by Konstantin Khorenko on v1 [1], does this error contract
> match the code? It says -ENODEV fails the rest as well, but
> vhost_blk_resubmit_one() checks vhost_vq_get_backend(vq) per virtqueue.
> On a multiqueue device where one vq has no backend, entries for the other
> vqs can still be resubmitted.
>
> The "any other error concerns only that entry" rule also does not hold
> for -EFAULT from copy_from_user() on reqs[i]. The buffer is unreadable,
> so continuing from nr + 1 makes no sense. Could the comment state the
> real per-errno behaviour?
>
> [1] https://lore.kernel.org/r/179578030084.10258.14556640974201502480.b4-review@b4
Fixed the comment.
More information about the Devel
mailing list