RDMA/hns: Fix memory leak of bonding resources
Subsystems (2)
Junxian Huang
maintainerPATCH v2 1/1 RDMA/hns: Fix memory leak of bonding resources
In a corner case of concurrent driver removal and driver reset, bonding resource is first released in hns_roce_hw_v2_exit() during driver removal, and then is allocated again in hns_roce_register_device() during driver reset. This leads to memory leak because the release timing has already passed. This may also lead to a kernel panic as below because of the leaked notifier callback:
Call trace: 0xffffa20fccc04978 (P) raw_notifier_call_chain+0x20/0x38 call_netdevice_notifiers_info+0x60/0xb8 netdev_lower_state_changed+0x4c/0xb8
As Sashiko suggested, the teardown order of bonding resources should be inverted to make sure the resources are released when the driver is removed.
---
v2:
* Invert the teardown order of bonding resources as suggested by
Jason and Sashiko.
v1: https://lore.kernel.org/linux-rdma/[email protected]/
--- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +1 -1
@@ -7654,8 +7654,8 @@ static int __init hns_roce_hw_v2_init(void) static void __exit hns_roce_hw_v2_exit(void) { -hns_roce_dealloc_bond_grp ();hnae3_unregister_client (&hns_roce_hw_v2_client); +hns_roce_dealloc_bond_grp ();hns_roce_cleanup_debugfs (); }
--
2.33.0
Quoted 17 lines · Junxian Huang
In a corner case of concurrent driver removal and driver reset, bonding resource is first released in
hns_roce_hw_v2_exit()during driver removal, and then is allocated again inhns_roce_register_device()during driver reset. This leads to memory leak because the release timing has already passed. This may also lead to a kernel panic as below because of the leaked notifier callback:Call trace: 0xffffa20fccc04978 (P) raw_notifier_call_chain+0x20/0x38 call_netdevice_notifiers_info+0x60/0xb8 netdev_lower_state_changed+0x4c/0xb8As Sashiko suggested, the teardown order of bonding resources should be inverted to make sure the resources are released when the driver is removed.
Quoted 5 lines
Fixes b37ad2e290fc ("RDMA/hns: Initialize bonding resources")Signed-off-by Junxian Huang <[email protected]>--- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to for-next, thanks
Jason