net/virtio-user: fix multi-process support

Message ID 20190325041215.30266-1-tiwei.bie@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio-user: fix multi-process support |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS

Commit Message

Tiwei Bie March 25, 2019, 4:12 a.m. UTC
This patch fixes the multi-process support for virtio-user.
Currently virtio-user just provides some limited secondary
process supports. Only some basic operations can be done in
secondary process on virtio-user port, e.g. getting port stats.
Actions which will trigger the communication with vhost backend
can't be done in secondary process for now, as the fds are
not synced between processes. The processing of server mode
devargs is also moved into virtio_user_dev_init().

Fixes: cdb068f031c6 ("bus/vdev: scan by multi-process channel")
Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
Cc: stable@dpdk.org

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c            | 15 +++++
 drivers/net/virtio/virtio_ethdev.h            |  2 +
 .../net/virtio/virtio_user/virtio_user_dev.c  |  3 +-
 .../net/virtio/virtio_user/virtio_user_dev.h  |  3 +-
 drivers/net/virtio/virtio_user_ethdev.c       | 61 +++++++++++--------
 5 files changed, 56 insertions(+), 28 deletions(-)
  

Comments

Maxime Coquelin March 27, 2019, 10:29 a.m. UTC | #1
On 3/25/19 5:12 AM, Tiwei Bie wrote:
> This patch fixes the multi-process support for virtio-user.
> Currently virtio-user just provides some limited secondary
> process supports. Only some basic operations can be done in
> secondary process on virtio-user port, e.g. getting port stats.
> Actions which will trigger the communication with vhost backend
> can't be done in secondary process for now, as the fds are
> not synced between processes. The processing of server mode
> devargs is also moved into virtio_user_dev_init().
> 
> Fixes: cdb068f031c6 ("bus/vdev: scan by multi-process channel")
> Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
> ---
>   drivers/net/virtio/virtio_ethdev.c            | 15 +++++
>   drivers/net/virtio/virtio_ethdev.h            |  2 +
>   .../net/virtio/virtio_user/virtio_user_dev.c  |  3 +-
>   .../net/virtio/virtio_user/virtio_user_dev.h  |  3 +-
>   drivers/net/virtio/virtio_user_ethdev.c       | 61 +++++++++++--------
>   5 files changed, 56 insertions(+), 28 deletions(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Maxime Coquelin March 27, 2019, 11:14 a.m. UTC | #2
On 3/25/19 5:12 AM, Tiwei Bie wrote:
> This patch fixes the multi-process support for virtio-user.
> Currently virtio-user just provides some limited secondary
> process supports. Only some basic operations can be done in
> secondary process on virtio-user port, e.g. getting port stats.
> Actions which will trigger the communication with vhost backend
> can't be done in secondary process for now, as the fds are
> not synced between processes. The processing of server mode
> devargs is also moved into virtio_user_dev_init().
> 
> Fixes: cdb068f031c6 ("bus/vdev: scan by multi-process channel")
> Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
> ---
>   drivers/net/virtio/virtio_ethdev.c            | 15 +++++
>   drivers/net/virtio/virtio_ethdev.h            |  2 +
>   .../net/virtio/virtio_user/virtio_user_dev.c  |  3 +-
>   .../net/virtio/virtio_user/virtio_user_dev.h  |  3 +-
>   drivers/net/virtio/virtio_user_ethdev.c       | 61 +++++++++++--------
>   5 files changed, 56 insertions(+), 28 deletions(-)
> 
Applied to dpdk-next-virtio/master.

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 85b223451..310008757 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -907,6 +907,21 @@  static const struct eth_dev_ops virtio_eth_dev_ops = {
 	.mac_addr_set            = virtio_mac_addr_set,
 };
 
+/*
+ * dev_ops for virtio-user in secondary processes, as we just have
+ * some limited supports currently.
+ */
+const struct eth_dev_ops virtio_user_secondary_eth_dev_ops = {
+	.dev_infos_get           = virtio_dev_info_get,
+	.stats_get               = virtio_dev_stats_get,
+	.xstats_get              = virtio_dev_xstats_get,
+	.xstats_get_names        = virtio_dev_xstats_get_names,
+	.stats_reset             = virtio_dev_stats_reset,
+	.xstats_reset            = virtio_dev_stats_reset,
+	/* collect stats per queue */
+	.queue_stats_mapping_set = virtio_dev_queue_stats_mapping_set,
+};
+
 static void
 virtio_update_stats(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 {
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index b8aab7da4..45e96f32b 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -47,6 +47,8 @@ 
 	 1u << VIRTIO_NET_F_HOST_TSO4      |	\
 	 1u << VIRTIO_NET_F_HOST_TSO6)
 
+extern const struct eth_dev_ops virtio_user_secondary_eth_dev_ops;
+
 /*
  * CQ function prototype
  */
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 2dc8f2051..07aabb527 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -426,7 +426,7 @@  virtio_user_dev_setup(struct virtio_user_dev *dev)
 int
 virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 		     int cq, int queue_size, const char *mac, char **ifname,
-		     int mrg_rxbuf, int in_order, int packed_vq)
+		     int server, int mrg_rxbuf, int in_order, int packed_vq)
 {
 	pthread_mutex_init(&dev->mutex, NULL);
 	snprintf(dev->path, PATH_MAX, "%s", path);
@@ -434,6 +434,7 @@  virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 	dev->max_queue_pairs = queues;
 	dev->queue_pairs = 1; /* mq disabled by default */
 	dev->queue_size = queue_size;
+	dev->is_server = server;
 	dev->mac_specified = 0;
 	dev->frontend_features = 0;
 	dev->unsupported_features = ~VIRTIO_USER_SUPPORTED_FEATURES;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index c57b298a6..829ad4140 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -61,7 +61,8 @@  int virtio_user_start_device(struct virtio_user_dev *dev);
 int virtio_user_stop_device(struct virtio_user_dev *dev);
 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 			 int cq, int queue_size, const char *mac, char **ifname,
-			 int mrg_rxbuf, int in_order, int packed_vq);
+			 int server, int mrg_rxbuf, int in_order,
+			 int packed_vq);
 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
 void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index c5a76bd91..129c2b9ef 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -514,6 +514,26 @@  virtio_user_pmd_probe(struct rte_vdev_device *dev)
 	char *mac_addr = NULL;
 	int ret = -1;
 
