Skip to content

Commit 644a66c

Browse files
Jiri Pirkodavem330
authored andcommitted
net: devlink: convert reload command to take implicit devlink->lock
Convert reload command to behave the same way as the rest of the commands and let if be called with devlink->lock held. Remove the temporary devl_lock taking from drivers. As the DEVLINK_NL_FLAG_NO_LOCK flag is no longer used, remove it alongside. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c2368b1 commit 644a66c

File tree

5 files changed

+5
-31
lines changed

5 files changed

+5
-31
lines changed

drivers/net/ethernet/mellanox/mlx4/main.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,11 +3958,9 @@ static int mlx4_devlink_reload_down(struct devlink *devlink, bool netns_change,
39583958
NL_SET_ERR_MSG_MOD(extack, "Namespace change is not supported");
39593959
return -EOPNOTSUPP;
39603960
}
3961-
devl_lock(devlink);
39623961
if (persist->num_vfs)
39633962
mlx4_warn(persist->dev, "Reload performed on PF, will cause reset on operating Virtual Functions\n");
39643963
mlx4_restart_one_down(persist->pdev);
3965-
devl_unlock(devlink);
39663964
return 0;
39673965
}
39683966

@@ -3975,10 +3973,8 @@ static int mlx4_devlink_reload_up(struct devlink *devlink, enum devlink_reload_a
39753973
struct mlx4_dev_persistent *persist = dev->persist;
39763974
int err;
39773975

3978-
devl_lock(devlink);
39793976
*actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT);
39803977
err = mlx4_restart_one_up(persist->pdev, true, devlink);
3981-
devl_unlock(devlink);
39823978
if (err)
39833979
mlx4_err(persist->dev, "mlx4_restart_one_up failed, ret=%d\n",
39843980
err);

drivers/net/ethernet/mellanox/mlx5/core/devlink.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ static int mlx5_devlink_reload_down(struct devlink *devlink, bool netns_change,
164164
NL_SET_ERR_MSG_MOD(extack, "reload while VFs are present is unfavorable");
165165
}
166166

167-
devl_lock(devlink);
168167
switch (action) {
169168
case DEVLINK_RELOAD_ACTION_DRIVER_REINIT:
170169
mlx5_unload_one_devl_locked(dev);
@@ -181,7 +180,6 @@ static int mlx5_devlink_reload_down(struct devlink *devlink, bool netns_change,
181180
ret = -EOPNOTSUPP;
182181
}
183182

184-
devl_unlock(devlink);
185183
return ret;
186184
}
187185

@@ -192,7 +190,6 @@ static int mlx5_devlink_reload_up(struct devlink *devlink, enum devlink_reload_a
192190
struct mlx5_core_dev *dev = devlink_priv(devlink);
193191
int ret = 0;
194192

195-
devl_lock(devlink);
196193
*actions_performed = BIT(action);
197194
switch (action) {
198195
case DEVLINK_RELOAD_ACTION_DRIVER_REINIT:
@@ -211,7 +208,6 @@ static int mlx5_devlink_reload_up(struct devlink *devlink, enum devlink_reload_a
211208
ret = -EOPNOTSUPP;
212209
}
213210

214-
devl_unlock(devlink);
215211
return ret;
216212
}
217213

drivers/net/ethernet/mellanox/mlxsw/core.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,7 @@ mlxsw_devlink_core_bus_device_reload_down(struct devlink *devlink,
14991499
if (!(mlxsw_core->bus->features & MLXSW_BUS_F_RESET))
15001500
return -EOPNOTSUPP;
15011501

1502-
devl_lock(devlink);
15031502
mlxsw_core_bus_device_unregister(mlxsw_core, true);
1504-
devl_unlock(devlink);
15051503
return 0;
15061504
}
15071505

@@ -1515,12 +1513,10 @@ mlxsw_devlink_core_bus_device_reload_up(struct devlink *devlink, enum devlink_re
15151513

15161514
*actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT) |
15171515
BIT(DEVLINK_RELOAD_ACTION_FW_ACTIVATE);
1518-
devl_lock(devlink);
15191516
err = mlxsw_core_bus_device_register(mlxsw_core->bus_info,
15201517
mlxsw_core->bus,
15211518
mlxsw_core->bus_priv, true,
15221519
devlink, extack);
1523-
devl_unlock(devlink);
15241520
return err;
15251521
}
15261522

