From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 7D022CF9E for ; Wed, 9 May 2018 11:31:18 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 2DA4822205; Wed, 9 May 2018 05:31:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 09 May 2018 05:31:18 -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=uZ/g3UiDaJzeLy VJBuSRf1yifcYuatvIyjWBYakPNF0=; b=nuU8ph7mtApbiOPfdO/J7s0GS9jvrc sX6nM+agJunjPtVmmf+44tP7LlqoW4DsR7nfAWzcujrzLEjWPO1W0KRugdE9B2uU JXshwzdtQk3g5VEScvJoc7SE2EZaifhbzYJp/11NvN3vrYixI1TNbE2mdlRBuLoW o/9RC1qAGgu+c= 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=uZ/g3UiDaJzeLyVJBuSRf1yifcYuatvIyjWBYakPNF0=; b=NY3w0Y2P 2PFZoj6dlHcXulQTzGejBqpIJBrFvmnbp9Y7SqhhUk2dqnriIdcd0urMWl8A8PnL PhlBsxj+0kNBt0JFtDk4qrDFqTU7cd7qPge6dhystMzk4WAiRz8TUfvKgy6EAn3i xpE5sXZbbESXcePXORkUHfwMtQIgpS1oyhBuXGZDMkvpGxvQVZu6wjmbcoy16LlH qa2vkj1S26rN97XOzLksQbSMxnqHLArJwjIwMlDCJ+VT7NZ5LL6Y5TtTICd1q3PJ F9w/5yCH2eAfrh1JTQlQ1U8GvbrziUT6QxlfWvpyKOqdxO47MNH0FAKsIpxc4zgB dPbn4KyuB/0Gyw== 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 81306E4ED0; Wed, 9 May 2018 05:31:17 -0400 (EDT) From: Thomas Monjalon To: matan@mellanox.com Cc: stable@dpdk.org Date: Wed, 9 May 2018 11:31:01 +0200 Message-Id: <20180509093105.25984-8-thomas@monjalon.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180509093105.25984-1-thomas@monjalon.net> References: <20180509093105.25984-1-thomas@monjalon.net> Subject: [dpdk-stable] [PATCH 07/11] ethdev: add lock to port allocation check 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: Wed, 09 May 2018 09:31:18 -0000 From: Matan Azrad When comparing the port name, there can be a race condition with a thread allocating a new port and writing the name at the same time. It can lead to match with a partial name by error. The check of the port is now considered as a critical section protected with locks. This fix will be even more required for multi-process when the port availability will rely only on the name, in a following patch. Fixes: 84934303a17c ("ethdev: synchronize port allocation") Cc: stable@dpdk.org Signed-off-by: Matan Azrad Acked-by: Thomas Monjalon --- lib/librte_ethdev/rte_ethdev.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index ae86d0ba7..357be2dca 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -227,8 +227,8 @@ rte_eth_dev_shared_data_prepare(void) rte_spinlock_unlock(&rte_eth_shared_data_lock); } -struct rte_eth_dev * -rte_eth_dev_allocated(const char *name) +static struct rte_eth_dev * +rte_eth_dev_allocated_lock_free(const char *name) { unsigned i; @@ -240,6 +240,22 @@ rte_eth_dev_allocated(const char *name) return NULL; } +struct rte_eth_dev * +rte_eth_dev_allocated(const char *name) +{ + struct rte_eth_dev *ethdev; + + rte_eth_dev_shared_data_prepare(); + + rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock); + + ethdev = rte_eth_dev_allocated_lock_free(name); + + rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock); + + return ethdev; +} + static uint16_t rte_eth_dev_find_free_port(void) { @@ -286,7 +302,7 @@ rte_eth_dev_allocate(const char *name) goto unlock; } - if (rte_eth_dev_allocated(name) != NULL) { + if (rte_eth_dev_allocated_lock_free(name) != NULL) { ethdev_log(ERR, "Ethernet Device with name %s already allocated!", name); -- 2.16.2