[7/8] vhost: configure device when any queue is ready for BLK device

Message ID 1661229305-240952-8-git-send-email-andy.pei@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series add multi queue support to vDPA ifc driver |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Pei, Andy Aug. 23, 2022, 4:35 a.m. UTC
  When boot from virtio blk device, seabois in QEMU only enables one queue.
To work in this scenario, vDPA BLK device back-end conf_dev when any
queue is ready.

Signed-off-by: Andy Pei <andy.pei@intel.com>
---
 lib/vhost/vhost_user.c | 56 +++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 12 deletions(-)
  

Patch

diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 4ad28ba..b65fba3 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -1451,6 +1451,25 @@ 
 #define VIRTIO_BUILTIN_NUM_VQS_TO_BE_READY 2u
 
 static int
+virtio_has_queue_ready(struct virtio_net *dev)
+{
+	struct vhost_virtqueue *vq;
+	uint32_t i, nr_vring = dev->nr_vring;
+
+	if (!dev->nr_vring)
+		return 0;
+
+	for (i = 0; i < nr_vring; i++) {
+		vq = dev->virtqueue[i];
+
+		if (vq_is_ready(dev, vq))
+			return 1;
+	}
+
+	return 0;
+}
+
+static int
 virtio_is_ready(struct virtio_net *dev)
 {
 	struct vhost_virtqueue *vq;
@@ -3167,9 +3186,33 @@  static int is_vring_iotlb(struct virtio_net *dev,
 	if (unlock_required)
 		vhost_user_unlock_all_queue_pairs(dev);
 
-	if (ret != 0 || !virtio_is_ready(dev))
+	if (ret != 0)
 		goto out;
 
+	vdpa_dev = dev->vdpa_dev;
+	if (vdpa_dev) {
+		if (vdpa_dev->ops->get_dev_type) {
+			ret = vdpa_dev->ops->get_dev_type(vdpa_dev, &vdpa_type);
+			if (ret) {
+				VHOST_LOG_CONFIG(dev->ifname, ERR,
+					"failed to get vdpa dev type.\n");
+				ret = -1;
+				goto out;
+			}
+		} else {
+			vdpa_type = RTE_VHOST_VDPA_DEVICE_TYPE_NET;
+		}
+	}
+
+	if (!virtio_is_ready(dev)) {
+		if (vdpa_type == RTE_VHOST_VDPA_DEVICE_TYPE_BLK) {
+			if (!virtio_has_queue_ready(dev))
+				goto out;
+		} else {
+			goto out;
+		}
+	}
+
 	/*
 	 * Virtio is now ready. If not done already, it is time
 	 * to notify the application it can process the rings and
@@ -3181,20 +3224,9 @@  static int is_vring_iotlb(struct virtio_net *dev,
 			dev->flags |= VIRTIO_DEV_RUNNING;
 	}
 
-	vdpa_dev = dev->vdpa_dev;
 	if (!vdpa_dev)
 		goto out;
 
-	if (vdpa_dev->ops->get_dev_type) {
-		ret = vdpa_dev->ops->get_dev_type(vdpa_dev, &vdpa_type);
-		if (ret) {
-			VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to get vdpa dev type.\n");
-			ret = -1;
-			goto out;
-		}
-	} else {
-		vdpa_type = RTE_VHOST_VDPA_DEVICE_TYPE_NET;
-	}
 	if (vdpa_type == RTE_VHOST_VDPA_DEVICE_TYPE_BLK
 		&& request != VHOST_USER_SET_VRING_CALL)
 		goto out;