Skip to content

Commit ef72e58

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa/mlx5: Decouple cvq iotlb handling from hw mapping code
The handling of the cvq iotlb is currently coupled with the creation and destruction of the hardware mkeys (mr). This patch moves cvq iotlb handling into its own function and shifts it to a scope that is not related to mr handling. As cvq handling is just a prune_iotlb + dup_iotlb cycle, put it all in the same "update" function. Finally, the destruction path is handled by directly pruning the iotlb. After this move is done the ASID mr code can be collapsed into a single function. Acked-by: Jason Wang <jasowang@redhat.com> Acked-by: Eugenio Pérez <eperezma@redhat.com> Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com> Message-Id: <20231018171456.1624030-8-dtatulea@nvidia.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 5059e6e commit ef72e58

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
120120
unsigned int asid);
121121
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);
122122
void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid);
123+
int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev,
124+
struct vhost_iotlb *iotlb,
125+
unsigned int asid);
123126
int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev);
124127

125128
#define mlx5_vdpa_warn(__dev, format, ...) \

drivers/vdpa/mlx5/core/mr.c

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -489,14 +489,6 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr
489489
}
490490
}
491491

492-
static void _mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
493-
{
494-
if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid)
495-
return;
496-
497-
prune_iotlb(mvdev);
498-
}
499-
500492
static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
501493
{
502494
struct mlx5_vdpa_mr *mr = &mvdev->mr;
@@ -522,25 +514,14 @@ void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
522514
mutex_lock(&mr->mkey_mtx);
523515

524516
_mlx5_vdpa_destroy_dvq_mr(mvdev, asid);
525-
_mlx5_vdpa_destroy_cvq_mr(mvdev, asid);
526517

527518
mutex_unlock(&mr->mkey_mtx);
528519
}
529520

530521
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev)
531522
{
532-
mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP]);
533523
mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]);
534-
}
535-
536-
static int _mlx5_vdpa_create_cvq_mr(struct mlx5_vdpa_dev *mvdev,
537-
struct vhost_iotlb *iotlb,
538-
unsigned int asid)
539-
{
540-
if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid)
541-
return 0;
542-
543-
return dup_iotlb(mvdev, iotlb);
524+
prune_iotlb(mvdev);
544525
}
545526

546527
static int _mlx5_vdpa_create_dvq_mr(struct mlx5_vdpa_dev *mvdev,
@@ -572,22 +553,7 @@ static int _mlx5_vdpa_create_dvq_mr(struct mlx5_vdpa_dev *mvdev,
572553
static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
573554
struct vhost_iotlb *iotlb, unsigned int asid)
574555
{
575-
int err;
576-
577-
err = _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid);
578-
if (err)
579-
return err;
580-
581-
err = _mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid);
582-
if (err)
583-
goto out_err;
584-
585-
return 0;
586-
587-
out_err:
588-
_mlx5_vdpa_destroy_dvq_mr(mvdev, asid);
589-
590-
return err;
556+
return _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid);
591557
}
592558

593559
int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
@@ -620,7 +586,24 @@ int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *io
620586
return err;
621587
}
622588

589+
int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev,
590+
struct vhost_iotlb *iotlb,
591+
unsigned int asid)
592+
{
593+
if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid)
594+
return 0;
595+
596+
prune_iotlb(mvdev);
597+
return dup_iotlb(mvdev, iotlb);
598+
}
599+
623600
int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev)
624601
{
625-
return mlx5_vdpa_create_mr(mvdev, NULL, 0);
602+
int err;
603+
604+
err = mlx5_vdpa_create_mr(mvdev, NULL, 0);
605+
if (err)
606+
return err;
607+
608+
return mlx5_vdpa_update_cvq_iotlb(mvdev, NULL, 0);
626609
}

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,10 +2934,13 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
29342934
return err;
29352935
}
29362936

2937-
if (change_map)
2937+
if (change_map) {
29382938
err = mlx5_vdpa_change_map(mvdev, iotlb, asid);
2939+
if (err)
2940+
return err;
2941+
}
29392942

2940-
return err;
2943+
return mlx5_vdpa_update_cvq_iotlb(mvdev, iotlb, asid);
29412944
}
29422945

29432946
static int mlx5_vdpa_set_map(struct vdpa_device *vdev, unsigned int asid,

0 commit comments

Comments
 (0)