Skip to content

Commit bc14151

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa/mlx5: Make iotlb helper functions more generic
They will be used in a follow-up patch. For dup_iotlb, avoid the src == dst case. This is an error. 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-17-dtatulea@nvidia.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 27e74c6 commit bc14151

File tree

1 file changed

+11
-8
lines changed
  • drivers/vdpa/mlx5/core

1 file changed

+11
-8
lines changed

drivers/vdpa/mlx5/core/mr.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,30 +454,33 @@ static void destroy_dma_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr)
454454
mlx5_vdpa_destroy_mkey(mvdev, mr->mkey);
455455
}
456456

457-
static int dup_iotlb(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *src)
457+
static int dup_iotlb(struct vhost_iotlb *dst, struct vhost_iotlb *src)
458458
{
459459
struct vhost_iotlb_map *map;
460460
u64 start = 0, last = ULLONG_MAX;
461461
int err;
462462

463+
if (dst == src)
464+
return -EINVAL;
465+
463466
if (!src) {
464-
err = vhost_iotlb_add_range(mvdev->cvq.iotlb, start, last, start, VHOST_ACCESS_RW);
467+
err = vhost_iotlb_add_range(dst, start, last, start, VHOST_ACCESS_RW);
465468
return err;
466469
}
467470

468471
for (map = vhost_iotlb_itree_first(src, start, last); map;
469472
map = vhost_iotlb_itree_next(map, start, last)) {
470-
err = vhost_iotlb_add_range(mvdev->cvq.iotlb, map->start, map->last,
473+
err = vhost_iotlb_add_range(dst, map->start, map->last,
471474
map->addr, map->perm);
472475
if (err)
473476
return err;
474477
}
475478
return 0;
476479
}
477480

478-
static void prune_iotlb(struct mlx5_vdpa_dev *mvdev)
481+
static void prune_iotlb(struct vhost_iotlb *iotlb)
479482
{
480-
vhost_iotlb_del_range(mvdev->cvq.iotlb, 0, ULLONG_MAX);
483+
vhost_iotlb_del_range(iotlb, 0, ULLONG_MAX);
481484
}
482485

483486
static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr)
@@ -544,7 +547,7 @@ void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
544547
for (int i = 0; i < MLX5_VDPA_NUM_AS; i++)
545548
mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[i]);
546549

547-
prune_iotlb(mvdev);
550+
prune_iotlb(mvdev->cvq.iotlb);
548551
}
549552

550553
static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
@@ -596,8 +599,8 @@ int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev,
596599

597600
spin_lock(&mvdev->cvq.iommu_lock);
598601

599-
prune_iotlb(mvdev);
600-
err = dup_iotlb(mvdev, iotlb);
602+
prune_iotlb(mvdev->cvq.iotlb);
603+
err = dup_iotlb(mvdev->cvq.iotlb, iotlb);
601604

602605
spin_unlock(&mvdev->cvq.iommu_lock);
603606

0 commit comments

Comments
 (0)