vdpa/mlx5: Introduce init/destroy for MR resources
There's currently not a lot of action happening during the init/destroy of MR resources. But more will be added in the upcoming patches. As the mr mutex lock init/destroy has been moved to these new functions, the lifetime has now shifted away from mlx5_vdpa_alloc_resources() / mlx5_vdpa_free_resources() into these new functions. However, the lifetime at the outer scope remains the same: mlx5_vdpa_dev_add() / mlx5_vdpa_dev_free() Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> Message-Id: <20240830105838.2666587-8-dtatulea@nvidia.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
58d4d50e75
commit
f30a1232b6
@ -138,6 +138,8 @@ int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in,
|
|||||||
int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
|
int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
|
||||||
struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
|
struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
|
||||||
struct vhost_iotlb *iotlb);
|
struct vhost_iotlb *iotlb);
|
||||||
|
int mlx5_vdpa_init_mr_resources(struct mlx5_vdpa_dev *mvdev);
|
||||||
|
void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev);
|
||||||
void mlx5_vdpa_clean_mrs(struct mlx5_vdpa_dev *mvdev);
|
void mlx5_vdpa_clean_mrs(struct mlx5_vdpa_dev *mvdev);
|
||||||
void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev,
|
void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev,
|
||||||
struct mlx5_vdpa_mr *mr);
|
struct mlx5_vdpa_mr *mr);
|
||||||
|
@ -846,3 +846,20 @@ int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mlx5_vdpa_init_mr_resources(struct mlx5_vdpa_dev *mvdev)
|
||||||
|
{
|
||||||
|
struct mlx5_vdpa_mr_resources *mres = &mvdev->mres;
|
||||||
|
|
||||||
|
INIT_LIST_HEAD(&mres->mr_list_head);
|
||||||
|
mutex_init(&mres->lock);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
|
||||||
|
{
|
||||||
|
struct mlx5_vdpa_mr_resources *mres = &mvdev->mres;
|
||||||
|
|
||||||
|
mutex_destroy(&mres->lock);
|
||||||
|
}
|
||||||
|
@ -256,7 +256,6 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
|
|||||||
mlx5_vdpa_warn(mvdev, "resources already allocated\n");
|
mlx5_vdpa_warn(mvdev, "resources already allocated\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
mutex_init(&mvdev->mres.lock);
|
|
||||||
res->uar = mlx5_get_uars_page(mdev);
|
res->uar = mlx5_get_uars_page(mdev);
|
||||||
if (IS_ERR(res->uar)) {
|
if (IS_ERR(res->uar)) {
|
||||||
err = PTR_ERR(res->uar);
|
err = PTR_ERR(res->uar);
|
||||||
@ -301,7 +300,6 @@ err_pd:
|
|||||||
err_uctx:
|
err_uctx:
|
||||||
mlx5_put_uars_page(mdev, res->uar);
|
mlx5_put_uars_page(mdev, res->uar);
|
||||||
err_uars:
|
err_uars:
|
||||||
mutex_destroy(&mvdev->mres.lock);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +316,6 @@ void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev)
|
|||||||
dealloc_pd(mvdev, res->pdn, res->uid);
|
dealloc_pd(mvdev, res->pdn, res->uid);
|
||||||
destroy_uctx(mvdev, res->uid);
|
destroy_uctx(mvdev, res->uid);
|
||||||
mlx5_put_uars_page(mvdev->mdev, res->uar);
|
mlx5_put_uars_page(mvdev->mdev, res->uar);
|
||||||
mutex_destroy(&mvdev->mres.lock);
|
|
||||||
res->valid = false;
|
res->valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3434,6 +3434,7 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
|
|||||||
|
|
||||||
free_fixed_resources(ndev);
|
free_fixed_resources(ndev);
|
||||||
mlx5_vdpa_clean_mrs(mvdev);
|
mlx5_vdpa_clean_mrs(mvdev);
|
||||||
|
mlx5_vdpa_destroy_mr_resources(&ndev->mvdev);
|
||||||
if (!is_zero_ether_addr(ndev->config.mac)) {
|
if (!is_zero_ether_addr(ndev->config.mac)) {
|
||||||
pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
|
pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
|
||||||
mlx5_mpfs_del_mac(pfmdev, ndev->config.mac);
|
mlx5_mpfs_del_mac(pfmdev, ndev->config.mac);
|
||||||
@ -3962,12 +3963,14 @@ 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->mres.mr_list_head);
|
err = mlx5_vdpa_init_mr_resources(mvdev);
|
||||||
|
if (err)
|
||||||
|
goto err_res;
|
||||||
|
|
||||||
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)
|
||||||
goto err_res;
|
goto err_mr_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = alloc_fixed_resources(ndev);
|
err = alloc_fixed_resources(ndev);
|
||||||
@ -4009,6 +4012,8 @@ err_res2:
|
|||||||
free_fixed_resources(ndev);
|
free_fixed_resources(ndev);
|
||||||
err_mr:
|
err_mr:
|
||||||
mlx5_vdpa_clean_mrs(mvdev);
|
mlx5_vdpa_clean_mrs(mvdev);
|
||||||
|
err_mr_res:
|
||||||
|
mlx5_vdpa_destroy_mr_resources(mvdev);
|
||||||
err_res:
|
err_res:
|
||||||
mlx5_vdpa_free_resources(&ndev->mvdev);
|
mlx5_vdpa_free_resources(&ndev->mvdev);
|
||||||
err_mpfs:
|
err_mpfs:
|
||||||
|
Loading…
Reference in New Issue
Block a user