drivers/net/netdevsim/dev.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -948,18 +948,15 @@ static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
948948
{
949949
struct nsim_dev *nsim_dev = devlink_priv(devlink);
950950

951-
devl_lock(devlink);
952951
if (nsim_dev->dont_allow_reload) {
953952
/* For testing purposes, user set debugfs dont_allow_reload
954953
* value to true. So forbid it.
955954
*/
956955
NL_SET_ERR_MSG_MOD(extack, "User forbid the reload for testing purposes");
957-
devl_unlock(devlink);
958956
return -EOPNOTSUPP;
959957
}
960958

961959
nsim_dev_reload_destroy(nsim_dev);
962-
devl_unlock(devlink);
963960
return 0;
964961
}
965962

@@ -970,19 +967,16 @@ static int nsim_dev_reload_up(struct devlink *devlink, enum devlink_reload_actio
970967
struct nsim_dev *nsim_dev = devlink_priv(devlink);
971968
int ret;
972969

973-
devl_lock(devlink);
974970
if (nsim_dev->fail_reload) {
975971
/* For testing purposes, user set debugfs fail_reload
976972
* value to true. Fail right away.
977973
*/
978974
NL_SET_ERR_MSG_MOD(extack, "User setup the reload to fail for testing purposes");
979-
devl_unlock(devlink);
980975
return -EINVAL;
981976
}
982977

983978
*actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT);
984979
ret = nsim_dev_reload_create(nsim_dev, extack);
985-
devl_unlock(devlink);
986980
return ret;
987981
}
988982

net/core/devlink.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -768,12 +768,6 @@ devlink_region_snapshot_get_by_id(struct devlink_region *region, u32 id)
768768
#define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3)
769769
#define DEVLINK_NL_FLAG_NEED_LINECARD BIT(4)
770770

771-
/* The per devlink instance lock is taken by default in the pre-doit
772-
* operation, yet several commands do not require this. The global
773-
* devlink lock is taken and protects from disruption by user-calls.
774-
*/
775-
#define DEVLINK_NL_FLAG_NO_LOCK BIT(5)
776-
777771
static int devlink_nl_pre_doit(const struct genl_ops *ops,
778772
struct sk_buff *skb, struct genl_info *info)
779773
{
@@ -788,8 +782,7 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
788782
mutex_unlock(&devlink_mutex);
789783
return PTR_ERR(devlink);
790784
}
791-
if (~ops->internal_flags & DEVLINK_NL_FLAG_NO_LOCK)
792-
devl_lock(devlink);
785+
devl_lock(devlink);
793786
info->user_ptr[0] = devlink;
794787
if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT) {
795788
devlink_port = devlink_port_get_from_info(devlink, info);
@@ -831,8 +824,7 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
831824
return 0;
832825

833826
unlock:
834-
if (~ops->internal_flags & DEVLINK_NL_FLAG_NO_LOCK)
835-
devl_unlock(devlink);
827+
devl_unlock(devlink);
836828
devlink_put(devlink);
837829
mutex_unlock(&devlink_mutex);
838830
return err;
@@ -849,8 +841,7 @@ static void devlink_nl_post_doit(const struct genl_ops *ops,
849841
linecard = info->user_ptr[1];
850842
devlink_linecard_put(linecard);
851843
}
852-
if (~ops->internal_flags & DEVLINK_NL_FLAG_NO_LOCK)
853-
devl_unlock(devlink);
844+
devl_unlock(devlink);
854845
devlink_put(devlink);
855846
mutex_unlock(&devlink_mutex);
856847
}
@@ -9414,7 +9405,6 @@ static const struct genl_small_ops devlink_nl_ops[] = {
94149405
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
94159406
.doit = devlink_nl_cmd_reload,
94169407
.flags = GENL_ADMIN_PERM,
9417-
.internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
94189408
},
94199409
{
94209410
.cmd = DEVLINK_CMD_PARAM_GET,
@@ -12507,10 +12497,12 @@ static void __net_exit devlink_pernet_pre_exit(struct net *net)
1250712497
mutex_lock(&devlink_mutex);
1250812498
devlinks_xa_for_each_registered_get(net, index, devlink) {
1250912499
WARN_ON(!(devlink->features & DEVLINK_F_RELOAD));
12500+
mutex_lock(&devlink->lock);
1251012501
err = devlink_reload(devlink, &init_net,
1251112502
DEVLINK_RELOAD_ACTION_DRIVER_REINIT,
1251212503
DEVLINK_RELOAD_LIMIT_UNSPEC,
1251312504
&actions_performed, NULL);
12505+
mutex_unlock(&devlink->lock);
1251412506
if (err && err != -EOPNOTSUPP)
1251512507
pr_warn("Failed to reload devlink instance into init_net\n");
1251612508
devlink_put(devlink);

0 commit comments

Comments
 (0)