Commit bfc54866 authored by Paolo Abeni's avatar Paolo Abeni

Merge branch 'mlx5-devlink-mutex-removal-part-1'

Moshe Shemesh Says:
===================
1) Fix devlink lock in mlx5 devlink eswitch callbacks

Following the commit 14e426bf "devlink: hold the instance lock
during eswitch_mode callbacks" which takes devlink instance lock for all
devlink eswitch callbacks and adds a temporary workaround, this patchset
removes the workaround, replaces devlink API functions by devl_ API
where called from mlx5 driver eswitch callbacks flows and adds devlink
instance lock in other driver's path that leads to these functions.
While moving to devl_ API the patchset removes part of the devlink API
functions which mlx5 was the last one to use and so not used by any
driver now.

The patchset also remove DEVLINK_NL_FLAG_NO_LOCK flag from the callbacks
of port_new/port which are called only from mlx5 driver and the already
locked by the patchset as parallel paths to the eswitch callbacks using
devl_ API functions.

This patchset will be followed by another patchset that will remove
DEVLINK_NL_FLAG_NO_LOCK flag from devlink reload and devlink health
callbacks. Thus we will have all devlink callbacks locked and it will
pave the way to remove devlink mutex.
===================

Link: https://lore.kernel.org/r/20220711081408.69452-1-saeed@kernel.orgSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 2afe4647 f0680ef0
...@@ -335,13 +335,16 @@ static void del_adev(struct auxiliary_device *adev) ...@@ -335,13 +335,16 @@ static void del_adev(struct auxiliary_device *adev)
int mlx5_attach_device(struct mlx5_core_dev *dev) int mlx5_attach_device(struct mlx5_core_dev *dev)
{ {
struct devlink *devlink = priv_to_devlink(dev);
struct mlx5_priv *priv = &dev->priv; struct mlx5_priv *priv = &dev->priv;
struct auxiliary_device *adev; struct auxiliary_device *adev;
struct auxiliary_driver *adrv; struct auxiliary_driver *adrv;
int ret = 0, i; int ret = 0, i;
devl_lock(devlink);
mutex_lock(&mlx5_intf_mutex); mutex_lock(&mlx5_intf_mutex);
priv->flags &= ~MLX5_PRIV_FLAGS_DETACH; priv->flags &= ~MLX5_PRIV_FLAGS_DETACH;
priv->flags |= MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW;
for (i = 0; i < ARRAY_SIZE(mlx5_adev_devices); i++) { for (i = 0; i < ARRAY_SIZE(mlx5_adev_devices); i++) {
if (!priv->adev[i]) { if (!priv->adev[i]) {
bool is_supported = false; bool is_supported = false;
...@@ -389,19 +392,24 @@ int mlx5_attach_device(struct mlx5_core_dev *dev) ...@@ -389,19 +392,24 @@ int mlx5_attach_device(struct mlx5_core_dev *dev)
break; break;
} }
} }
priv->flags &= ~MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW;
mutex_unlock(&mlx5_intf_mutex); mutex_unlock(&mlx5_intf_mutex);
devl_unlock(devlink);
return ret; return ret;
} }
void mlx5_detach_device(struct mlx5_core_dev *dev) void mlx5_detach_device(struct mlx5_core_dev *dev)
{ {
struct devlink *devlink = priv_to_devlink(dev);
struct mlx5_priv *priv = &dev->priv; struct mlx5_priv *priv = &dev->priv;
struct auxiliary_device *adev; struct auxiliary_device *adev;
struct auxiliary_driver *adrv; struct auxiliary_driver *adrv;
pm_message_t pm = {}; pm_message_t pm = {};
int i; int i;
devl_lock(devlink);
mutex_lock(&mlx5_intf_mutex); mutex_lock(&mlx5_intf_mutex);
priv->flags |= MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW;
for (i = ARRAY_SIZE(mlx5_adev_devices) - 1; i >= 0; i--) { for (i = ARRAY_SIZE(mlx5_adev_devices) - 1; i >= 0; i--) {
if (!priv->adev[i]) if (!priv->adev[i])
continue; continue;
...@@ -430,18 +438,24 @@ void mlx5_detach_device(struct mlx5_core_dev *dev) ...@@ -430,18 +438,24 @@ void mlx5_detach_device(struct mlx5_core_dev *dev)
del_adev(&priv->adev[i]->adev); del_adev(&priv->adev[i]->adev);
priv->adev[i] = NULL; priv->adev[i] = NULL;
} }
priv->flags &= ~MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW;
priv->flags |= MLX5_PRIV_FLAGS_DETACH; priv->flags |= MLX5_PRIV_FLAGS_DETACH;
mutex_unlock(&mlx5_intf_mutex); mutex_unlock(&mlx5_intf_mutex);
devl_unlock(devlink);
} }
int mlx5_register_device(struct mlx5_core_dev *dev) int mlx5_register_device(struct mlx5_core_dev *dev)
{ {
struct devlink *devlink;
int ret; int ret;
devlink = priv_to_devlink(dev);
devl_lock(devlink);
mutex_lock(&mlx5_intf_mutex); mutex_lock(&mlx5_intf_mutex);
dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV; dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV;
ret = mlx5_rescan_drivers_locked(dev); ret = mlx5_rescan_drivers_locked(dev);
mutex_unlock(&mlx5_intf_mutex); mutex_unlock(&mlx5_intf_mutex);
devl_unlock(devlink);
if (ret) if (ret)
mlx5_unregister_device(dev); mlx5_unregister_device(dev);
...@@ -450,10 +464,15 @@ int mlx5_register_device(struct mlx5_core_dev *dev) ...@@ -450,10 +464,15 @@ int mlx5_register_device(struct mlx5_core_dev *dev)
void mlx5_unregister_device(struct mlx5_core_dev *dev) void mlx5_unregister_device(struct mlx5_core_dev *dev)
{ {
struct devlink *devlink;
devlink = priv_to_devlink(dev);
devl_lock(devlink);
mutex_lock(&mlx5_intf_mutex); mutex_lock(&mlx5_intf_mutex);
dev->priv.flags = MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV; dev->priv.flags = MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV;
mlx5_rescan_drivers_locked(dev); mlx5_rescan_drivers_locked(dev);
mutex_unlock(&mlx5_intf_mutex); mutex_unlock(&mlx5_intf_mutex);
devl_unlock(devlink);
} }
static int add_drivers(struct mlx5_core_dev *dev) static int add_drivers(struct mlx5_core_dev *dev)
...@@ -526,16 +545,22 @@ static void delete_drivers(struct mlx5_core_dev *dev) ...@@ -526,16 +545,22 @@ static void delete_drivers(struct mlx5_core_dev *dev)
int mlx5_rescan_drivers_locked(struct mlx5_core_dev *dev) int mlx5_rescan_drivers_locked(struct mlx5_core_dev *dev)
{ {
struct mlx5_priv *priv = &dev->priv; struct mlx5_priv *priv = &dev->priv;
int err = 0;
lockdep_assert_held(&mlx5_intf_mutex); lockdep_assert_held(&mlx5_intf_mutex);
if (priv->flags & MLX5_PRIV_FLAGS_DETACH) if (priv->flags & MLX5_PRIV_FLAGS_DETACH)
return 0; return 0;
priv->flags |= MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW;
delete_drivers(dev); delete_drivers(dev);
if (priv->flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV) if (priv->flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)
return 0; goto out;
err = add_drivers(dev);
return add_drivers(dev); out:
priv->flags &= ~MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW;
return err;
} }
bool mlx5_same_hw_devs(struct mlx5_core_dev *dev, struct mlx5_core_dev *peer_dev) bool mlx5_same_hw_devs(struct mlx5_core_dev *dev, struct mlx5_core_dev *peer_dev)
......
...@@ -21,6 +21,7 @@ int mlx5e_devlink_port_register(struct mlx5e_priv *priv) ...@@ -21,6 +21,7 @@ int mlx5e_devlink_port_register(struct mlx5e_priv *priv)
struct netdev_phys_item_id ppid = {}; struct netdev_phys_item_id ppid = {};
struct devlink_port *dl_port; struct devlink_port *dl_port;
unsigned int dl_port_index; unsigned int dl_port_index;
int ret;
if (mlx5_core_is_pf(priv->mdev)) { if (mlx5_core_is_pf(priv->mdev)) {
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
...@@ -41,7 +42,13 @@ int mlx5e_devlink_port_register(struct mlx5e_priv *priv) ...@@ -41,7 +42,13 @@ int mlx5e_devlink_port_register(struct mlx5e_priv *priv)
memset(dl_port, 0, sizeof(*dl_port)); memset(dl_port, 0, sizeof(*dl_port));
devlink_port_attrs_set(dl_port, &attrs); devlink_port_attrs_set(dl_port, &attrs);
return devlink_port_register(devlink, dl_port, dl_port_index); if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW))
devl_lock(devlink);
ret = devl_port_register(devlink, dl_port, dl_port_index);
if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW))
devl_unlock(devlink);
return ret;
} }
void mlx5e_devlink_port_type_eth_set(struct mlx5e_priv *priv) void mlx5e_devlink_port_type_eth_set(struct mlx5e_priv *priv)
...@@ -54,8 +61,13 @@ void mlx5e_devlink_port_type_eth_set(struct mlx5e_priv *priv) ...@@ -54,8 +61,13 @@ void mlx5e_devlink_port_type_eth_set(struct mlx5e_priv *priv)
void mlx5e_devlink_port_unregister(struct mlx5e_priv *priv) void mlx5e_devlink_port_unregister(struct mlx5e_priv *priv)
{ {
struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv); struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv);
struct devlink *devlink = priv_to_devlink(priv->mdev);
devlink_port_unregister(dl_port); if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW))
devl_lock(devlink);
devl_port_unregister(dl_port);
if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW))
devl_unlock(devlink);
} }
struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev) struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
......
...@@ -87,11 +87,11 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_ ...@@ -87,11 +87,11 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_
devlink = priv_to_devlink(dev); devlink = priv_to_devlink(dev);
dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num); dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num);
err = devlink_port_register(devlink, dl_port, dl_port_index); err = devl_port_register(devlink, dl_port, dl_port_index);
if (err) if (err)
goto reg_err; goto reg_err;
err = devlink_rate_leaf_create(dl_port, vport); err = devl_rate_leaf_create(dl_port, vport);
if (err) if (err)
goto rate_err; goto rate_err;
...@@ -99,7 +99,7 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_ ...@@ -99,7 +99,7 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_
return 0; return 0;
rate_err: rate_err:
devlink_port_unregister(dl_port); devl_port_unregister(dl_port);
reg_err: reg_err:
mlx5_esw_dl_port_free(dl_port); mlx5_esw_dl_port_free(dl_port);
return err; return err;
...@@ -118,10 +118,10 @@ void mlx5_esw_offloads_devlink_port_unregister(struct mlx5_eswitch *esw, u16 vpo ...@@ -118,10 +118,10 @@ void mlx5_esw_offloads_devlink_port_unregister(struct mlx5_eswitch *esw, u16 vpo
if (vport->dl_port->devlink_rate) { if (vport->dl_port->devlink_rate) {
mlx5_esw_qos_vport_update_group(esw, vport, NULL, NULL); mlx5_esw_qos_vport_update_group(esw, vport, NULL, NULL);
devlink_rate_leaf_destroy(vport->dl_port); devl_rate_leaf_destroy(vport->dl_port);
} }
devlink_port_unregister(vport->dl_port); devl_port_unregister(vport->dl_port);
mlx5_esw_dl_port_free(vport->dl_port); mlx5_esw_dl_port_free(vport->dl_port);
vport->dl_port = NULL; vport->dl_port = NULL;
} }
...@@ -156,11 +156,11 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_p ...@@ -156,11 +156,11 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_p
devlink_port_attrs_pci_sf_set(dl_port, controller, pfnum, sfnum, !!controller); devlink_port_attrs_pci_sf_set(dl_port, controller, pfnum, sfnum, !!controller);
devlink = priv_to_devlink(dev); devlink = priv_to_devlink(dev);
dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num); dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num);
err = devlink_port_register(devlink, dl_port, dl_port_index); err = devl_port_register(devlink, dl_port, dl_port_index);
if (err) if (err)
return err; return err;
err = devlink_rate_leaf_create(dl_port, vport); err = devl_rate_leaf_create(dl_port, vport);
if (err) if (err)
goto rate_err; goto rate_err;
...@@ -168,7 +168,7 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_p ...@@ -168,7 +168,7 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_p
return 0; return 0;
rate_err: rate_err:
devlink_port_unregister(dl_port); devl_port_unregister(dl_port);
return err; return err;
} }
...@@ -182,9 +182,9 @@ void mlx5_esw_devlink_sf_port_unregister(struct mlx5_eswitch *esw, u16 vport_num ...@@ -182,9 +182,9 @@ void mlx5_esw_devlink_sf_port_unregister(struct mlx5_eswitch *esw, u16 vport_num
if (vport->dl_port->devlink_rate) { if (vport->dl_port->devlink_rate) {
mlx5_esw_qos_vport_update_group(esw, vport, NULL, NULL); mlx5_esw_qos_vport_update_group(esw, vport, NULL, NULL);
devlink_rate_leaf_destroy(vport->dl_port); devl_rate_leaf_destroy(vport->dl_port);
} }
devlink_port_unregister(vport->dl_port); devl_port_unregister(vport->dl_port);
vport->dl_port = NULL; vport->dl_port = NULL;
} }
...@@ -1296,6 +1296,7 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int num_vfs) ...@@ -1296,6 +1296,7 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int num_vfs)
*/ */
int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs) int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs)
{ {
struct devlink *devlink;
bool toggle_lag; bool toggle_lag;
int ret; int ret;
...@@ -1307,6 +1308,8 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs) ...@@ -1307,6 +1308,8 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs)
if (toggle_lag) if (toggle_lag)
mlx5_lag_disable_change(esw->dev); mlx5_lag_disable_change(esw->dev);
devlink = priv_to_devlink(esw->dev);
devl_lock(devlink);
down_write(&esw->mode_lock); down_write(&esw->mode_lock);
if (!mlx5_esw_is_fdb_created(esw)) { if (!mlx5_esw_is_fdb_created(esw)) {
ret = mlx5_eswitch_enable_locked(esw, num_vfs); ret = mlx5_eswitch_enable_locked(esw, num_vfs);
...@@ -1320,6 +1323,7 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs) ...@@ -1320,6 +1323,7 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs)
esw->esw_funcs.num_vfs = num_vfs; esw->esw_funcs.num_vfs = num_vfs;
} }
up_write(&esw->mode_lock); up_write(&esw->mode_lock);
devl_unlock(devlink);
if (toggle_lag) if (toggle_lag)
mlx5_lag_enable_change(esw->dev); mlx5_lag_enable_change(esw->dev);
...@@ -1330,9 +1334,13 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs) ...@@ -1330,9 +1334,13 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs)
/* When disabling sriov, free driver level resources. */ /* When disabling sriov, free driver level resources. */
void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf) void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf)
{ {
struct devlink *devlink;
if (!mlx5_esw_allowed(esw)) if (!mlx5_esw_allowed(esw))
return; return;
devlink = priv_to_devlink(esw->dev);
devl_lock(devlink);
down_write(&esw->mode_lock); down_write(&esw->mode_lock);
/* If driver is unloaded, this function is called twice by remove_one() /* If driver is unloaded, this function is called twice by remove_one()
* and mlx5_unload(). Prevent the second call. * and mlx5_unload(). Prevent the second call.
...@@ -1354,13 +1362,14 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf) ...@@ -1354,13 +1362,14 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf)
struct devlink *devlink = priv_to_devlink(esw->dev); struct devlink *devlink = priv_to_devlink(esw->dev);
esw_offloads_del_send_to_vport_meta_rules(esw); esw_offloads_del_send_to_vport_meta_rules(esw);
devlink_rate_nodes_destroy(devlink); devl_rate_nodes_destroy(devlink);
} }
esw->esw_funcs.num_vfs = 0; esw->esw_funcs.num_vfs = 0;
unlock: unlock:
up_write(&esw->mode_lock); up_write(&esw->mode_lock);
devl_unlock(devlink);
} }
/* Free resources for corresponding eswitch mode. It is called by devlink /* Free resources for corresponding eswitch mode. It is called by devlink
...@@ -1389,18 +1398,23 @@ void mlx5_eswitch_disable_locked(struct mlx5_eswitch *esw) ...@@ -1389,18 +1398,23 @@ void mlx5_eswitch_disable_locked(struct mlx5_eswitch *esw)
mlx5_esw_acls_ns_cleanup(esw); mlx5_esw_acls_ns_cleanup(esw);
if (esw->mode == MLX5_ESWITCH_OFFLOADS) if (esw->mode == MLX5_ESWITCH_OFFLOADS)
devlink_rate_nodes_destroy(devlink); devl_rate_nodes_destroy(devlink);
} }
void mlx5_eswitch_disable(struct mlx5_eswitch *esw) void mlx5_eswitch_disable(struct mlx5_eswitch *esw)
{ {
struct devlink *devlink;
if (!mlx5_esw_allowed(esw)) if (!mlx5_esw_allowed(esw))
return; return;
mlx5_lag_disable_change(esw->dev); mlx5_lag_disable_change(esw->dev);
devlink = priv_to_devlink(esw->dev);
devl_lock(devlink);
down_write(&esw->mode_lock); down_write(&esw->mode_lock);
mlx5_eswitch_disable_locked(esw); mlx5_eswitch_disable_locked(esw);
up_write(&esw->mode_lock); up_write(&esw->mode_lock);
devl_unlock(devlink);
mlx5_lag_enable_change(esw->dev); mlx5_lag_enable_change(esw->dev);
} }
......
...@@ -3064,6 +3064,7 @@ static void esw_offloads_steering_cleanup(struct mlx5_eswitch *esw) ...@@ -3064,6 +3064,7 @@ static void esw_offloads_steering_cleanup(struct mlx5_eswitch *esw)
static void static void
esw_vfs_changed_event_handler(struct mlx5_eswitch *esw, const u32 *out) esw_vfs_changed_event_handler(struct mlx5_eswitch *esw, const u32 *out)
{ {
struct devlink *devlink;
bool host_pf_disabled; bool host_pf_disabled;
u16 new_num_vfs; u16 new_num_vfs;
...@@ -3075,6 +3076,8 @@ esw_vfs_changed_event_handler(struct mlx5_eswitch *esw, const u32 *out) ...@@ -3075,6 +3076,8 @@ esw_vfs_changed_event_handler(struct mlx5_eswitch *esw, const u32 *out)
if (new_num_vfs == esw->esw_funcs.num_vfs || host_pf_disabled) if (new_num_vfs == esw->esw_funcs.num_vfs || host_pf_disabled)
return; return;
devlink = priv_to_devlink(esw->dev);
devl_lock(devlink);
/* Number of VFs can only change from "0 to x" or "x to 0". */ /* Number of VFs can only change from "0 to x" or "x to 0". */
if (esw->esw_funcs.num_vfs > 0) { if (esw->esw_funcs.num_vfs > 0) {
mlx5_eswitch_unload_vf_vports(esw, esw->esw_funcs.num_vfs); mlx5_eswitch_unload_vf_vports(esw, esw->esw_funcs.num_vfs);
...@@ -3087,6 +3090,7 @@ esw_vfs_changed_event_handler(struct mlx5_eswitch *esw, const u32 *out) ...@@ -3087,6 +3090,7 @@ esw_vfs_changed_event_handler(struct mlx5_eswitch *esw, const u32 *out)
return; return;
} }
esw->esw_funcs.num_vfs = new_num_vfs; esw->esw_funcs.num_vfs = new_num_vfs;
devl_unlock(devlink);
} }
static void esw_functions_changed_event_handler(struct work_struct *work) static void esw_functions_changed_event_handler(struct work_struct *work)
...@@ -3342,27 +3346,6 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode) ...@@ -3342,27 +3346,6 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode)
return 0; return 0;
} }
/* 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.
*/
static void mlx5_eswtich_mode_callback_enter(struct devlink *devlink,
struct mlx5_eswitch *esw)
{
devl_unlock(devlink);
down_write(&esw->mode_lock);
}
static void mlx5_eswtich_mode_callback_exit(struct devlink *devlink,
struct mlx5_eswitch *esw)
{
up_write(&esw->mode_lock);
devl_lock(devlink);
}
int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
...@@ -3377,15 +3360,6 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, ...@@ -3377,15 +3360,6 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
if (esw_mode_from_devlink(mode, &mlx5_mode)) if (esw_mode_from_devlink(mode, &mlx5_mode))
return -EINVAL; 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); mlx5_lag_disable_change(esw->dev);
err = mlx5_esw_try_lock(esw); err = mlx5_esw_try_lock(esw);
if (err < 0) { if (err < 0) {
...@@ -3418,7 +3392,6 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, ...@@ -3418,7 +3392,6 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
mlx5_esw_unlock(esw); mlx5_esw_unlock(esw);
enable_lag: enable_lag:
mlx5_lag_enable_change(esw->dev); mlx5_lag_enable_change(esw->dev);
devl_lock(devlink);
return err; return err;
} }
...@@ -3431,9 +3404,9 @@ int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode) ...@@ -3431,9 +3404,9 @@ int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode)
if (IS_ERR(esw)) if (IS_ERR(esw))
return PTR_ERR(esw); return PTR_ERR(esw);
mlx5_eswtich_mode_callback_enter(devlink, esw); down_write(&esw->mode_lock);
err = esw_mode_to_devlink(esw->mode, mode); err = esw_mode_to_devlink(esw->mode, mode);
mlx5_eswtich_mode_callback_exit(devlink, esw); up_write(&esw->mode_lock);
return err; return err;
} }
...@@ -3480,7 +3453,7 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode, ...@@ -3480,7 +3453,7 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode,
if (IS_ERR(esw)) if (IS_ERR(esw))
return PTR_ERR(esw); return PTR_ERR(esw);
mlx5_eswtich_mode_callback_enter(devlink, esw); down_write(&esw->mode_lock);
switch (MLX5_CAP_ETH(dev, wqe_inline_mode)) { switch (MLX5_CAP_ETH(dev, wqe_inline_mode)) {
case MLX5_CAP_INLINE_MODE_NOT_REQUIRED: case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
...@@ -3514,11 +3487,11 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode, ...@@ -3514,11 +3487,11 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode,
goto out; goto out;
esw->offloads.inline_mode = mlx5_mode; esw->offloads.inline_mode = mlx5_mode;
mlx5_eswtich_mode_callback_exit(devlink, esw); up_write(&esw->mode_lock);
return 0; return 0;
out: out:
mlx5_eswtich_mode_callback_exit(devlink, esw); up_write(&esw->mode_lock);
return err; return err;
} }
...@@ -3531,9 +3504,9 @@ int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode) ...@@ -3531,9 +3504,9 @@ int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode)
if (IS_ERR(esw)) if (IS_ERR(esw))
return PTR_ERR(esw); return PTR_ERR(esw);
mlx5_eswtich_mode_callback_enter(devlink, esw); down_write(&esw->mode_lock);
err = esw_inline_mode_to_devlink(esw->offloads.inline_mode, mode); err = esw_inline_mode_to_devlink(esw->offloads.inline_mode, mode);
mlx5_eswtich_mode_callback_exit(devlink, esw); up_write(&esw->mode_lock);
return err; return err;
} }
...@@ -3549,7 +3522,7 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, ...@@ -3549,7 +3522,7 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
if (IS_ERR(esw)) if (IS_ERR(esw))
return PTR_ERR(esw); return PTR_ERR(esw);
mlx5_eswtich_mode_callback_enter(devlink, esw); down_write(&esw->mode_lock);
if (encap != DEVLINK_ESWITCH_ENCAP_MODE_NONE && if (encap != DEVLINK_ESWITCH_ENCAP_MODE_NONE &&
(!MLX5_CAP_ESW_FLOWTABLE_FDB(dev, reformat) || (!MLX5_CAP_ESW_FLOWTABLE_FDB(dev, reformat) ||
...@@ -3592,7 +3565,7 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, ...@@ -3592,7 +3565,7 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
} }
unlock: unlock:
mlx5_eswtich_mode_callback_exit(devlink, esw); up_write(&esw->mode_lock);
return err; return err;
} }
...@@ -3605,9 +3578,9 @@ int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink, ...@@ -3605,9 +3578,9 @@ int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink,
if (IS_ERR(esw)) if (IS_ERR(esw))
return PTR_ERR(esw); return PTR_ERR(esw);
mlx5_eswtich_mode_callback_enter(devlink, esw); down_write(&esw->mode_lock);
*encap = esw->offloads.encap; *encap = esw->offloads.encap;
mlx5_eswtich_mode_callback_exit(devlink, esw); up_write(&esw->mode_lock);
return 0; return 0;
} }
......
...@@ -551,6 +551,10 @@ enum { ...@@ -551,6 +551,10 @@ enum {
* creation/deletion on drivers rescan. Unset during device attach. * creation/deletion on drivers rescan. Unset during device attach.
*/ */
MLX5_PRIV_FLAGS_DETACH = 1 << 2, MLX5_PRIV_FLAGS_DETACH = 1 << 2,
/* Distinguish between mlx5e_probe/remove called by module init/cleanup
* and called by other flows which can already hold devlink lock
*/
MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW = 1 << 3,
}; };
struct mlx5_adev { struct mlx5_adev {
......
...@@ -1569,9 +1569,6 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro ...@@ -1569,9 +1569,6 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
u32 controller, u16 pf, u32 sf, u32 controller, u16 pf, u32 sf,
bool external); bool external);
int devlink_rate_leaf_create(struct devlink_port *port, void *priv);
void devlink_rate_leaf_destroy(struct devlink_port *devlink_port);
void devlink_rate_nodes_destroy(struct devlink *devlink);
void devlink_port_linecard_set(struct devlink_port *devlink_port, void devlink_port_linecard_set(struct devlink_port *devlink_port,
struct devlink_linecard *linecard); struct devlink_linecard *linecard);
struct devlink_linecard * struct devlink_linecard *
......
...@@ -1712,7 +1712,7 @@ static int devlink_port_new_notifiy(struct devlink *devlink, ...@@ -1712,7 +1712,7 @@ static int devlink_port_new_notifiy(struct devlink *devlink,
if (!msg) if (!msg)
return -ENOMEM; return -ENOMEM;
mutex_lock(&devlink->lock); lockdep_assert_held(&devlink->lock);
devlink_port = devlink_port_get_by_index(devlink, port_index); devlink_port = devlink_port_get_by_index(devlink, port_index);
if (!devlink_port) { if (!devlink_port) {
err = -ENODEV; err = -ENODEV;
...@@ -1725,11 +1725,9 @@ static int devlink_port_new_notifiy(struct devlink *devlink, ...@@ -1725,11 +1725,9 @@ static int devlink_port_new_notifiy(struct devlink *devlink,
goto out; goto out;
err = genlmsg_reply(msg, info); err = genlmsg_reply(msg, info);
mutex_unlock(&devlink->lock);
return err; return err;
out: out:
mutex_unlock(&devlink->lock);
nlmsg_free(msg); nlmsg_free(msg);
return err; return err;
} }
...@@ -9067,13 +9065,11 @@ static const struct genl_small_ops devlink_nl_ops[] = { ...@@ -9067,13 +9065,11 @@ static const struct genl_small_ops devlink_nl_ops[] = {
.cmd = DEVLINK_CMD_PORT_NEW, .cmd = DEVLINK_CMD_PORT_NEW,
.doit = devlink_nl_cmd_port_new_doit, .doit = devlink_nl_cmd_port_new_doit,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
}, },
{ {
.cmd = DEVLINK_CMD_PORT_DEL, .cmd = DEVLINK_CMD_PORT_DEL,
.doit = devlink_nl_cmd_port_del_doit, .doit = devlink_nl_cmd_port_del_doit,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
}, },
{ {
.cmd = DEVLINK_CMD_LINECARD_GET, .cmd = DEVLINK_CMD_LINECARD_GET,
...@@ -10006,20 +10002,13 @@ int devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv) ...@@ -10006,20 +10002,13 @@ int devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv)
} }
EXPORT_SYMBOL_GPL(devl_rate_leaf_create); EXPORT_SYMBOL_GPL(devl_rate_leaf_create);
int /**
devlink_rate_leaf_create(struct devlink_port *devlink_port, void *priv) * devl_rate_leaf_destroy - destroy devlink rate leaf
{ *
struct devlink *devlink = devlink_port->devlink; * @devlink_port: devlink port linked to the rate object
int ret; *
* Destroy the devlink rate object of type leaf on provided @devlink_port.
mutex_lock(&devlink->lock); */
ret = devl_rate_leaf_create(devlink_port, priv);
mutex_unlock(&devlink->lock);
return ret;
}
EXPORT_SYMBOL_GPL(devlink_rate_leaf_create);
void devl_rate_leaf_destroy(struct devlink_port *devlink_port) void devl_rate_leaf_destroy(struct devlink_port *devlink_port)
{ {
struct devlink_rate *devlink_rate = devlink_port->devlink_rate; struct devlink_rate *devlink_rate = devlink_port->devlink_rate;
...@@ -10037,27 +10026,6 @@ void devl_rate_leaf_destroy(struct devlink_port *devlink_port) ...@@ -10037,27 +10026,6 @@ void devl_rate_leaf_destroy(struct devlink_port *devlink_port)
} }
EXPORT_SYMBOL_GPL(devl_rate_leaf_destroy); EXPORT_SYMBOL_GPL(devl_rate_leaf_destroy);
/**
* devlink_rate_leaf_destroy - destroy devlink rate leaf
*
* @devlink_port: devlink port linked to the rate object
*
* Context: Takes and release devlink->lock <mutex>.
*/
void devlink_rate_leaf_destroy(struct devlink_port *devlink_port)
{
struct devlink_rate *devlink_rate = devlink_port->devlink_rate;
struct devlink *devlink = devlink_port->devlink;
if (!devlink_rate)
return;
mutex_lock(&devlink->lock);
devl_rate_leaf_destroy(devlink_port);
mutex_unlock(&devlink->lock);
}
EXPORT_SYMBOL_GPL(devlink_rate_leaf_destroy);
/** /**
* devl_rate_nodes_destroy - destroy all devlink rate nodes on device * devl_rate_nodes_destroy - destroy all devlink rate nodes on device
* @devlink: devlink instance * @devlink: devlink instance
...@@ -10095,24 +10063,6 @@ void devl_rate_nodes_destroy(struct devlink *devlink) ...@@ -10095,24 +10063,6 @@ void devl_rate_nodes_destroy(struct devlink *devlink)
} }
EXPORT_SYMBOL_GPL(devl_rate_nodes_destroy); EXPORT_SYMBOL_GPL(devl_rate_nodes_destroy);
/**
* devlink_rate_nodes_destroy - destroy all devlink rate nodes on device
*
* @devlink: devlink instance
*
* Unset parent for all rate objects and destroy all rate nodes
* on specified device.
*
* Context: Takes and release devlink->lock <mutex>.
*/
void devlink_rate_nodes_destroy(struct devlink *devlink)
{
mutex_lock(&devlink->lock);
devl_rate_nodes_destroy(devlink);
mutex_unlock(&devlink->lock);
}
EXPORT_SYMBOL_GPL(devlink_rate_nodes_destroy);
/** /**
* devlink_port_linecard_set - Link port with a linecard * devlink_port_linecard_set - Link port with a linecard
* *
......
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