Skip to content

Commit 9ee8110

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa/mlx5: Fix mr->initialized semantics
The mr->initialized flag is shared between the control vq and data vq part of the mr init/uninit. But if the control vq and data vq get placed in different ASIDs, it can happen that initializing the control vq will prevent the data vq mr from being initialized. This patch consolidates the control and data vq init parts into their own init functions. The mr->initialized will now be used for the data vq only. The control vq currently doesn't need a flag. The uninitializing part is also taken care of: mlx5_vdpa_destroy_mr got split into data and control vq functions which are now also ASID aware. Fixes: 8fcd20c ("vdpa/mlx5: Support different address spaces for control and data") Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com> Reviewed-by: Eugenio Pérez <eperezma@redhat.com> Reviewed-by: Gal Pressman <gal@nvidia.com> Message-Id: <20230802171231.11001-3-dtatulea@nvidia.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 3fe0241 commit 9ee8110

File tree

2 files changed

+71
-27
lines changed

2 files changed

+71
-27
lines changed

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {
3131
struct list_head head;
3232
unsigned long num_directs;
3333
unsigned long num_klms;
34+
/* state of dvq mr */
3435
bool initialized;
3536

3637
/* serialize mkey creation and destruction */

drivers/vdpa/mlx5/core/mr.c

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr
489489
}
490490
}
491491

492-
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev)
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+
500+
static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
493501
{
494502
struct mlx5_vdpa_mr *mr = &mvdev->mr;
495503

496-
mutex_lock(&mr->mkey_mtx);
504+
if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid)
505+
return;
506+
497507
if (!mr->initialized)
498-
goto out;
508+
return;
499509

500-
prune_iotlb(mvdev);
501510
if (mr->user_mr)
502511
destroy_user_mr(mvdev, mr);
503512
else
504513
destroy_dma_mr(mvdev, mr);
505514

506515
mr->initialized = false;
507-
out:
516+
}
517+
518+
static void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
519+
{
520+
struct mlx5_vdpa_mr *mr = &mvdev->mr;
521+
522+
mutex_lock(&mr->mkey_mtx);
523+
524+
_mlx5_vdpa_destroy_dvq_mr(mvdev, asid);
525+
_mlx5_vdpa_destroy_cvq_mr(mvdev, asid);
526+
508527
mutex_unlock(&mr->mkey_mtx);
509528
}
510529

511-
static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
512-
struct vhost_iotlb *iotlb, unsigned int asid)
530+
void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev)
531+
{
532+
mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP]);
533+
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);
544+
}
545+
546+
static int _mlx5_vdpa_create_dvq_mr(struct mlx5_vdpa_dev *mvdev,
547+
struct vhost_iotlb *iotlb,
548+
unsigned int asid)
513549
{
514550
struct mlx5_vdpa_mr *mr = &mvdev->mr;
515551
int err;
516552

517-
if (mr->initialized)
553+
if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid)
518554
return 0;
519555

520-
if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) {
521-
if (iotlb)
522-
err = create_user_mr(mvdev, iotlb);
523-
else
524-
err = create_dma_mr(mvdev, mr);
556+
if (mr->initialized)
557+
return 0;
525558

526-
if (err)
527-
return err;
528-
}
559+
if (iotlb)
560+
err = create_user_mr(mvdev, iotlb);
561+
else
562+
err = create_dma_mr(mvdev, mr);
529563

530-
if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) {
531-
err = dup_iotlb(mvdev, iotlb);
532-
if (err)
533-
goto out_err;
534-
}
564+
if (err)
565+
return err;
535566

536567
mr->initialized = true;
568+
569+
return 0;
570+
}
571+
572+
static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
573+
struct vhost_iotlb *iotlb, unsigned int asid)
574+
{
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+
537585
return 0;
538586

539587
out_err:
540-
if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) {
541-
if (iotlb)
542-
destroy_user_mr(mvdev, mr);
543-
else
544-
destroy_dma_mr(mvdev, mr);
545-
}
588+
_mlx5_vdpa_destroy_dvq_mr(mvdev, asid);
546589

547590
return err;
548591
}

0 commit comments

Comments
 (0)