Skip to content

Commit f9fcb38

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa/mlx5: Move mr mutex out of mr struct
The mutex is named like it is supposed to protect only the mkey but in reality it is a global lock for all mr resources. Shift the mutex to it's rightful location (struct mlx5_vdpa_dev) and give it a more appropriate name. Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com> Acked-by: Eugenio Pérez <eperezma@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com> Message-Id: <20231018171456.1624030-13-dtatulea@nvidia.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 119c68e commit f9fcb38

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ struct mlx5_vdpa_mr {
3434
/* state of dvq mr */
3535
bool initialized;
3636

37-
/* serialize mkey creation and destruction */
38-
struct mutex mkey_mtx;
3937
bool user_mr;
4038
};
4139

@@ -94,6 +92,8 @@ struct mlx5_vdpa_dev {
9492
u32 generation;
9593

9694
struct mlx5_vdpa_mr mr;
95+
/* serialize mr access */
96+
struct mutex mr_mtx;
9797
struct mlx5_control_vq cvq;
9898
struct workqueue_struct *wq;
9999
unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS];

drivers/vdpa/mlx5/core/mr.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,11 @@ static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_
509509
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev,
510510
struct mlx5_vdpa_mr *mr)
511511
{
512-
mutex_lock(&mr->mkey_mtx);
512+
mutex_lock(&mvdev->mr_mtx);
513513

514514
_mlx5_vdpa_destroy_mr(mvdev, mr);
515515

516-
mutex_unlock(&mr->mkey_mtx);
516+
mutex_unlock(&mvdev->mr_mtx);
517517
}
518518

519519
void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
@@ -550,9 +550,10 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
550550
{
551551
int err;
552552

553-
mutex_lock(&mvdev->mr.mkey_mtx);
553+
mutex_lock(&mvdev->mr_mtx);
554554
err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb);
555-
mutex_unlock(&mvdev->mr.mkey_mtx);
555+
mutex_unlock(&mvdev->mr_mtx);
556+
556557
return err;
557558
}
558559

@@ -563,14 +564,14 @@ int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *io
563564
int err = 0;
564565

565566
*change_map = false;
566-
mutex_lock(&mr->mkey_mtx);
567+
mutex_lock(&mvdev->mr_mtx);
567568
if (mr->initialized) {
568569
mlx5_vdpa_info(mvdev, "memory map update\n");
569570
*change_map = true;
570571
}
571572
if (!*change_map)
572573
err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb);
573-
mutex_unlock(&mr->mkey_mtx);
574+
mutex_unlock(&mvdev->mr_mtx);
574575

575576
return err;
576577
}

drivers/vdpa/mlx5/core/resources.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ 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->mr.mkey_mtx);
259+
mutex_init(&mvdev->mr_mtx);
260260
res->uar = mlx5_get_uars_page(mdev);
261261
if (IS_ERR(res->uar)) {
262262
err = PTR_ERR(res->uar);
@@ -301,7 +301,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
301301
err_uctx:
302302
mlx5_put_uars_page(mdev, res->uar);
303303
err_uars:
304-
mutex_destroy(&mvdev->mr.mkey_mtx);
304+
mutex_destroy(&mvdev->mr_mtx);
305305
return err;
306306
}
307307

@@ -318,6 +318,6 @@ void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev)
318318
dealloc_pd(mvdev, res->pdn, res->uid);
319319
destroy_uctx(mvdev, res->uid);
320320
mlx5_put_uars_page(mvdev->mdev, res->uar);
321-
mutex_destroy(&mvdev->mr.mkey_mtx);
321+
mutex_destroy(&mvdev->mr_mtx);
322322
res->valid = false;
323323
}

0 commit comments

Comments
 (0)