@@ -52,6 +52,7 @@ struct devlink {
struct mutex lock; /* Serializes access to devlink instance specific objects such as
* port, sb, dpipe, resource, params, region, traps and more.
*/
+ struct mutex reload_lock; /* Protects reload operation */
u8 reload_failed:1,
reload_enabled:1,
registered:1;
@@ -3307,29 +3307,32 @@ static int devlink_reload(struct devlink *devlink, struct net *dest_net,
u32 remote_reload_stats[DEVLINK_RELOAD_STATS_ARRAY_SIZE];
int err;
- if (!devlink->reload_enabled)
- return -EOPNOTSUPP;
+ mutex_lock(&devlink->reload_lock);
+ if (!devlink->reload_enabled) {
+ err = -EOPNOTSUPP;
+ goto done;
+ }
memcpy(remote_reload_stats, devlink->stats.remote_reload_stats,
sizeof(remote_reload_stats));
err = devlink->ops->reload_down(devlink, !!dest_net, action, limit, extack);
if (err)
- return err;
+ goto done;
if (dest_net && !net_eq(dest_net, devlink_net(devlink)))
devlink_reload_netns_change(devlink, dest_net);
err = devlink->ops->reload_up(devlink, action, limit, actions_performed, extack);
devlink_reload_failed_set(devlink, !!err);
- if (err)
- return err;
WARN_ON(!(*actions_performed & BIT(action)));
/* Catch driver on updating the remote action within devlink reload */
WARN_ON(memcmp(remote_reload_stats, devlink->stats.remote_reload_stats,
sizeof(remote_reload_stats)));
devlink_reload_stats_update(devlink, limit, *actions_performed);
- return 0;
+done:
+ mutex_unlock(&devlink->reload_lock);
+ return err;
}
static int
@@ -8118,6 +8121,7 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size)
INIT_LIST_HEAD(&devlink->trap_policer_list);
mutex_init(&devlink->lock);
mutex_init(&devlink->reporters_lock);
+ mutex_init(&devlink->reload_lock);
return devlink;
}
EXPORT_SYMBOL_GPL(devlink_alloc);
@@ -8166,9 +8170,9 @@ EXPORT_SYMBOL_GPL(devlink_unregister);
*/
void devlink_reload_enable(struct devlink *devlink)
{
- mutex_lock(&devlink_mutex);
+ mutex_lock(&devlink->reload_lock);
devlink->reload_enabled = true;
- mutex_unlock(&devlink_mutex);
+ mutex_unlock(&devlink->reload_lock);
}
EXPORT_SYMBOL_GPL(devlink_reload_enable);
@@ -8182,12 +8186,12 @@ EXPORT_SYMBOL_GPL(devlink_reload_enable);
*/
void devlink_reload_disable(struct devlink *devlink)
{
- mutex_lock(&devlink_mutex);
+ mutex_lock(&devlink->reload_lock);
/* Mutex is taken which ensures that no reload operation is in
* progress while setting up forbidded flag.
*/
devlink->reload_enabled = false;
- mutex_unlock(&devlink_mutex);
+ mutex_unlock(&devlink->reload_lock);
}
EXPORT_SYMBOL_GPL(devlink_reload_disable);
@@ -8198,6 +8202,7 @@ EXPORT_SYMBOL_GPL(devlink_reload_disable);
*/
void devlink_free(struct devlink *devlink)
{
+ mutex_destroy(&devlink->reload_lock);
mutex_destroy(&devlink->reporters_lock);
mutex_destroy(&devlink->lock);
WARN_ON(!list_empty(&devlink->trap_policer_list));