Skip to content

Commit 9d3e1c0

Browse files
Parvi Kaustubhigregkh
authored andcommitted
IB/usnic: Fix potential deadlock
[ Upstream commit 8036e90 ] Acquiring the rtnl lock while holding usdev_lock could result in a deadlock. For example: usnic_ib_query_port() | mutex_lock(&us_ibdev->usdev_lock) | ib_get_eth_speed() | rtnl_lock() rtnl_lock() | usnic_ib_netdevice_event() | mutex_lock(&us_ibdev->usdev_lock) This commit moves the usdev_lock acquisition after the rtnl lock has been released. This is safe to do because usdev_lock is not protecting anything being accessed in ib_get_eth_speed(). Hence, the correct order of holding locks (rtnl -> usdev_lock) is not violated. Signed-off-by: Parvi Kaustubhi <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent d9c25a6 commit 9d3e1c0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/infiniband/hw/usnic/usnic_ib_verbs.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,16 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port,
310310

311311
usnic_dbg("\n");
312312

313-
mutex_lock(&us_ibdev->usdev_lock);
314313
if (ib_get_eth_speed(ibdev, port, &props->active_speed,
315-
&props->active_width)) {
316-
mutex_unlock(&us_ibdev->usdev_lock);
314+
&props->active_width))
317315
return -EINVAL;
318-
}
319316

317+
/*
318+
* usdev_lock is acquired after (and not before) ib_get_eth_speed call
319+
* because acquiring rtnl_lock in ib_get_eth_speed, while holding
320+
* usdev_lock could lead to a deadlock.
321+
*/
322+
mutex_lock(&us_ibdev->usdev_lock);
320323
/* props being zeroed by the caller, avoid zeroing it here */
321324

322325
props->lid = 0;

0 commit comments

Comments
 (0)