Skip to content

Commit 47fb3c1

Browse files
shirazsaleemdledford
authored andcommitted
i40iw: Prevent multiple netdev event notifier registrations
Netdev event notifier registration/de-registration is not synchronized with a lock and there is a possibility of a duplicate registration of notifier before the unregister completes. Register netdev event notifiers during module init and de-register them at module exit. This avoids the need to tie the registration to first netdev client interface open and de-registration to last client interface close and the synchronization to achieve it. This also fixes a crash due to duplicate registration. BUG: unable to handle kernel paging request at ffffffffa0d60388 IP: [<ffffffff8160f75d>] notifier_call_chain+0x3d/0x70 PGD 190d067 PUD 190e063 PMD 76c840067 PTE 0 Oops: 0000 [#1] SMP Modules linked in: i40e(OF-) fuse btrfs zlib_deflate raid6_pq xor vfat msdos [..] e1000e vxlan ip_tunnel ptp pps_core i2c_core video [last unloaded: i40iw] CPU: 1 PID: 27101 Comm: modprobe Tainted: GF W O-------------- 3.10.0-229.el7.x86_64 #1 Hardware name: Gigabyte Technology Co., Ltd. To be filled by O.E.M./Q87M-D2H, BIOS F7 01/17/2014 task: ffff88076e8a96c0 ti: ffff8806959c8000 task.ti: ffff8806959c8000 RIP: 0010:[<ffffffff8160f75d>] [<ffffffff8160f75d>] notifier_call_chain+0x3d/0x70 RSP: 0018:ffff8806959cbb38 EFLAGS: 00010282 RAX: ffffffffa0d60380 RBX: 00000000fffffffd RCX: 0000000000000000 0708] RDX: 0000000000000000 RSI: ffff88081227a000 RDI: 0000000000000002 RBP: ffff8806959cbb60 R08: 0000000000000246 R09: 000000000000700c R10: ffff88080e16ea40 R11: 00000000000ae8df R12: ffffffffa0d60380 R13: 0000000000000002 R14: ffff88076e738800 R15: 0000000000000000 FS: 00007f604ef4a740(0000) GS:ffff88083e240000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffffa0d60388 CR3: 0000000753cd2000 CR4: 00000000001407e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Stack: ffffffff819e73a0 0000000000000000 0000000000000002 ffff88076e738800 00000000ffffffff ffff8806959cbba0 ffffffff8109d61d 0000000000000000 0000000000000000 ffff88076e738800 0000000000000000 ffff88076e738800 Call Trace: [<ffffffff8109d61d>] __blocking_notifier_call_chain+0x4d/0x70 [<ffffffff8109d656>] blocking_notifier_call_chain+0x16/0x20 [<ffffffff8156b9e4>] __inet_del_ifa+0x154/0x2b0 [<ffffffff8156d102>] inetdev_event+0x182/0x530 [<ffffffff8160f76c>] notifier_call_chain+0x4c/0x70 [<ffffffff8109d446>] raw_notifier_call_chain+0x16/0x20 [<ffffffff814f71fd>] call_netdevice_notifiers+0x2d/0x60 [<ffffffff814f8845>] rollback_registered_many+0x105/0x220 [<ffffffff814f89a0>] rollback_registered+0x40/0x70 [<ffffffff814f9c88>] unregister_netdevice_queue+0x48/0x80 [<ffffffff814f9cdc>] unregister_netdev+0x1c/0x30 [<ffffffffa0067139>] i40e_vsi_release+0x2a9/0x2b0 [i40e] [<ffffffffa00674e8>] i40e_remove+0x128/0x2b0 [i40e] [<ffffffff813092db>] pci_device_remove+0x3b/0xb0 [<ffffffff813d26ef>] __device_release_driver+0x7f/0xf0 [<ffffffff813d3068>] driver_detach+0xb8/0xc0 [<ffffffff813d22db>] bus_remove_driver+0x9b/0x120 [<ffffffff813d36dc>] driver_unregister+0x2c/0x50 [<ffffffff81307d4c>] pci_unregister_driver+0x2c/0x90 [<ffffffffa008f9d0>] i40e_exit_module+0x10/0x23 [i40e] [<ffffffff810dad0b>] SyS_delete_module+0x16b/0x2d0 [<ffffffff81013b0c>] ? do_notify_resume+0x9c/0xb0 [<ffffffff81613da9>] system_call_fastpath+0x16/0x1b Code: e5 41 57 4d 89 c7 41 56 49 89 d6 41 55 49 89 f5 41 54 53 89 cb 75 14 eb 3d 0f 1f 44 00 00 83 eb 01 74 25 4d 85 e4 74 20 4c 89 e0 <4c> 8b 60 08 4c 89 f2 4c 89 ee 48 89 c7 ff 10 4d 85 ff 74 04 41 RIP [<ffffffff8160f75d>] notifier_call_chain+0x3d/0x70 Signed-off-by: Shiraz Saleem <shiraz.saleem@intel.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent cd9100c commit 47fb3c1

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

drivers/infiniband/hw/i40iw/i40iw.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ enum init_completion_state {
201201
CEQ_CREATED,
202202
ILQ_CREATED,
203203
IEQ_CREATED,
204-
INET_NOTIFIER,
205204
IP_ADDR_REGISTERED,
206205
RDMA_DEV_REGISTERED
207206
};

drivers/infiniband/hw/i40iw/i40iw_main.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ static struct notifier_block i40iw_net_notifier = {
9999
.notifier_call = i40iw_net_event
100100
};
101101

102-
static atomic_t i40iw_notifiers_registered;
103-
104102
/**
105103
* i40iw_find_i40e_handler - find a handler given a client info
106104
* @ldev: pointer to a client info
@@ -1376,11 +1374,20 @@ static enum i40iw_status_code i40iw_initialize_dev(struct i40iw_device *iwdev,
13761374
*/
13771375
static void i40iw_register_notifiers(void)
13781376
{
1379-
if (atomic_inc_return(&i40iw_notifiers_registered) == 1) {
1380-
register_inetaddr_notifier(&i40iw_inetaddr_notifier);
1381-
register_inet6addr_notifier(&i40iw_inetaddr6_notifier);
1382-
register_netevent_notifier(&i40iw_net_notifier);
1383-
}
1377+
register_inetaddr_notifier(&i40iw_inetaddr_notifier);
1378+
register_inet6addr_notifier(&i40iw_inetaddr6_notifier);
1379+
register_netevent_notifier(&i40iw_net_notifier);
1380+
}
1381+
1382+
/**
1383+
* i40iw_unregister_notifiers - unregister tcp ip notifiers
1384+
*/
1385+
1386+
static void i40iw_unregister_notifiers(void)
1387+
{
1388+
unregister_netevent_notifier(&i40iw_net_notifier);
1389+
unregister_inetaddr_notifier(&i40iw_inetaddr_notifier);
1390+
unregister_inet6addr_notifier(&i40iw_inetaddr6_notifier);
13841391
}
13851392

13861393
/**
@@ -1467,12 +1474,6 @@ static void i40iw_deinit_device(struct i40iw_device *iwdev)
14671474
if (!iwdev->reset)
14681475
i40iw_del_macip_entry(iwdev, (u8)iwdev->mac_ip_table_idx);
14691476
/* fallthrough */
1470-
case INET_NOTIFIER:
1471-
if (!atomic_dec_return(&i40iw_notifiers_registered)) {
1472-
unregister_netevent_notifier(&i40iw_net_notifier);
1473-
unregister_inetaddr_notifier(&i40iw_inetaddr_notifier);
1474-
unregister_inet6addr_notifier(&i40iw_inetaddr6_notifier);
1475-
}
14761477
/* fallthrough */
14771478
case PBLE_CHUNK_MEM:
14781479
i40iw_destroy_pble_pool(dev, iwdev->pble_rsrc);
@@ -1672,8 +1673,6 @@ static int i40iw_open(struct i40e_info *ldev, struct i40e_client *client)
16721673
break;
16731674
iwdev->init_state = PBLE_CHUNK_MEM;
16741675
iwdev->virtchnl_wq = alloc_ordered_workqueue("iwvch", WQ_MEM_RECLAIM);
1675-
i40iw_register_notifiers();
1676-
iwdev->init_state = INET_NOTIFIER;
16771676
status = i40iw_add_mac_ip(iwdev);
16781677
if (status)
16791678
break;
@@ -2023,6 +2022,8 @@ static int __init i40iw_init_module(void)
20232022
i40iw_client.type = I40E_CLIENT_IWARP;
20242023
spin_lock_init(&i40iw_handler_lock);
20252024
ret = i40e_register_client(&i40iw_client);
2025+
i40iw_register_notifiers();
2026+
20262027
return ret;
20272028
}
20282029

