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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 May 2020 06:15:13 +0000 (08:15 +0200)
commit4c499dafdd63a46b26d2eb2391cbfce293a7504b
treebd3fb2c54fd742d9d3db792a75dc60a8f7724d98
parent169b8b62717af0f05b1fa88bdf9efa3ba285b4d9
RDMA/cm: Fix ordering of xa_alloc_cyclic() in ib_create_cm_id()

commit e8dc4e885c459343970b25acd9320fe9ee5492e7 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/core/cm.c