Skip to content

Commit de85624

Browse files
Jianbo Liugregkh
authored andcommitted
net/mlx5e: Keep netdev when leave switchdev for devlink set legacy only
[ Upstream commit 2a4f56f ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 47c78d3 commit de85624

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
@@ -6510,8 +6510,23 @@ static void _mlx5e_remove(struct auxiliary_device *adev)
65106510

65116511
mlx5_core_uplink_netdev_set(mdev, NULL);
65126512
mlx5e_dcbnl_delete_app(priv);
6513-
unregister_netdev(priv->netdev);
6514-
_mlx5e_suspend(adev, false);
6513+
/* When unload driver, the netdev is in registered state
6514+
* if it's from legacy mode. If from switchdev mode, it
6515+
* is already unregistered before changing to NIC profile.
6516+
*/
6517+
if (priv->netdev->reg_state == NETREG_REGISTERED) {
6518+
unregister_netdev(priv->netdev);
6519+
_mlx5e_suspend(adev, false);
6520+
} else {
6521+
struct mlx5_core_dev *pos;
6522+
int i;
6523+
6524+
if (test_bit(MLX5E_STATE_DESTROYING, &priv->state))
6525+
mlx5_sd_for_each_dev(i, mdev, pos)
6526+
mlx5e_destroy_mdev_resources(pos);
6527+
else
6528+
_mlx5e_suspend(adev, true);
6529+
}
65156530
/* Avoid cleanup if profile rollback failed. */
65166531
if (priv->profile)
65176532
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
@@ -1508,6 +1508,21 @@ mlx5e_vport_uplink_rep_unload(struct mlx5e_rep_priv *rpriv)
15081508

15091509
priv = netdev_priv(netdev);
15101510

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

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

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

3762+
if (mode == DEVLINK_ESWITCH_MODE_LEGACY)
3763+
esw->dev->priv.flags |= MLX5_PRIV_FLAGS_SWITCH_LEGACY;
37623764
mlx5_eswitch_disable_locked(esw);
37633765
if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV) {
37643766
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
@@ -555,6 +555,7 @@ enum {
555555
* creation/deletion on drivers rescan. Unset during device attach.
556556
*/
557557
MLX5_PRIV_FLAGS_DETACH = 1 << 2,
558+
MLX5_PRIV_FLAGS_SWITCH_LEGACY = 1 << 3,
558559
};
559560

560561
struct mlx5_adev {

0 commit comments

Comments
 (0)