[dpdk-stable] [PATCH] ethdev: fix port id allocation

Yuanhan Liu yliu at fridaylinux.org
Sun Feb 11 08:53:13 CET 2018


On Sun, Feb 11, 2018 at 07:40:22AM +0000, Matan Azrad wrote:
> [ backported from upstream commit 8ee892a2385c50427c03db5cef1789babceb5999 ]

Applied to dpdk-stable/17.11.

Thanks.

	--yliu

> 
> 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 at intel.com>
> Signed-off-by: Matan Azrad <matan at mellanox.com>
> Acked-by: Thomas Monjalon <thomas at monjalon.net>
> Acked-by: Konstantin Ananyev <konstantin.ananyev at 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


More information about the stable mailing list