Skip to content

Commit 92e5995

Browse files
IronShenkuba-moo
authored andcommitted
net: hns3: fix oops when unload drivers paralleling
When unload hclge driver, it tries to disable sriov first for each ae_dev node from hnae3_ae_dev_list. If user unloads hns3 driver at the time, because it removes all the ae_dev nodes, and it may cause oops. But we can't simply use hnae3_common_lock for this. Because in the process flow of pci_disable_sriov(), it will trigger the remove flow of VF, which will also take hnae3_common_lock. To fixes it, introduce a new mutex to protect the unload process. Fixes: 0dd8a25 ("net: hns3: disable sriov before unload hclge layer") Signed-off-by: Jian Shen <[email protected]> Signed-off-by: Jijie Shao <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ba1af25 commit 92e5995

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

drivers/net/ethernet/hisilicon/hns3/hnae3.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ EXPORT_SYMBOL(hnae3_unregister_ae_algo_prepare);
4040
*/
4141
static DEFINE_MUTEX(hnae3_common_lock);
4242

43+
/* ensure the drivers being unloaded one by one */
44+
static DEFINE_MUTEX(hnae3_unload_lock);
45+
46+
void hnae3_acquire_unload_lock(void)
47+
{
48+
mutex_lock(&hnae3_unload_lock);
49+
}
50+
EXPORT_SYMBOL(hnae3_acquire_unload_lock);
51+
52+
void hnae3_release_unload_lock(void)
53+
{
54+
mutex_unlock(&hnae3_unload_lock);
55+
}
56+
EXPORT_SYMBOL(hnae3_release_unload_lock);
57+
4358
static bool hnae3_client_match(enum hnae3_client_type client_type)
4459
{
4560
if (client_type == HNAE3_CLIENT_KNIC ||

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,4 +963,6 @@ int hnae3_register_client(struct hnae3_client *client);
963963
void hnae3_set_client_init_flag(struct hnae3_client *client,
964964
struct hnae3_ae_dev *ae_dev,
965965
unsigned int inited);
966+
void hnae3_acquire_unload_lock(void);
967+
void hnae3_release_unload_lock(void);
966968
#endif

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6002,9 +6002,11 @@ module_init(hns3_init_module);
60026002
*/
60036003
static void __exit hns3_exit_module(void)
60046004
{
6005+
hnae3_acquire_unload_lock();
60056006
pci_unregister_driver(&hns3_driver);
60066007
hnae3_unregister_client(&client);
60076008
hns3_dbg_unregister_debugfs();
6009+
hnae3_release_unload_lock();
60086010
}
60096011
module_exit(hns3_exit_module);
60106012

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12919,9 +12919,11 @@ static int __init hclge_init(void)
1291912919

1292012920
static void __exit hclge_exit(void)
1292112921
{
12922+
hnae3_acquire_unload_lock();
1292212923
hnae3_unregister_ae_algo_prepare(&ae_algo);
1292312924
hnae3_unregister_ae_algo(&ae_algo);
1292412925
destroy_workqueue(hclge_wq);
12926+
hnae3_release_unload_lock();
1292512927
}
1292612928
module_init(hclge_init);
1292712929
module_exit(hclge_exit);

drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,8 +3410,10 @@ static int __init hclgevf_init(void)
34103410

34113411
static void __exit hclgevf_exit(void)
34123412
{
3413+
hnae3_acquire_unload_lock();
34133414
hnae3_unregister_ae_algo(&ae_algovf);
34143415
destroy_workqueue(hclgevf_wq);
3416+
hnae3_release_unload_lock();
34153417
}
34163418
module_init(hclgevf_init);
34173419
module_exit(hclgevf_exit);

0 commit comments

Comments
 (0)