Skip to content

Commit 2a4f56f

Browse files
Jianbo Liukuba-moo
authored andcommitted
net/mlx5e: Keep netdev when leave switchdev for devlink set legacy only
In the cited commit, when changing from switchdev to legacy mode, uplink representor's netdev is kept, and its profile is replaced with nic profile, so netdev is detached from old profile, then attach to new profile. During profile change, the hardware resources allocated by the old profile will be cleaned up. However, the cleanup is relying on the related kernel modules. And they may need to flush themselves first, which is triggered by netdev events, for example, NETDEV_UNREGISTER. However, netdev is kept, or netdev_register is called after the cleanup, which may cause troubles because the resources are still referred by kernel modules. The same process applies to all the caes when uplink is leaving switchdev mode, including devlink eswitch mode set legacy, driver unload and devlink reload. For the first one, it can be blocked and returns failure to users, whenever possible. But it's hard for the others. Besides, the attachment to nic profile is unnecessary as the netdev will be unregistered anyway for such cases. So in this patch, the original behavior is kept only for devlink eswitch set mode legacy. For the others, moves netdev unregistration before the profile change. Fixes: 7a9fb35 ("net/mlx5e: Do not reload ethernet ports when changing eswitch mode") Signed-off-by: Jianbo Liu <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5a03b36 commit 2a4f56f

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6542,8 +6542,23 @@ static void _mlx5e_remove(struct auxiliary_device *adev)
65426542

65436543
mlx5_core_uplink_netdev_set(mdev, NULL);
65446544
mlx5e_dcbnl_delete_app(priv);
6545-
unregister_netdev(priv->netdev);
6546-
_mlx5e_suspend(adev, false);
6545+
/* When unload driver, the netdev is in registered state
6546+
* if it's from legacy mode. If from switchdev mode, it
6547+
* is already unregistered before changing to NIC profile.
6548+
*/
6549+
if (priv->netdev->reg_state == NETREG_REGISTERED) {
6550+
unregister_netdev(priv->netdev);
6551+
_mlx5e_suspend(adev, false);
6552+
} else {
6553+
struct mlx5_core_dev *pos;
6554+
int i;
6555+
6556+
if (test_bit(MLX5E_STATE_DESTROYING, &priv->state))
6557+
mlx5_sd_for_each_dev(i, mdev, pos)
6558+
mlx5e_destroy_mdev_resources(pos);
6559+
else
6560+
_mlx5e_suspend(adev, true);
6561+
}
65476562
/* Avoid cleanup if profile rollback failed. */
65486563
if (priv->profile)
65496564
priv->profile->cleanup(priv);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,21 @@ mlx5e_vport_uplink_rep_unload(struct mlx5e_rep_priv *rpriv)
15091509

15101510
priv = netdev_priv(netdev);
15111511

1512+
/* This bit is set when using devlink to change eswitch mode from
1513+
* switchdev to legacy. As need to keep uplink netdev ifindex, we
1514+
* detach uplink representor profile and attach NIC profile only.
1515+
* The netdev will be unregistered later when unload NIC auxiliary
1516+
* driver for this case.
1517+
* We explicitly block devlink eswitch mode change if any IPSec rules
1518+
* offloaded, but can't block other cases, such as driver unload
1519+
* and devlink reload. We have to unregister netdev before profile
1520+
* change for those cases. This is to avoid resource leak because
1521+
* the offloaded rules don't have the chance to be unoffloaded before
1522+
* cleanup which is triggered by detach uplink representor profile.
1523+
*/
1524+
if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_SWITCH_LEGACY))
1525+
unregister_netdev(netdev);
1526+
15121527
mlx5e_netdev_attach_nic_profile(priv);
15131528
}
15141529

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,6 +3777,8 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
37773777
esw->eswitch_operation_in_progress = true;
37783778
up_write(&esw->mode_lock);
37793779

3780+
if (mode == DEVLINK_ESWITCH_MODE_LEGACY)
3781+
esw->dev->priv.flags |= MLX5_PRIV_FLAGS_SWITCH_LEGACY;
37803782
mlx5_eswitch_disable_locked(esw);
37813783
if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV) {
37823784
if (mlx5_devlink_trap_get_num_active(esw->dev)) {

include/linux/mlx5/driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ enum {
524524
* creation/deletion on drivers rescan. Unset during device attach.
525525
*/
526526
MLX5_PRIV_FLAGS_DETACH = 1 << 2,
527+
MLX5_PRIV_FLAGS_SWITCH_LEGACY = 1 << 3,
527528
};
528529

529530
struct mlx5_adev {

0 commit comments

Comments
 (0)