Skip to content

Commit a53b59e

Browse files
KAGA-KOKOdavem330
authored andcommitted
net: enic: Cure the enic api locking trainwreck
enic_dev_wait() has a BUG_ON(in_interrupt()). Chasing the callers of enic_dev_wait() revealed the gems of enic_reset() and enic_tx_hang_reset() which are both invoked through work queues in order to be able to call rtnl_lock(). So far so good. After locking rtnl both functions acquire enic::enic_api_lock which serializes against the (ab)use from infiniband. This is where the trainwreck starts. enic::enic_api_lock is a spin_lock() which implicitly disables preemption, but both functions invoke a ton of functions under that lock which can sleep. The BUG_ON(in_interrupt()) does not trigger in that case because it can't detect the preempt disabled condition. This clearly has never been tested with any of the mandatory debug options for 7+ years, which would have caught that for sure. Cure it by adding a enic_api_busy member to struct enic, which is modified and evaluated with enic::enic_api_lock held. If enic_api_devcmd_proxy_by_index() observes enic::enic_api_busy as true, it drops enic::enic_api_lock and busy waits for enic::enic_api_busy to become false. It would be smarter to wait for a completion of that busy period, but enic_api_devcmd_proxy_by_index() is called with other spin locks held which obviously can't sleep. Remove the BUG_ON(in_interrupt()) check as well because it's incomplete and with proper debugging enabled the problem would have been caught from the debug checks in schedule_timeout(). Fixes: 0b03856 ("drivers/net: enic: Add an interface for USNIC to interact with firmware") Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2ec13cb commit a53b59e

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

drivers/net/ethernet/cisco/enic/enic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct enic {
169169
u16 num_vfs;
170170
#endif
171171
spinlock_t enic_api_lock;
172+
bool enic_api_busy;
172173
struct enic_port_profile *pp;
173174

174175
/* work queue cache line section */

drivers/net/ethernet/cisco/enic/enic_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ int enic_api_devcmd_proxy_by_index(struct net_device *netdev, int vf,
3434
struct vnic_dev *vdev = enic->vdev;
3535

3636
spin_lock(&enic->enic_api_lock);
37+
while (enic->enic_api_busy) {
38+
spin_unlock(&enic->enic_api_lock);
39+
cpu_relax();
40+
spin_lock(&enic->enic_api_lock);
41+
}
42+
3743
spin_lock_bh(&enic->devcmd_lock);
3844

3945
vnic_dev_cmd_proxy_by_index_start(vdev, vf);

drivers/net/ethernet/cisco/enic/enic_main.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,8 +2107,6 @@ static int enic_dev_wait(struct vnic_dev *vdev,
21072107
int done;
21082108
int err;
21092109

2110-
BUG_ON(in_interrupt());
2111-
21122110
err = start(vdev, arg);
21132111
if (err)
21142112
return err;
@@ -2297,6 +2295,13 @@ static int enic_set_rss_nic_cfg(struct enic *enic)
22972295
rss_hash_bits, rss_base_cpu, rss_enable);
22982296
}
22992297

2298+
static void enic_set_api_busy(struct enic *enic, bool busy)
2299+
{
2300+
spin_lock(&enic->enic_api_lock);
2301+
enic->enic_api_busy = busy;
2302+
spin_unlock(&enic->enic_api_lock);
2303+
}
2304+
23002305
static void enic_reset(struct work_struct *work)
23012306
{
23022307
struct enic *enic = container_of(work, struct enic, reset);
@@ -2306,15 +2311,20 @@ static void enic_reset(struct work_struct *work)
23062311

23072312
rtnl_lock();
23082313

2309-
spin_lock(&enic->enic_api_lock);
2314+
/* Stop any activity from infiniband */
2315+
enic_set_api_busy(enic, true);
2316+
23102317
enic_stop(enic->netdev);
23112318
enic_dev_soft_reset(enic);
23122319
enic_reset_addr_lists(enic);
23132320
enic_init_vnic_resources(enic);
23142321
enic_set_rss_nic_cfg(enic);
23152322
enic_dev_set_ig_vlan_rewrite_mode(enic);
23162323
enic_open(enic->netdev);
2317-
spin_unlock(&enic->enic_api_lock);
2324+
2325+
/* Allow infiniband to fiddle with the device again */
2326+
enic_set_api_busy(enic, false);
2327+
23182328
call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
23192329

23202330
rtnl_unlock();
@@ -2326,7 +2336,9 @@ static void enic_tx_hang_reset(struct work_struct *work)
23262336

23272337
rtnl_lock();
23282338

2329-
spin_lock(&enic->enic_api_lock);
2339+
/* Stop any activity from infiniband */
2340+
enic_set_api_busy(enic, true);
2341+
23302342
enic_dev_hang_notify(enic);
23312343
enic_stop(enic->netdev);
23322344
enic_dev_hang_reset(enic);
@@ -2335,7 +2347,10 @@ static void enic_tx_hang_reset(struct work_struct *work)
23352347
enic_set_rss_nic_cfg(enic);
23362348
enic_dev_set_ig_vlan_rewrite_mode(enic);
23372349
enic_open(enic->netdev);
2338-
spin_unlock(&enic->enic_api_lock);
2350+
2351+
/* Allow infiniband to fiddle with the device again */
2352+
enic_set_api_busy(enic, false);
2353+
23392354
call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
23402355

23412356
rtnl_unlock();

0 commit comments

Comments
 (0)