Infiniband clients must be attached and detached in a specific order in ibcore.

Currently the linking order of the infiniband, IB, modules decide in which
order the clients are attached and detached. For example one IB client may
use resources from another IB client. This can lead to a potential deadlock
at shutdown. For example if the ipoib is unregistered after the ib_multicast
client is detached, then if ipoib is using multicast addresses a deadlock may
happen, because ib_multicast will wait for all its resources to be freed before
returning from the remove method.

Fix this by using module_xxx_order() instead of module_xxx().

Differential Revision:	https://reviews.freebsd.org/D23973
MFC after:		1 week
Sponsored by:		Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2020-07-06 08:50:11 +00:00
parent 6a7ff0600b
commit 1866c98e64
18 changed files with 52 additions and 35 deletions

View File

@ -4218,8 +4218,8 @@ static void __exit mlx4_cleanup(void)
destroy_workqueue(mlx4_wq); destroy_workqueue(mlx4_wq);
} }
module_init(mlx4_init); module_init_order(mlx4_init, SI_ORDER_FIRST);
module_exit(mlx4_cleanup); module_exit_order(mlx4_cleanup, SI_ORDER_FIRST);
static int static int
mlx4_evhand(module_t mod, int event, void *arg) mlx4_evhand(module_t mod, int event, void *arg)

View File

@ -304,8 +304,8 @@ static void __exit mlx4_en_cleanup(void)
mlx4_unregister_interface(&mlx4_en_interface); mlx4_unregister_interface(&mlx4_en_interface);
} }
module_init(mlx4_en_init); module_init_order(mlx4_en_init, SI_ORDER_SIXTH);
module_exit(mlx4_en_cleanup); module_exit_order(mlx4_en_cleanup, SI_ORDER_SIXTH);
static int static int
mlx4en_evhand(module_t mod, int event, void *arg) mlx4en_evhand(module_t mod, int event, void *arg)

View File

@ -3319,8 +3319,8 @@ static void __exit mlx4_ib_cleanup(void)
destroy_workqueue(wq); destroy_workqueue(wq);
} }
module_init_order(mlx4_ib_init, SI_ORDER_THIRD); module_init_order(mlx4_ib_init, SI_ORDER_SEVENTH);
module_exit(mlx4_ib_cleanup); module_exit_order(mlx4_ib_cleanup, SI_ORDER_SEVENTH);
static int static int
mlx4ib_evhand(module_t mod, int event, void *arg) mlx4ib_evhand(module_t mod, int event, void *arg)

View File

@ -2026,5 +2026,5 @@ static void __exit cleanup(void)
pci_unregister_driver(&mlx5_core_driver); pci_unregister_driver(&mlx5_core_driver);
} }
module_init(init); module_init_order(init, SI_ORDER_FIRST);
module_exit(cleanup); module_exit_order(cleanup, SI_ORDER_FIRST);

View File

@ -4723,8 +4723,8 @@ mlx5e_show_version(void __unused *arg)
} }
SYSINIT(mlx5e_show_version, SI_SUB_DRIVERS, SI_ORDER_ANY, mlx5e_show_version, NULL); SYSINIT(mlx5e_show_version, SI_SUB_DRIVERS, SI_ORDER_ANY, mlx5e_show_version, NULL);
module_init_order(mlx5e_init, SI_ORDER_THIRD); module_init_order(mlx5e_init, SI_ORDER_SIXTH);
module_exit_order(mlx5e_cleanup, SI_ORDER_THIRD); module_exit_order(mlx5e_cleanup, SI_ORDER_SIXTH);
#if (__FreeBSD_version >= 1100000) #if (__FreeBSD_version >= 1100000)
MODULE_DEPEND(mlx5en, linuxkpi, 1, 1, 1); MODULE_DEPEND(mlx5en, linuxkpi, 1, 1, 1);

View File

@ -139,5 +139,5 @@ static void __exit mlx5_fpga_tools_exit(void)
mlx5_fpga_tools_char_deinit(); mlx5_fpga_tools_char_deinit();
} }
module_init(mlx5_fpga_tools_init); module_init_order(mlx5_fpga_tools_init, SI_ORDER_SECOND);
module_exit(mlx5_fpga_tools_exit); module_exit_order(mlx5_fpga_tools_exit, SI_ORDER_SECOND);

View File

@ -3399,5 +3399,5 @@ mlx5_ib_show_version(void __unused *arg)
} }
SYSINIT(mlx5_ib_show_version, SI_SUB_DRIVERS, SI_ORDER_ANY, mlx5_ib_show_version, NULL); SYSINIT(mlx5_ib_show_version, SI_SUB_DRIVERS, SI_ORDER_ANY, mlx5_ib_show_version, NULL);
module_init_order(mlx5_ib_init, SI_ORDER_THIRD); module_init_order(mlx5_ib_init, SI_ORDER_SEVENTH);
module_exit_order(mlx5_ib_cleanup, SI_ORDER_THIRD); module_exit_order(mlx5_ib_cleanup, SI_ORDER_SEVENTH);

View File

@ -1271,8 +1271,8 @@ static void __exit mthca_cleanup(void)
mthca_catas_cleanup(); mthca_catas_cleanup();
} }
module_init_order(mthca_init, SI_ORDER_THIRD); module_init_order(mthca_init, SI_ORDER_SEVENTH);
module_exit(mthca_cleanup); module_exit_order(mthca_cleanup, SI_ORDER_SEVENTH);
MODULE_VERSION(mthca, 1); MODULE_VERSION(mthca, 1);
MODULE_DEPEND(mthca, ibcore, 1, 1, 1); MODULE_DEPEND(mthca, ibcore, 1, 1, 1);

