summaryrefslogtreecommitdiff
path: root/net/devlink/devl_internal.h
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2023-01-05 22:33:57 -0800
committerDavid S. Miller <davem@davemloft.net>2023-01-06 12:56:19 +0000
commited539ba614a079ea696b92beef1eafec66f831a4 (patch)
tree4c6df2d81001a8a5243d9cb9b9d390a68b98c7ff /net/devlink/devl_internal.h
parent870c7ad4a52be2acff92d0355ca118654c7efece (diff)
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/devl_internal.h')
-rw-r--r--net/devlink/devl_internal.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index 6342552e5f99..01a00df81d0e 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -86,6 +86,14 @@ extern struct genl_family devlink_nl_family;
struct devlink *devlinks_xa_find_get(struct net *net, unsigned long *indexp);
+static inline bool devl_is_registered(struct devlink *devlink)
+{
+ /* To prevent races the caller must hold the instance lock
+ * or another lock taken during unregistration.
+ */
+ return xa_get_mark(&devlinks, devlink->index, DEVLINK_REGISTERED);
+}
+
/* Netlink */
#define DEVLINK_NL_FLAG_NEED_PORT BIT(0)
#define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1)