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

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
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ struct mlx5_vdpa_mr {
	bool user_mr;

	refcount_t refcount;
	struct list_head mr_list;
};

struct mlx5_vdpa_resources {
@@ -95,6 +96,7 @@ struct mlx5_vdpa_dev {
	u32 generation;

	struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS];
	struct list_head mr_list_head;
	/* serialize mr access */
	struct mutex mr_mtx;
	struct mlx5_control_vq cvq;
+23 −0
Original line number Diff line number Diff line
@@ -508,6 +508,8 @@ static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_

	vhost_iotlb_free(mr->iotlb);

	list_del(&mr->mr_list);

	kfree(mr);
}

@@ -560,12 +562,31 @@ void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev,
	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)
{
	for (int i = 0; i < MLX5_VDPA_NUM_AS; i++)
		mlx5_vdpa_update_mr(mvdev, NULL, i);

	prune_iotlb(mvdev->cvq.iotlb);

	mlx5_vdpa_show_mr_leaks(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,
	if (err)
		goto err_iotlb;

	list_add_tail(&mr->mr_list, &mvdev->mr_list_head);

	return 0;

err_iotlb:
+2 −0
Original line number Diff line number Diff line
@@ -3722,6 +3722,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
	if (err)
		goto err_mpfs;

	INIT_LIST_HEAD(&mvdev->mr_list_head);

	if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
		err = mlx5_vdpa_create_dma_mr(mvdev);
		if (err)