Skip to contentSkip to conversation

virtio: PCI Port Hotplug

PATCH Superseded Bernard Iremonger 4 participants 8 messages Jul 7, 2015 – Jul 9, 2015 Network drivers

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover virtio: PCI Port Hotplug

This patchset contains changes to add support for PCI Port Hotplug It also contains a fix to virtqueue_detatch_unused(). It also contains a fix to testpmd to facilate testing on VM's.

Changes in V4:
Rebase to latest code.
Move freeing of queue memory from uninit() function to close() function. Change to testpmd to facilate testing on VM.

Changes in V3:
Rebase to latest code.
Free queue memory in uninit() function.

Changes in V2:
Rebase to use new drivers directory.
Reuse memzones.

Bernard Iremonger (4):
virtio: add support for PCI Port Hotplug
virtio: check vq parameter in virtqueue_detatch_unused() function
virtio: free queue memory in virtio_dev_close()
test-pmd: remove call to rte_eth_promiscuous_disable() from
detach_port()

 app/test-pmd/testpmd.c             |    4 +-
 drivers/net/virtio/virtio_ethdev.c |   91 +++++++++++++++++++++++++++++++++---
 drivers/net/virtio/virtqueue.c     |   14 +++--
 3 files changed, 93 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v4 1/4 virtio: add support for PCI Port Hotplug

This patch depends on the Port Hotplug Framework. It implements the eth_dev_uninit_t() function for virtio pmd.

---
 drivers/net/virtio/virtio_ethdev.c |   72 ++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 7 deletions(-)
drivers/net/virtio/virtio_ethdev.c +65 -7
index fe5f9a1..b88f297 100644
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -51,6 +51,7 @@
 #include <rte_pci.h>
 #include <rte_ether.h>
 #include <rte_common.h>
+#include <rte_errno.h>
 
 #include <rte_memory.h>
 #include <rte_eal.h>
@@ -63,6 +64,7 @@
 
 
 static int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
+static int eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev);
 static int  virtio_dev_configure(struct rte_eth_dev *dev);
 static int  virtio_dev_start(struct rte_eth_dev *dev);
 static void virtio_dev_stop(struct rte_eth_dev *dev);
@@ -324,8 +326,12 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 	mz = rte_memzone_reserve_aligned(vq_name, vq->vq_ring_size,
 		socket_id, 0, VIRTIO_PCI_VRING_ALIGN);
 	if (mz == NULL) {
-		rte_free(vq);
-		return -ENOMEM;
+		if (rte_errno == EEXIST)
+			mz = rte_memzone_lookup(vq_name);
+		if (mz == NULL) {
+			rte_free(vq);
+			return -ENOMEM;
+		}
 	}
 
 	/*
@@ -358,8 +364,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 			vq_size * hw->vtnet_hdr_size,
 			socket_id, 0, RTE_CACHE_LINE_SIZE);
 		if (vq->virtio_net_hdr_mz == NULL) {
-			rte_free(vq);
-			return -ENOMEM;
+			if (rte_errno == EEXIST)
+				vq->virtio_net_hdr_mz =
+					rte_memzone_lookup(vq_name);
+			if (vq->virtio_net_hdr_mz == NULL) {
+				rte_free(vq);
+				return -ENOMEM;
+			}
 		}
 		vq->virtio_net_hdr_mem =
 			vq->virtio_net_hdr_mz->phys_addr;
@@ -372,8 +383,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 		vq->virtio_net_hdr_mz = rte_memzone_reserve_aligned(vq_name,
 			PAGE_SIZE, socket_id, 0, RTE_CACHE_LINE_SIZE);
 		if (vq->virtio_net_hdr_mz == NULL) {
-			rte_free(vq);
-			return -ENOMEM;
+			if (rte_errno == EEXIST)
+				vq->virtio_net_hdr_mz =
+					rte_memzone_lookup(vq_name);
+			if (vq->virtio_net_hdr_mz == NULL) {
+				rte_free(vq);
+				return -ENOMEM;
+			}
 		}
 		vq->virtio_net_hdr_mem =
 			vq->virtio_net_hdr_mz->phys_addr;
@@ -1250,12 +1266,52 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	return 0;
 }
 
+static int
+eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
+{
+	struct rte_pci_device *pci_dev;
+	struct virtio_hw *hw = eth_dev->data->dev_private;
+
+	PMD_INIT_FUNC_TRACE();
+
+	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
+		return -EPERM;
+
+	if (hw->started == 1) {
+		virtio_dev_stop(eth_dev);
+		virtio_dev_close(eth_dev);
+	}
+	pci_dev = eth_dev->pci_dev;
+
+	eth_dev->dev_ops = NULL;
+	eth_dev->tx_pkt_burst = NULL;
+	eth_dev->rx_pkt_burst = NULL;
+
+	rte_free(hw->cvq);
+	hw->cvq = NULL;
+
+	rte_free(eth_dev->data->mac_addrs);
+	eth_dev->data->mac_addrs = NULL;
+
+	/* reset interrupt callback  */
+	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
+		rte_intr_callback_unregister(&pci_dev->intr_handle,
+						virtio_interrupt_handler,
+						eth_dev);
+
+	PMD_INIT_LOG(DEBUG, "dev_uninit completed");
+
+	return 0;
+}
+
 static struct eth_driver rte_virtio_pmd = {
 	.pci_drv = {
 		.name = "rte_virtio_pmd",
 		.id_table = pci_id_virtio_map,
+		.drv_flags = RTE_PCI_DRV_DETACHABLE,
 	},
 	.eth_dev_init = eth_virtio_dev_init,
+	.eth_dev_uninit = eth_virtio_dev_uninit,
 	.dev_private_size = sizeof(struct virtio_hw),
 };
 
