Skip to content

Commit 2ae8c7e

Browse files
shayshyikuba-moo
authored andcommitted
net/mlx5: Fix Unbinding uplink-netdev in switchdev mode
It is possible to unbind the uplink ETH driver while the E-Switch is in switchdev mode. This leads to netdevice reference counting issues[1], as the driver removal path was not designed to clean up from this state. During uplink ETH driver removal (_mlx5e_remove), the code now waits for any concurrent E-Switch mode transition to finish. It then removes the REPs auxiliary device, if exists. This ensures a graceful cleanup. [1] unregister_netdevice: waiting for eth2 to become free. Usage count = 2 ref_tracker: netdev@00000000c912e04b has 1/1 users at ib_device_set_netdev+0x130/0x270 [ib_core] mlx5_ib_vport_rep_load+0xf4/0x3e0 [mlx5_ib] mlx5_esw_offloads_rep_load+0xc7/0xe0 [mlx5_core] esw_offloads_enable+0x583/0x900 [mlx5_core] mlx5_eswitch_enable_locked+0x1b2/0x290 [mlx5_core] mlx5_devlink_eswitch_mode_set+0x107/0x3e0 [mlx5_core] devlink_nl_eswitch_set_doit+0x60/0xd0 genl_family_rcv_msg_doit+0xe0/0x130 genl_rcv_msg+0x183/0x290 netlink_rcv_skb+0x4b/0xf0 genl_rcv+0x24/0x40 netlink_unicast+0x255/0x380 netlink_sendmsg+0x1f3/0x420 __sock_sendmsg+0x38/0x60 __sys_sendto+0x119/0x180 __x64_sys_sendto+0x20/0x30 Fixes: 7a9fb35 ("net/mlx5e: Do not reload ethernet ports when changing eswitch mode") Signed-off-by: Shay Drory <shayd@nvidia.com> Reviewed-by: Mark Bloch <mbloch@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/1769411695-18820-2-git-send-email-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e9acda5 commit 2ae8c7e

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,17 @@ bool mlx5_same_hw_devs(struct mlx5_core_dev *dev, struct mlx5_core_dev *peer_dev
575575
return plen && flen && flen == plen &&
576576
!memcmp(fsystem_guid, psystem_guid, flen);
577577
}
578+
579+
void mlx5_core_reps_aux_devs_remove(struct mlx5_core_dev *dev)
580+
{
581+
struct mlx5_priv *priv = &dev->priv;
582+
583+
if (priv->adev[MLX5_INTERFACE_PROTOCOL_ETH])
584+
device_lock_assert(&priv->adev[MLX5_INTERFACE_PROTOCOL_ETH]->adev.dev);
585+
else
586+
mlx5_core_err(dev, "ETH driver already removed\n");
587+
if (priv->adev[MLX5_INTERFACE_PROTOCOL_IB_REP])
588+
del_adev(&priv->adev[MLX5_INTERFACE_PROTOCOL_IB_REP]->adev);
589+
if (priv->adev[MLX5_INTERFACE_PROTOCOL_ETH_REP])
590+
del_adev(&priv->adev[MLX5_INTERFACE_PROTOCOL_ETH_REP]->adev);
591+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6842,6 +6842,7 @@ static void _mlx5e_remove(struct auxiliary_device *adev)
68426842
struct mlx5e_priv *priv = netdev_priv(netdev);
68436843
struct mlx5_core_dev *mdev = edev->mdev;
68446844

6845+
mlx5_eswitch_safe_aux_devs_remove(mdev);
68456846
mlx5_core_uplink_netdev_set(mdev, NULL);
68466847

68476848
if (priv->profile)

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ int mlx5_esw_ipsec_vf_packet_offload_set(struct mlx5_eswitch *esw, struct mlx5_v
929929
int mlx5_esw_ipsec_vf_packet_offload_supported(struct mlx5_core_dev *dev,
930930
u16 vport_num);
931931
bool mlx5_esw_host_functions_enabled(const struct mlx5_core_dev *dev);
932+
void mlx5_eswitch_safe_aux_devs_remove(struct mlx5_core_dev *dev);
932933
#else /* CONFIG_MLX5_ESWITCH */
933934
/* eswitch API stubs */
934935
static inline int mlx5_eswitch_init(struct mlx5_core_dev *dev) { return 0; }
@@ -1012,6 +1013,9 @@ mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhca_id)
10121013
return false;
10131014
}
10141015

1016+
static inline void
1017+
mlx5_eswitch_safe_aux_devs_remove(struct mlx5_core_dev *dev) {}
1018+
10151019
#endif /* CONFIG_MLX5_ESWITCH */
10161020

10171021
#endif /* __MLX5_ESWITCH_H__ */

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,6 +3981,32 @@ static bool mlx5_devlink_switchdev_active_mode_change(struct mlx5_eswitch *esw,
39813981
return true;
39823982
}
39833983

3984+
#define MLX5_ESW_HOLD_TIMEOUT_MS 7000
3985+
#define MLX5_ESW_HOLD_RETRY_DELAY_MS 500
3986+
3987+
void mlx5_eswitch_safe_aux_devs_remove(struct mlx5_core_dev *dev)
3988+
{
3989+
unsigned long timeout;
3990+
bool hold_esw = true;
3991+
3992+
/* Wait for any concurrent eswitch mode transition to complete. */
3993+
if (!mlx5_esw_hold(dev)) {
3994+
timeout = jiffies + msecs_to_jiffies(MLX5_ESW_HOLD_TIMEOUT_MS);
3995+
while (!mlx5_esw_hold(dev)) {
3996+
if (!time_before(jiffies, timeout)) {
3997+
hold_esw = false;
3998+
break;
3999+
}
4000+
msleep(MLX5_ESW_HOLD_RETRY_DELAY_MS);
4001+
}
4002+
}
4003+
if (hold_esw) {
4004+
if (mlx5_eswitch_mode(dev) == MLX5_ESWITCH_OFFLOADS)
4005+
mlx5_core_reps_aux_devs_remove(dev);
4006+
mlx5_esw_release(dev);
4007+
}
4008+
}
4009+
39844010
int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
39854011
struct netlink_ext_ack *extack)
39864012
{

drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ int mlx5_register_device(struct mlx5_core_dev *dev);
290290
void mlx5_unregister_device(struct mlx5_core_dev *dev);
291291
void mlx5_dev_set_lightweight(struct mlx5_core_dev *dev);
292292
bool mlx5_dev_is_lightweight(struct mlx5_core_dev *dev);
293+
void mlx5_core_reps_aux_devs_remove(struct mlx5_core_dev *dev);
293294

294295
void mlx5_fw_reporters_create(struct mlx5_core_dev *dev);
295296
int mlx5_query_mtpps(struct mlx5_core_dev *dev, u32 *mtpps, u32 mtpps_size);

0 commit comments

Comments
 (0)