Skip to contentSkip to conversation

virtio PCI Port Hotplug

PATCH Superseded Bernard Iremonger 3 participants 13 messages Jul 14, 2015 – Jul 15, 2015 Network drivers

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#2 lore raw

PATCH 2/5 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 file 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.9.1
#4 lore raw

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

In reply to Bernard Iremonger

Add function virtio_free_queues() and call from virtio_dev_close() Use virtio_dev_rx_queue_release() and virtio_dev_tx_queue_release()

---
 drivers/net/virtio/virtio_ethdev.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/net/virtio/virtio_ethdev.c +19 -0
index b32b3e9..4676ab1 100644
@@ -438,6 +438,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++) {
+		virtio_dev_rx_queue_release(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++) {
+		virtio_dev_tx_queue_release(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;
@@ -451,6 +469,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.9.1
#0 lore raw

v5 cover virtio PCI Port Hotplug

Changes in V5:
Rebase.
Add proper queue release patch (patch 3). Reorder patches, moved previous patch 3 to patch 4, moved previous patch 4 to patch 5.

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: add proper queue release
virtio: free queue memory in virtio_dev_close()

 drivers/net/virtio/virtio_ethdev.c | 122 +++++++++++++++++++++++++++++--------
 drivers/net/virtio/virtio_ethdev.h |   8 ++-
 drivers/net/virtio/virtio_rxtx.c   |  12 ++++
 drivers/net/virtio/virtqueue.c     |  14 +++--
 4 files changed, 124 insertions(+), 32 deletions(-)
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/5 virtio: add proper queue release

Add functions virtio_dev_queue_release(), virtio_dev_rx_queue_release() and virtio_dev_tx_queue_release().

---
 drivers/net/virtio/virtio_ethdev.c | 31 +++++++++++++------------------
 drivers/net/virtio/virtio_ethdev.h |  8 +++++++-
 drivers/net/virtio/virtio_rxtx.c   | 12 ++++++++++++
 3 files changed, 32 insertions(+), 19 deletions(-)
drivers/net/virtio/virtio_ethdev.c +13 -18
index b88f297..b32b3e9 100644
@@ -80,9 +80,6 @@ static int virtio_dev_link_update(struct rte_eth_dev *dev,
 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);
@@ -240,6 +237,19 @@ virtio_set_multiple_queues(struct rte_eth_dev *dev, uint16_t nb_queues)
 	return 0;
 }
 
+void
+virtio_dev_queue_release(struct virtqueue *vq) {
+	struct virtio_hw *hw = vq->hw;
+
+	if (vq) {
+		/* 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);
+	}
+}
+
 int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 			int queue_type,
 			uint16_t queue_idx,
@@ -553,10 +563,8 @@ static const struct eth_dev_ops virtio_eth_dev_ops = {
 	.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,
@@ -1335,19 +1343,6 @@ rte_virtio_pmd_init(const char *name __rte_unused,
 }
 
 /*
- * 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.
  */
drivers/net/virtio/virtio_ethdev.h +7 -1
index df2cb7d..3858b00 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
@@ -84,15 +84,21 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 			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);
 
drivers/net/virtio/virtio_rxtx.c +12 -0
index 091c7fb..5388caa 100644
@@ -401,6 +401,12 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 	return 0;
 }
 
+void
+virtio_dev_rx_queue_release(void *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 +461,12 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,
 	return 0;
 }
 
+void
+virtio_dev_tx_queue_release(void *txq)
+{
+	virtio_dev_queue_release(txq);
+}
+
 static void
 virtio_discard_rxbuf(struct virtqueue *vq, struct rte_mbuf *m)
 {
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/5 virtio: add support for PCI Port Hotplug

In reply to Bernard Iremonger

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 file 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.9.1
#12 lore raw

PATCH v5 5/5 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 file changed, 1 insertion(+), 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.9.1
#5 lore raw

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

In reply to Bernard Iremonger
Quoted 8 lines · On Tue, 14 Jul 2015 14:10:58 +0100 Bernard Iremonger…

static void

drivers/net/virtio/virtio_ethdev.c +7 -0
+virtio_free_queues(struct rte_eth_dev *dev)
+{
+	unsigned int i;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		virtio_dev_rx_queue_release(dev->data->rx_queues[i]);
+		dev->data->rx_queues[i] = NULL;

drivers/net/virtio/virtio_ethdev.c virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx, · line 457

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +10 -0
+	}
+	dev->data->nb_rx_queues = 0;
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		virtio_dev_tx_queue_release(dev->data->tx_queues[i]);
+		dev->data->tx_queues[i] = NULL;
+	}
+	dev->data->nb_tx_queues = 0;
+}
+

Where does command queue get freed?

#9 lore raw

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

In reply to Bernard Iremonger
Quoted 40 lines

-----Original Message-----
From: Iremonger, Bernard
Sent: Tuesday, July 14, 2015 9:11 PM
To: [email protected]
Cc: Ouyang, Changchun; [email protected]; Iremonger, Bernard
Subject: [PATCH 4/5] virtio: free queue memory in virtio_dev_close()

Add function virtio_free_queues() and call from virtio_dev_close() Use virtio_dev_rx_queue_release() and virtio_dev_tx_queue_release()

---
 drivers/net/virtio/virtio_ethdev.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/net/virtio/virtio_ethdev.c +14 -0
index b32b3e9..4676ab1 100644
@@ -438,6 +438,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++) {
+		virtio_dev_rx_queue_release(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++) {
+		virtio_dev_tx_queue_release(dev->data->tx_queues[i]);
+		dev->data->tx_queues[i] = NULL;
+	}
+	dev->data->nb_tx_queues = 0;

drivers/net/virtio/virtio_ethdev.c virtio_dev_cq_queue_setup(struct rte_eth_dev

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +4 -0
+}
+
+static void
 virtio_dev_close(struct rte_eth_dev *dev)  {
 	struct virtio_hw *hw = dev->data->dev_private; @@ -451,6 +469,7
 @@ virtio_dev_close(struct rte_eth_dev *dev)
 	vtpci_reset(hw);
 	hw->started = 0;
 	virtio_dev_free_mbufs(dev);
+	virtio_free_queues(dev);

Validate it with vhost sample or not for this change?

Quoted 5 lines

}

static void
--
1.9.1

#10 lore raw

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

Hi Ouyang,

<snip>

Quoted 26 lines
Quoted 15 lines
drivers/net/virtio/virtio_ethdev.c +9 -0
@@ -438,6 +438,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++) {
+		virtio_dev_rx_queue_release(dev->data->rx_queues[i]);
+		dev->data->rx_queues[i] = NULL;
+	}
+	dev->data->nb_rx_queues = 0;
+

