Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jiri Pirko and committed by
David S. Miller
644a66c6 c2368b19

+5 -31
-4
drivers/net/ethernet/mellanox/mlx4/main.c
··· 3958 3958 NL_SET_ERR_MSG_MOD(extack, "Namespace change is not supported"); 3959 3959 return -EOPNOTSUPP; 3960 3960 } 3961 - devl_lock(devlink); 3962 3961 if (persist->num_vfs) 3963 3962 mlx4_warn(persist->dev, "Reload performed on PF, will cause reset on operating Virtual Functions\n"); 3964 3963 mlx4_restart_one_down(persist->pdev); 3965 - devl_unlock(devlink); 3966 3964 return 0; 3967 3965 } 3968 3966 ··· 3973 3975 struct mlx4_dev_persistent *persist = dev->persist; 3974 3976 int err; 3975 3977 3976 - devl_lock(devlink); 3977 3978 *actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT); 3978 3979 err = mlx4_restart_one_up(persist->pdev, true, devlink); 3979 - devl_unlock(devlink); 3980 3980 if (err) 3981 3981 mlx4_err(persist->dev, "mlx4_restart_one_up failed, ret=%d\n", 3982 3982 err);
-4
drivers/net/ethernet/mellanox/mlx5/core/devlink.c
··· 164 164 NL_SET_ERR_MSG_MOD(extack, "reload while VFs are present is unfavorable"); 165 165 } 166 166 167 - devl_lock(devlink); 168 167 switch (action) { 169 168 case DEVLINK_RELOAD_ACTION_DRIVER_REINIT: 170 169 mlx5_unload_one_devl_locked(dev); ··· 180 181 ret = -EOPNOTSUPP; 181 182 } 182 183 183 - devl_unlock(devlink); 184 184 return ret; 185 185 } 186 186 ··· 190 192 struct mlx5_core_dev *dev = devlink_priv(devlink); 191 193 int ret = 0; 192 194 193 - devl_lock(devlink); 194 195 *actions_performed = BIT(action); 195 196 switch (action) { 196 197 case DEVLINK_RELOAD_ACTION_DRIVER_REINIT: ··· 208 211 ret = -EOPNOTSUPP; 209 212 } 210 213 211 - devl_unlock(devlink); 212 214 return ret; 213 215 } 214 216
-4
drivers/net/ethernet/mellanox/mlxsw/core.c
··· 1499 1499 if (!(mlxsw_core->bus->features & MLXSW_BUS_F_RESET)) 1500 1500 return -EOPNOTSUPP; 1501 1501 1502 - devl_lock(devlink); 1503 1502 mlxsw_core_bus_device_unregister(mlxsw_core, true); 1504 - devl_unlock(devlink); 1505 1503 return 0; 1506 1504 } 1507 1505 ··· 1513 1515 1514 1516 *actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT) | 1515 1517 BIT(DEVLINK_RELOAD_ACTION_FW_ACTIVATE); 1516 - devl_lock(devlink); 1517 1518 err = mlxsw_core_bus_device_register(mlxsw_core->bus_info, 1518 1519 mlxsw_core->bus, 1519 1520 mlxsw_core->bus_priv, true, 1520 1521 devlink, extack); 1521 - devl_unlock(devlink); 1522 1522 return err; 1523 1523 } 1524 1524
-6
drivers/net/netdevsim/dev.c
··· 948 948 { 949 949 struct nsim_dev *nsim_dev = devlink_priv(devlink); 950 950 951 - devl_lock(devlink); 952 951 if (nsim_dev->dont_allow_reload) { 953 952 /* For testing purposes, user set debugfs dont_allow_reload 954 953 * value to true. So forbid it. 955 954 */ 956 955 NL_SET_ERR_MSG_MOD(extack, "User forbid the reload for testing purposes"); 957 - devl_unlock(devlink); 958 956 return -EOPNOTSUPP; 959 957 } 960 958 961 959 nsim_dev_reload_destroy(nsim_dev); 962 - devl_unlock(devlink); 963 960 return 0; 964 961 } 965 962 ··· 967 970 struct nsim_dev *nsim_dev = devlink_priv(devlink); 968 971 int ret; 969 972 970 - devl_lock(devlink); 971 973 if (nsim_dev->fail_reload) { 972 974 /* For testing purposes, user set debugfs fail_reload 973 975 * value to true. Fail right away. 974 976 */ 975 977 NL_SET_ERR_MSG_MOD(extack, "User setup the reload to fail for testing purposes"); 976 - devl_unlock(devlink); 977 978 return -EINVAL; 978 979 } 979 980 980 981 *actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT); 981 982 ret = nsim_dev_reload_create(nsim_dev, extack); 982 - devl_unlock(devlink); 983 983 return ret; 984 984 } 985 985
+5 -13
net/core/devlink.c
··· 768 768 #define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3) 769 769 #define DEVLINK_NL_FLAG_NEED_LINECARD BIT(4) 770 770 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 - 777 771 static int devlink_nl_pre_doit(const struct genl_ops *ops, 778 772 struct sk_buff *skb, struct genl_info *info) 779 773 { ··· 782 788 mutex_unlock(&devlink_mutex); 783 789 return PTR_ERR(devlink); 784 790 } 785 - if (~ops->internal_flags & DEVLINK_NL_FLAG_NO_LOCK) 786 - devl_lock(devlink); 791 + devl_lock(devlink); 787 792 info->user_ptr[0] = devlink; 788 793 if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT) { 789 794 devlink_port = devlink_port_get_from_info(devlink, info); ··· 824 831 return 0; 825 832 826 833 unlock: 827 - if (~ops->internal_flags & DEVLINK_NL_FLAG_NO_LOCK) 828 - devl_unlock(devlink); 834 + devl_unlock(devlink); 829 835 devlink_put(devlink); 830 836 mutex_unlock(&devlink_mutex); 831 837 return err; ··· 841 849 linecard = info->user_ptr[1]; 842 850 devlink_linecard_put(linecard); 843 851 } 844 - if (~ops->internal_flags & DEVLINK_NL_FLAG_NO_LOCK) 845 - devl_unlock(devlink); 852 + devl_unlock(devlink); 846 853 devlink_put(devlink); 847 854 mutex_unlock(&devlink_mutex); 848 855 } ··· 9405 9414 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 9406 9415 .doit = devlink_nl_cmd_reload, 9407 9416 .flags = GENL_ADMIN_PERM, 9408 - .internal_flags = DEVLINK_NL_FLAG_NO_LOCK, 9409 9417 }, 9410 9418 { 9411 9419 .cmd = DEVLINK_CMD_PARAM_GET, ··· 12497 12507 mutex_lock(&devlink_mutex); 12498 12508 devlinks_xa_for_each_registered_get(net, index, devlink) { 12499 12509 WARN_ON(!(devlink->features & DEVLINK_F_RELOAD)); 12510 + mutex_lock(&devlink->lock); 12500 12511 err = devlink_reload(devlink, &init_net, 12501 12512 DEVLINK_RELOAD_ACTION_DRIVER_REINIT, 12502 12513 DEVLINK_RELOAD_LIMIT_UNSPEC, 12503 12514 &actions_performed, NULL); 12515 + mutex_unlock(&devlink->lock); 12504 12516 if (err && err != -EOPNOTSUPP) 12505 12517 pr_warn("Failed to reload devlink instance into init_net\n"); 12506 12518 devlink_put(devlink);