Thread (33 messages) 33 messages, 4 authors, 2021-10-21

[dpdk-dev] [RFC V2] ethdev: fix issue that dev close in PMD calls twice

From: Huisong Li <lihuisong@huawei.com>
Date: 2021-08-03 02:34:27
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

Ethernet devices in DPDK can be released by rte_eth_dev_close() and
rte_dev_remove(). These APIs both call xxx_dev_close() in PMD layer
to uninstall hardware. However, the two APIs do not have explicit
invocation restrictions. In other words, at the ethdev layer, it is
possible to call rte_eth_dev_close() before calling rte_dev_remove()
or rte_eal_hotplug_remove(). In such a bad scenario, the primary
process may be fine, but it may cause that xxx_dev_close() in the PMD
layer will be called twice in the secondary process. So this patch
fixes it.

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

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 v2: fix commit description
---
 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..429c4c7 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 process,
+	 * 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 process and secondary process, 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help