drivers/net/virtio/virtio_ethdev.c virtio_dev_cq_queue_setup(struct rte_eth_dev · line 459

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +8 -0
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		virtio_dev_tx_queue_release(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; @@ -451,6 +469,7

@@

Quoted 7 lines

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

Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +1 -0
 virtio_dev_close(struct rte_eth_dev *dev)
 	vtpci_reset(hw);
 	hw->started = 0;
 	virtio_dev_free_mbufs(dev);
+	virtio_free_queues(dev);

Validate it with vhost sample or not for this change?

I have tested this change with testpmd on a Fedora VM.

Regards,

Bernard.

Quoted 6 lines
Quoted 6 lines

}

static void
--
1.9.1

#6 lore raw

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

In reply to Stephen Hemminger
Quoted 21 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, July 14, 2015 7:28 PM
To: Iremonger, Bernard
Cc: [email protected]; Ouyang, Changchun
Subject: Re: [PATCH 4/5] virtio: free queue memory in virtio_dev_close()

Quoted 11 lines · On Tue, 14 Jul 2015 14:10:58 +0100 Bernard Iremonger…

static void

drivers/net/virtio/virtio_ethdev.c +10 -0
+virtio_free_queues(struct rte_eth_dev *dev) {
+	unsigned int i;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		virtio_dev_rx_queue_release(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++) {
Quoted 8 lines

drivers/net/virtio/virtio_ethdev.c virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx, · line 457

Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +6 -0
+		virtio_dev_tx_queue_release(dev->data->tx_queues[i]);
+		dev->data->tx_queues[i] = NULL;
+	}
+	dev->data->nb_tx_queues = 0;
+}
+

Where does command queue get freed?

The command queue is set up in the eth_virtio_dev_init() function and freed in the eth_virtio_dev_uninit() function.

Regards,

Bernard.

#11 lore raw

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

In reply to Iremonger, Bernard

Hi, Bernard

Quoted 45 lines

-----Original Message-----
From: Iremonger, Bernard
Sent: Wednesday, July 15, 2015 4:02 PM
To: Ouyang, Changchun; [email protected]
Cc: Xu, Qian Q; [email protected]
Subject: RE: [PATCH 4/5] virtio: free queue memory in virtio_dev_close()

Hi Ouyang,

<snip>

Quoted 26 lines
Quoted 15 lines
drivers/net/virtio/virtio_ethdev.c +9 -0
@@ -438,6 +438,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++) {
+		virtio_dev_rx_queue_release(dev->data->rx_queues[i]);
+		dev->data->rx_queues[i] = NULL;
+	}
+	dev->data->nb_rx_queues = 0;
+

