Skip to content

Commit 5dc31bd

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 <[email protected]> Acked-by: Eugenio Pérez <[email protected]> Signed-off-by: Dragos Tatulea <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Si-Wei Liu <[email protected]> Tested-by: Si-Wei Liu <[email protected]> Tested-by: Lei Yang <[email protected]>
1 parent cf6e024 commit 5dc31bd

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
@@ -3203,12 +3203,19 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev, u32 group,
32033203
unsigned int asid)
32043204
{
32053205
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
3206+
int err = 0;
32063207

32073208
if (group >= MLX5_VDPA_NUMVQ_GROUPS)
32083209
return -EINVAL;
32093210

32103211
mvdev->group2asid[group] = asid;
3211-
return 0;
3212+
3213+
mutex_lock(&mvdev->mr_mtx);
3214+
if (group == MLX5_VDPA_CVQ_GROUP && mvdev->mr[asid])
3215+
err = mlx5_vdpa_update_cvq_iotlb(mvdev, mvdev->mr[asid]->iotlb, asid);
3216+
mutex_unlock(&mvdev->mr_mtx);
3217+
3218+
return err;
32123219
}
32133220

32143221
static const struct vdpa_config_ops mlx5_vdpa_ops = {

0 commit comments

Comments
 (0)