patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] ethdev: fix port id allocation
@ 2018-02-11  7:40 Matan Azrad
  2018-02-11  7:53 ` Yuanhan Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Matan Azrad @ 2018-02-11  7:40 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: stable

[ backported from upstream commit 8ee892a2385c50427c03db5cef1789babceb5999 ]

rte_eth_dev_find_free_port() found a free port by state checking.
The state field are in local process memory, so other DPDK processes
may get the same port ID because their local states may be different.

Replace the state checking by the ethdev port name checking,
so, if the name is an empty string the port ID will be detected as
unused.

Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")

Suggested-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---


Backported this commit for LTS release 17.11.1.
Please let me know for any issue with this commit, will be happy to help. 

 lib/librte_ether/rte_ethdev.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 9dcb0d2..4d23bc1 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -192,8 +192,12 @@ struct rte_eth_dev *
 	unsigned i;
 
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
+		/* Using shared name field to find a free port. */
+		if (rte_eth_dev_data[i].name[0] == '\0') {
+			RTE_ASSERT(rte_eth_devices[i].state ==
+				   RTE_ETH_DEV_UNUSED);
 			return i;
+		}
 	}
 	return RTE_MAX_ETHPORTS;
 }
@@ -218,15 +222,15 @@ struct rte_eth_dev *
 	uint16_t port_id;
 	struct rte_eth_dev *eth_dev;
 
+	if (rte_eth_dev_data == NULL)
+		rte_eth_dev_data_alloc();
+
 	port_id = rte_eth_dev_find_free_port();
 	if (port_id == RTE_MAX_ETHPORTS) {
 		RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
 		return NULL;
 	}
 
-	if (rte_eth_dev_data == NULL)
-		rte_eth_dev_data_alloc();
-
 	if (rte_eth_dev_allocated(name) != NULL) {
 		RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
 				name);
-- 
1.8.3.1

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

end of thread, other threads:[~2018-02-11  7:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-11  7:40 [dpdk-stable] [PATCH] ethdev: fix port id allocation Matan Azrad
2018-02-11  7:53 ` Yuanhan Liu

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).