devlink: remove linecards lock

Similar to other devlink objects, convert the linecards list to be
protected by devlink instance lock. Alongside with that rename the
create/destroy() functions to devl_* to indicate the devlink instance
lock needs to be held while calling them.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jiri Pirko 2023-01-18 16:21:04 +01:00 committed by Jakub Kicinski
parent 854617f52a
commit 5cc9049cb9
5 changed files with 20 additions and 37 deletions

View File

@ -1259,9 +1259,9 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core,
linecard->linecards = linecards; linecard->linecards = linecards;
mutex_init(&linecard->lock); mutex_init(&linecard->lock);
devlink_linecard = devlink_linecard_create(priv_to_devlink(mlxsw_core), devlink_linecard = devl_linecard_create(priv_to_devlink(mlxsw_core),
slot_index, &mlxsw_linecard_ops, slot_index, &mlxsw_linecard_ops,
linecard); linecard);
if (IS_ERR(devlink_linecard)) if (IS_ERR(devlink_linecard))
return PTR_ERR(devlink_linecard); return PTR_ERR(devlink_linecard);
@ -1285,7 +1285,7 @@ static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core,
if (linecard->active) if (linecard->active)
mlxsw_linecard_active_clear(linecard); mlxsw_linecard_active_clear(linecard);
mlxsw_linecard_bdev_del(linecard); mlxsw_linecard_bdev_del(linecard);
devlink_linecard_destroy(linecard->devlink_linecard); devl_linecard_destroy(linecard->devlink_linecard);
mutex_destroy(&linecard->lock); mutex_destroy(&linecard->lock);
} }

View File

@ -1687,9 +1687,9 @@ void devl_rate_nodes_destroy(struct devlink *devlink);
void devlink_port_linecard_set(struct devlink_port *devlink_port, void devlink_port_linecard_set(struct devlink_port *devlink_port,
struct devlink_linecard *linecard); struct devlink_linecard *linecard);
struct devlink_linecard * struct devlink_linecard *
devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, devl_linecard_create(struct devlink *devlink, unsigned int linecard_index,
const struct devlink_linecard_ops *ops, void *priv); const struct devlink_linecard_ops *ops, void *priv);
void devlink_linecard_destroy(struct devlink_linecard *linecard); void devl_linecard_destroy(struct devlink_linecard *linecard);
void devlink_linecard_provision_set(struct devlink_linecard *linecard, void devlink_linecard_provision_set(struct devlink_linecard *linecard,
const char *type); const char *type);
void devlink_linecard_provision_clear(struct devlink_linecard *linecard); void devlink_linecard_provision_clear(struct devlink_linecard *linecard);

View File

