Skip to content

Commit d7d7512

Browse files
shayshyidavem330
authored andcommitted
devlink: Fix devlink parallel commands processing
Commit 870c7ad ("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 a380687 ("devlink: take device reference for devlink object"). Without this commit, it would not be safe to access devlink->dev lockless. Fixes: 870c7ad ("devlink: protect devlink->dev by the instance lock") Signed-off-by: Shay Drory <shayd@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 343041b commit d7d7512

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

net/devlink/netlink.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs,
193193
devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]);
194194

195195
devlinks_xa_for_each_registered_get(net, index, devlink) {
196-
devl_dev_lock(devlink, dev_lock);
197-
if (devl_is_registered(devlink) &&
198-
strcmp(devlink->dev->bus->name, busname) == 0 &&
199-
strcmp(dev_name(devlink->dev), devname) == 0)
200-
return devlink;
201-
devl_dev_unlock(devlink, dev_lock);
196+
if (strcmp(devlink->dev->bus->name, busname) == 0 &&
197+
strcmp(dev_name(devlink->dev), devname) == 0) {
198+
devl_dev_lock(devlink, dev_lock);
199+
if (devl_is_registered(devlink))
200+
return devlink;
201+
devl_dev_unlock(devlink, dev_lock);
202+
}
202203
devlink_put(devlink);
203204
}
204205

0 commit comments

Comments
 (0)