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 0D2062BF2 for ; Tue, 22 May 2018 13:37:34 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id EBB2021B15; Tue, 22 May 2018 07:37:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 22 May 2018 07:37:32 -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=EbJqdNeH6cl9mV a+21qiCltRJ1nFOIaBxSJ7ymMTNhw=; b=IYj0cqfdjxQkoEgbSejbXWIFavI8Y2 T9YCdWI0TsigovuKbRaXsWc7S6B3evpauw1/h5Vpw+kBrADle7QTI4wGrHOhmDLW aEI+1nPwthfcWC6SYvFCKQKAtRcPPsqQ8d56G66CskSoCrJg1fXHRnjdxdAZQxoj 0mHqdFchXuHCg= 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=EbJqdNeH6cl9mVa+21qiCltRJ1nFOIaBxSJ7ymMTNhw=; b=aNQaSCtd +ZvW6i6BsXANp7QfJZS4kF2mzdQ6pbM9ccvW7sLNemPwkNngOdHKvV9fKWesy+wO 2L79ePj+C6632nrQFUS0+tNyVoOz+l/WvBO2nvO16YgIEhBukpyFlf4UoZQSb9KF vnmYATB3L9FvfP9+4BW/9IvXPXO04FNIbv+40L/Uukpgw/9S2g4uhc2GtQ+KyFS1 Dcq9gvg4tdpKr70jwVWsLvmEN7nvEJRLwQlgtuteBaXyyFExbetX1QW8IwnE9lqx SvFT/ZMf0wnok6DdIPO+5lNVBAfJRSbXUzcMDbBq91CAay8lCyC0iS+ApXOjqD/A WOzwDYDEYUOuvw== X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: 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 EB11CE4910; Tue, 22 May 2018 07:37:31 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: matan@mellanox.com, ferruh.yigit@intel.com, anatoly.burakov@intel.com, gaetan.rivet@6wind.com Date: Tue, 22 May 2018 13:37:27 +0200 Message-Id: <20180522113727.3116-1-thomas@monjalon.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <2833093.uzJjkH71XI@xps> References: <2833093.uzJjkH71XI@xps> Subject: [dpdk-dev] [PATCH v3] bus/vdev: replace device list lock by a recursive one 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 11:37:34 -0000 A device like failsafe can manage sub-devices. When removing such device, it removes its sub-devices and try to take the same vdev_device_list_lock. It was causing a deadlock because the lock was not recursive. Fixes: 35f462839b69 ("bus/vdev: add lock on device list") Suggested-by: Anatoly Burakov Signed-off-by: Thomas Monjalon --- v3: try recursive lock WARNING: not yet tested! --- drivers/bus/vdev/vdev.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 099b9ff85..6139dd551 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -36,7 +36,9 @@ TAILQ_HEAD(vdev_device_list, rte_vdev_device); static struct vdev_device_list vdev_device_list = TAILQ_HEAD_INITIALIZER(vdev_device_list); -static rte_spinlock_t vdev_device_list_lock = RTE_SPINLOCK_INITIALIZER; +/* The lock needs to be recursive because a vdev can manage another vdev. */ +static rte_spinlock_recursive_t vdev_device_list_lock = + RTE_SPINLOCK_RECURSIVE_INITIALIZER; struct vdev_driver_list vdev_driver_list = TAILQ_HEAD_INITIALIZER(vdev_driver_list); @@ -249,7 +251,7 @@ rte_vdev_init(const char *name, const char *args) struct rte_devargs *devargs; int ret; - rte_spinlock_lock(&vdev_device_list_lock); + rte_spinlock_recursive_lock(&vdev_device_list_lock); ret = insert_vdev(name, args, &dev); if (ret == 0) { ret = vdev_probe_all_drivers(dev); @@ -263,7 +265,7 @@ rte_vdev_init(const char *name, const char *args) free(dev); } } - rte_spinlock_unlock(&vdev_device_list_lock); + rte_spinlock_recursive_unlock(&vdev_device_list_lock); return ret; } @@ -293,7 +295,7 @@ rte_vdev_uninit(const char *name) if (name == NULL) return -EINVAL; - rte_spinlock_lock(&vdev_device_list_lock); + rte_spinlock_recursive_lock(&vdev_device_list_lock); dev = find_vdev(name); if (!dev) { @@ -311,7 +313,7 @@ rte_vdev_uninit(const char *name) free(dev); unlock: - rte_spinlock_unlock(&vdev_device_list_lock); + rte_spinlock_recursive_unlock(&vdev_device_list_lock); return ret; } @@ -355,7 +357,7 @@ vdev_action(const struct rte_mp_msg *mp_msg, const void *peer) ou->num = 1; num = 0; - rte_spinlock_lock(&vdev_device_list_lock); + rte_spinlock_recursive_lock(&vdev_device_list_lock); TAILQ_FOREACH(dev, &vdev_device_list, next) { devname = rte_vdev_device_name(dev); if (strlen(devname) == 0) { @@ -369,7 +371,7 @@ vdev_action(const struct rte_mp_msg *mp_msg, const void *peer) devname, strerror(rte_errno)); num++; } - rte_spinlock_unlock(&vdev_device_list_lock); + rte_spinlock_recursive_unlock(&vdev_device_list_lock); ou->type = VDEV_SCAN_REP; ou->num = num; @@ -445,10 +447,10 @@ vdev_scan(void) if (!dev) return -1; - rte_spinlock_lock(&vdev_device_list_lock); + rte_spinlock_recursive_lock(&vdev_device_list_lock); if (find_vdev(devargs->name)) { - rte_spinlock_unlock(&vdev_device_list_lock); + rte_spinlock_recursive_unlock(&vdev_device_list_lock); free(dev); continue; } @@ -459,7 +461,7 @@ vdev_scan(void) TAILQ_INSERT_TAIL(&vdev_device_list, dev, next); - rte_spinlock_unlock(&vdev_device_list_lock); + rte_spinlock_recursive_unlock(&vdev_device_list_lock); } return 0; @@ -498,7 +500,7 @@ vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const struct rte_vdev_device *vstart; struct rte_vdev_device *dev; - rte_spinlock_lock(&vdev_device_list_lock); + rte_spinlock_recursive_lock(&vdev_device_list_lock); if (start != NULL) { vstart = RTE_DEV_TO_VDEV_CONST(start); dev = TAILQ_NEXT(vstart, next); @@ -510,7 +512,7 @@ vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, break; dev = TAILQ_NEXT(dev, next); } - rte_spinlock_unlock(&vdev_device_list_lock); + rte_spinlock_recursive_unlock(&vdev_device_list_lock); return dev ? &dev->device : NULL; } -- 2.16.2