Commit dfdfd130 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

devlink: protect health reporter operation with instance lock

Similar to other devlink objects, protect the reporters list
by devlink instance lock. Alongside add unlocked versions
of health reporter create/destroy functions and use them in drivers
on call paths where the instance lock is held.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 65a20c2e
...@@ -2051,7 +2051,7 @@ static int mlxsw_core_health_init(struct mlxsw_core *mlxsw_core) ...@@ -2051,7 +2051,7 @@ static int mlxsw_core_health_init(struct mlxsw_core *mlxsw_core)
if (!(mlxsw_core->bus->features & MLXSW_BUS_F_TXRX)) if (!(mlxsw_core->bus->features & MLXSW_BUS_F_TXRX))
return 0; return 0;
fw_fatal = devlink_health_reporter_create(devlink, &mlxsw_core_health_fw_fatal_ops, fw_fatal = devl_health_reporter_create(devlink, &mlxsw_core_health_fw_fatal_ops,
0, mlxsw_core); 0, mlxsw_core);
if (IS_ERR(fw_fatal)) { if (IS_ERR(fw_fatal)) {
dev_err(mlxsw_core->bus_info->dev, "Failed to create fw fatal reporter"); dev_err(mlxsw_core->bus_info->dev, "Failed to create fw fatal reporter");
...@@ -2072,7 +2072,7 @@ static int mlxsw_core_health_init(struct mlxsw_core *mlxsw_core) ...@@ -2072,7 +2072,7 @@ static int mlxsw_core_health_init(struct mlxsw_core *mlxsw_core)
err_fw_fatal_config: err_fw_fatal_config:
mlxsw_core_trap_unregister(mlxsw_core, &mlxsw_core_health_listener, mlxsw_core); mlxsw_core_trap_unregister(mlxsw_core, &mlxsw_core_health_listener, mlxsw_core);
err_trap_register: err_trap_register:
devlink_health_reporter_destroy(mlxsw_core->health.fw_fatal); devl_health_reporter_destroy(mlxsw_core->health.fw_fatal);
return err; return err;
} }
...@@ -2085,7 +2085,7 @@ static void mlxsw_core_health_fini(struct mlxsw_core *mlxsw_core) ...@@ -2085,7 +2085,7 @@ static void mlxsw_core_health_fini(struct mlxsw_core *mlxsw_core)
mlxsw_core_trap_unregister(mlxsw_core, &mlxsw_core_health_listener, mlxsw_core); mlxsw_core_trap_unregister(mlxsw_core, &mlxsw_core_health_listener, mlxsw_core);
/* Make sure there is no more event work scheduled */ /* Make sure there is no more event work scheduled */
mlxsw_core_flush_owq(); mlxsw_core_flush_owq();
devlink_health_reporter_destroy(mlxsw_core->health.fw_fatal); devl_health_reporter_destroy(mlxsw_core->health.fw_fatal);
} }
static void mlxsw_core_irq_event_handler_init(struct mlxsw_core *mlxsw_core) static void mlxsw_core_irq_event_handler_init(struct mlxsw_core *mlxsw_core)
......
...@@ -233,14 +233,14 @@ int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink) ...@@ -233,14 +233,14 @@ int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink)
int err; int err;
health->empty_reporter = health->empty_reporter =
devlink_health_reporter_create(devlink, devl_health_reporter_create(devlink,
&nsim_dev_empty_reporter_ops, &nsim_dev_empty_reporter_ops,
0, health); 0, health);
if (IS_ERR(health->empty_reporter)) if (IS_ERR(health->empty_reporter))
return PTR_ERR(health->empty_reporter); return PTR_ERR(health->empty_reporter);
health->dummy_reporter = health->dummy_reporter =
devlink_health_reporter_create(devlink, devl_health_reporter_create(devlink,
&nsim_dev_dummy_reporter_ops, &nsim_dev_dummy_reporter_ops,
0, health); 0, health);
if (IS_ERR(health->dummy_reporter)) { if (IS_ERR(health->dummy_reporter)) {
...@@ -266,9 +266,9 @@ int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink) ...@@ -266,9 +266,9 @@ int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink)
return 0; return 0;
err_dummy_reporter_destroy: err_dummy_reporter_destroy:
devlink_health_reporter_destroy(health->dummy_reporter); devl_health_reporter_destroy(health->dummy_reporter);
err_empty_reporter_destroy: err_empty_reporter_destroy:
devlink_health_reporter_destroy(health->empty_reporter); devl_health_reporter_destroy(health->empty_reporter);
return err; return err;
} }
...@@ -278,6 +278,6 @@ void nsim_dev_health_exit(struct nsim_dev *nsim_dev) ...@@ -278,6 +278,6 @@ void nsim_dev_health_exit(struct nsim_dev *nsim_dev)
debugfs_remove_recursive(health->ddir); debugfs_remove_recursive(health->ddir);
kfree(health->recovered_break_msg); kfree(health->recovered_break_msg);
devlink_health_reporter_destroy(health->dummy_reporter); devl_health_reporter_destroy(health->dummy_reporter);
devlink_health_reporter_destroy(health->empty_reporter); devl_health_reporter_destroy(health->empty_reporter);
} }
...@@ -1865,7 +1865,7 @@ int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name, ...@@ -1865,7 +1865,7 @@ int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
const void *value, u32 value_len); const void *value, u32 value_len);
struct devlink_health_reporter * struct devlink_health_reporter *
devlink_health_reporter_create(struct devlink *devlink, devl_port_health_reporter_create(struct devlink_port *port,
const struct devlink_health_reporter_ops *ops, const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv); u64 graceful_period, void *priv);
...@@ -1874,9 +1874,25 @@ devlink_port_health_reporter_create(struct devlink_port *port, ...@@ -1874,9 +1874,25 @@ devlink_port_health_reporter_create(struct devlink_port *port,
const struct devlink_health_reporter_ops *ops, const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv); u64 graceful_period, void *priv);
struct devlink_health_reporter *
devl_health_reporter_create(struct devlink *devlink,
const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv);
struct devlink_health_reporter *
devlink_health_reporter_create(struct devlink *devlink,
const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv);
void
devl_health_reporter_destroy(struct devlink_health_reporter *reporter);
void void
devlink_health_reporter_destroy(struct devlink_health_reporter *reporter); devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
void
devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter);
void void
devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter); devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter);
......
...@@ -7337,7 +7337,7 @@ __devlink_health_reporter_create(struct devlink *devlink, ...@@ -7337,7 +7337,7 @@ __devlink_health_reporter_create(struct devlink *devlink,
} }
/** /**
* devlink_port_health_reporter_create - create devlink health reporter for * devl_port_health_reporter_create - create devlink health reporter for
* specified port instance * specified port instance
* *
* @port: devlink_port which should contain the new reporter * @port: devlink_port which should contain the new reporter
...@@ -7346,12 +7346,13 @@ __devlink_health_reporter_create(struct devlink *devlink, ...@@ -7346,12 +7346,13 @@ __devlink_health_reporter_create(struct devlink *devlink,
* @priv: priv * @priv: priv
*/ */
struct devlink_health_reporter * struct devlink_health_reporter *
devlink_port_health_reporter_create(struct devlink_port *port, devl_port_health_reporter_create(struct devlink_port *port,
const struct devlink_health_reporter_ops *ops, const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv) u64 graceful_period, void *priv)
{ {
struct devlink_health_reporter *reporter; struct devlink_health_reporter *reporter;
devl_assert_locked(port->devlink);
mutex_lock(&port->reporters_lock); mutex_lock(&port->reporters_lock);
if (__devlink_health_reporter_find_by_name(&port->reporter_list, if (__devlink_health_reporter_find_by_name(&port->reporter_list,
&port->reporters_lock, ops->name)) { &port->reporters_lock, ops->name)) {
...@@ -7370,10 +7371,26 @@ devlink_port_health_reporter_create(struct devlink_port *port, ...@@ -7370,10 +7371,26 @@ devlink_port_health_reporter_create(struct devlink_port *port,
mutex_unlock(&port->reporters_lock); mutex_unlock(&port->reporters_lock);
return reporter; return reporter;
} }
EXPORT_SYMBOL_GPL(devl_port_health_reporter_create);
struct devlink_health_reporter *
devlink_port_health_reporter_create(struct devlink_port *port,
const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv)
{
struct devlink_health_reporter *reporter;
struct devlink *devlink = port->devlink;
devl_lock(devlink);
reporter = devl_port_health_reporter_create(port, ops,
graceful_period, priv);
devl_unlock(devlink);
return reporter;
}
EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create); EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create);
/** /**
* devlink_health_reporter_create - create devlink health reporter * devl_health_reporter_create - create devlink health reporter
* *
* @devlink: devlink * @devlink: devlink
* @ops: ops * @ops: ops
...@@ -7381,12 +7398,13 @@ EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create); ...@@ -7381,12 +7398,13 @@ EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create);
* @priv: priv * @priv: priv
*/ */
struct devlink_health_reporter * struct devlink_health_reporter *
devlink_health_reporter_create(struct devlink *devlink, devl_health_reporter_create(struct devlink *devlink,
const struct devlink_health_reporter_ops *ops, const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv) u64 graceful_period, void *priv)
{ {
struct devlink_health_reporter *reporter; struct devlink_health_reporter *reporter;
devl_assert_locked(devlink);
mutex_lock(&devlink->reporters_lock); mutex_lock(&devlink->reporters_lock);
if (devlink_health_reporter_find_by_name(devlink, ops->name)) { if (devlink_health_reporter_find_by_name(devlink, ops->name)) {
reporter = ERR_PTR(-EEXIST); reporter = ERR_PTR(-EEXIST);
...@@ -7403,6 +7421,21 @@ devlink_health_reporter_create(struct devlink *devlink, ...@@ -7403,6 +7421,21 @@ devlink_health_reporter_create(struct devlink *devlink,
mutex_unlock(&devlink->reporters_lock); mutex_unlock(&devlink->reporters_lock);
return reporter; return reporter;
} }
EXPORT_SYMBOL_GPL(devl_health_reporter_create);
struct devlink_health_reporter *
devlink_health_reporter_create(struct devlink *devlink,
const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv)
{
struct devlink_health_reporter *reporter;
devl_lock(devlink);
reporter = devl_health_reporter_create(devlink, ops,
graceful_period, priv);
devl_unlock(devlink);
return reporter;
}
EXPORT_SYMBOL_GPL(devlink_health_reporter_create); EXPORT_SYMBOL_GPL(devlink_health_reporter_create);
static void static void
...@@ -7429,35 +7462,61 @@ __devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) ...@@ -7429,35 +7462,61 @@ __devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
} }
/** /**
* devlink_health_reporter_destroy - destroy devlink health reporter * devl_health_reporter_destroy - destroy devlink health reporter
* *
* @reporter: devlink health reporter to destroy * @reporter: devlink health reporter to destroy
*/ */
void void
devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) devl_health_reporter_destroy(struct devlink_health_reporter *reporter)
{ {
struct mutex *lock = &reporter->devlink->reporters_lock; struct mutex *lock = &reporter->devlink->reporters_lock;
devl_assert_locked(reporter->devlink);
mutex_lock(lock); mutex_lock(lock);
__devlink_health_reporter_destroy(reporter); __devlink_health_reporter_destroy(reporter);
mutex_unlock(lock); mutex_unlock(lock);
} }
EXPORT_SYMBOL_GPL(devl_health_reporter_destroy);
void
devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
{
struct devlink *devlink = reporter->devlink;
devl_lock(devlink);
devl_health_reporter_destroy(reporter);
devl_unlock(devlink);
}
EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy); EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy);
/** /**
* devlink_port_health_reporter_destroy - destroy devlink port health reporter * devl_port_health_reporter_destroy - destroy devlink port health reporter
* *
* @reporter: devlink health reporter to destroy * @reporter: devlink health reporter to destroy
*/ */
void void
devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter) devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter)
{ {
struct mutex *lock = &reporter->devlink_port->reporters_lock; struct mutex *lock = &reporter->devlink_port->reporters_lock;
devl_assert_locked(reporter->devlink);
mutex_lock(lock); mutex_lock(lock);
__devlink_health_reporter_destroy(reporter); __devlink_health_reporter_destroy(reporter);
mutex_unlock(lock); mutex_unlock(lock);
} }
EXPORT_SYMBOL_GPL(devl_port_health_reporter_destroy);
void
devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter)
{
struct devlink *devlink = reporter->devlink;
devl_lock(devlink);
devl_port_health_reporter_destroy(reporter);
devl_unlock(devlink);
}
EXPORT_SYMBOL_GPL(devlink_port_health_reporter_destroy); EXPORT_SYMBOL_GPL(devlink_port_health_reporter_destroy);
static int static int
...@@ -7805,12 +7864,11 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, ...@@ -7805,12 +7864,11 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
unsigned long port_index; unsigned long port_index;
int idx = 0; int idx = 0;
devl_lock(devlink);
if (!devl_is_registered(devlink))
goto next_devlink;
mutex_lock(&devlink->reporters_lock); mutex_lock(&devlink->reporters_lock);
if (!devl_is_registered(devlink)) {
mutex_unlock(&devlink->reporters_lock);
devlink_put(devlink);
continue;
}
list_for_each_entry(reporter, &devlink->reporter_list, list_for_each_entry(reporter, &devlink->reporter_list,
list) { list) {
...@@ -7824,6 +7882,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, ...@@ -7824,6 +7882,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
NLM_F_MULTI); NLM_F_MULTI);
if (err) { if (err) {
mutex_unlock(&devlink->reporters_lock); mutex_unlock(&devlink->reporters_lock);
devl_unlock(devlink);
devlink_put(devlink); devlink_put(devlink);
state->idx = idx; state->idx = idx;
goto out; goto out;
...@@ -7832,10 +7891,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, ...@@ -7832,10 +7891,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
} }
mutex_unlock(&devlink->reporters_lock); mutex_unlock(&devlink->reporters_lock);
devl_lock(devlink);
if (!devl_is_registered(devlink))
goto next_devlink;
xa_for_each(&devlink->ports, port_index, port) { xa_for_each(&devlink->ports, port_index, port) {
mutex_lock(&port->reporters_lock); mutex_lock(&port->reporters_lock);
list_for_each_entry(reporter, &port->reporter_list, list) { list_for_each_entry(reporter, &port->reporter_list, list) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment