Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 2eacf4b

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vdpa/mlx5: implement .reset_map driver op
Since commit 6f5312f ("vdpa/mlx5: Add support for running with virtio_vdpa"), mlx5_vdpa starts with preallocate 1:1 DMA MR at device creation time. This 1:1 DMA MR will be implicitly destroyed while the first .set_map call is invoked, in which case callers like vhost-vdpa will start to set up custom mappings. When the .reset callback is invoked, the custom mappings will be cleared and the 1:1 DMA MR will be re-created. In order to reduce excessive memory mapping cost in live migration, it is desirable to decouple the vhost-vdpa IOTLB abstraction from the virtio device life cycle, i.e. mappings can be kept around intact across virtio device reset. Leverage the .reset_map callback, which is meant to destroy the regular MR (including cvq mapping) on the given ASID and recreate the initial DMA mapping. That way, the device .reset op runs free from having to maintain and clean up memory mappings by itself. Additionally, implement .compat_reset to cater for older userspace, which may wish to see mapping to be cleared during reset. Co-developed-by: Dragos Tatulea <[email protected]> Signed-off-by: Dragos Tatulea <[email protected]> Signed-off-by: Si-Wei Liu <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Tested-by: Lei Yang <[email protected]>
1 parent bc91df5 commit 2eacf4b

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev,
127127
struct vhost_iotlb *iotlb,
128128
unsigned int asid);
129129
int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev);
130+
int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid);
130131

131132
#define mlx5_vdpa_warn(__dev, format, ...) \
132133
dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \

drivers/vdpa/mlx5/core/mr.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,20 @@ int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev)
645645

646646
return mlx5_vdpa_update_cvq_iotlb(mvdev, NULL, 0);
647647
}
648+
649+
int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
650+
{
651+
if (asid >= MLX5_VDPA_NUM_AS)
652+
return -EINVAL;
653+
654+
mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[asid]);
655+
656+
if (asid == 0 && MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
657+
if (mlx5_vdpa_create_dma_mr(mvdev))
658+
mlx5_vdpa_warn(mvdev, "create DMA MR failed\n");
659+
} else {
660+
mlx5_vdpa_update_cvq_iotlb(mvdev, NULL, asid);
661+
}
662+
663+
return 0;
664+
}

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ static void init_group_to_asid_map(struct mlx5_vdpa_dev *mvdev)
28762876
mvdev->group2asid[i] = 0;
28772877
}
28782878

2879-
static int mlx5_vdpa_reset(struct vdpa_device *vdev)
2879+
static int mlx5_vdpa_compat_reset(struct vdpa_device *vdev, u32 flags)
28802880
{
28812881
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
28822882
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
@@ -2888,7 +2888,8 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)
28882888
unregister_link_notifier(ndev);
28892889
teardown_driver(ndev);
28902890
clear_vqs_ready(ndev);
2891-
mlx5_vdpa_destroy_mr_resources(&ndev->mvdev);
2891+
if (flags & VDPA_RESET_F_CLEAN_MAP)
2892+
mlx5_vdpa_destroy_mr_resources(&ndev->mvdev);
28922893
ndev->mvdev.status = 0;
28932894
ndev->mvdev.suspended = false;
28942895
ndev->cur_num_vqs = 0;
@@ -2899,7 +2900,8 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)
28992900
init_group_to_asid_map(mvdev);
29002901
++mvdev->generation;
29012902

2902-
if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
2903+
if ((flags & VDPA_RESET_F_CLEAN_MAP) &&
2904+
MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
29032905
if (mlx5_vdpa_create_dma_mr(mvdev))
29042906
mlx5_vdpa_warn(mvdev, "create MR failed\n");
29052907
}
@@ -2908,6 +2910,11 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)
29082910
return 0;
29092911
}
29102912

2913+
static int mlx5_vdpa_reset(struct vdpa_device *vdev)
2914+
{
2915+
return mlx5_vdpa_compat_reset(vdev, 0);
2916+
}
2917+
29112918
static size_t mlx5_vdpa_get_config_size(struct vdpa_device *vdev)
29122919
{
29132920
return sizeof(struct virtio_net_config);
@@ -2987,6 +2994,18 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, unsigned int asid,
29872994
return err;
29882995
}
29892996

2997+
static int mlx5_vdpa_reset_map(struct vdpa_device *vdev, unsigned int asid)
2998+
{
2999+
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
3000+
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
3001+
int err;
3002+
3003+
down_write(&ndev->reslock);
3004+
err = mlx5_vdpa_reset_mr(mvdev, asid);
3005+
up_write(&ndev->reslock);
3006+
return err;
3007+
}
3008+
29903009
static struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
29913010
{
29923011
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
@@ -3250,11 +3269,13 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = {
32503269
.get_status = mlx5_vdpa_get_status,
32513270
.set_status = mlx5_vdpa_set_status,
32523271
.reset = mlx5_vdpa_reset,
3272+
.compat_reset = mlx5_vdpa_compat_reset,
32533273
.get_config_size = mlx5_vdpa_get_config_size,
32543274
.get_config = mlx5_vdpa_get_config,
32553275
.set_config = mlx5_vdpa_set_config,
32563276
.get_generation = mlx5_vdpa_get_generation,
32573277
.set_map = mlx5_vdpa_set_map,
3278+
.reset_map = mlx5_vdpa_reset_map,
32583279
.set_group_asid = mlx5_set_group_asid,
32593280
.get_vq_dma_dev = mlx5_get_vq_dma_dev,
32603281
.free = mlx5_vdpa_free,

0 commit comments

Comments
 (0)