summaryrefslogtreecommitdiff
path: root/net/devlink/devl_internal.h
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2023-01-06 12:56:20 +0000
committerDavid S. Miller <davem@davemloft.net>2023-01-06 12:56:20 +0000
commit6bd4755c7c499dbcef46eaaeafa1a319da583b29 (patch)
tree4eb9d0f62f2fd24e44f7e5e83375d8d3c269cba1 /net/devlink/devl_internal.h
parent6b754d7bd007c5f68fbb2d9abd5c00d253b033d0 (diff)
parent82a3aef2e6af2fdd04d542c83b7a35990d94afc9 (diff)
Merge branch 'devlink-unregister'
Jakub Kicinski says: ==================== devlink: remove the wait-for-references on unregister Move the registration and unregistration of the devlink instances under their instance locks. Don't perform the netdev-style wait for all references when unregistering the instance. Instead the devlink instance refcount will only ensure that the memory of the instance is not freed. All places which acquire access to devlink instances via a reference must check that the instance is still registered under the instance lock. This fixes the problem of the netdev code accessing devlink instances before they are registered. RFC: https://lore.kernel.org/all/20221217011953.152487-1-kuba@kernel.org/ - rewrite the cover letter - rewrite the commit message for patch 1 - un-export and rename devl_is_alive - squash the netdevsim patches ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/devlink/devl_internal.h')
-rw-r--r--net/devlink/devl_internal.h28
1 files changed, 13 insertions, 15 deletions
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index adf9f6c177db..5d2bbe295659 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -12,7 +12,6 @@
#include <net/net_namespace.h>
#define DEVLINK_REGISTERED XA_MARK_1
-#define DEVLINK_UNREGISTERING XA_MARK_2
#define DEVLINK_RELOAD_STATS_ARRAY_SIZE \
(__DEVLINK_RELOAD_LIMIT_MAX * __DEVLINK_RELOAD_ACTION_MAX)
@@ -52,7 +51,6 @@ struct devlink {
struct lock_class_key lock_key;
u8 reload_failed:1;
refcount_t refcount;
- struct completion comp;
struct rcu_head rcu;
struct notifier_block netdevice_nb;
char priv[] __aligned(NETDEV_ALIGN);
@@ -82,18 +80,17 @@ extern struct genl_family devlink_nl_family;
* in loop body in order to release the reference.
*/
#define devlinks_xa_for_each_registered_get(net, index, devlink) \
- for (index = 0, \
- devlink = devlinks_xa_find_get_first(net, &index); \
- devlink; devlink = devlinks_xa_find_get_next(net, &index))
+ for (index = 0; (devlink = devlinks_xa_find_get(net, &index)); index++)
-struct devlink *
-devlinks_xa_find_get(struct net *net, unsigned long *indexp,
- void * (*xa_find_fn)(struct xarray *, unsigned long *,
- unsigned long, xa_mark_t));
-struct devlink *
-devlinks_xa_find_get_first(struct net *net, unsigned long *indexp);
-struct devlink *
-devlinks_xa_find_get_next(struct net *net, unsigned long *indexp);
+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)
@@ -135,12 +132,13 @@ struct devlink_gen_cmd {
*/
#define devlink_dump_for_each_instance_get(msg, state, devlink) \
for (; (devlink = devlinks_xa_find_get(sock_net(msg->sk), \
- &state->instance, xa_find)); \
+ &state->instance)); \
state->instance++, state->idx = 0)
extern const struct genl_small_ops devlink_nl_ops[56];
-struct devlink *devlink_get_from_attrs(struct net *net, struct nlattr **attrs);
+struct devlink *
+devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs);
void devlink_notify_unregister(struct devlink *devlink);
void devlink_notify_register(struct devlink *devlink);