[dpdk-dev] [RFC V1] ethdev: fix the issue that dev uninit may be called twice

Huisong Li lihuisong at huawei.com
Mon Aug 2 14:46:37 CEST 2021


Ethernet devices in DPDK can be released by rte_eth_dev_close() and
rte_dev_remove(). However, these two APIs do not have explicit invocation
restrictions. In other words, at the ethdev layer, calling
rte_eth_dev_close() and then rte_dev_remove() or rte_eal_hotplug_remove()
is allowed. In such a bad scenario, the primary process may be fine, but it
may cause that dev_unint() in the secondary process will be called twice,
and even other serious problems. So this patch fixes it.

Fixes: 99a2dd955fba ("lib: remove librte_ prefix from directory names")

Signed-off-by: Huisong Li <lihuisong at huawei.com>
---
 lib/ethdev/ethdev_pci.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h
index 8edca82..14a0e01 100644
--- a/lib/ethdev/ethdev_pci.h
+++ b/lib/ethdev/ethdev_pci.h
@@ -151,6 +151,19 @@ rte_eth_dev_pci_generic_remove(struct rte_pci_device *pci_dev,
 	if (!eth_dev)
 		return 0;
 
+	/*
+	 * The eth_dev->data->name doesn't be cleared by the secondary precess,
+	 * so above "eth_dev" isn't NULL after rte_eth_dev_close() called.
+	 * Namely, whether "eth_dev" is NULL cannot be used to determine whether
+	 * an ethdev port has been released.
+	 * For both primary precess and secondary precess, eth_dev->state is
+	 * RTE_ETH_DEV_UNUSED, which means the ethdev port has been released.
+	 */
+	if (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.8.1



More information about the dev mailing list