From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: matan@mellanox.com, ferruh.yigit@intel.com,
anatoly.burakov@intel.com, gaetan.rivet@6wind.com
Subject: [dpdk-dev] [PATCH v3] bus/vdev: replace device list lock by a recursive one
Date: Tue, 22 May 2018 13:37:27 +0200 [thread overview]
Message-ID: <20180522113727.3116-1-thomas@monjalon.net> (raw)
In-Reply-To: <2833093.uzJjkH71XI@xps>
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 <anatoly.burakov@intel.com>
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
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
next prev parent reply other threads:[~2018-05-22 11:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-21 16:11 [dpdk-dev] [PATCH] bus/vdev: reduce scope of device list lock Thomas Monjalon
2018-05-21 16:45 ` [dpdk-dev] [PATCH v2] bus/vdev: fix " Thomas Monjalon
2018-05-21 17:28 ` Matan Azrad
2018-05-22 9:11 ` Gaëtan Rivet
2018-05-22 9:05 ` [dpdk-dev] [PATCH] bus/vdev: reduce " Burakov, Anatoly
2018-05-22 9:20 ` Thomas Monjalon
2018-05-22 11:37 ` Thomas Monjalon [this message]
2018-05-22 12:08 ` [dpdk-dev] [PATCH v3] bus/vdev: replace device list lock by a recursive one Matan Azrad
2018-05-22 13:34 ` Burakov, Anatoly
2018-05-22 14:38 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180522113727.3116-1-thomas@monjalon.net \
--to=thomas@monjalon.net \
--cc=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=gaetan.rivet@6wind.com \
--cc=matan@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).