@ -247,7 +247,6 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
mutex_init(&devlink->lock); mutex_init(&devlink->lock);
lockdep_set_class(&devlink->lock, &devlink->lock_key); lockdep_set_class(&devlink->lock, &devlink->lock_key);
mutex_init(&devlink->reporters_lock); mutex_init(&devlink->reporters_lock);
mutex_init(&devlink->linecards_lock);
refcount_set(&devlink->refcount, 1); refcount_set(&devlink->refcount, 1);
return devlink; return devlink;
@ -269,7 +268,6 @@ void devlink_free(struct devlink *devlink)
{ {
ASSERT_DEVLINK_NOT_REGISTERED(devlink); ASSERT_DEVLINK_NOT_REGISTERED(devlink);
mutex_destroy(&devlink->linecards_lock);
mutex_destroy(&devlink->reporters_lock); mutex_destroy(&devlink->reporters_lock);
WARN_ON(!list_empty(&devlink->trap_policer_list)); WARN_ON(!list_empty(&devlink->trap_policer_list));
WARN_ON(!list_empty(&devlink->trap_group_list)); WARN_ON(!list_empty(&devlink->trap_group_list));

View File

@ -38,7 +38,6 @@ struct devlink {
struct list_head trap_group_list; struct list_head trap_group_list;
struct list_head trap_policer_list; struct list_head trap_policer_list;
struct list_head linecard_list; struct list_head linecard_list;
struct mutex linecards_lock; /* protects linecard_list */
const struct devlink_ops *ops; const struct devlink_ops *ops;
u64 features; u64 features;
struct xarray snapshot_ids; struct xarray snapshot_ids;

View File

@ -282,13 +282,10 @@ devlink_linecard_get_from_attrs(struct devlink *devlink, struct nlattr **attrs)
u32 linecard_index = nla_get_u32(attrs[DEVLINK_ATTR_LINECARD_INDEX]); u32 linecard_index = nla_get_u32(attrs[DEVLINK_ATTR_LINECARD_INDEX]);
struct devlink_linecard *linecard; struct devlink_linecard *linecard;
mutex_lock(&devlink->linecards_lock);
linecard = devlink_linecard_get_by_index(devlink, linecard_index); linecard = devlink_linecard_get_by_index(devlink, linecard_index);
if (linecard)
refcount_inc(&linecard->refcount);
mutex_unlock(&devlink->linecards_lock);
if (!linecard) if (!linecard)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
refcount_inc(&linecard->refcount);
return linecard; return linecard;
} }
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
@ -2129,7 +2126,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,
devlink_dump_for_each_instance_get(msg, state, devlink) { devlink_dump_for_each_instance_get(msg, state, devlink) {
int idx = 0; int idx = 0;
mutex_lock(&devlink->linecards_lock); devl_lock(devlink);
if (!devl_is_registered(devlink)) if (!devl_is_registered(devlink))
goto next_devlink; goto next_devlink;
@ -2147,7 +2144,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,
cb->extack); cb->extack);
mutex_unlock(&linecard->state_lock); mutex_unlock(&linecard->state_lock);
if (err) { if (err) {
mutex_unlock(&devlink->linecards_lock); devl_unlock(devlink);
devlink_put(devlink); devlink_put(devlink);
state->idx = idx; state->idx = idx;
goto out; goto out;
@ -2155,7 +2152,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,
idx++; idx++;
} }
next_devlink: next_devlink:
mutex_unlock(&devlink->linecards_lock); devl_unlock(devlink);
devlink_put(devlink); devlink_put(devlink);
} }
out: out:
@ -10223,7 +10220,7 @@ static void devlink_linecard_types_fini(struct devlink_linecard *linecard)
} }
/** /**
* devlink_linecard_create - Create devlink linecard * devl_linecard_create - Create devlink linecard
* *
* @devlink: devlink * @devlink: devlink
* @linecard_index: driver-specific numerical identifier of the linecard * @linecard_index: driver-specific numerical identifier of the linecard
@ -10236,8 +10233,8 @@ static void devlink_linecard_types_fini(struct devlink_linecard *linecard)
* Return: Line card structure or an ERR_PTR() encoded error code. * Return: Line card structure or an ERR_PTR() encoded error code.
*/ */
struct devlink_linecard * struct devlink_linecard *
devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, devl_linecard_create(struct devlink *devlink, unsigned int linecard_index,
const struct devlink_linecard_ops *ops, void *priv) const struct devlink_linecard_ops *ops, void *priv)
{ {
struct devlink_linecard *linecard; struct devlink_linecard *linecard;
int err; int err;
@ -10246,17 +10243,12 @@ devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index,
!ops->types_count || !ops->types_get)) !ops->types_count || !ops->types_get))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
mutex_lock(&devlink->linecards_lock); if (devlink_linecard_index_exists(devlink, linecard_index))
if (devlink_linecard_index_exists(devlink, linecard_index)) {
mutex_unlock(&devlink->linecards_lock);
return ERR_PTR(-EEXIST); return ERR_PTR(-EEXIST);
}
linecard = kzalloc(sizeof(*linecard), GFP_KERNEL); linecard = kzalloc(sizeof(*linecard), GFP_KERNEL);
if (!linecard) { if (!linecard)
mutex_unlock(&devlink->linecards_lock);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
}
linecard->devlink = devlink; linecard->devlink = devlink;
linecard->index = linecard_index; linecard->index = linecard_index;
@ -10269,35 +10261,29 @@ devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index,
if (err) { if (err) {
mutex_destroy(&linecard->state_lock); mutex_destroy(&linecard->state_lock);
kfree(linecard); kfree(linecard);
mutex_unlock(&devlink->linecards_lock);
return ERR_PTR(err); return ERR_PTR(err);
} }
list_add_tail(&linecard->list, &devlink->linecard_list); list_add_tail(&linecard->list, &devlink->linecard_list);
refcount_set(&linecard->refcount, 1); refcount_set(&linecard->refcount, 1);
mutex_unlock(&devlink->linecards_lock);
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
return linecard; return linecard;
} }
EXPORT_SYMBOL_GPL(devlink_linecard_create); EXPORT_SYMBOL_GPL(devl_linecard_create);
/** /**
* devlink_linecard_destroy - Destroy devlink linecard * devl_linecard_destroy - Destroy devlink linecard
* *
* @linecard: devlink linecard * @linecard: devlink linecard
*/ */
void devlink_linecard_destroy(struct devlink_linecard *linecard) void devl_linecard_destroy(struct devlink_linecard *linecard)
{ {
struct devlink *devlink = linecard->devlink;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL); devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL);
mutex_lock(&devlink->linecards_lock);
list_del(&linecard->list); list_del(&linecard->list);
devlink_linecard_types_fini(linecard); devlink_linecard_types_fini(linecard);
mutex_unlock(&devlink->linecards_lock);
devlink_linecard_put(linecard); devlink_linecard_put(linecard);
} }
EXPORT_SYMBOL_GPL(devlink_linecard_destroy); EXPORT_SYMBOL_GPL(devl_linecard_destroy);
/** /**
* devlink_linecard_provision_set - Set provisioning on linecard * devlink_linecard_provision_set - Set provisioning on linecard