drivers/net/virtio/virtio_ethdev.c virtio_dev_cq_queue_setup(struct rte_eth_dev · line 459

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +8 -0
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		virtio_dev_tx_queue_release(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; @@ -451,6 +469,7

@@

Quoted 7 lines

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

Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +1 -0
 virtio_dev_close(struct rte_eth_dev *dev)
 	vtpci_reset(hw);
 	hw->started = 0;
 	virtio_dev_free_mbufs(dev);
+	virtio_free_queues(dev);

Validate it with vhost sample or not for this change?

Quoted 1 line

I have tested this change with testpmd on a Fedora VM.

I think we should make sure it will not break any current test case for virtio, So before applying it, it needs use vhost sample on host and test the virtio driver on guest.

Thanks
Changchun

#7 lore raw

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

In reply to Iremonger, Bernard
Quoted 39 lines

-----Original Message-----
From: Iremonger, Bernard
Sent: Wednesday, July 15, 2015 4:27 PM
To: Stephen Hemminger
Cc: [email protected]; Ouyang, Changchun
Subject: RE: [PATCH 4/5] virtio: free queue memory in virtio_dev_close()

Quoted 21 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, July 14, 2015 7:28 PM
To: Iremonger, Bernard
Cc: [email protected]; Ouyang, Changchun
Subject: Re: [PATCH 4/5] virtio: free queue memory in virtio_dev_close()

Quoted 11 lines · On Tue, 14 Jul 2015 14:10:58 +0100 Bernard Iremonger…

static void

drivers/net/virtio/virtio_ethdev.c +10 -0
+virtio_free_queues(struct rte_eth_dev *dev) {
+	unsigned int i;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		virtio_dev_rx_queue_release(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++) {
Quoted 8 lines

drivers/net/virtio/virtio_ethdev.c virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx, · line 457

Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +6 -0
+		virtio_dev_tx_queue_release(dev->data->tx_queues[i]);
+		dev->data->tx_queues[i] = NULL;
+	}
+	dev->data->nb_tx_queues = 0;
+}
+

Where does command queue get freed?

Quoted 3 lines

The command queue is set up in the eth_virtio_dev_init() function and freed in the eth_virtio_dev_uninit() function.

Do you mean control vq?

Quoted 3 lines

Regards,

Bernard.

#8 lore raw

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

Quoted 50 lines

-----Original Message-----
From: Ouyang, Changchun
Sent: Wednesday, July 15, 2015 9:39 AM
To: Iremonger, Bernard; Stephen Hemminger
Cc: [email protected]; Ouyang, Changchun
Subject: RE: [PATCH 4/5] virtio: free queue memory in virtio_dev_close()

Quoted 39 lines

-----Original Message-----
From: Iremonger, Bernard
Sent: Wednesday, July 15, 2015 4:27 PM
To: Stephen Hemminger
Cc: [email protected]; Ouyang, Changchun
Subject: RE: [PATCH 4/5] virtio: free queue memory in virtio_dev_close()

Quoted 30 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, July 14, 2015 7:28 PM
To: Iremonger, Bernard
Cc: [email protected]; Ouyang, Changchun
Subject: Re: [PATCH 4/5] virtio: free queue memory in virtio_dev_close()

Quoted 7 lines · On Tue, 14 Jul 2015 14:10:58 +0100 Bernard Iremonger…

static void

drivers/net/virtio/virtio_ethdev.c +6 -0
+virtio_free_queues(struct rte_eth_dev *dev) {
+	unsigned int i;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		virtio_dev_rx_queue_release(dev->data->rx_queues[i]);
+		dev->data->rx_queues[i] = NULL;

drivers/net/virtio/virtio_ethdev.c virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx, · line 457

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +10 -0
+	}
+	dev->data->nb_rx_queues = 0;
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		virtio_dev_tx_queue_release(dev->data->tx_queues[i]);
+		dev->data->tx_queues[i] = NULL;
+	}
+	dev->data->nb_tx_queues = 0;
+}
+

Where does command queue get freed?

Quoted 5 lines
Quoted 3 lines

The command queue is set up in the eth_virtio_dev_init() function and freed in the eth_virtio_dev_uninit() function.

Do you mean control vq?

I am referring to hw->cvq.

Regards,

Bernard.