View File

@ -4180,5 +4180,5 @@ static void __exit ib_cm_cleanup(void)
} }
module_init_order(ib_cm_init, SI_ORDER_SECOND); module_init_order(ib_cm_init, SI_ORDER_SECOND);
module_exit_order(ib_cm_cleanup, SI_ORDER_FIRST); module_exit_order(ib_cm_cleanup, SI_ORDER_SECOND);

View File

@ -4619,5 +4619,5 @@ static void __exit cma_cleanup(void)
destroy_workqueue(cma_wq); destroy_workqueue(cma_wq);
} }
module_init(cma_init); module_init_order(cma_init, SI_ORDER_FOURTH);
module_exit(cma_cleanup); module_exit_order(cma_cleanup, SI_ORDER_FOURTH);

View File

@ -1060,8 +1060,25 @@ static void __exit ib_core_cleanup(void)
destroy_workqueue(ib_wq); destroy_workqueue(ib_wq);
} }
module_init(ib_core_init); /*
module_exit(ib_core_cleanup); * Typical loading and unloading order values and their use:
*
* SI_ORDER_FIRST (default for module_init):
* Core modules (PCI, infiniband)
* SI_ORDER_SECOND (default for module_exit):
* Infiniband core modules (CM)
* SI_ORDER_THIRD:
* SI_ORDER_FOURTH:
* Infiniband core modules (CMA)
* SI_ORDER_FIFTH:
* Infiniband user-space modules (UCM,UCMA,UMAD,UVERBS,IPOIB)
* SI_ORDER_SIXTH:
* Network HW driver modules
* SI_ORDER_SEVENTH:
* Infiniband HW driver modules
*/
module_init_order(ib_core_init, SI_ORDER_FIRST);
module_exit_order(ib_core_cleanup, SI_ORDER_FIRST);
MODULE_VERSION(ibcore, 1); MODULE_VERSION(ibcore, 1);
MODULE_DEPEND(ibcore, linuxkpi, 1, 1, 1); MODULE_DEPEND(ibcore, linuxkpi, 1, 1, 1);

View File

@ -1052,5 +1052,5 @@ static void __exit iw_cm_cleanup(void)
destroy_workqueue(iwcm_wq); destroy_workqueue(iwcm_wq);
} }
module_init(iw_cm_init); module_init_order(iw_cm_init, SI_ORDER_FIRST);
module_exit(iw_cm_cleanup); module_exit_order(iw_cm_cleanup, SI_ORDER_FIRST);

View File

@ -1371,5 +1371,5 @@ static void __exit ib_ucm_cleanup(void)
idr_destroy(&ctx_id_table); idr_destroy(&ctx_id_table);
} }
module_init_order(ib_ucm_init, SI_ORDER_THIRD); module_init_order(ib_ucm_init, SI_ORDER_FIFTH);
module_exit(ib_ucm_cleanup); module_exit_order(ib_ucm_cleanup, SI_ORDER_FIFTH);

View File

@ -1782,5 +1782,5 @@ static void __exit ucma_cleanup(void)
idr_destroy(&multicast_idr); idr_destroy(&multicast_idr);
} }
module_init(ucma_init); module_init_order(ucma_init, SI_ORDER_FIFTH);
module_exit(ucma_cleanup); module_exit_order(ucma_cleanup, SI_ORDER_FIFTH);

View File

@ -1405,5 +1405,5 @@ static void __exit ib_umad_cleanup(void)
unregister_chrdev_region(overflow_maj, IB_UMAD_MAX_PORTS * 2); unregister_chrdev_region(overflow_maj, IB_UMAD_MAX_PORTS * 2);
} }
module_init_order(ib_umad_init, SI_ORDER_THIRD); module_init_order(ib_umad_init, SI_ORDER_FIFTH);
module_exit(ib_umad_cleanup); module_exit_order(ib_umad_cleanup, SI_ORDER_FIFTH);

View File

@ -1431,5 +1431,5 @@ static void __exit ib_uverbs_cleanup(void)
idr_destroy(&ib_uverbs_srq_idr); idr_destroy(&ib_uverbs_srq_idr);
} }
module_init_order(ib_uverbs_init, SI_ORDER_THIRD); module_init_order(ib_uverbs_init, SI_ORDER_FIFTH);
module_exit(ib_uverbs_cleanup); module_exit_order(ib_uverbs_cleanup, SI_ORDER_FIFTH);

View File

@ -1753,8 +1753,8 @@ ipoib_resolvemulti(struct ifnet *ifp, struct sockaddr **llsa,
} }
} }
module_init(ipoib_init_module); module_init_order(ipoib_init_module, SI_ORDER_FIFTH);
module_exit(ipoib_cleanup_module); module_exit_order(ipoib_cleanup_module, SI_ORDER_FIFTH);
static int static int
ipoib_evhand(module_t mod, int event, void *arg) ipoib_evhand(module_t mod, int event, void *arg)

View File

@ -594,5 +594,5 @@ static void __exit ib_madeye_cleanup(void)
ib_unregister_client(&madeye_client); ib_unregister_client(&madeye_client);
} }
module_init(ib_madeye_init); module_init_order(ib_madeye_init, SI_ORDER_THIRD);
module_exit(ib_madeye_cleanup); module_exit_order(ib_madeye_cleanup, SI_ORDER_THIRD);