RDMA/mlx5: Track netdev to avoid deadlock during netdev notifier unregister
authorJiri Pirko <jiri@nvidia.com>
Tue, 1 Nov 2022 14:36:01 +0000 (15:36 +0100)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 9 Feb 2023 04:40:57 +0000 (20:40 -0800)
commitdca55da0a15717dde509d17163946e951bad56c4
tree2ca0c18b8531afaaa229ec7237506fa3d5afc674
parentc7d4e6ab3165693342c21f6faf80d983137fee0c
RDMA/mlx5: Track netdev to avoid deadlock during netdev notifier unregister

When removing a network namespace with mlx5 devlink instance being in
it, following callchain is performed:

cleanup_net (takes down_read(&pernet_ops_rwsem)
devlink_pernet_pre_exit()
devlink_reload()
mlx5_devlink_reload_down()
mlx5_unload_one_devl_locked()
mlx5_detach_device()
del_adev()
mlx5r_remove()
__mlx5_ib_remove()
mlx5_ib_roce_cleanup()
mlx5_remove_netdev_notifier()
unregister_netdevice_notifier (takes down_write(&pernet_ops_rwsem)

This deadlocks.

Resolve this by converting to register_netdevice_notifier_dev_net()
which does not take pernet_ops_rwsem and moves the notifier block around
according to netdev it takes as arg.

Use previously introduced netdev added/removed events to track uplink
netdev to be used for register_netdevice_notifier_dev_net() purposes.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mlx5/mlx5_ib.h
drivers/net/ethernet/mellanox/mlx5/core/events.c