Skip to content

Commit fbdd004

Browse files
paravmellanoxjgunthorpe
authored andcommitted
RDMA/mlx5: Fix devlink deadlock on net namespace deletion
When a mlx5 core devlink instance is reloaded in different net namespace, its associated IB device is deleted and recreated. Example sequence is: $ ip netns add foo $ devlink dev reload pci/0000:00:08.0 netns foo $ ip netns del foo mlx5 IB device needs to attach and detach the netdevice to it through the netdev notifier chain during load and unload sequence. A below call graph of the unload flow. cleanup_net() down_read(&pernet_ops_rwsem); <- first sem acquired ops_pre_exit_list() pre_exit() devlink_pernet_pre_exit() devlink_reload() mlx5_devlink_reload_down() mlx5_unload_one() [...] mlx5_ib_remove() mlx5_ib_unbind_slave_port() mlx5_remove_netdev_notifier() unregister_netdevice_notifier() down_write(&pernet_ops_rwsem);<- recurrsive lock Hence, when net namespace is deleted, mlx5 reload results in deadlock. When deadlock occurs, devlink mutex is also held. This not only deadlocks the mlx5 device under reload, but all the processes which attempt to access unrelated devlink devices are deadlocked. Hence, fix this by mlx5 ib driver to register for per net netdev notifier instead of global one, which operats on the net namespace without holding the pernet_ops_rwsem. Fixes: 4383cfc ("net/mlx5: Add devlink reload") Link: https://lore.kernel.org/r/20201026134359.23150-1-parav@nvidia.com Signed-off-by: Parav Pandit <parav@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent edebc84 commit fbdd004

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎drivers/infiniband/hw/mlx5/main.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,8 @@ static int mlx5_add_netdev_notifier(struct mlx5_ib_dev *dev, u8 port_num)
33053305
int err;
33063306

33073307
dev->port[port_num].roce.nb.notifier_call = mlx5_netdev_event;
3308-
err = register_netdevice_notifier(&dev->port[port_num].roce.nb);
3308+
err = register_netdevice_notifier_net(mlx5_core_net(dev->mdev),
3309+
&dev->port[port_num].roce.nb);
33093310
if (err) {
33103311
dev->port[port_num].roce.nb.notifier_call = NULL;
33113312
return err;
@@ -3317,7 +3318,8 @@ static int mlx5_add_netdev_notifier(struct mlx5_ib_dev *dev, u8 port_num)
33173318
static void mlx5_remove_netdev_notifier(struct mlx5_ib_dev *dev, u8 port_num)
33183319
{
33193320
if (dev->port[port_num].roce.nb.notifier_call) {
3320-
unregister_netdevice_notifier(&dev->port[port_num].roce.nb);
3321+
unregister_netdevice_notifier_net(mlx5_core_net(dev->mdev),
3322+
&dev->port[port_num].roce.nb);
33213323
dev->port[port_num].roce.nb.notifier_call = NULL;
33223324
}
33233325
}

‎drivers/net/ethernet/mellanox/mlx5/core/lib/mlx5.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,4 @@ int mlx5_create_encryption_key(struct mlx5_core_dev *mdev,
9090
u32 key_type, u32 *p_key_id);
9191
void mlx5_destroy_encryption_key(struct mlx5_core_dev *mdev, u32 key_id);
9292

93-
static inline struct net *mlx5_core_net(struct mlx5_core_dev *dev)
94-
{
95-
return devlink_net(priv_to_devlink(dev));
96-
}
97-
9893
#endif

‎include/linux/mlx5/driver.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,4 +1213,22 @@ static inline bool mlx5_is_roce_enabled(struct mlx5_core_dev *dev)
12131213
return val.vbool;
12141214
}
12151215

1216+
/**
1217+
* mlx5_core_net - Provide net namespace of the mlx5_core_dev
1218+
* @dev: mlx5 core device
1219+
*
1220+
* mlx5_core_net() returns the net namespace of mlx5 core device.
1221+
* This can be called only in below described limited context.
1222+
* (a) When a devlink instance for mlx5_core is registered and
1223+
* when devlink reload operation is disabled.
1224+
* or
1225+
* (b) during devlink reload reload_down() and reload_up callbacks
1226+
* where it is ensured that devlink instance's net namespace is
1227+
* stable.
1228+
*/
1229+
static inline struct net *mlx5_core_net(struct mlx5_core_dev *dev)
1230+
{
1231+
return devlink_net(priv_to_devlink(dev));
1232+
}
1233+
12161234
#endif /* MLX5_DRIVER_H */

0 commit comments

Comments
 (0)