@@ -372,6 +372,11 @@ static int vhost_worker(void *data)
return 0;
}
+static int vhost_vq_num_batch_descs(struct vhost_virtqueue *vq)
+{
+ return vq->max_descs - UIO_MAXIOV;
+}
+
static void vhost_vq_free_iovecs(struct vhost_virtqueue *vq)
{
kfree(vq->descs);
@@ -394,7 +399,9 @@ static long vhost_dev_alloc_iovecs(struct vhost_dev *dev)
for (i = 0; i < dev->nvqs; ++i) {
vq = dev->vqs[i];
vq->max_descs = dev->iov_limit;
- vq->batch_descs = dev->iov_limit - UIO_MAXIOV;
+ if (vhost_vq_num_batch_descs(vq) < 0) {
+ return -EINVAL;
+ }
vq->descs = kmalloc_array(vq->max_descs,
sizeof(*vq->descs),
GFP_KERNEL);
@@ -2333,7 +2340,7 @@ static int fetch_descs(struct vhost_virtqueue *vq)
if (vq->ndescs)
return 0;
- while (!ret && vq->ndescs <= vq->batch_descs)
+ while (!ret && vq->ndescs <= vhost_vq_num_batch_descs(vq))
ret = fetch_buf(vq);
return vq->ndescs ? 0 : ret;
@@ -102,7 +102,6 @@ struct vhost_virtqueue {
int ndescs;
int first_desc;
int max_descs;
- int batch_descs;
const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS];
struct file *kick;
It can be deduced from "max_descs". Signed-off-by: Eugenio PĂ©rez <eperezma@redhat.com> --- drivers/vhost/vhost.c | 11 +++++++++-- drivers/vhost/vhost.h | 1 - 2 files changed, 9 insertions(+), 3 deletions(-)