[vhost,15/16] vdpa/mlx5: Make iotlb helper functions more generic

Message ID 20230928164550.980832-17-dtatulea@nvidia.com
State New
Headers
Series vdpa: Add support for vq descriptor mappings |

Commit Message

Dragos Tatulea Sept. 28, 2023, 4:45 p.m. UTC
  They will be used in a followup patch.

Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
---
 drivers/vdpa/mlx5/core/mr.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
  

Comments

Eugenio Perez Martin Oct. 5, 2023, 10:14 a.m. UTC | #1
On Thu, Sep 28, 2023 at 6:50 PM Dragos Tatulea <dtatulea@nvidia.com> wrote:
>
> They will be used in a followup patch.
>
> Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
> ---
>  drivers/vdpa/mlx5/core/mr.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c
> index 3dee6d9bed6b..a4135c16b5bf 100644
> --- a/drivers/vdpa/mlx5/core/mr.c
> +++ b/drivers/vdpa/mlx5/core/mr.c
> @@ -454,20 +454,20 @@ static void destroy_dma_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr)
>         mlx5_vdpa_destroy_mkey(mvdev, mr->mkey);
>  }
>
> -static int dup_iotlb(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *src)
> +static int dup_iotlb(struct vhost_iotlb *iotlb, struct vhost_iotlb *src)

It would be great to move this patch to vhost/iotlb, especially
because it can be reused by vdpa_sim. But it can be done on top for
sure,

Acked-by: Eugenio Pérez <eperezma@redhat.com>

>  {
>         struct vhost_iotlb_map *map;
>         u64 start = 0, last = ULLONG_MAX;
>         int err;
>
>         if (!src) {
> -               err = vhost_iotlb_add_range(mvdev->cvq.iotlb, start, last, start, VHOST_ACCESS_RW);
> +               err = vhost_iotlb_add_range(iotlb, start, last, start, VHOST_ACCESS_RW);
>                 return err;
>         }
>
>         for (map = vhost_iotlb_itree_first(src, start, last); map;
>                 map = vhost_iotlb_itree_next(map, start, last)) {
> -               err = vhost_iotlb_add_range(mvdev->cvq.iotlb, map->start, map->last,
> +               err = vhost_iotlb_add_range(iotlb, map->start, map->last,
>                                             map->addr, map->perm);
>                 if (err)
>                         return err;
> @@ -475,9 +475,9 @@ static int dup_iotlb(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *src)
>         return 0;
>  }
>
> -static void prune_iotlb(struct mlx5_vdpa_dev *mvdev)
> +static void prune_iotlb(struct vhost_iotlb *iotlb)
>  {
> -       vhost_iotlb_del_range(mvdev->cvq.iotlb, 0, ULLONG_MAX);
> +       vhost_iotlb_del_range(iotlb, 0, ULLONG_MAX);
>  }
>
>  static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr)
> @@ -544,7 +544,7 @@ void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
>         for (int i = 0; i < MLX5_VDPA_NUM_AS; i++)
>                 mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[i]);
>
> -       prune_iotlb(mvdev);
> +       prune_iotlb(mvdev->cvq.iotlb);
>  }
>
>  static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
> @@ -596,8 +596,8 @@ int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev,
>
>         spin_lock(&mvdev->cvq.iommu_lock);
>
> -       prune_iotlb(mvdev);
> -       err = dup_iotlb(mvdev, iotlb);
> +       prune_iotlb(mvdev->cvq.iotlb);
> +       err = dup_iotlb(mvdev->cvq.iotlb, iotlb);
>
>         spin_unlock(&mvdev->cvq.iommu_lock);
>
> --
> 2.41.0
>
  
Dragos Tatulea Oct. 5, 2023, 12:16 p.m. UTC | #2
On Thu, 2023-10-05 at 12:14 +0200, Eugenio Perez Martin wrote:
> On Thu, Sep 28, 2023 at 6:50 PM Dragos Tatulea <dtatulea@nvidia.com> wrote:
> > 
> > They will be used in a followup patch.
> > 
> > Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
> > ---
> >  drivers/vdpa/mlx5/core/mr.c | 16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c
> > index 3dee6d9bed6b..a4135c16b5bf 100644
> > --- a/drivers/vdpa/mlx5/core/mr.c
> > +++ b/drivers/vdpa/mlx5/core/mr.c
> > @@ -454,20 +454,20 @@ static void destroy_dma_mr(struct mlx5_vdpa_dev
> > *mvdev, struct mlx5_vdpa_mr *mr)
> >         mlx5_vdpa_destroy_mkey(mvdev, mr->mkey);
> >  }
> > 
> > -static int dup_iotlb(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *src)
> > +static int dup_iotlb(struct vhost_iotlb *iotlb, struct vhost_iotlb *src)
> 
> It would be great to move this patch to vhost/iotlb, especially
> because it can be reused by vdpa_sim. But it can be done on top for
> sure,
> 
Ack. Will create a separate patch for this after the series.

Thanks,
Dragos

