From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by dpdk.org (Postfix) with ESMTP id 09E0D2BAF for ; Sun, 20 May 2018 13:00:51 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 9F77F2217D; Sun, 20 May 2018 07:00:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 20 May 2018 07:00:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=W8Ecvcj4vtEfe3 sZEW8MZyeP0r3F/eflDg1fB7cJxhU=; b=Zp4QFaYkytXiWg+oH8nPtDEGD1e0ic JTi2FXV29iYqgS4muZnO9r08ECODFkbhjFgWdaWCJQ2B3ej38AXmIc6G4he9b/yR B9nyRSPTrWnLtu3nayMPrzEFrBSALMmaQj9hAwDz0VJAhyP8mFxsD9lBfnG6Go4G B8HlIToX2NG9o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=W8Ecvcj4vtEfe3sZEW8MZyeP0r3F/eflDg1fB7cJxhU=; b=BTu8euW/ xIWMvV3ip1UMwQtcQnhkocOln5iZXLekGg9ORWCJVYvweyOWUz18AWGaIJu73f2v Slg/o1Ob2Wx6E2J04AwgZq8KP9xwQeQmVCCBBIJSlxwQJf4bae/cm3pA+pvAu8rs zcdYevvwfq222x2PhR2K2o2IKk3F0U/lKZ5nhjYGge80PduUq1myxD578d69X9P6 +o3c8lm1/e15hJP2vdK3G2Vq8wQTpeNpfXeF561/KXvmJQO8/VZqMZhPXe+XJgKy euESf+5AOxCIwMzMRpmySxnnE4z6AmAmLCOq7CL+8Xyd5bygkL9xqN2Aa0yD03nT IS+0ZHbLDSu3WA== X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from xps.monjalon.net (114.149.6.93.rev.sfr.net [93.6.149.114]) by mail.messagingengine.com (Postfix) with ESMTPA id 08A0F10252; Sun, 20 May 2018 07:00:49 -0400 (EDT) From: Thomas Monjalon To: stable@dpdk.org Cc: Matan Azrad Date: Sun, 20 May 2018 13:00:05 +0200 Message-Id: <20180520110006.9026-4-thomas@monjalon.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180520110006.9026-1-thomas@monjalon.net> References: <20180520110006.9026-1-thomas@monjalon.net> Subject: [dpdk-stable] [PATCH 18.02 3/4] ethdev: fix port visibility before initialization X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 May 2018 11:00:51 -0000 The port was set to the state ATTACHED during allocation. The consequence was to iterate over ports which are not initialized. The state ATTACHED is now set as the last step of probing. The uniqueness of port name is now checked before the availability of a port id for allocation (order reversed). As the state is not set on allocation anymore, it is also not checked in the function telling whether a port is allocated or not. The name of the port is set on allocation, so it is enough as a check. Fixes: 5588909af21b ("ethdev: add device iterator") Signed-off-by: Thomas Monjalon Signed-off-by: Matan Azrad Reviewed-by: Andrew Rybchenko Reviewed-by: Stephen Hemminger --- lib/librte_ether/rte_ethdev.c | 17 +++++++++-------- lib/librte_ether/rte_ethdev_driver.h | 2 ++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 4ce990776..04a1e474e 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -235,7 +235,7 @@ _rte_eth_dev_allocated(const char *name) unsigned i; for (i = 0; i < RTE_MAX_ETHPORTS; i++) { - if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) && + if (rte_eth_devices[i].data != NULL && strcmp(rte_eth_devices[i].data->name, name) == 0) return &rte_eth_devices[i]; } @@ -280,7 +280,6 @@ eth_dev_get(uint16_t port_id) struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id]; eth_dev->data = &rte_eth_dev_shared_data->data[port_id]; - eth_dev->state = RTE_ETH_DEV_ATTACHED; eth_dev_last_created_port = port_id; @@ -298,18 +297,18 @@ rte_eth_dev_allocate(const char *name) /* Synchronize port creation between primary and secondary threads. */ rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock); - port_id = rte_eth_dev_find_free_port(); - if (port_id == RTE_MAX_ETHPORTS) { - RTE_LOG(ERR, EAL, "Reached maximum number of Ethernet ports\n"); - goto unlock; - } - if (_rte_eth_dev_allocated(name) != NULL) { RTE_LOG(ERR, EAL, "Ethernet Device with name %s already allocated!\n", name); goto unlock; } + port_id = rte_eth_dev_find_free_port(); + if (port_id == RTE_MAX_ETHPORTS) { + RTE_LOG(ERR, EAL, "Reached maximum number of Ethernet ports\n"); + goto unlock; + } + eth_dev = eth_dev_get(port_id); snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name); eth_dev->data->port_id = port_id; @@ -3392,6 +3391,8 @@ rte_eth_dev_probing_finish(struct rte_eth_dev *dev) { if (dev == NULL) return; + + dev->state = RTE_ETH_DEV_ATTACHED; } int diff --git a/lib/librte_ether/rte_ethdev_driver.h b/lib/librte_ether/rte_ethdev_driver.h index 77297f331..a0780cdcc 100644 --- a/lib/librte_ether/rte_ethdev_driver.h +++ b/lib/librte_ether/rte_ethdev_driver.h @@ -106,6 +106,8 @@ int _rte_eth_dev_callback_process(struct rte_eth_dev *dev, * This is the last step of device probing. * It must be called after a port is allocated and initialized successfully. * + * The state is set as RTE_ETH_DEV_ATTACHED. + * * @param dev * New ethdev port. */ -- 2.16.2