mirror of
https://github.com/torvalds/linux
synced 2024-09-16 00:58:07 +00:00
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> Reviewed-by: Si-Wei Liu <si-wei.liu@oracle.com> Tested-by: Si-Wei Liu <si-wei.liu@oracle.com> Tested-by: Lei Yang <leiyang@redhat.com>
This commit is contained in:
parent
1b3ce9576f
commit
186e25387e
|
@ -34,8 +34,6 @@ struct mlx5_vdpa_mr {
|
||||||
/* state of dvq mr */
|
/* state of dvq mr */
|
||||||
bool initialized;
|
bool initialized;
|
||||||
|
|
||||||
/* serialize mkey creation and destruction */
|
|
||||||
struct mutex mkey_mtx;
|
|
||||||
bool user_mr;
|
bool user_mr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,6 +92,8 @@ struct mlx5_vdpa_dev {
|
||||||
u32 generation;
|
u32 generation;
|
||||||
|
|
||||||
struct mlx5_vdpa_mr mr;
|
struct mlx5_vdpa_mr mr;
|
||||||
|
/* serialize mr access */
|
||||||
|
struct mutex mr_mtx;
|
||||||
struct mlx5_control_vq cvq;
|
struct mlx5_control_vq cvq;
|
||||||
struct workqueue_struct *wq;
|
struct workqueue_struct *wq;
|
||||||
unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS];
|
unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS];
|
||||||
|
|
|
@ -509,11 +509,11 @@ static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_
|
||||||
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev,
|
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev,
|
||||||
struct mlx5_vdpa_mr *mr)
|
struct mlx5_vdpa_mr *mr)
|
||||||
{
|
{
|
||||||
mutex_lock(&mr->mkey_mtx);
|
mutex_lock(&mvdev->mr_mtx);
|
||||||
|
|
||||||
_mlx5_vdpa_destroy_mr(mvdev, mr);
|
_mlx5_vdpa_destroy_mr(mvdev, mr);
|
||||||
|
|
||||||
mutex_unlock(&mr->mkey_mtx);
|
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)
|
||||||
|
@ -550,9 +550,10 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
mutex_lock(&mvdev->mr.mkey_mtx);
|
mutex_lock(&mvdev->mr_mtx);
|
||||||
err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb);
|
err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb);
|
||||||
mutex_unlock(&mvdev->mr.mkey_mtx);
|
mutex_unlock(&mvdev->mr_mtx);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,14 +564,14 @@ int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *io
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
*change_map = false;
|
*change_map = false;
|
||||||
mutex_lock(&mr->mkey_mtx);
|
mutex_lock(&mvdev->mr_mtx);
|
||||||
if (mr->initialized) {
|
if (mr->initialized) {
|
||||||
mlx5_vdpa_info(mvdev, "memory map update\n");
|
mlx5_vdpa_info(mvdev, "memory map update\n");
|
||||||
*change_map = true;
|
*change_map = true;
|
||||||
}
|
}
|
||||||
if (!*change_map)
|
if (!*change_map)
|
||||||
err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb);
|
err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb);
|
||||||
mutex_unlock(&mr->mkey_mtx);
|
mutex_unlock(&mvdev->mr_mtx);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,7 @@ 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->mr.mkey_mtx);
|
mutex_init(&mvdev->mr_mtx);
|
||||||
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 +301,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
|
||||||
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->mr.mkey_mtx);
|
mutex_destroy(&mvdev->mr_mtx);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +318,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->mr.mkey_mtx);
|
mutex_destroy(&mvdev->mr_mtx);
|
||||||
res->valid = false;
|
res->valid = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue