Re: [PATCH v4 5/7] virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




在 2021/9/29 下午2:11, Wu Zongyong 写道:

Signed-off-by: Wu Zongyong <wuzongyong@xxxxxxxxxxxxxxxxx>


Commit log please.


---
  drivers/virtio/virtio_vdpa.c | 25 ++++++++++++++++++++-----
  1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index 72eaef2caeb1..8aa4ebe2a2a2 100644
--- a/drivers/virtio/virtio_vdpa.c
+++ b/drivers/virtio/virtio_vdpa.c
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
  	/* Assume split virtqueue, switch to packed if necessary */
  	struct vdpa_vq_state state = {0};
  	unsigned long flags;
-	u32 align, num;
+	u32 align, max_num, min_num = 0;
+	bool may_reduce_num = true;
  	int err;
if (!name)
@@ -163,22 +164,36 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
  	if (!info)
  		return ERR_PTR(-ENOMEM);
- num = ops->get_vq_num_max(vdpa);
-	if (num == 0) {
+	max_num = ops->get_vq_num_max(vdpa);
+	if (max_num == 0) {
  		err = -ENOENT;
  		goto error_new_virtqueue;
  	}
+ if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdpa);
+	if (min_num > max_num) {
+		err = -ENOENT;
+		goto error_new_virtqueue;
+	}


If we really want to do this, let's move this to vdpa core during device probing.

Or just leave it as is (device risk itself).

Thanks


+
+	may_reduce_num = (max_num == min_num) ? false : true;
+
  	/* Create the vring */
  	align = ops->get_vq_align(vdpa);
-	vq = vring_create_virtqueue(index, num, align, vdev,
-				    true, true, ctx,
+	vq = vring_create_virtqueue(index, max_num, align, vdev,
+				    true, may_reduce_num, ctx,
  				    virtio_vdpa_notify, callback, name);
  	if (!vq) {
  		err = -ENOMEM;
  		goto error_new_virtqueue;
  	}
+ if (virtqueue_get_vring_size(vq) < min_num) {
+		err = -EINVAL;
+		goto err_vq;
+	}
+
  	/* Setup virtqueue callback */
  	cb.callback = virtio_vdpa_virtqueue_cb;
  	cb.private = info;

_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization




[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux