From: Tiwei Bie <tiwei.bie@intel.com>
To: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org
Subject: [dpdk-dev] [PATCH 4/5] net/virtio: release port upon close
Date: Wed, 5 Jun 2019 17:43:41 +0800 [thread overview]
Message-ID: <20190605094342.17563-5-tiwei.bie@intel.com> (raw)
In-Reply-To: <20190605094342.17563-1-tiwei.bie@intel.com>
Set RTE_ETH_DEV_CLOSE_REMOVE upon probe so all the private
resources for the port can be freed by rte_eth_dev_close().
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
drivers/net/virtio/virtio_ethdev.c | 42 ++++++++++++-------
.../net/virtio/virtio_user/virtio_user_dev.h | 1 -
drivers/net/virtio/virtio_user_ethdev.c | 12 ++----
3 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 46d2e4ac6..afb2ca209 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -35,6 +35,7 @@
#include "virtio_logs.h"
#include "virtqueue.h"
#include "virtio_rxtx.h"
+#include "virtio_user/virtio_user_dev.h"
static int eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev);
static int virtio_dev_configure(struct rte_eth_dev *dev);
@@ -733,6 +734,17 @@ virtio_dev_close(struct rte_eth_dev *dev)
vtpci_reset(hw);
virtio_dev_free_mbufs(dev);
virtio_free_queues(hw);
+
+#ifdef RTE_VIRTIO_USER
+ if (hw->virtio_user_dev)
+ virtio_user_dev_uninit(hw->virtio_user_dev);
+ else
+#endif
+ if (dev->device) {
+ rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(dev));
+ if (!hw->modern)
+ rte_pci_ioport_unmap(VTPCI_IO(hw));
+ }
}
static void
@@ -1645,10 +1657,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
hw->weak_barriers = !vtpci_with_feature(hw, VIRTIO_F_ORDER_PLATFORM);
- if (!hw->virtio_user_dev) {
+ if (!hw->virtio_user_dev)
pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
- rte_eth_copy_pci_info(eth_dev, pci_dev);
- }
/* If host does not support both status and MSI-X then disable LSC */
if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) &&
@@ -1840,6 +1850,12 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
return 0;
}
+ /*
+ * Pass the information to the rte_eth_dev_close() that it should also
+ * release the private port resources.
+ */
+ eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
/* Allocate memory for storing MAC addresses */
eth_dev->data->mac_addrs = rte_zmalloc("virtio",
VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN, 0);
@@ -1865,6 +1881,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
if (ret < 0)
goto err_virtio_init;
+ hw->opened = true;
+
return 0;
err_virtio_init:
@@ -1882,8 +1900,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
static int
eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
{
- struct virtio_hw *hw = eth_dev->data->dev_private;
-
PMD_INIT_FUNC_TRACE();
if (rte_eal_process_type() == RTE_PROC_SECONDARY)
@@ -1896,12 +1912,6 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
eth_dev->tx_pkt_burst = NULL;
eth_dev->rx_pkt_burst = NULL;
- if (eth_dev->device) {
- rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
- if (!hw->modern)
- rte_pci_ioport_unmap(VTPCI_IO(hw));
- }
-
PMD_INIT_LOG(DEBUG, "dev_uninit completed");
return 0;
@@ -1963,7 +1973,13 @@ static int eth_virtio_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
static int eth_virtio_pci_remove(struct rte_pci_device *pci_dev)
{
- return rte_eth_dev_pci_generic_remove(pci_dev, eth_virtio_dev_uninit);
+ int ret;
+
+ ret = rte_eth_dev_pci_generic_remove(pci_dev, eth_virtio_dev_uninit);
+ /* Port has already been released by close. */
+ if (ret == -ENODEV)
+ ret = 0;
+ return ret;
}
static struct rte_pci_driver rte_virtio_pmd = {
@@ -2123,8 +2139,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
DEV_RX_OFFLOAD_VLAN_STRIP))
hw->use_simple_rx = 0;
- hw->opened = true;
-
return 0;
}
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index db7dc607a..ad8683771 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -9,7 +9,6 @@
#include <stdbool.h>
#include "../virtio_pci.h"
#include "../virtio_ring.h"
-#include "vhost.h"
struct virtio_user_queue {
uint16_t used_idx;
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 893f48a5d..0a57db730 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -20,6 +20,7 @@
#include "virtqueue.h"
#include "virtio_rxtx.h"
#include "virtio_user/virtio_user_dev.h"
+#include "virtio_user/vhost.h"
#define virtio_user_get_dev(hw) \
((struct virtio_user_dev *)(hw)->virtio_user_dev)
@@ -697,8 +698,6 @@ virtio_user_pmd_remove(struct rte_vdev_device *vdev)
{
const char *name;
struct rte_eth_dev *eth_dev;
- struct virtio_hw *hw;
- struct virtio_user_dev *dev;
if (!vdev)
return -EINVAL;
@@ -706,8 +705,9 @@ virtio_user_pmd_remove(struct rte_vdev_device *vdev)
name = rte_vdev_device_name(vdev);
PMD_DRV_LOG(INFO, "Un-Initializing %s", name);
eth_dev = rte_eth_dev_allocated(name);
+ /* Port has already been released by close. */
if (!eth_dev)
- return -ENODEV;
+ return 0;
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
return rte_eth_dev_release_port(eth_dev);
@@ -715,12 +715,6 @@ virtio_user_pmd_remove(struct rte_vdev_device *vdev)
/* make sure the device is stopped, queues freed */
rte_eth_dev_close(eth_dev->data->port_id);
- hw = eth_dev->data->dev_private;
- dev = hw->virtio_user_dev;
- virtio_user_dev_uninit(dev);
-
- rte_eth_dev_release_port(eth_dev);
-
return 0;
}
--
2.17.1
next prev parent reply other threads:[~2019-06-05 9:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-05 9:43 [dpdk-dev] [PATCH 0/5] virtio: release port upon close Tiwei Bie
2019-06-05 9:43 ` [dpdk-dev] [PATCH 1/5] net/virtio: fix queue memory leak on error Tiwei Bie
2019-06-05 12:35 ` Maxime Coquelin
2019-06-05 9:43 ` [dpdk-dev] [PATCH 2/5] net/virtio: unmap port IO for legacy device Tiwei Bie
2019-06-05 14:31 ` Maxime Coquelin
2019-06-05 9:43 ` [dpdk-dev] [PATCH 3/5] net/virtio: unmap device on initialization error Tiwei Bie
2019-06-05 14:33 ` Maxime Coquelin
2019-06-05 9:43 ` Tiwei Bie [this message]
2019-06-17 14:42 ` [dpdk-dev] [PATCH 4/5] net/virtio: release port upon close Maxime Coquelin
2019-06-05 9:43 ` [dpdk-dev] [PATCH 5/5] app/testpmd: drop the workaround for virtio-user Tiwei Bie
2019-06-17 14:44 ` Maxime Coquelin
2019-06-20 9:59 ` [dpdk-dev] [PATCH 0/5] virtio: release port upon close Maxime Coquelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190605094342.17563-5-tiwei.bie@intel.com \
--to=tiwei.bie@intel.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
--cc=zhihong.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.