+	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
+		const char *name = rte_vdev_device_name(dev);
+		eth_dev = rte_eth_dev_attach_secondary(name);
+		if (!eth_dev) {
+			RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+			return -1;
+		}
+
+		if (eth_virtio_dev_init(eth_dev) < 0) {
+			PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
+			rte_eth_dev_release_port(eth_dev);
+			return -1;
+		}
+
+		eth_dev->dev_ops = &virtio_user_secondary_eth_dev_ops;
+		eth_dev->device = &dev->device;
+		rte_eth_dev_probing_finish(eth_dev);
+		return 0;
+	}
+
 	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_args);
 	if (!kvlist) {
 		PMD_INIT_LOG(ERR, "error when parsing param");
@@ -635,33 +655,19 @@  virtio_user_pmd_probe(struct rte_vdev_device *dev)
 		}
 	}
 
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-		struct virtio_user_dev *vu_dev;
+	eth_dev = virtio_user_eth_dev_alloc(dev);
+	if (!eth_dev) {
+		PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
+		goto end;
+	}
 
-		eth_dev = virtio_user_eth_dev_alloc(dev);
-		if (!eth_dev) {
-			PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
-			goto end;
-		}
-
-		hw = eth_dev->data->dev_private;
-		vu_dev = virtio_user_get_dev(hw);
-		if (server_mode == 1)
-			vu_dev->is_server = true;
-		else
-			vu_dev->is_server = false;
-		if (virtio_user_dev_init(hw->virtio_user_dev, path, queues, cq,
-				 queue_size, mac_addr, &ifname, mrg_rxbuf,
-				 in_order, packed_vq) < 0) {
-			PMD_INIT_LOG(ERR, "virtio_user_dev_init fails");
-			virtio_user_eth_dev_free(eth_dev);
-			goto end;
-		}
-
-	} else {
-		eth_dev = rte_eth_dev_attach_secondary(rte_vdev_device_name(dev));
-		if (!eth_dev)
-			goto end;
+	hw = eth_dev->data->dev_private;
+	if (virtio_user_dev_init(hw->virtio_user_dev, path, queues, cq,
+			 queue_size, mac_addr, &ifname, server_mode,
+			 mrg_rxbuf, in_order, packed_vq) < 0) {
+		PMD_INIT_LOG(ERR, "virtio_user_dev_init fails");
+		virtio_user_eth_dev_free(eth_dev);
+		goto end;
 	}
 
 	/* previously called by rte_pci_probe() for physical dev */
@@ -703,6 +709,9 @@  virtio_user_pmd_remove(struct rte_vdev_device *vdev)
 	if (!eth_dev)
 		return -ENODEV;
 
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return rte_eth_dev_release_port(eth_dev);
+
 	/* make sure the device is stopped, queues freed */
 	rte_eth_dev_close(eth_dev->data->port_id);