[dpdk-dev] [PATCH V2] ethdev: fix eth device released repeatedly
Huisong Li
lihuisong at huawei.com
Tue Oct 12 13:39:34 CEST 2021
The rte_eth_dev_pci_generic_remove() will be called to detach an Ethernet
device when App calls rte_dev_remove() to detach a pci device. In addition,
the rte_eth_dev_close() can also detach an Ethernet device.
In secondary process, if App first calls rte_eth_dev_close() and then calls
rte_dev_remove(), because rte_eth_dev_close() doesn't clear "eth_dev->data"
, the address of the released Ethernet device can still be found by device
name. As a result, the Ethernet device will be released repeatedly in this
case. The state of the Ethernet device is equal to RTE_ETH_DEV_UNUSED after
calling rte_eth_dev_close(). Use this state to avoid this problem.
Signed-off-by: Huisong Li <lihuisong at huawei.com>
---
v1 -> v2:
* fix the commit log description.
RFC -> v1:
* fix commit log and add a judgment for secondary process.
---
lib/ethdev/ethdev_pci.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h
index 8edca82ce8..af01cceddf 100644
--- a/lib/ethdev/ethdev_pci.h
+++ b/lib/ethdev/ethdev_pci.h
@@ -151,6 +151,21 @@ rte_eth_dev_pci_generic_remove(struct rte_pci_device *pci_dev,
if (!eth_dev)
return 0;
+ /*
+ * In secondary process, if applications first call rte_eth_dev_close()
+ * and then call this interface, because rte_eth_dev_close() doesn't
+ * clear eth_dev->data, the address of the released Ethernet device can
+ * still be found by device name. As a result, the Ethernet device will
+ * be released repeatedly in this case.
+ * The state of the Ethernet device is equal to RTE_ETH_DEV_UNUSED after
+ * calling rte_eth_dev_close(). Use this state to avoid this problem.
+ */
+ if (rte_eal_process_type() != RTE_PROC_PRIMARY &&
+ eth_dev->state == RTE_ETH_DEV_UNUSED) {
+ RTE_ETHDEV_LOG(INFO, "The ethdev port has been released.");
+ return 0;
+ }
+
if (dev_uninit) {
ret = dev_uninit(eth_dev);
if (ret)
--
2.33.0
More information about the dev
mailing list