@@ -2034,6 +2035,7 @@ static int __init i40iw_init_module(void)
20342035
*/
20352036
static void __exit i40iw_exit_module(void)
20362037
{
2038+
i40iw_unregister_notifiers();
20372039
i40e_unregister_client(&i40iw_client);
20382040
}
20392041

drivers/infiniband/hw/i40iw/i40iw_utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int i40iw_inetaddr_event(struct notifier_block *notifier,
160160
return NOTIFY_DONE;
161161

162162
iwdev = &hdl->device;
163-
if (iwdev->init_state < INET_NOTIFIER)
163+
if (iwdev->init_state < IP_ADDR_REGISTERED || iwdev->closing)
164164
return NOTIFY_DONE;
165165

166166
netdev = iwdev->ldev->netdev;
@@ -217,7 +217,7 @@ int i40iw_inet6addr_event(struct notifier_block *notifier,
217217
return NOTIFY_DONE;
218218

219219
iwdev = &hdl->device;
220-
if (iwdev->init_state < INET_NOTIFIER)
220+
if (iwdev->init_state < IP_ADDR_REGISTERED || iwdev->closing)
221221
return NOTIFY_DONE;
222222

223223
netdev = iwdev->ldev->netdev;
@@ -266,7 +266,7 @@ int i40iw_net_event(struct notifier_block *notifier, unsigned long event, void *
266266
if (!iwhdl)
267267
return NOTIFY_DONE;
268268
iwdev = &iwhdl->device;
269-
if (iwdev->init_state < INET_NOTIFIER)
269+
if (iwdev->init_state < IP_ADDR_REGISTERED || iwdev->closing)
270270
return NOTIFY_DONE;
271271
p = (__be32 *)neigh->primary_key;
272272
i40iw_copy_ip_ntohl(local_ipaddr, p);

0 commit comments

Comments
 (0)