Skip to content

Commit c5c0b1c

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa/mlx5: Introduce mr for vq descriptor
Introduce the vq descriptor group and mr per ASID. Until now .set_map on ASID 1 was only updating the cvq iotlb. From now on it also creates a mkey for it. The current patch doesn't use it but follow-up patches will add hardware support for mapping the vq descriptors. 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-15-dtatulea@nvidia.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 51f9574 commit c5c0b1c

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ struct mlx5_vdpa_wq_ent {
7070
enum {
7171
MLX5_VDPA_DATAVQ_GROUP,
7272
MLX5_VDPA_CVQ_GROUP,
73+
MLX5_VDPA_DATAVQ_DESC_GROUP,
7374
MLX5_VDPA_NUMVQ_GROUPS
7475
};
7576

7677
enum {
77-
MLX5_VDPA_NUM_AS = MLX5_VDPA_NUMVQ_GROUPS
78+
MLX5_VDPA_NUM_AS = 2
7879
};
7980

8081
struct mlx5_vdpa_dev {
@@ -89,7 +90,7 @@ struct mlx5_vdpa_dev {
8990
u16 max_idx;
9091
u32 generation;
9192

92-
struct mlx5_vdpa_mr *mr;
93+
struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS];
9394
/* serialize mr access */
9495
struct mutex mr_mtx;
9596
struct mlx5_control_vq cvq;

drivers/vdpa/mlx5/core/mr.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,10 @@ void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev,
511511

512512
_mlx5_vdpa_destroy_mr(mvdev, mr);
513513

514-
if (mvdev->mr == mr)
515-
mvdev->mr = NULL;
514+
for (int i = 0; i < MLX5_VDPA_NUM_AS; i++) {
515+
if (mvdev->mr[i] == mr)
516+
mvdev->mr[i] = NULL;
517+
}
516518

517519
mutex_unlock(&mvdev->mr_mtx);
518520

@@ -523,11 +525,11 @@ void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev,
523525
struct mlx5_vdpa_mr *new_mr,
524526
unsigned int asid)
525527
{
526-
struct mlx5_vdpa_mr *old_mr = mvdev->mr;
528+
struct mlx5_vdpa_mr *old_mr = mvdev->mr[asid];
527529

528530
mutex_lock(&mvdev->mr_mtx);
529531

530-
mvdev->mr = new_mr;
532+
mvdev->mr[asid] = new_mr;
531533
if (old_mr) {
532534
_mlx5_vdpa_destroy_mr(mvdev, old_mr);
533535
kfree(old_mr);
@@ -539,7 +541,9 @@ void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev,
539541

540542
void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
541543
{
542-
mlx5_vdpa_destroy_mr(mvdev, mvdev->mr);
544+
for (int i = 0; i < MLX5_VDPA_NUM_AS; i++)
545+
mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[i]);
546+
543547
prune_iotlb(mvdev);
544548
}
545549

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,8 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque
862862
{
863863
int inlen = MLX5_ST_SZ_BYTES(create_virtio_net_q_in);
864864
u32 out[MLX5_ST_SZ_DW(create_virtio_net_q_out)] = {};
865+
struct mlx5_vdpa_dev *mvdev = &ndev->mvdev;
866+
struct mlx5_vdpa_mr *vq_mr;
865867
void *obj_context;
866868
u16 mlx_features;
867869
void *cmd_hdr;
@@ -914,7 +916,9 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque
914916
MLX5_SET64(virtio_q, vq_ctx, desc_addr, mvq->desc_addr);
915917
MLX5_SET64(virtio_q, vq_ctx, used_addr, mvq->device_addr);
916918
MLX5_SET64(virtio_q, vq_ctx, available_addr, mvq->driver_addr);
917-
MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, ndev->mvdev.mr->mkey);
919+
vq_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]];
920+
if (vq_mr)
921+
MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, vq_mr->mkey);
918922
MLX5_SET(virtio_q, vq_ctx, umem_1_id, mvq->umem1.id);
919923
MLX5_SET(virtio_q, vq_ctx, umem_1_size, mvq->umem1.size);
920924
MLX5_SET(virtio_q, vq_ctx, umem_2_id, mvq->umem2.id);
@@ -2679,7 +2683,8 @@ static void restore_channels_info(struct mlx5_vdpa_net *ndev)
26792683
}
26802684

26812685
static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,
2682-
struct mlx5_vdpa_mr *new_mr, unsigned int asid)
2686+
struct mlx5_vdpa_mr *new_mr,
2687+
unsigned int asid)
26832688
{
26842689
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
26852690
int err;
@@ -2698,8 +2703,10 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,
26982703

26992704
restore_channels_info(ndev);
27002705
err = setup_driver(mvdev);
2706+
if (err)
2707+
return err;
27012708

2702-
return err;
2709+
return 0;
27032710
}
27042711

27052712
/* reslock must be held for this function */
@@ -2919,8 +2926,8 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
29192926
struct mlx5_vdpa_mr *new_mr;
29202927
int err;
29212928

2922-
if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid)
2923-
goto end;
2929+
if (asid >= MLX5_VDPA_NUM_AS)
2930+
return -EINVAL;
29242931

29252932
if (vhost_iotlb_itree_first(iotlb, 0, U64_MAX)) {
29262933
new_mr = mlx5_vdpa_create_mr(mvdev, iotlb);
@@ -2934,7 +2941,7 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
29342941
new_mr = NULL;
29352942
}
29362943

2937-
if (!mvdev->mr) {
2944+
if (!mvdev->mr[asid]) {
29382945
mlx5_vdpa_update_mr(mvdev, new_mr, asid);
29392946
} else {
29402947
err = mlx5_vdpa_change_map(mvdev, new_mr, asid);
@@ -2944,7 +2951,6 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
29442951
}
29452952
}
29462953

2947-
end:
29482954
return mlx5_vdpa_update_cvq_iotlb(mvdev, iotlb, asid);
29492955

29502956
out_err:

0 commit comments

Comments
 (0)