Skip to content

Commit 55229ea

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 <[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 625e4b5 commit 55229ea

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
@@ -861,6 +861,8 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque
861861
{
862862
int inlen = MLX5_ST_SZ_BYTES(create_virtio_net_q_in);
863863
u32 out[MLX5_ST_SZ_DW(create_virtio_net_q_out)] = {};
864+
struct mlx5_vdpa_dev *mvdev = &ndev->mvdev;
865+
struct mlx5_vdpa_mr *vq_mr;
864866
void *obj_context;
865867
u16 mlx_features;
866868
void *cmd_hdr;
@@ -913,7 +915,9 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque
913915
MLX5_SET64(virtio_q, vq_ctx, desc_addr, mvq->desc_addr);
914916
MLX5_SET64(virtio_q, vq_ctx, used_addr, mvq->device_addr);
915917
MLX5_SET64(virtio_q, vq_ctx, available_addr, mvq->driver_addr);
916-
MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, ndev->mvdev.mr->mkey);
918+
vq_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]];
919+
if (vq_mr)
920+
MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, vq_mr->mkey);
917921
MLX5_SET(virtio_q, vq_ctx, umem_1_id, mvq->umem1.id);
918922
MLX5_SET(virtio_q, vq_ctx, umem_1_size, mvq->umem1.size);
919923
MLX5_SET(virtio_q, vq_ctx, umem_2_id, mvq->umem2.id);
@@ -2673,7 +2677,8 @@ static void restore_channels_info(struct mlx5_vdpa_net *ndev)
26732677
}
26742678

26752679
static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,
2676-
struct mlx5_vdpa_mr *new_mr, unsigned int asid)
2680+
struct mlx5_vdpa_mr *new_mr,
2681+
unsigned int asid)
26772682
{
26782683
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
26792684
int err;
@@ -2692,8 +2697,10 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,
26922697

26932698
restore_channels_info(ndev);
26942699
err = setup_driver(mvdev);
2700+
if (err)
2701+
return err;
26952702

2696-
return err;
2703+
return 0;
26972704
}
26982705

26992706
/* reslock must be held for this function */
@@ -2913,8 +2920,8 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
29132920
struct mlx5_vdpa_mr *new_mr;
29142921
int err;
29152922

2916-
if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid)
2917-
goto end;
2923+
if (asid >= MLX5_VDPA_NUM_AS)
2924+
return -EINVAL;
29182925

29192926
if (vhost_iotlb_itree_first(iotlb, 0, U64_MAX)) {
29202927
new_mr = mlx5_vdpa_create_mr(mvdev, iotlb);
@@ -2928,7 +2935,7 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
29282935
new_mr = NULL;
29292936
}
29302937

2931-
if (!mvdev->mr) {
2938+
if (!mvdev->mr[asid]) {
29322939
mlx5_vdpa_update_mr(mvdev, new_mr, asid);
29332940
} else {
29342941
err = mlx5_vdpa_change_map(mvdev, new_mr, asid);
@@ -2938,7 +2945,6 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
29382945
}
29392946
}
29402947

2941-
end:
29422948
return mlx5_vdpa_update_cvq_iotlb(mvdev, iotlb, asid);
29432949

29442950
out_err:

0 commit comments

Comments
 (0)