@@ -1398,6 +1454,8 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
 			     "Before freeing rxq[%d] used and unused buf", i);
 		VIRTQUEUE_DUMP((struct virtqueue *)dev->data->rx_queues[i]);
 
+		PMD_INIT_LOG(DEBUG, "rx_queues[%d]=%p",
+				i, dev->data->rx_queues[i]);
 		while ((buf = (struct rte_mbuf *)virtqueue_detatch_unused(
 					dev->data->rx_queues[i])) != NULL) {
 			rte_pktmbuf_free(buf);
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH v4 2/4 virtio: check vq parameter in virtqueue_detatch_unused() function

In reply to Bernard Iremonger

If vq is NULL, there is a segmentation fault.

---
 drivers/net/virtio/virtqueue.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
drivers/net/virtio/virtqueue.c +8 -6
index 8a3005f..7f60e3e 100644
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -60,11 +60,13 @@ virtqueue_detatch_unused(struct virtqueue *vq)
 	struct rte_mbuf *cookie;
 	int idx;
 
-	for (idx = 0; idx < vq->vq_nentries; idx++) {
-		if ((cookie = vq->vq_descx[idx].cookie) != NULL) {
-			vq->vq_descx[idx].cookie = NULL;
-			return cookie;
+	if (vq != NULL)
+		for (idx = 0; idx < vq->vq_nentries; idx++) {
+			cookie = vq->vq_descx[idx].cookie;
+			if (cookie != NULL) {
+				vq->vq_descx[idx].cookie = NULL;
+				return cookie;
+			}
 		}
-	}
 	return NULL;
 }
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH v4 3/4 virtio: free queue memory in virtio_dev_close()

In reply to Bernard Iremonger

Add function virtio_free_queues() and call from virtio_dev_close()

---
 drivers/net/virtio/virtio_ethdev.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
drivers/net/virtio/virtio_ethdev.c +19 -0
index b88f297..ed99f33 100644
@@ -428,6 +428,24 @@ virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx,
 }
 
 static void
+virtio_free_queues(struct rte_eth_dev *dev)
+{
+	unsigned int i;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rte_free(dev->data->rx_queues[i]);
+		dev->data->rx_queues[i] = NULL;
+	}
+	dev->data->nb_rx_queues = 0;
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		rte_free(dev->data->tx_queues[i]);
+		dev->data->tx_queues[i] = NULL;
+	}
+	dev->data->nb_tx_queues = 0;
+}
+
+static void
 virtio_dev_close(struct rte_eth_dev *dev)
 {
 	struct virtio_hw *hw = dev->data->dev_private;
@@ -441,6 +459,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
 	vtpci_reset(hw);
 	hw->started = 0;
 	virtio_dev_free_mbufs(dev);
+	virtio_free_queues(dev);
 }
 
 static void
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH v4 4/4 test-pmd: remove call to rte_eth_promiscuous_disable() from detach_port()

In reply to Bernard Iremonger

At this point the stop() and close() functions have already been called. The rte_eth_promiscuous_disable() function does not return on the VM.

---
 app/test-pmd/testpmd.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
app/test-pmd/testpmd.c +1 -3
index 82b465d..4769533 100644
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -1542,8 +1542,6 @@ detach_port(uint8_t port_id)
 		return;
 	}
 
-	rte_eth_promiscuous_disable(port_id);
-
 	if (rte_eth_dev_detach(port_id, name))
 		return;
 
