From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH 07/11] ethdev: add lock to port allocation check Date: Thu, 10 May 2018 13:33:56 -0700 Message-ID: <20180510133356.0c4bacb0@xeon-e3> References: <20180509094337.26112-1-thomas@monjalon.net> <20180509094337.26112-8-thomas@monjalon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org, Matan Azrad , stable@dpdk.org To: Thomas Monjalon Return-path: Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) by dpdk.org (Postfix) with ESMTP id 3B8441B816 for ; Thu, 10 May 2018 22:33:59 +0200 (CEST) Received: by mail-pl0-f66.google.com with SMTP id c11-v6so1948775plr.5 for ; Thu, 10 May 2018 13:33:59 -0700 (PDT) In-Reply-To: <20180509094337.26112-8-thomas@monjalon.net> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, 9 May 2018 11:43:33 +0200 Thomas Monjalon wrote: > > +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; > +} > + Not sure about this. The code it self is correct, but it creates a racy semantic. If caller doesn't already hold a lock then there is no guarantee that the device returned won't be destroyed by some other thread or that the name was just allocated by some other process.