From: Shay Drory mlx5_ldev_add_mdev() would add a newly probed device to the LAG even when the LAG is already active, mutating membership while getters may be iterating it and while the active mapping assumes a fixed member set. A LAG of VFs/SFs is the only one whose members come independently of its activation. Reject the join of a virt LAG capable function when the group's virt LAG is active. The device stays out of the LAG until it is reprobed and the LAG is disabled. The other join paths cannot reach an active LAG. A LAG of PFs is activated only once all the PFs of the card are members, so there is no further PF that could join it, and SD secondaries join at load, before MPESW can be enabled. Hence the check is limited to virt LAG capable functions, and it is a no-op for existing configurations. In addition, do not register the eswitch devcom component of such a device, so it does not pair with the eswitches of the LAG members. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Mark Bloch Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 4 ++++ drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c | 9 +++++++++ drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c index 474784131091..1323114ce7f9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c @@ -3572,6 +3572,10 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw, xa_init(&esw->offloads.peer_flows); mutex_init(&esw->offloads.peer_mutex); + /* do not pair a virt LAG capable VF/SF that is not part of a LAG */ + if (!mlx5_core_is_pf(esw->dev) && mlx5_virt_lag_nonmember(esw->dev)) + return; + if (!MLX5_CAP_ESW(esw->dev, merged_eswitch)) return; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c index 3e88b3f51612..abcab76fced0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c @@ -2448,6 +2448,11 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev) mutex_unlock(&ldev->lock); return -EAGAIN; } + + if (mlx5_virt_lag_is_supported(dev) && __mlx5_lag_is_active(ldev)) { + mutex_unlock(&ldev->lock); + return -EOPNOTSUPP; + } mlx5_ldev_get(ldev); err = mlx5_ldev_add_mdev(ldev, dev, 0); if (err) { @@ -2536,6 +2541,10 @@ void mlx5_lag_add_mdev(struct mlx5_core_dev *dev) err = __mlx5_lag_dev_add_mdev(dev); mlx5_devcom_comp_unlock(dev->priv.hca_devcom_comp); + if (err == -EOPNOTSUPP) { + mlx5_lag_unregister_hca_devcom_comp(dev); + return; + } if (err) { msleep(100); goto recheck; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h index 330f5ab83a18..61afccba68ca 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h @@ -271,6 +271,11 @@ static inline void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) {} static inline void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) {} #endif +static inline bool mlx5_virt_lag_nonmember(struct mlx5_core_dev *dev) +{ + return mlx5_virt_lag_is_supported(dev) && !mlx5_lag_dev(dev); +} + static inline bool mlx5_lag_is_supported(struct mlx5_core_dev *dev) { if (!MLX5_CAP_GEN(dev, vport_group_manager) || -- 2.44.0