Commit f16d6512 authored by Dragos Tatulea's avatar Dragos Tatulea Committed by Michael S. Tsirkin

vdpa/mlx5: Add mkey leak detection

Track allocated mrs in a list and show warning when leaks are detected
on device free or reset.
Reviewed-by: default avatarGal Pressman <gal@nvidia.com>
Acked-by: default avatarEugenio Pérez <eperezma@redhat.com>
Signed-off-by: default avatarDragos Tatulea <dtatulea@nvidia.com>
Message-Id: <20231225151203.152687-9-dtatulea@nvidia.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent a06bd11b
...@@ -37,6 +37,7 @@ struct mlx5_vdpa_mr { ...@@ -37,6 +37,7 @@ struct mlx5_vdpa_mr {
bool user_mr; bool user_mr;
refcount_t refcount; refcount_t refcount;
struct list_head mr_list;
}; };
struct mlx5_vdpa_resources { struct mlx5_vdpa_resources {
...@@ -95,6 +96,7 @@ struct mlx5_vdpa_dev { ...@@ -95,6 +96,7 @@ struct mlx5_vdpa_dev {
u32 generation; u32 generation;
struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS]; struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS];
struct list_head mr_list_head;
/* serialize mr access */ /* serialize mr access */
struct mutex mr_mtx; struct mutex mr_mtx;
struct mlx5_control_vq cvq; struct mlx5_control_vq cvq;
......
...@@ -508,6 +508,8 @@ static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_ ...@@ -508,6 +508,8 @@ static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_
vhost_iotlb_free(mr->iotlb); vhost_iotlb_free(mr->iotlb);
list_del(&mr->mr_list);
kfree(mr); kfree(mr);
} }
...@@ -560,12 +562,31 @@ void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, ...@@ -560,12 +562,31 @@ void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev,
mutex_unlock(&mvdev->mr_mtx); mutex_unlock(&mvdev->mr_mtx);
} }
static void mlx5_vdpa_show_mr_leaks(struct mlx5_vdpa_dev *mvdev)
{
struct mlx5_vdpa_mr *mr;
mutex_lock(&mvdev->mr_mtx);
list_for_each_entry(mr, &mvdev->mr_list_head, mr_list) {
mlx5_vdpa_warn(mvdev, "mkey still alive after resource delete: "
"mr: %p, mkey: 0x%x, refcount: %u\n",
mr, mr->mkey, refcount_read(&mr->refcount));
}
mutex_unlock(&mvdev->mr_mtx);
}
void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev) void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
{ {
for (int i = 0; i < MLX5_VDPA_NUM_AS; i++) for (int i = 0; i < MLX5_VDPA_NUM_AS; i++)
mlx5_vdpa_update_mr(mvdev, NULL, i); mlx5_vdpa_update_mr(mvdev, NULL, i);
prune_iotlb(mvdev->cvq.iotlb); prune_iotlb(mvdev->cvq.iotlb);
mlx5_vdpa_show_mr_leaks(mvdev);
} }
static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
...@@ -592,6 +613,8 @@ static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, ...@@ -592,6 +613,8 @@ static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
if (err) if (err)
goto err_iotlb; goto err_iotlb;
list_add_tail(&mr->mr_list, &mvdev->mr_list_head);
return 0; return 0;
err_iotlb: err_iotlb:
......
...@@ -3722,6 +3722,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, ...@@ -3722,6 +3722,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
if (err) if (err)
goto err_mpfs; goto err_mpfs;
INIT_LIST_HEAD(&mvdev->mr_list_head);
if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
err = mlx5_vdpa_create_dma_mr(mvdev); err = mlx5_vdpa_create_dma_mr(mvdev);
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment