From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id C9548235 for ; Tue, 22 May 2018 11:05:15 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 May 2018 02:05:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,429,1520924400"; d="scan'208";a="226261566" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.237.220.101]) ([10.237.220.101]) by orsmga005.jf.intel.com with ESMTP; 22 May 2018 02:05:13 -0700 To: Thomas Monjalon , dev@dpdk.org Cc: matan@mellanox.com, ferruh.yigit@intel.com References: <20180521161156.25724-1-thomas@monjalon.net> From: "Burakov, Anatoly" Message-ID: <8f0eb83d-5090-c7c8-5c3d-c4eecb96e596@intel.com> Date: Tue, 22 May 2018 10:05:11 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180521161156.25724-1-thomas@monjalon.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] bus/vdev: reduce scope of device list lock 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: Tue, 22 May 2018 09:05:16 -0000 On 21-May-18 5:11 PM, Thomas Monjalon wrote: > The lock vdev_device_list_lock was taken before calling > "remove" function for the device. > So it prevents to remove sub-devices (as in failsafe) inside > its own "remove" function, because of a deadlock. > > The lock is now only protecting the device list inside > the bus driver. > > Fixes: 35f462839b69 ("bus/vdev: add lock on device list") > > Signed-off-by: Thomas Monjalon > --- > drivers/bus/vdev/vdev.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c > index 099b9ff85..2fbc86806 100644 > --- a/drivers/bus/vdev/vdev.c > +++ b/drivers/bus/vdev/vdev.c > @@ -293,25 +293,23 @@ rte_vdev_uninit(const char *name) > if (name == NULL) > return -EINVAL; > > - rte_spinlock_lock(&vdev_device_list_lock); > - > dev = find_vdev(name); > if (!dev) { > ret = -ENOENT; > - goto unlock; > + return ret; > } Without that lock, all of this would be racy - find_dev would iterate a tailq that might change under its feet, and tailq_remove may be called with a pointer that has already been removed. How about changing the lock to a recursive lock? Failsafe would be removing devices from within the same thread, correct? > > ret = vdev_remove_driver(dev); > if (ret) > - goto unlock; > + return ret; > > + rte_spinlock_lock(&vdev_device_list_lock); > TAILQ_REMOVE(&vdev_device_list, dev, next); > devargs = dev->device.devargs; > rte_devargs_remove(devargs->bus->name, devargs->name); > free(dev); > - > -unlock: > rte_spinlock_unlock(&vdev_device_list_lock); > + > return ret; > } > > -- Thanks, Anatoly