* [PATCH net v2] devlink: Fix devlink parallel commands processing
@ 2024-03-12 10:52 Shay Drory
2024-03-12 12:13 ` Jiri Pirko
2024-03-13 8:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Shay Drory @ 2024-03-12 10:52 UTC (permalink / raw)
To: netdev, pabeni, davem, kuba, edumazet; +Cc: jiri, Shay Drory
Commit 870c7ad4a52b ("devlink: protect devlink->dev by the instance
lock") added devlink instance locking inside a loop that iterates over
all the registered devlink instances on the machine in the pre-doit
phase. This can lead to serialization of devlink commands over
different devlink instances.
For example: While the first devlink instance is executing firmware
flash, all commands to other devlink instances on the machine are
forced to wait until the first devlink finishes.
Therefore, in the pre-doit phase, take the devlink instance lock only
for the devlink instance the command is targeting. Devlink layer is
taking a reference on the devlink instance, ensuring the devlink->dev
pointer is valid. This reference taking was introduced by commit
a380687200e0 ("devlink: take device reference for devlink object").
Without this commit, it would not be safe to access devlink->dev
lockless.
Fixes: 870c7ad4a52b ("devlink: protect devlink->dev by the instance lock")
Signed-off-by: Shay Drory <shayd@nvidia.com>
---
v1->v2:
- Simplify the code by removing the goto
---
net/devlink/netlink.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c
index 499885c8b9ca..593605c1b1ef 100644
--- a/net/devlink/netlink.c
+++ b/net/devlink/netlink.c
@@ -193,12 +193,13 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs,
devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]);
devlinks_xa_for_each_registered_get(net, index, devlink) {
- devl_dev_lock(devlink, dev_lock);
- if (devl_is_registered(devlink) &&
- strcmp(devlink->dev->bus->name, busname) == 0 &&
- strcmp(dev_name(devlink->dev), devname) == 0)
- return devlink;
- devl_dev_unlock(devlink, dev_lock);
+ if (strcmp(devlink->dev->bus->name, busname) == 0 &&
+ strcmp(dev_name(devlink->dev), devname) == 0) {
+ devl_dev_lock(devlink, dev_lock);
+ if (devl_is_registered(devlink))
+ return devlink;
+ devl_dev_unlock(devlink, dev_lock);
+ }
devlink_put(devlink);
}
--
2.38.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net v2] devlink: Fix devlink parallel commands processing
2024-03-12 10:52 [PATCH net v2] devlink: Fix devlink parallel commands processing Shay Drory
@ 2024-03-12 12:13 ` Jiri Pirko
2024-03-13 8:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2024-03-12 12:13 UTC (permalink / raw)
To: Shay Drory; +Cc: netdev, pabeni, davem, kuba, edumazet, jiri
Tue, Mar 12, 2024 at 11:52:38AM CET, shayd@nvidia.com wrote:
>Commit 870c7ad4a52b ("devlink: protect devlink->dev by the instance
>lock") added devlink instance locking inside a loop that iterates over
>all the registered devlink instances on the machine in the pre-doit
>phase. This can lead to serialization of devlink commands over
>different devlink instances.
>
>For example: While the first devlink instance is executing firmware
>flash, all commands to other devlink instances on the machine are
>forced to wait until the first devlink finishes.
>
>Therefore, in the pre-doit phase, take the devlink instance lock only
>for the devlink instance the command is targeting. Devlink layer is
>taking a reference on the devlink instance, ensuring the devlink->dev
>pointer is valid. This reference taking was introduced by commit
>a380687200e0 ("devlink: take device reference for devlink object").
>Without this commit, it would not be safe to access devlink->dev
>lockless.
>
>Fixes: 870c7ad4a52b ("devlink: protect devlink->dev by the instance lock")
>Signed-off-by: Shay Drory <shayd@nvidia.com>
>---
>v1->v2:
> - Simplify the code by removing the goto
Indeed nicer. Thanks!
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net v2] devlink: Fix devlink parallel commands processing
2024-03-12 10:52 [PATCH net v2] devlink: Fix devlink parallel commands processing Shay Drory
2024-03-12 12:13 ` Jiri Pirko
@ 2024-03-13 8:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-13 8:40 UTC (permalink / raw)
To: Shay Drory; +Cc: netdev, pabeni, davem, kuba, edumazet, jiri
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Tue, 12 Mar 2024 12:52:38 +0200 you wrote:
> Commit 870c7ad4a52b ("devlink: protect devlink->dev by the instance
> lock") added devlink instance locking inside a loop that iterates over
> all the registered devlink instances on the machine in the pre-doit
> phase. This can lead to serialization of devlink commands over
> different devlink instances.
>
> For example: While the first devlink instance is executing firmware
> flash, all commands to other devlink instances on the machine are
> forced to wait until the first devlink finishes.
>
> [...]
Here is the summary with links:
- [net,v2] devlink: Fix devlink parallel commands processing
https://git.kernel.org/netdev/net/c/d7d75124965a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-13 8:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-12 10:52 [PATCH net v2] devlink: Fix devlink parallel commands processing Shay Drory
2024-03-12 12:13 ` Jiri Pirko
2024-03-13 8:40 ` patchwork-bot+netdevbpf
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).