> Acked-by: Eugenio Pérez <eperezma@redhat.com>
> 
> >  {
> >         struct vhost_iotlb_map *map;
> >         u64 start = 0, last = ULLONG_MAX;
> >         int err;
> > 
> >         if (!src) {
> > -               err = vhost_iotlb_add_range(mvdev->cvq.iotlb, start, last,
> > start, VHOST_ACCESS_RW);
> > +               err = vhost_iotlb_add_range(iotlb, start, last, start,
> > VHOST_ACCESS_RW);
> >                 return err;
> >         }
> > 
> >         for (map = vhost_iotlb_itree_first(src, start, last); map;
> >                 map = vhost_iotlb_itree_next(map, start, last)) {
> > -               err = vhost_iotlb_add_range(mvdev->cvq.iotlb, map->start,
> > map->last,
> > +               err = vhost_iotlb_add_range(iotlb, map->start, map->last,
> >                                             map->addr, map->perm);
> >                 if (err)
> >                         return err;
> > @@ -475,9 +475,9 @@ static int dup_iotlb(struct mlx5_vdpa_dev *mvdev, struct
> > vhost_iotlb *src)
> >         return 0;
> >  }
> > 
> > -static void prune_iotlb(struct mlx5_vdpa_dev *mvdev)
> > +static void prune_iotlb(struct vhost_iotlb *iotlb)
> >  {
> > -       vhost_iotlb_del_range(mvdev->cvq.iotlb, 0, ULLONG_MAX);
> > +       vhost_iotlb_del_range(iotlb, 0, ULLONG_MAX);
> >  }
> > 
> >  static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct
> > mlx5_vdpa_mr *mr)
> > @@ -544,7 +544,7 @@ void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev
> > *mvdev)
> >         for (int i = 0; i < MLX5_VDPA_NUM_AS; i++)
> >                 mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[i]);
> > 
> > -       prune_iotlb(mvdev);
> > +       prune_iotlb(mvdev->cvq.iotlb);
> >  }
> > 
> >  static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
> > @@ -596,8 +596,8 @@ int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev
> > *mvdev,
> > 
> >         spin_lock(&mvdev->cvq.iommu_lock);
> > 
> > -       prune_iotlb(mvdev);
> > -       err = dup_iotlb(mvdev, iotlb);
> > +       prune_iotlb(mvdev->cvq.iotlb);
> > +       err = dup_iotlb(mvdev->cvq.iotlb, iotlb);
> > 
> >         spin_unlock(&mvdev->cvq.iommu_lock);
> > 
> > --
> > 2.41.0
> > 
>
  

Patch

diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c
index 3dee6d9bed6b..a4135c16b5bf 100644
--- a/drivers/vdpa/mlx5/core/mr.c
+++ b/drivers/vdpa/mlx5/core/mr.c
@@ -454,20 +454,20 @@  static void destroy_dma_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr)
 	mlx5_vdpa_destroy_mkey(mvdev, mr->mkey);
 }
 
-static int dup_iotlb(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *src)
+static int dup_iotlb(struct vhost_iotlb *iotlb, struct vhost_iotlb *src)
 {
 	struct vhost_iotlb_map *map;
 	u64 start = 0, last = ULLONG_MAX;
 	int err;
 
 	if (!src) {
-		err = vhost_iotlb_add_range(mvdev->cvq.iotlb, start, last, start, VHOST_ACCESS_RW);
+		err = vhost_iotlb_add_range(iotlb, start, last, start, VHOST_ACCESS_RW);
 		return err;
 	}
 
 	for (map = vhost_iotlb_itree_first(src, start, last); map;
 		map = vhost_iotlb_itree_next(map, start, last)) {
-		err = vhost_iotlb_add_range(mvdev->cvq.iotlb, map->start, map->last,
+		err = vhost_iotlb_add_range(iotlb, map->start, map->last,
 					    map->addr, map->perm);
 		if (err)
 			return err;
@@ -475,9 +475,9 @@  static int dup_iotlb(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *src)
 	return 0;
 }
 
-static void prune_iotlb(struct mlx5_vdpa_dev *mvdev)
+static void prune_iotlb(struct vhost_iotlb *iotlb)
 {
-	vhost_iotlb_del_range(mvdev->cvq.iotlb, 0, ULLONG_MAX);
+	vhost_iotlb_del_range(iotlb, 0, ULLONG_MAX);
 }
 
 static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr)
@@ -544,7 +544,7 @@  void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
 	for (int i = 0; i < MLX5_VDPA_NUM_AS; i++)
 		mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[i]);
 
-	prune_iotlb(mvdev);
+	prune_iotlb(mvdev->cvq.iotlb);
 }
 
 static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
@@ -596,8 +596,8 @@  int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev,
 
 	spin_lock(&mvdev->cvq.iommu_lock);
 
-	prune_iotlb(mvdev);
-	err = dup_iotlb(mvdev, iotlb);
+	prune_iotlb(mvdev->cvq.iotlb);
+	err = dup_iotlb(mvdev->cvq.iotlb, iotlb);
 
 	spin_unlock(&mvdev->cvq.iommu_lock);