net/mlx5: Remove devl_unlock from mlx5_devlink_eswitch_mode_set
authorMoshe Shemesh <moshe@nvidia.com>
Mon, 11 Jul 2022 08:14:07 +0000 (01:14 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 12 Jul 2022 08:26:23 +0000 (10:26 +0200)
The callback mlx5_devlink_eswitch_mode_set() had unlocked devlink as a
temporary workaround once devlink instance lock was added to devlink
eswitch callbacks. Now that all flows triggered by this function
that took devlink lock are using devl_ API and all parallel paths are
locked we can remove this workaround.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index ccda3a0a25942fc77c2b945694e9d615bb3fd119..d3da52e3fc677fff57ba1cfe4253cc09ca2d5200 100644 (file)
@@ -2177,10 +2177,8 @@ out_free:
 static int esw_offloads_start(struct mlx5_eswitch *esw,
                              struct netlink_ext_ack *extack)
 {
-       struct devlink *devlink = priv_to_devlink(esw->dev);
        int err, err1;
 
-       devl_lock(devlink);
        esw->mode = MLX5_ESWITCH_OFFLOADS;
        err = mlx5_eswitch_enable_locked(esw, esw->dev->priv.sriov.num_vfs);
        if (err) {
@@ -2202,7 +2200,6 @@ static int esw_offloads_start(struct mlx5_eswitch *esw,
                                           "Inline mode is different between vports");
                }
        }
-       devl_unlock(devlink);
        return err;
 }
 
@@ -3243,10 +3240,8 @@ err_metadata:
 static int esw_offloads_stop(struct mlx5_eswitch *esw,
                             struct netlink_ext_ack *extack)
 {
-       struct devlink *devlink = priv_to_devlink(esw->dev);
        int err, err1;
 
-       devl_lock(devlink);
        esw->mode = MLX5_ESWITCH_LEGACY;
        err = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_IGNORE_NUM_VFS);
        if (err) {
@@ -3258,7 +3253,6 @@ static int esw_offloads_stop(struct mlx5_eswitch *esw,
                                           "Failed setting eswitch back to offloads");
                }
        }
-       devl_unlock(devlink);
 
        return err;
 }
@@ -3366,15 +3360,6 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
        if (esw_mode_from_devlink(mode, &mlx5_mode))
                return -EINVAL;
 
-       /* FIXME: devl_unlock() followed by devl_lock() inside driver callback
-        * is never correct and prone to races. It's a transitional workaround,
-        * never repeat this pattern.
-        *
-        * This code MUST be fixed before removing devlink_mutex as it is safe
-        * to do only because of that mutex.
-        */
-       devl_unlock(devlink);
-
        mlx5_lag_disable_change(esw->dev);
        err = mlx5_esw_try_lock(esw);
        if (err < 0) {
@@ -3387,9 +3372,7 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
        if (cur_mlx5_mode == mlx5_mode)
                goto unlock;
 
-       devl_lock(devlink);
        mlx5_eswitch_disable_locked(esw);
-       devl_unlock(devlink);
        if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV) {
                if (mlx5_devlink_trap_get_num_active(esw->dev)) {
                        NL_SET_ERR_MSG_MOD(extack,
@@ -3400,9 +3383,7 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
                err = esw_offloads_start(esw, extack);
        } else if (mode == DEVLINK_ESWITCH_MODE_LEGACY) {
                err = esw_offloads_stop(esw, extack);
-               devl_lock(devlink);
                mlx5_rescan_drivers(esw->dev);
-               devl_unlock(devlink);
        } else {
                err = -EINVAL;
        }
@@ -3411,7 +3392,6 @@ unlock:
        mlx5_esw_unlock(esw);
 enable_lag:
        mlx5_lag_enable_change(esw->dev);
-       devl_lock(devlink);
        return err;
 }