RDMA/uverbs: Allow drivers to create a new HW object during rereg_mr
authorJason Gunthorpe <jgg@nvidia.com>
Mon, 30 Nov 2020 07:58:37 +0000 (09:58 +0200)
committerJason Gunthorpe <jgg@nvidia.com>
Mon, 7 Dec 2020 18:06:23 +0000 (14:06 -0400)
commit6e0954b11c056570cb29676a84e2f8dc4d1dd05e
tree0c72abb6ece5e7f6fb2bde31a5d0596020e22840
parentadac4cb3c1ff5c47c9f47be5d017a0e054176e3c
RDMA/uverbs: Allow drivers to create a new HW object during rereg_mr

mlx5 has an ugly flow where it tries to allocate a new MR and replace the
existing MR in the same memory during rereg. This is very complicated and
buggy. Instead of trying to replace in-place inside the driver, provide
support from uverbs to change the entire HW object assigned to a handle
during rereg_mr.

Since destroying a MR is allowed to fail (ie if a MW is pointing at it)
and can't be detected in advance, the algorithm creates a completely new
uobject to hold the new MR and swaps the IDR entries of the two objects.

The old MR in the temporary IDR entry is destroyed, and if it fails
rereg_mr succeeds and destruction is deferred to FD release. This
complexity is why this cannot live in a driver safely.

Link: https://lore.kernel.org/r/20201130075839.278575-4-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/rdma_core.c
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/hw/hns/hns_roce_device.h
drivers/infiniband/hw/hns/hns_roce_mr.c
drivers/infiniband/hw/mlx4/mlx4_ib.h
drivers/infiniband/hw/mlx4/mr.c
drivers/infiniband/hw/mlx5/mlx5_ib.h
drivers/infiniband/hw/mlx5/mr.c
include/rdma/ib_verbs.h
include/rdma/uverbs_types.h