diff options
author | Jakub Kicinski <kuba@kernel.org> | 2023-01-05 22:33:57 -0800 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2023-01-06 12:56:19 +0000 |
commit | ed539ba614a079ea696b92beef1eafec66f831a4 (patch) | |
tree | 4c6df2d81001a8a5243d9cb9b9d390a68b98c7ff /net/devlink/netlink.c | |
parent | 870c7ad4a52be2acff92d0355ca118654c7efece (diff) | |
download | lwn-ed539ba614a079ea696b92beef1eafec66f831a4.tar.gz lwn-ed539ba614a079ea696b92beef1eafec66f831a4.zip |
devlink: always check if the devlink instance is registered
Always check under the instance lock whether the devlink instance
is still / already registered.
This is a no-op for the most part, as the unregistration path currently
waits for all references. On the init path, however, we may temporarily
open up a race with netdev code, if netdevs are registered before the
devlink instance. This is temporary, the next change fixes it, and this
commit has been split out for the ease of review.
Note that in case of iterating over sub-objects which have their
own lock (regions and line cards) we assume an implicit dependency
between those objects existing and devlink unregistration.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/devlink/netlink.c')
-rw-r--r-- | net/devlink/netlink.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 69111746f5d9..b5b8ac6db2d1 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -98,7 +98,8 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs) devlinks_xa_for_each_registered_get(net, index, devlink) { devl_lock(devlink); - if (strcmp(devlink->dev->bus->name, busname) == 0 && + if (devl_is_registered(devlink) && + strcmp(devlink->dev->bus->name, busname) == 0 && strcmp(dev_name(devlink->dev), devname) == 0) return devlink; devl_unlock(devlink); @@ -211,7 +212,12 @@ int devlink_nl_instance_iter_dump(struct sk_buff *msg, devlink_dump_for_each_instance_get(msg, state, devlink) { devl_lock(devlink); - err = cmd->dump_one(msg, devlink, cb); + + if (devl_is_registered(devlink)) + err = cmd->dump_one(msg, devlink, cb); + else + err = 0; + devl_unlock(devlink); devlink_put(devlink); |