Signature · 1 line
1.7.4.1
#4 lore raw

Re: [PATCH v4 3/4] virtio: free queue memory in virtio_dev_close()

In reply to Bernard Iremonger
Quoted 37 lines · On Tue, 7 Jul 2015 10:18:06 +0100 Bernard Iremonger…

Add function virtio_free_queues() and call from virtio_dev_close()

---
 drivers/net/virtio/virtio_ethdev.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
drivers/net/virtio/virtio_ethdev.c +18 -0
index b88f297..ed99f33 100644
@@ -428,6 +428,24 @@ virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx,
 }
 
 static void
+virtio_free_queues(struct rte_eth_dev *dev)
+{
+	unsigned int i;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rte_free(dev->data->rx_queues[i]);
+		dev->data->rx_queues[i] = NULL;
+	}
+	dev->data->nb_rx_queues = 0;
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		rte_free(dev->data->tx_queues[i]);
+		dev->data->tx_queues[i] = NULL;
+	}
+	dev->data->nb_tx_queues = 0;
+}
+
+static void
 virtio_dev_close(struct rte_eth_dev *dev)
 {
 	struct virtio_hw *hw = dev->data->dev_private;

drivers/net/virtio/virtio_ethdev.c virtio_dev_close(struct rte_eth_dev *dev) · line 465

Quoted 7 lines
drivers/net/virtio/virtio_ethdev.c +1 -0
@@ -441,6 +459,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
 	vtpci_reset(hw);
 	hw->started = 0;
 	virtio_dev_free_mbufs(dev);
+	virtio_free_queues(dev);
 }
 
 static void

I think virtio should implement regular queue free:

Subject: virtio: add proper queue release

When rx or tx queue is released, the virtio driver leaks memory because it never frees the associated queue structure.

lib/librte_pmd_virtio/virtio_ethdev.c +13 -18
@@ -78,9 +78,6 @@ static int virtio_dev_link_update(struct
 static void virtio_set_hwaddr(struct virtio_hw *hw);
 static void virtio_get_hwaddr(struct virtio_hw *hw);
 
-static void virtio_dev_rx_queue_release(__rte_unused void *rxq);
-static void virtio_dev_tx_queue_release(__rte_unused void *txq);
-
 static void virtio_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
 static void virtio_dev_stats_reset(struct rte_eth_dev *dev);
 static void virtio_dev_free_mbufs(struct rte_eth_dev *dev);
@@ -389,6 +386,19 @@ int virtio_dev_queue_setup(struct rte_et
 	return 0;
 }
 
+
+void
+virtio_dev_queue_release(struct virtqueue *vq)
+{
+	struct virtio_hw *hw = vq->hw;
+
+	/* Select and deactivate the queue */
+	VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, vq->queue_id);
+	VIRTIO_WRITE_REG_4(hw, VIRTIO_PCI_QUEUE_PFN, 0);
+
+	rte_free(vq);
+}
+
 static int
 virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx,
 		uint32_t socket_id)
@@ -536,10 +546,8 @@ static struct eth_dev_ops virtio_eth_dev
 	.stats_reset             = virtio_dev_stats_reset,
 	.link_update             = virtio_dev_link_update,
 	.rx_queue_setup          = virtio_dev_rx_queue_setup,
-	/* meaningfull only to multiple queue */
 	.rx_queue_release        = virtio_dev_rx_queue_release,
 	.tx_queue_setup          = virtio_dev_tx_queue_setup,
-	/* meaningfull only to multiple queue */
 	.tx_queue_release        = virtio_dev_tx_queue_release,
 	/* collect stats per queue */
 	.queue_stats_mapping_set = virtio_dev_queue_stats_mapping_set,
@@ -1278,19 +1286,6 @@ rte_virtio_pmd_init(const char *name __r
 }
 
 /*
- * Only 1 queue is supported, no queue release related operation
- */
-static void
-virtio_dev_rx_queue_release(__rte_unused void *rxq)
-{
-}
-
-static void
-virtio_dev_tx_queue_release(__rte_unused void *txq)
-{
-}
-
-/*
  * Configure virtio device
  * It returns 0 on success.
  */
lib/librte_pmd_virtio/virtio_ethdev.h +6 -0
@@ -84,15 +84,21 @@ int virtio_dev_queue_setup(struct rte_et
 			unsigned int socket_id,
 			struct virtqueue **pvq);
 
