[dpdk-dev] [PATCH] net/vhost: fix segfault when creating vdev dynamically

Junjie Chen junjie.j.chen at intel.com
Tue Mar 27 18:05:26 CEST 2018


when creating vdev dynamically, vhost pmd driver start directly without
checking TX/RX queues ready or not, and thus cause segmentation fault when
vhost library accessing queues. This patch add flag to check whether queues
setup or not, and add driver start call into dev_start to allow user start
it after setting up queue.

Fixes: aed0b12930b33("net/vhost: fix socket file deleted on stop")
Signed-off-by: Junjie Chen <junjie.j.chen at intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 3aae01c..719a150 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -118,6 +118,7 @@ struct pmd_internal {
 	char *iface_name;
 	uint16_t max_queues;
 	rte_atomic32_t started;
+	rte_atomic32_t once;
 };
 
 struct internal_list {
@@ -772,12 +773,24 @@ rte_eth_vhost_get_vid_from_port_id(uint16_t port_id)
 static int
 eth_dev_start(struct rte_eth_dev *dev)
 {
+	int ret = 0;
 	struct pmd_internal *internal = dev->data->dev_private;
 
+	if (unlikely(rte_atomic32_read(&internal->once) == 0)) {
+		ret = rte_vhost_driver_start(internal->iface_name);
+		if (ret < 0) {
+			RTE_LOG(ERR, PMD, "Failed to start driver for %s\n",
+				internal->iface_name);
+			return ret;
+		}
+
+		rte_atomic32_set(&internal->once, 1);
+	}
+
 	rte_atomic32_set(&internal->started, 1);
 	update_queuing_status(dev);
 
-	return 0;
+	return ret;
 }
 
 static void
@@ -1101,7 +1114,11 @@ eth_dev_vhost_create(struct rte_vdev_device *dev, char *iface_name,
 		goto error;
 	}
 
-	if (rte_vhost_driver_start(iface_name) < 0) {
+	if (!data->rx_queues || !data->tx_queues) {
+		RTE_LOG(INFO, PMD,
+			"TX/RX queue is not ready, driver will not start\n");
+		rte_atomic32_set(&internal->once, 0);
+	} else if (rte_vhost_driver_start(iface_name) < 0) {
 		RTE_LOG(ERR, PMD, "Failed to start driver for %s\n",
 			iface_name);
 		goto error;
-- 
2.7.4



More information about the dev mailing list