From: <dlinkin@nvidia.com>
To: <netdev@vger.kernel.org>
Cc: <davem@davemloft.net>, <kuba@kernel.org>, <jiri@nvidia.com>,
<parav@nvidia.com>, <vladbu@nvidia.com>,
Dmytro Linkin <dlinkin@nvidia.com>
Subject: [PATCH net-next 3/3] devlink: Protect rate list with lock while switching modes
Date: Wed, 23 Jun 2021 16:43:15 +0300 [thread overview]
Message-ID: <1624455795-5160-4-git-send-email-dlinkin@nvidia.com> (raw)
In-Reply-To: <1624455795-5160-1-git-send-email-dlinkin@nvidia.com>
From: Dmytro Linkin <dlinkin@nvidia.com>
Devlink eswitch set command doesn't hold devlink->lock, which makes
possible race condition between rate list traversing and others devlink
rate KAPI calls, like devlink_rate_nodes_destroy().
Hold devlink lock while traversing the list.
Fixes: a8ecb93ef03d ("devlink: Introduce rate nodes")
Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
net/core/devlink.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 153d432..8fdd04f 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -2710,11 +2710,15 @@ static int devlink_rate_nodes_check(struct devlink *devlink, u16 mode,
{
struct devlink_rate *devlink_rate;
+ /* Take the lock to sync with devlink_rate_nodes_destroy() */
+ mutex_lock(&devlink->lock);
list_for_each_entry(devlink_rate, &devlink->rate_list, list)
if (devlink_rate_is_node(devlink_rate)) {
+ mutex_unlock(&devlink->lock);
NL_SET_ERR_MSG_MOD(extack, "Rate node(s) exists.");
return -EBUSY;
}
+ mutex_unlock(&devlink->lock);
return 0;
}
--
1.8.3.1
next prev parent reply other threads:[~2021-06-23 13:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-23 13:43 [PATCH net-next 0/3] Fixes for devlink rate objects API dlinkin
2021-06-23 13:43 ` [PATCH net-next 1/3] devlink: Decrease refcnt of parent rate object on leaf destroy dlinkin
2021-06-23 13:43 ` [PATCH net-next 2/3] devlink: Remove eswitch mode check for mode set call dlinkin
2021-06-23 13:43 ` dlinkin [this message]
2021-06-23 22:50 ` [PATCH net-next 0/3] Fixes for devlink rate objects API patchwork-bot+netdevbpf
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=1624455795-5160-4-git-send-email-dlinkin@nvidia.com \
--to=dlinkin@nvidia.com \
--cc=davem@davemloft.net \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=parav@nvidia.com \
--cc=vladbu@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).