DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 20.05] ethdev: clear struct on releasing port
@ 2020-02-13 14:33 Thomas Monjalon
  2020-02-13 15:16 ` Ferruh Yigit
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Monjalon @ 2020-02-13 14:33 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Andrew Rybchenko

The function rte_eth_dev_release_port() is called by drivers
when closing or removing a device.
Its main usage should be via rte_eth_dev_close() by up-to-date
drivers which are compliant with RTE_ETH_DEV_CLOSE_REMOVE flag.

When a port is released, the data (rte_eth_dev_data) are cleared,
but the pointers in rte_eth_dev were not cleared.
It may cause issues with code paths trying to use dangling pointers
(e.g. the .device pointer which may reference a removed rte_device).
Everything is now cleared to 0 when releasing.
The state is explicitly set to RTE_ETH_DEV_UNUSED which is 0 anyway.

Using this patch may reveal bugs in some code paths:
	- device pointer must be saved before closing a port if needed
	- drivers must close ports on device remove for consistent cleanup

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_ethdev/rte_ethdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 774c721b34..2a43a9abe9 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -553,8 +553,6 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 
 	rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
 
-	eth_dev->state = RTE_ETH_DEV_UNUSED;
-
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 		rte_free(eth_dev->data->rx_queues);
 		rte_free(eth_dev->data->tx_queues);
@@ -563,6 +561,8 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 		rte_free(eth_dev->data->dev_private);
 		memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
 	}
+	memset(eth_dev, 0, sizeof(struct rte_eth_dev));
+	eth_dev->state = RTE_ETH_DEV_UNUSED;
 
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
 
-- 
2.25.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-13 19:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-13 14:33 [dpdk-dev] [PATCH 20.05] ethdev: clear struct on releasing port Thomas Monjalon
2020-02-13 15:16 ` Ferruh Yigit
2020-02-13 15:27   ` Thomas Monjalon
2020-02-13 16:05     ` Ferruh Yigit
2020-02-13 19:43       ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).