Skip to content

Commit 1fcc6ea

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa/mlx5: Update cvq iotlb mapping on ASID change
For the following sequence: - cvq group is in ASID 0 - .set_map(1, cvq_iotlb) - .set_group_asid(cvq_group, 1) ... the cvq mapping from ASID 0 will be used. This is not always correct behaviour. This patch adds support for the above mentioned flow by saving the iotlb on each .set_map and updating the cvq iotlb with it on a cvq group change. 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-18-dtatulea@nvidia.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent bc14151 commit 1fcc6ea

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct mlx5_vdpa_mr {
3232
unsigned long num_directs;
3333
unsigned long num_klms;
3434

35+
struct vhost_iotlb *iotlb;
36+
3537
bool user_mr;
3638
};
3739

drivers/vdpa/mlx5/core/mr.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_
502502
destroy_user_mr(mvdev, mr);
503503
else
504504
destroy_dma_mr(mvdev, mr);
505+
506+
vhost_iotlb_free(mr->iotlb);
505507
}
506508

507509
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev,
@@ -561,6 +563,30 @@ static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
561563
else
562564
err = create_dma_mr(mvdev, mr);
563565

566+
if (err)
567+
return err;
568+
569+
mr->iotlb = vhost_iotlb_alloc(0, 0);
570+
if (!mr->iotlb) {
571+
err = -ENOMEM;
572+
goto err_mr;
573+
}
574+
575+
err = dup_iotlb(mr->iotlb, iotlb);
576+
if (err)
577+
goto err_iotlb;
578+
579+
return 0;
580+
581+
err_iotlb:
582+
vhost_iotlb_free(mr->iotlb);
583+
584+
err_mr:
585+
if (iotlb)
586+
destroy_user_mr(mvdev, mr);
587+
else
588+
destroy_dma_mr(mvdev, mr);
589+
564590
return err;
565591
}
566592

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3209,12 +3209,19 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev, u32 group,
32093209
unsigned int asid)
32103210
{
32113211
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
3212+
int err = 0;
32123213

32133214
if (group >= MLX5_VDPA_NUMVQ_GROUPS)
32143215
return -EINVAL;
32153216

32163217
mvdev->group2asid[group] = asid;
3217-
return 0;
3218+
3219+
mutex_lock(&mvdev->mr_mtx);
3220+
if (group == MLX5_VDPA_CVQ_GROUP && mvdev->mr[asid])
3221+
err = mlx5_vdpa_update_cvq_iotlb(mvdev, mvdev->mr[asid]->iotlb, asid);
3222+
mutex_unlock(&mvdev->mr_mtx);
3223+
3224+
return err;
32183225
}
32193226

32203227
static const struct vdpa_config_ops mlx5_vdpa_ops = {

0 commit comments

Comments
 (0)