Skip to content

Commit b03fc43

Browse files
elic307imstsirkin
authored andcommitted
vdpa/mlx5: Fix tracking of current number of VQs
Modify the code such that ndev->cur_num_vqs better reflects the actual number of data virtqueues. The value can be accurately realized after features have been negotiated. This is to prevent possible failures when modifying the RQT object if the cur_num_vqs bears invalid value. No issue was actually encountered but this also makes the code more readable. Fixes: c5a5cd3 ("vdpa/mlx5: Support configuring max data virtqueue") Signed-off-by: Eli Cohen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Si-Wei Liu<[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent f8ae3a4 commit b03fc43

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,8 +1246,7 @@ static int create_rqt(struct mlx5_vdpa_net *ndev)
12461246
if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
12471247
num = 1;
12481248
else
1249-
num = mlx5vdpa16_to_cpu(&ndev->mvdev,
1250-
ndev->config.max_virtqueue_pairs);
1249+
num = ndev->cur_num_vqs / 2;
12511250

12521251
max_rqt = min_t(int, roundup_pow_of_two(num),
12531252
1 << MLX5_CAP_GEN(ndev->mvdev.mdev, log_max_rqt_size));
@@ -1983,6 +1982,11 @@ static int mlx5_vdpa_set_driver_features(struct vdpa_device *vdev, u64 features)
19831982
return err;
19841983

19851984
ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
1985+
if (ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_MQ))
1986+
ndev->cur_num_vqs = 2 * mlx5vdpa16_to_cpu(mvdev, ndev->config.max_virtqueue_pairs);
1987+
else
1988+
ndev->cur_num_vqs = 2;
1989+
19861990
update_cvq_info(mvdev);
19871991
return err;
19881992
}
@@ -2233,6 +2237,7 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)
22332237
clear_vqs_ready(ndev);
22342238
mlx5_vdpa_destroy_mr(&ndev->mvdev);
22352239
ndev->mvdev.status = 0;
2240+
ndev->cur_num_vqs = 0;
22362241
memset(ndev->event_cbs, 0, sizeof(*ndev->event_cbs) * (mvdev->max_vqs + 1));
22372242
ndev->mvdev.actual_features = 0;
22382243
++mvdev->generation;
@@ -2641,9 +2646,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
26412646

26422647
ndev->nb.notifier_call = event_handler;
26432648
mlx5_notifier_register(mdev, &ndev->nb);
2644-
ndev->cur_num_vqs = 2 * mlx5_vdpa_max_qps(max_vqs);
26452649
mvdev->vdev.mdev = &mgtdev->mgtdev;
2646-
err = _vdpa_register_device(&mvdev->vdev, ndev->cur_num_vqs + 1);
2650+
err = _vdpa_register_device(&mvdev->vdev, 2 * mlx5_vdpa_max_qps(max_vqs) + 1);
26472651
if (err)
26482652
goto err_reg;
26492653

0 commit comments

Comments
 (0)