+void virtio_dev_queue_release(struct virtqueue *vq);
+
 int  virtio_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
 		uint16_t nb_rx_desc, unsigned int socket_id,
 		const struct rte_eth_rxconf *rx_conf,
 		struct rte_mempool *mb_pool);
 
+void virtio_dev_rx_queue_release(void *rxq);
+
 int  virtio_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
 		uint16_t nb_tx_desc, unsigned int socket_id,
 		const struct rte_eth_txconf *tx_conf);
 
+void virtio_dev_tx_queue_release(void *txq);
+
 uint16_t virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 		uint16_t nb_pkts);
 
lib/librte_pmd_virtio/virtio_rxtx.c +14 -0
@@ -401,6 +401,13 @@ virtio_dev_rx_queue_setup(struct rte_eth
 	return 0;
 }
 
+void
+virtio_dev_rx_queue_release(void *rxq)
+{
+	if (rxq)
+		virtio_dev_queue_release(rxq);
+}
+
 /*
  * struct rte_eth_dev *dev: Used to update dev
  * uint16_t nb_desc: Defaults to values read from config space
@@ -455,6 +462,13 @@ virtio_dev_tx_queue_setup(struct rte_eth
 	return 0;
 }
 
+void
+virtio_dev_tx_queue_release(void *txq)
+{
+	if (txq)
+		virtio_dev_queue_release(txq);
+}
+
 static void
 virtio_discard_rxbuf(struct virtqueue *vq, struct rte_mbuf *m)
 {
#6 lore raw

Re: [PATCH v4 4/4] test-pmd: remove call to rte_eth_promiscuous_disable() from detach_port()

In reply to Bernard Iremonger
Quoted 10 lines

-----Original Message-----
From: Iremonger, Bernard
Sent: Tuesday, July 7, 2015 5:18 PM
To: [email protected]
Cc: Ouyang, Changchun; Iremonger, Bernard
Subject: [PATCH v4 4/4] test-pmd: remove call to
rte_eth_promiscuous_disable() from detach_port()

Quoted 2 lines

At this point the stop() and close() functions have already been called. The rte_eth_promiscuous_disable() function does not return on the VM.

I think we need root the cause why it doesn't return on the VM.

Quoted 20 lines
---
 app/test-pmd/testpmd.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0 -0

82b465d..4769533 100644

app/test-pmd/testpmd.c +1 -1
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without

app/test-pmd/testpmd.c detach_port(uint8_t port_id) · line 1546

Quoted 5 lines
app/test-pmd/testpmd.c +0 -2
@@ -1542,8 +1542,6 @@ detach_port(uint8_t port_id)
 		return;
 	}
 
-	rte_eth_promiscuous_disable(port_id);
-

It seems a workaround.

Quoted 5 lines
app/test-pmd/testpmd.c +0 -1
 	if (rte_eth_dev_detach(port_id, name))
 		return;
 
--

1.7.4.1

#7 lore raw

Re: [PATCH v4 4/4] test-pmd: remove call to rte_eth_promiscuous_disable() from detach_port()

Quoted 11 lines · Changchun
Quoted 10 lines

-----Original Message-----
From: Iremonger, Bernard
Sent: Tuesday, July 7, 2015 5:18 PM
To: [email protected]
Cc: Ouyang, Changchun; Iremonger, Bernard
Subject: [PATCH v4 4/4] test-pmd: remove call to
rte_eth_promiscuous_disable() from detach_port()

At this point the stop() and close() functions have already been called. The rte_eth_promiscuous_disable() function does not return on the VM.

I think we need root the cause why it doesn't return on the VM.

It seems this patch is correct.
The root cause is that when close() is called, virtio-net device will be reset by vtpci_reset(), and at this point all virtqueues will be invalid in virtio-net device.
After resetting device, we should not call rte_eth_promiscuous_disable(), because it will use an one of virtqueues. Anyway, promiscuous configuration will be initialized when the device is reset.

Regards,
Tetsuya

Quoted 32 lines
Quoted 20 lines
---
 app/test-pmd/testpmd.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0 -0

82b465d..4769533 100644

app/test-pmd/testpmd.c +1 -1
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without

app/test-pmd/testpmd.c detach_port(uint8_t port_id) · line 1546

Quoted 5 lines
app/test-pmd/testpmd.c +0 -2
@@ -1542,8 +1542,6 @@ detach_port(uint8_t port_id)
 		return;
 	}
 
-	rte_eth_promiscuous_disable(port_id);
-

It seems a workaround.

Quoted 5 lines
app/test-pmd/testpmd.c +0 -1
 	if (rte_eth_dev_detach(port_id, name))
 		return;
 
--

1.7.4.1