IB/ipoib: Fix sysfs Pkey create<->remove possible deadlock
authorShalom Lagziel <shaloml@mellanox.com>
Sun, 24 Sep 2017 18:46:32 +0000 (21:46 +0300)
committerDoug Ledford <dledford@redhat.com>
Mon, 25 Sep 2017 15:47:23 +0000 (11:47 -0400)
commit9c6f42e9254150d2772242d9f8bd8d0b7b7431ff
tree21ae36b5cd27156f07541442822bbf3bd0499f15
parentedd31551148c09608feee6b8756ad148d550ee3b
IB/ipoib: Fix sysfs Pkey create<->remove possible deadlock

A possible ABBA lock can happen with RTNL and vlan_rwsem.
For example:

Flow A: Device Flush
__ipoib_ib_dev_flush
down_read(vlan_rwsem)  // Lock A
ipoib_flush_ah
flush_workqueue(priv->wq)  // Wait for completion
A work on shared WQ (Mcast carrier)
ipoib_mcast_carrier_on_task
while (!rtnl_trylock())         // Wait for lock B

Flow B: Sysfs PKEY delete
ipoib_vlan_delete
lock(RTNL)  // Lock B
down_write(vlan_rwsem)  // Wait for lock A

This can happen with PKEY creates as well. The solution is to release
the RTNL lock in sysfs functions in case it is not possible to lock
VLAN RW semaphore and reset the SYS call.

Fixes: 69956d83267e ("IB/ipoib: Sync between remove_one to sysfs calls that use rtnl_lock")
Signed-off-by: Shalom Lagziel <shaloml@mellanox.com>
Signed-off-by: Alex Vesker <valex@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/ulp/ipoib/ipoib_vlan.c