OSDN Git Service

RDMA/cma: Fix locking for the RDMA_CM_LISTEN state
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 2 Sep 2020 08:11:17 +0000 (11:11 +0300)
committerJason Gunthorpe <jgg@nvidia.com>
Thu, 17 Sep 2020 12:09:24 +0000 (09:09 -0300)
commitd490ee52f0a5dbd9d1bccabd6bf00c40c1234a79
treedfca7eaf0a30b63925cbbf0b5883ac31dbea7431
parent732d41c545bb359cbb8c94698bdc1f8bcf82279c
RDMA/cma: Fix locking for the RDMA_CM_LISTEN state

There is a strange unlocked read of the ID state when checking for
reuseaddr. This is because an ID cannot be reusable once it becomes a
listening ID. Instead of using the state to exclude reuse, just clear it
as part of rdma_listen()'s flow to convert reusable into not reusable.

Once a ID goes to listen there is no way back out, and the only use of
reusable is on the bind_list check.

Finally, update the checks under handler_mutex to use READ_ONCE and audit
that once RDMA_CM_LISTEN is observed in a req callback it is stable under
the handler_mutex.

Link: https://lore.kernel.org/r/20200902081122.745412-4-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/cma.c