Skip to content

Commit f30a123

Browse files
dtatuleamstsirkin
authored andcommitted
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 <[email protected]> Reviewed-by: Cosmin Ratiu <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 58d4d50 commit f30a123

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in,
138138
int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
139139
struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
140140
struct vhost_iotlb *iotlb);
141+
int mlx5_vdpa_init_mr_resources(struct mlx5_vdpa_dev *mvdev);
142+
void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev);
141143
void mlx5_vdpa_clean_mrs(struct mlx5_vdpa_dev *mvdev);
142144
void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev,
143145
struct mlx5_vdpa_mr *mr);

drivers/vdpa/mlx5/core/mr.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,20 @@ int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
846846

847847
return 0;
848848
}
849+
850+
int mlx5_vdpa_init_mr_resources(struct mlx5_vdpa_dev *mvdev)
851+
{
852+
struct mlx5_vdpa_mr_resources *mres = &mvdev->mres;
853+
854+
INIT_LIST_HEAD(&mres->mr_list_head);
855+
mutex_init(&mres->lock);
856+
857+
return 0;
858+
}
859+
860+
void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
861+
{
862+
struct mlx5_vdpa_mr_resources *mres = &mvdev->mres;
863+
864+
mutex_destroy(&mres->lock);
865+
}

drivers/vdpa/mlx5/core/resources.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
256256
mlx5_vdpa_warn(mvdev, "resources already allocated\n");
257257
return -EINVAL;
258258
}
259-
mutex_init(&mvdev->mres.lock);
260259
res->uar = mlx5_get_uars_page(mdev);
261260
if (IS_ERR(res->uar)) {
262261
err = PTR_ERR(res->uar);
@@ -301,7 +300,6 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
301300
err_uctx:
302301
mlx5_put_uars_page(mdev, res->uar);
303302
err_uars:
304-
mutex_destroy(&mvdev->mres.lock);
305303
return err;
306304
}
307305

@@ -318,7 +316,6 @@ void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev)
318316
dealloc_pd(mvdev, res->pdn, res->uid);
319317
destroy_uctx(mvdev, res->uid);
320318
mlx5_put_uars_page(mvdev->mdev, res->uar);
321-
mutex_destroy(&mvdev->mres.lock);
322319
res->valid = false;
323320
}
324321

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3434,6 +3434,7 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
34343434

34353435
free_fixed_resources(ndev);
34363436
mlx5_vdpa_clean_mrs(mvdev);
3437+
mlx5_vdpa_destroy_mr_resources(&ndev->mvdev);
34373438
if (!is_zero_ether_addr(ndev->config.mac)) {
34383439
pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
34393440
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,
39623963
if (err)
39633964
goto err_mpfs;
39643965

3965-
INIT_LIST_HEAD(&mvdev->mres.mr_list_head);
3966+
err = mlx5_vdpa_init_mr_resources(mvdev);
3967+
if (err)
3968+
goto err_res;
39663969

39673970
if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
39683971
err = mlx5_vdpa_create_dma_mr(mvdev);
39693972
if (err)
3970-
goto err_res;
3973+
goto err_mr_res;
39713974
}
39723975

39733976
err = alloc_fixed_resources(ndev);
@@ -4009,6 +4012,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
40094012
free_fixed_resources(ndev);
40104013
err_mr:
40114014
mlx5_vdpa_clean_mrs(mvdev);
4015+
err_mr_res:
4016+
mlx5_vdpa_destroy_mr_resources(mvdev);
40124017
err_res:
40134018
mlx5_vdpa_free_resources(&ndev->mvdev);
40144019
err_mpfs:

0 commit comments

Comments
 (0)