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 838441B7BF for ; Thu, 10 May 2018 00:43:29 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5A77222846; Wed, 9 May 2018 18:43:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 09 May 2018 18:43:27 -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=IepncaRUVkM/qT k2Jlva37nrRLMZJablpykn47vtNc4=; b=YuWriqwxf0dMSudvZrm+8y85GGhQyx OcMFdLTR5gHhAPPYqARUkJAOdtGUbqzqSQaRe6vhG3T7Teqc3SH5lwEJvjv0D0TB eh+I3pVEEGQvwKPdc25B+sZ+iqi+xhmxQbTGE0vWs70Y3a5bmX36A6YhfSEiF0lW 2NGNPCyswPrEs= 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=IepncaRUVkM/qTk2Jlva37nrRLMZJablpykn47vtNc4=; b=dCa2hf+a fdEkIO/fQh349m7dy1KvjOHFvabgTS0kQjeO/1xiR191rq2sv6189/i5VspttBLc 6M2eragVd6hI13U2Tt2VdsEGWN3Z7s2r9KpPaAomW+TbsjnkDNX84T/r667tSKSR oiNvKFnmT3uFQAkoy3b063KVr+n7B+BRvhCvSzv0jtOWG0r6i06ZF72PXcWkZ2Fk Zi+Mk/xXSWTybOLo1CZht3MLYB05P6Mb7rsHqkXmChXscDh0pQHD4Xo0jEXp6eJC Thj2yskm7MY4xO2FpgTOF51lp686dBJIrkakP2UK0fOCjuL986B4E3oKH1FKP+4z lhSlXRdpyAU9yw== X-ME-Sender: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id ACCA5E4EEF; Wed, 9 May 2018 18:43:26 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: Matan Azrad Date: Thu, 10 May 2018 00:43:10 +0200 Message-Id: <20180509224313.27289-9-thomas@monjalon.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180509224313.27289-1-thomas@monjalon.net> References: <20180509094337.26112-1-thomas@monjalon.net> <20180509224313.27289-1-thomas@monjalon.net> Subject: [dpdk-dev] [PATCH v2 08/11] ethdev: fix port visibility before initialization X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 May 2018 22:43:30 -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") Cc: stable@dpdk.org Signed-off-by: Thomas Monjalon Signed-off-by: Matan Azrad --- lib/librte_ethdev/rte_ethdev.c | 18 +++++++++--------- lib/librte_ethdev/rte_ethdev_driver.h | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 4fa7400d5..c5d9c7fe4 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -233,7 +233,7 @@ rte_eth_dev_allocated_nolock(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]; } @@ -278,7 +278,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; @@ -296,16 +295,15 @@ 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) { - ethdev_log(ERR, "Reached maximum number of Ethernet ports"); + if (rte_eth_dev_allocated_nolock(name) != NULL) { + ethdev_log(ERR, "Ethernet device with name %s already allocated", + name); goto unlock; } - if (rte_eth_dev_allocated_nolock(name) != NULL) { - ethdev_log(ERR, - "Ethernet Device with name %s already allocated!", - name); + port_id = rte_eth_dev_find_free_port(); + if (port_id == RTE_MAX_ETHPORTS) { + ethdev_log(ERR, "Reached maximum number of Ethernet ports"); goto unlock; } @@ -3387,6 +3385,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_ethdev/rte_ethdev_driver.h b/lib/librte_ethdev/rte_ethdev_driver.h index 3821f0b1d..3640dff68 100644 --- a/lib/librte_ethdev/rte_ethdev_driver.h +++ b/lib/librte_ethdev/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