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 77D8BAABE; Wed, 9 May 2018 11:43:50 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 244DE22581; Wed, 9 May 2018 05:43:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 09 May 2018 05:43: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=uZ/g3UiDaJzeLy VJBuSRf1yifcYuatvIyjWBYakPNF0=; b=nohIMAXls9YHzHXHClzujIueZkHu0+ 3If+o1Vd4PxtE6i+zkYrL7gF3q1rWyTnkOPTtuqMEZ25oPRGx8dJRddSxX/a8yIz 6vUtiUUQqbm9wLS/MUcP6oDcZAntIhwBMtek2g2bEWYdVivohKsjV40MxUNk+JYV SZ1qY0icgifCI= 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=X7CBoThS 2ciJavLV4B62lDh98GSVMb74IF1EoTPCVpckcLaqukgagVUYdyHAMFED5QbXIw2q dIArZJfZ9n5SaNJzeDVjUCFzqtkPPBJSezC05KBs0g0snMW4TqfHr1fXZAcsllVU TtidWCT73S3IXy57kDe1feUE3f8RyzubXm3sIiRrUvX9nl+gAdFjgVjTCU6xplnu xoF6pQYnG6EU8Ybyl5Xu5YPTAJB85uLx+V76ZGtGH2disKmnK3cF52w2ypLi1nbp t8x9q3O5+AZvBx8/x9yzCJnDzlOG7TYwZp4EI1a6XD7T+d1HgmXvK2b3JOP3liKu UMOxsaiIYlCydA== 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 64420E508F; Wed, 9 May 2018 05:43:49 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: Matan Azrad , stable@dpdk.org Date: Wed, 9 May 2018 11:43:33 +0200 Message-Id: <20180509094337.26112-8-thomas@monjalon.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180509094337.26112-1-thomas@monjalon.net> References: <20180509094337.26112-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:43:51 -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