ethdev: fix eth device released repeatedly

Message ID 20211008082114.22468-1-lihuisong@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series ethdev: fix eth device released repeatedly |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional fail Functional Testing issues
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

lihuisong (C) Oct. 8, 2021, 8:21 a.m. UTC
  In secondary process, because it doesn't clear eth_dev->data, the "eth_dev"
above will not be NULL when rte_eth_dev_close() has been called before this
interface is called. In this case, Ethernet device will be released
repeatedly. The state of the Ethernet device is equal to RTE_ETH_DEV_UNUSED
after calling rte_eth_dev_close(). Using this state resolves problem.

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

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
RFC -> v1:
 * fix commit log and add a judgment for secondary process.

---
 lib/ethdev/ethdev_pci.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

Thomas Monjalon Oct. 8, 2021, 10:23 a.m. UTC | #1
08/10/2021 10:21, Huisong Li:
> In secondary process, because it doesn't clear eth_dev->data, the "eth_dev"
> above will not be NULL when rte_eth_dev_close() has been called before this
> interface is called. In this case, Ethernet device will be released
> repeatedly. The state of the Ethernet device is equal to RTE_ETH_DEV_UNUSED
> after calling rte_eth_dev_close(). Using this state resolves problem.

Sorry I have difficulties to understand.
The use of "it" everywhere doesn't help.
You should name things instead of refering to "it".

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

For sure that's not the root cause.
  
lihuisong (C) Oct. 9, 2021, 1:29 a.m. UTC | #2
在 2021/10/8 18:23, Thomas Monjalon 写道:
> 08/10/2021 10:21, Huisong Li:
>> In secondary process, because it doesn't clear eth_dev->data, the "eth_dev"
>> above will not be NULL when rte_eth_dev_close() has been called before this
>> interface is called. In this case, Ethernet device will be released
>> repeatedly. The state of the Ethernet device is equal to RTE_ETH_DEV_UNUSED
>> after calling rte_eth_dev_close(). Using this state resolves problem.
> Sorry I have difficulties to understand.
> The use of "it" everywhere doesn't help.
> You should name things instead of refering to "it".
ok. I will fix it. Thanks.
>> Fixes: 99a2dd955fba ("lib: remove librte_ prefix from directory names")
> For sure that's not the root cause.
>
>
>
> .
  

Patch

diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h
index 8edca82ce8..be695feefe 100644
--- a/lib/ethdev/ethdev_pci.h
+++ b/lib/ethdev/ethdev_pci.h
@@ -151,6 +151,20 @@  rte_eth_dev_pci_generic_remove(struct rte_pci_device *pci_dev,
 	if (!eth_dev)
 		return 0;
 
+	/*
+	 * In secondary process, because it doesn't clear eth_dev->data, the
+	 * "eth_dev" above will not be NULL when rte_eth_dev_close() has been
+	 * called before this interface is called.
+	 * In this case, Ethernet device will be released repeatedly.
+	 * The state of the Ethernet device is equal to RTE_ETH_DEV_UNUSED after
+	 * calling rte_eth_dev_close(). Using this state resolves 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)