From: Michael Baum <michaelba@nvidia.com>
To: <dev@dpdk.org>
Cc: Matan Azrad <matan@nvidia.com>,
Raslan Darawsheh <rasland@nvidia.com>,
Viacheslav Ovsiienko <viacheslavo@nvidia.com>, <stable@dpdk.org>
Subject: [dpdk-dev] [PATCH 5/6] common/mlx5: fix device list operation concurrency
Date: Tue, 31 Aug 2021 23:37:31 +0300 [thread overview]
Message-ID: <20210831203732.3411134-6-michaelba@nvidia.com> (raw)
In-Reply-To: <20210831203732.3411134-1-michaelba@nvidia.com>
The MLX5 common driver has a global list of mlx5 devices which are
probed.
In probe function it create one and insert it to the list. Similarly it
removes the device in remove function.
These operations are not safe as there can be such operations in
parallel, by different threads.
Add global lock for the list and use it to insert or remove.
Fixes: 8a41f4deccc3 ("common/mlx5: introduce layer for multiple class drivers")
Cc: stable@dpdk.org
Signed-off-by: Michael Baum <michaelba@nvidia.com>
---
drivers/common/mlx5/mlx5_common.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index f6e440dca1..4321cb3a9c 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -50,6 +50,7 @@ static TAILQ_HEAD(mlx5_drivers, mlx5_class_driver) drivers_list =
/* Head of devices. */
static TAILQ_HEAD(mlx5_devices, mlx5_common_device) devices_list =
TAILQ_HEAD_INITIALIZER(devices_list);
+static pthread_mutex_t devices_list_lock;
static const struct {
const char *name;
@@ -222,7 +223,9 @@ mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size)
static void
dev_release(struct mlx5_common_device *dev)
{
+ pthread_mutex_lock(&devices_list_lock);
TAILQ_REMOVE(&devices_list, dev, next);
+ pthread_mutex_unlock(&devices_list_lock);
rte_free(dev);
}
@@ -315,7 +318,9 @@ mlx5_common_dev_probe(struct rte_device *eal_dev)
if (!dev)
return -ENOMEM;
dev->dev = eal_dev;
+ pthread_mutex_lock(&devices_list_lock);
TAILQ_INSERT_HEAD(&devices_list, dev, next);
+ pthread_mutex_unlock(&devices_list_lock);
new_device = true;
}
/*
@@ -440,6 +445,7 @@ mlx5_common_init(void)
if (mlx5_common_initialized)
return;
+ pthread_mutex_init(&devices_list_lock, NULL);
mlx5_glue_constructor();
mlx5_common_driver_init();
mlx5_common_initialized = true;
--
2.25.1
next prev parent reply other threads:[~2021-08-31 20:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-31 20:37 [dpdk-dev] [PATCH 0/6] mlx5: some independent fixes Michael Baum
2021-08-31 20:37 ` [dpdk-dev] [PATCH 1/6] net/mlx5: fix shared device context creation error flow Michael Baum
2021-09-05 8:46 ` Raslan Darawsheh
2021-08-31 20:37 ` [dpdk-dev] [PATCH 2/6] net/mlx5: fix PCI probing " Michael Baum
2021-09-05 8:53 ` Raslan Darawsheh
2021-08-31 20:37 ` [dpdk-dev] [PATCH 3/6] net/mlx5: fix allow duplicate pattern devarg default Michael Baum
2021-08-31 20:37 ` [dpdk-dev] [PATCH 4/6] common/mlx5: fix class combination validation Michael Baum
2021-08-31 20:37 ` Michael Baum [this message]
2021-08-31 20:37 ` [dpdk-dev] [PATCH 6/6] common/mlx5: fix resource cleanliness in a device remove Michael Baum
2021-09-01 7:46 ` [dpdk-dev] [PATCH 0/6] mlx5: some independent fixes Matan Azrad
2021-09-12 10:36 ` [dpdk-dev] [PATCH v2 " Michael Baum
2021-09-12 10:36 ` [dpdk-dev] [PATCH v2 1/6] net/mlx5: fix memory leak in the SH creation Michael Baum
2021-09-12 10:36 ` [dpdk-dev] [PATCH v2 2/6] net/mlx5: fix memory leak in PCI probe Michael Baum
2021-09-12 10:36 ` [dpdk-dev] [PATCH v2 3/6] net/mlx5: fix allow duplicate pattern devarg default Michael Baum
2021-09-12 10:36 ` [dpdk-dev] [PATCH v2 4/6] common/mlx5: fix class combination validation Michael Baum
2021-09-12 10:36 ` [dpdk-dev] [PATCH v2 5/6] common/mlx5: fix device list operation concurrency Michael Baum
2021-09-12 10:36 ` [dpdk-dev] [PATCH v2 6/6] common/mlx5: fix resource cleanliness in a device remove Michael Baum
2021-09-20 21:25 ` [dpdk-dev] [PATCH v2 0/6] mlx5: some independent fixes 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=20210831203732.3411134-6-michaelba@nvidia.com \
--to=michaelba@nvidia.com \
--cc=dev@dpdk.org \
--cc=matan@nvidia.com \
--cc=rasland@nvidia.com \
--cc=stable@dpdk.org \
--cc=viacheslavo@nvidia.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).