RDMA/mlx5: Fix handling of IOVA != user_va in ODP paths
authorJason Gunthorpe <jgg@mellanox.com>
Wed, 15 Jan 2020 12:43:37 +0000 (14:43 +0200)
committerLeon Romanovsky <leonro@mellanox.com>
Thu, 16 Jan 2020 14:15:07 +0000 (16:15 +0200)
commit8ffc32485158528f870b62707077ab494ba31deb
tree1bc4a0f1071236ae49ff180fb79cdda5dbfd4b9e
parenta73a895588520a40e52f967a7b2892baf810c708
RDMA/mlx5: Fix handling of IOVA != user_va in ODP paths

Till recently it was not possible for userspace to specify a different
IOVA, but with the new ibv_reg_mr_iova() library call this can be done.

To compute the user_va we must compute:
  user_va = (iova - iova_start) + user_va_start

while being cautious of overflow and other math problems.

The iova is not reliably stored in the mmkey when the MR is created. Only
the cached creation path (the common one) set it, so it must also be set
when creating uncached MRs.

Fix the weird use of iova when computing the starting page index in the
MR. In the normal case, when iova == umem.address:
  iova & (~(BIT(page_shift) - 1)) ==
  ALIGN_DOWN(umem.address, odp->page_size) ==
  ib_umem_start(odp)

And when iova is different using it in math with a user_va is wrong.

Finally, do not allow an implicit ODP to be created with a non-zero IOVA
as we have no support for that.

Fixes: 7bdf65d411c1 ("IB/mlx5: Handle page faults")
Signed-off-by: Moni Shoua <monis@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
drivers/infiniband/hw/mlx5/mr.c
drivers/infiniband/hw/mlx5/odp.c