RDMA/cm: Fix ordering of xa_alloc_cyclic() in ib_create_cm_id()
authorJason Gunthorpe <jgg@mellanox.com>
Tue, 10 Mar 2020 09:25:31 +0000 (11:25 +0200)
committerJason Gunthorpe <jgg@mellanox.com>
Tue, 17 Mar 2020 20:05:51 +0000 (17:05 -0300)
commite8dc4e885c459343970b25acd9320fe9ee5492e7
treeb288f5ba4ab604be52dd2744cbd889f47fd43d56
parent9e57a9aa694cfc28f9549d2ce587309fdac15bfb
RDMA/cm: Fix ordering of xa_alloc_cyclic() in ib_create_cm_id()

xa_alloc_cyclic() is a SMP release to be paired with some later acquire
during xa_load() as part of cm_acquire_id().

As such, xa_alloc_cyclic() must be done after the cm_id is fully
initialized, in particular, it absolutely must be after the
refcount_set(), otherwise the refcount_inc() in cm_acquire_id() may not
see the set.

As there are several cases where a reader will be able to use the
id.local_id after cm_acquire_id in the IB_CM_IDLE state there needs to be
an unfortunate split into a NULL allocate and a finalizing xa_store.

Fixes: a977049dacde ("[PATCH] IB: Add the kernel CM implementation")
Link: https://lore.kernel.org/r/20200310092545.251365-2-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/cm.c