RDMA/mlx5: Always remove MRs from the cache before destroying them
authorJason Gunthorpe <jgg@mellanox.com>
Tue, 10 Mar 2020 08:22:33 +0000 (10:22 +0200)
committerJason Gunthorpe <jgg@mellanox.com>
Fri, 13 Mar 2020 14:08:01 +0000 (11:08 -0300)
commit1769c4c575489be28891c98f1e3f0a4252ca750a
treedb61866d6622bec7c408970f64e799cd34635ecb
parentb91e1751fbcee7692e45308e74d8816c43802ede
RDMA/mlx5: Always remove MRs from the cache before destroying them

The cache bucket tracks the total number of MRs that exists, both inside
and outside of the cache. Removing a MR from the cache (by setting
cache_ent to NULL) without updating total_mrs will cause the tracking to
leak and be inflated.

Further fix the rereg_mr path to always destroy the MR. reg_create will
always overwrite all the MR data in mlx5_ib_mr, so the MR must be
completely destroyed, in all cases, before this function can be
called. Detach the MR from the cache and unconditionally destroy it to
avoid leaking HW mkeys.

Fixes: afd1417404fb ("IB/mlx5: Use direct mkey destroy command upon UMR unreg failure")
Fixes: 56e11d628c5d ("IB/mlx5: Added support for re-registration of MRs")
Link: https://lore.kernel.org/r/20200310082238.239865-8-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/mlx5/mr.c