RDMA/devices: Re-organize device.c locking
authorJason Gunthorpe <jgg@mellanox.com>
Thu, 7 Feb 2019 05:41:54 +0000 (22:41 -0700)
committerJason Gunthorpe <jgg@mellanox.com>
Fri, 8 Feb 2019 23:56:45 +0000 (16:56 -0700)
commit921eab1143aadf976a42cac4605b4d35159b355d
tree597549c34b64fee575f20db29f0b0ca8623a04b0
parent0df91bb67334eebaf73d4ba32567e16d55f4f116
RDMA/devices: Re-organize device.c locking

The locking here started out with a single lock that covered everything
and then has lately veered into crazy town.

The fundamental problem is that several places need to iterate over a
linked list, but also need to drop their locks to avoid deadlock during
client callbacks.

xarray's restartable iteration offers a simple solution to the
problem. Once all the lists are xarrays we can drop locks in the places
that need that and rely on xarray to provide consistency and locking for
the data structure.

The resulting simplification is that each of the three lists has a
dedicated rwsem that must be held when working with the list it
covers. One data structure is no longer covered by multiple locks.

The sleeping semaphore is selected because the read side generally needs
to be held over something sleeping, and using RCU reader locking in those
cases is overkill.

In the process this simplifies the entire registration/unregistration flow
to be the expected list of setups and the reversed list of matching
teardowns, and the registration lock 'refcount' can now be revised to be
released after the ULPs are removed, providing a very sane semantic for
this feature.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/device.c
include/rdma/ib_verbs.h