vdpa/mlx5: Fixes for ASID handling
Subsystems (3)
Dragos Tatulea
maintainercover vdpa/mlx5: Fixes for ASID handling
This patch series is based on Eugenio's fix for handling CVQs in a different ASID [0].
The first patch is the actual fix.
The next 2 patches are fixing a possible issue that I found while implementing patch 1. The patches are ordered like this for clarity.
[0] https://lore.kernel.org/lkml/[email protected]/
Dragos Tatulea (1):
vdpa/mlx5: Fix mr->initialized semantics
Eugenio Pérez (1):
vdpa/mlx5: Delete control vq iotlb in destroy_mr only when necessary
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 +- 3 files changed, 74 insertions(+), 29 deletions(-)
Signature · 6 lines
2.41.0 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Dragos Tatulea
maintainerPATCH 1/2 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.
--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)
drivers/vdpa/mlx5/core/mlx5_vdpa.h +1 -0
@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */
drivers/vdpa/mlx5/core/mr.c +70 -27
130 lines not on this page · raw message
Signature · 6 lines
2.41.0 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 91 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);
drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);
This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
One example is that, if we only do dup_iotlb() but not try to create dma mr here, we will break virtio-vdpa:
commit 6f5312f801836e6af9bcbb0bdb44dc423e129206
Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300
vdpa/mlx5: Add support for running with virtio_vdpa
In order to support running vdpa using vritio_vdpa driver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.
We create the 1:1 MR in mlx5_vdpa_dev_add() only in case firmware supports the general capability umem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.
If the set_map() callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.
Thanks
Quoted 69 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --
Quoted 2 lines
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Dragos Tatulea
maintainerRe: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 101 lines · Jason Wang
Quoted 100 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces forcontrol and data")
Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>---
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++---------2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr { struct list_head head; unsigned long num_directs; unsigned long num_klms; + /* state of dvq mr */ bool initialized; /* serialize mkey creation and destruction */drivers/vdpa/mlx5/core/mr.c +13
-4@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) + return; + + prune_iotlb(mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) { struct mlx5_vdpa_mr *mr = &mvdev->mr; - mutex_lock(&mr->mkey_mtx); + if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) + return; + if (!mr->initialized) - goto out; + return; - prune_iotlb(mvdev); if (mr->user_mr) destroy_user_mr(mvdev, mr);else
destroy_dma_mr(mvdev, mr);
mr->initialized= false;drivers/vdpa/mlx5/core/mr.c +3
-1-out: +} + +static void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsignedint asid)
drivers/vdpa/mlx5/core/mr.c +8
-0+{ + struct mlx5_vdpa_mr *mr = &mvdev->mr; + + mutex_lock(&mr->mkey_mtx); + + _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); + _mlx5_vdpa_destroy_cvq_mr(mvdev, asid); +
mutex_unlock(&mr->mkey_mtx);
}-static int _mlx5_vdpa_create_mr(struct
mlx5_vdpa_dev*mvdev, - structvhost_iotlb*iotlb, unsigned int asid)drivers/vdpa/mlx5/core/mr.c +3
-0+void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ + mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-Quoted 1 line
group2asid[MLX5_VDPA_CVQ_GROUP]);
+ mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-
Quoted 1 line
group2asid[MLX5_VDPA_DATAVQ_GROUP]);
Quoted 14 lines
drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, + unsigned int asid) +{ + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) + return 0; + + return dup_iotlb(mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Are you worried by the changes in this patch or about the possibility of having
The reason for this change is that I noticed if you create one mr in one asid you could be blocked out from creating another one in a different asid due to mr->initialized being true. To me that seemed problematic. Is it not?
Quoted 3 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:
How will that be possible? _mlx5_vdpa_create_mr calls _mlx5_vdpa_create_dvq_mr and _mlx5_vdpa_create_cvq_mr. The only thing that is different in this patch is that the cvq is not protected by an init flag. My understanding was that it would be ok to dup_iotlb again. Is it not? If not I could add an additional initialized flag for the cvq mr.
Thanks,
Dragos
Quoted 103 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206
Author: Eli Cohen <[email protected]>
Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 72 lines
drivers/vdpa/mlx5/core/mr.c +5
-0+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, + unsigned int asid){
structmlx5_vdpa_mr*mr =&mvdev->mr;
int err;- if (
mr->initialized)
+ if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) return 0;- if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) { - if (iotlb)
- err =create_user_mr(mvdev, iotlb); - else
- err =create_dma_mr(mvdev, mr); + if (mr->initialized)
+ return 0;- if (err)
- return err;
- }
+ if (iotlb)
+ err =create_user_mr(mvdev, iotlb); + else
+ err =create_dma_mr(mvdev, mr);- if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) { - err =
dup_iotlb(mvdev, iotlb);
- if (err)
- gotoout_err;
- }
+ if (err)
+ return err;
mr->initialized= true;drivers/vdpa/mlx5/core/mr.c +6
-0+ + return 0; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, unsigned intasid)
drivers/vdpa/mlx5/core/mr.c +11
-0+{ + int err; + + err = _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); + if (err) + return err; + + err = _mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid); + if (err) + goto out_err; +return 0;
out_err:
- if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) { - if (iotlb)
-destroy_user_mr(mvdev, mr);
- else
-destroy_dma_mr(mvdev, mr);
- }
+_mlx5_vdpa_destroy_dvq_mr(mvdev, asid);return err;
}
--
2.41.0
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 117 lines · Dragos Tatulea
Quoted 101 lines · Jason Wang
Quoted 100 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces forcontrol and data")
Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev- >group2asid[MLX5_VDPA_CVQ_GROUP]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev- >group2asid[MLX5_VDPA_DATAVQ_GROUP]);Quoted 14 lines
drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 5 lines
Are you worried by the changes in this patch or about the possibility of having
The reason for this change is that I noticed if you create one mr in one asid you could be blocked out from creating another one in a different asid due to
mr->initializedbeing true. To me that seemed problematic. Is it not?
My feeling is that mr.c should be device agnostic. It needs to know nothing about the device details to work. But this patch seems to break the layer.
Quoted 9 lines
Quoted 4 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:How will that be possible?
_mlx5_vdpa_create_mrcalls_mlx5_vdpa_create_dvq_mrand_mlx5_vdpa_create_cvq_mr. The only thing that is different in this patch is that the cvq is not protected by an init flag. My understanding was that it would be ok todup_iotlbagain. Is it not? If not I could add an additional initialized flag for the cvq mr.
You are right here.
Thanks
Quoted 108 lines
Thanks,
DragosQuoted 103 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 72 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Dragos Tatulea
maintainerRe: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 130 lines · Jason Wang
Quoted 120 lines · Dragos Tatulea
Quoted 104 lines · Jason Wang
Quoted 103 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces forcontrol and data")
Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>---
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++---------2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr { struct list_head head; unsigned long num_directs; unsigned long num_klms; + /* state of dvq mr */ bool initialized; /* serialize mkey creation and destruction */drivers/vdpa/mlx5/core/mr.c +1
-1@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)drivers/vdpa/mlx5/core/mr.c +8
-0+{ + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) + return; + + prune_iotlb(mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)
{
structmlx5_vdpa_mr*mr =&mvdev->mr;-
mutex_lock(&mr->mkey_mtx);
+ if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) + return;
+
if (!mr->initialized)
- goto out;
+ return;-
prune_iotlb(mvdev);
if (mr->user_mr)
destroy_user_mr(mvdev, mr);
else
destroy_dma_mr(mvdev, mr);
mr->initialized= false;drivers/vdpa/mlx5/core/mr.c +3
-1-out: +} + +static void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)drivers/vdpa/mlx5/core/mr.c +8
-0+{ + struct mlx5_vdpa_mr *mr = &mvdev->mr; + + mutex_lock(&mr->mkey_mtx); + + _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); + _mlx5_vdpa_destroy_cvq_mr(mvdev, asid); +
mutex_unlock(&mr->mkey_mtx);
}-static int _mlx5_vdpa_create_mr(struct
mlx5_vdpa_dev*mvdev, - structvhost_iotlb*iotlb, unsigned int asid)drivers/vdpa/mlx5/core/mr.c +3
-0+void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ + mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-Quoted 1 line
group2asid[MLX5_VDPA_CVQ_GROUP]);
+ mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-
Quoted 1 line
group2asid[MLX5_VDPA_DATAVQ_GROUP]);
Quoted 14 lines
drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, + unsigned int asid) +{ + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) + return 0; + + return dup_iotlb(mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 8 lines
Are you worried by the changes in this patch or about the possibility of having
The reason for this change is that I noticed if you create one mr in one asid
you could be blocked out from creating another one in a different asid due tomr->initializedbeing true. To me that seemed problematic. Is it not?
Quoted 4 lines
My feeling is that
mr.cshould be device agnostic. It needs to know nothing about the device details to work. But this patch seems to break the layer.
But the same logic was there before (with the exception of cvq not having an init flag anymore). So what am I missing here?
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:How will that be possible?
_mlx5_vdpa_create_mrcalls_mlx5_vdpa_create_dvq_mr
and_mlx5_vdpa_create_cvq_mr. The only thing that is different in this patch is
that the cvq is not protected by an init flag. My understanding was that it would be ok todup_iotlbagain. Is it not? If not I could add an additional initialized flag for the cvq mr.
Quoted 115 lines
You are right here.
Thanks
Quoted 109 lines
Thanks,
DragosQuoted 104 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206
Author: Eli Cohen <[email protected]>
Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that
1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 72 lines
drivers/vdpa/mlx5/core/mr.c +5
-0+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, + unsigned int asid){
structmlx5_vdpa_mr*mr =&mvdev->mr;
int err;- if (
mr->initialized)
+ if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) return 0;- if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) { - if (iotlb)
- err =create_user_mr(mvdev, iotlb); - else
- err =create_dma_mr(mvdev, mr); + if (mr->initialized)
+ return 0;- if (err)
- return err;
- }
+ if (iotlb)
+ err =create_user_mr(mvdev, iotlb); + else
+ err =create_dma_mr(mvdev, mr);- if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) { - err =
dup_iotlb(mvdev, iotlb);
- if (err)
- gotoout_err;
- }
+ if (err)
+ return err;
mr->initialized= true;drivers/vdpa/mlx5/core/mr.c +6
-0+ + return 0; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, unsigned intasid)
drivers/vdpa/mlx5/core/mr.c +11
-0+{ + int err; + + err = _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); + if (err) + return err; + + err = _mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid); + if (err) + goto out_err; +return 0;
out_err:
- if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) { - if (iotlb)
-destroy_user_mr(mvdev, mr);
- else
-destroy_dma_mr(mvdev, mr);
- }
+_mlx5_vdpa_destroy_dvq_mr(mvdev, asid);return err;
}
--
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 132 lines · Dragos Tatulea
Quoted 130 lines · Jason Wang
Quoted 128 lines · Dragos Tatulea
Quoted 104 lines · Jason Wang
Quoted 103 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces forcontrol and data")
Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +1
-1@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)drivers/vdpa/mlx5/core/mr.c +8
-0+{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev,unsigned
int asid){ struct mlx5_vdpa_mr *mr = &mvdev->mr;drivers/vdpa/mlx5/core/mr.c +7
-4-mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)drivers/vdpa/mlx5/core/mr.c +8
-2+{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, - struct vhost_iotlb *iotlb, unsigned intasid)
drivers/vdpa/mlx5/core/mr.c +3
-0+void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ + mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-Quoted 1 line
group2asid[MLX5_VDPA_CVQ_GROUP]);
+ mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-
Quoted 1 line
group2asid[MLX5_VDPA_DATAVQ_GROUP]);
Quoted 14 lines
drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Are you worried by the changes in this patch or about the possibility of having
The reason for this change is that I noticed if you create one mr in one asid
you could be blocked out from creating another one in a different asid due tomr->initializedbeing true. To me that seemed problematic. Is it not?
Quoted 6 lines
Quoted 4 lines
My feeling is that
mr.cshould be device agnostic. It needs to know nothing about the device details to work. But this patch seems to break the layer.But the same logic was there before (with the exception of cvq not having an init flag anymore). So what am I missing here?
Nothing, I think you're right.
I think we can have this patch go first and tweak on top by moving CVQ aware logic into the net specific codes.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Dragos Tatulea
maintainerRe: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 151 lines · Jason Wang
Quoted 150 lines · Dragos Tatulea
Quoted 148 lines · Jason Wang
Quoted 136 lines · Dragos Tatulea
Quoted 117 lines · Jason Wang
Quoted 115 lines · Dragos Tatulea
The
mr->initializedflag 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. Themr->initializedwill 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_mrgot
split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spacesfor
control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>---
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++------
---2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr { struct list_head head; unsigned long num_directs; unsigned long num_klms; + /* state of dvq mr */ bool initialized; /* serialize mkey creation and destruction */drivers/vdpa/mlx5/core/mr.c +0
-0@@ -489,60 +489,103 @@ static void destroy_user_mr(struct
mlx5_vdpa_dev
*mvdev, structmlx5_vdpa_mr*mr
}
}drivers/vdpa/mlx5/core/mr.c +1
-1-void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)drivers/vdpa/mlx5/core/mr.c +8
-0+{ + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) + return; + + prune_iotlb(mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)
{
structmlx5_vdpa_mr*mr =&mvdev->mr;-
mutex_lock(&mr->mkey_mtx);
+ if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) + return;
+
if (!mr->initialized)
- goto out;
+ return;-
prune_iotlb(mvdev);
if (mr->user_mr)
destroy_user_mr(mvdev, mr);
else
destroy_dma_mr(mvdev, mr);
mr->initialized= false;drivers/vdpa/mlx5/core/mr.c +3
-1-out: +} + +static void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)drivers/vdpa/mlx5/core/mr.c +8
-0+{ + struct mlx5_vdpa_mr *mr = &mvdev->mr; + + mutex_lock(&mr->mkey_mtx); + + _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); + _mlx5_vdpa_destroy_cvq_mr(mvdev, asid); +
mutex_unlock(&mr->mkey_mtx);
}-static int _mlx5_vdpa_create_mr(struct
mlx5_vdpa_dev*mvdev, - structvhost_iotlb*iotlb, unsigned int
asid)drivers/vdpa/mlx5/core/mr.c +3
-0+void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ + mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-Quoted 1 line
group2asid[MLX5_VDPA_CVQ_GROUP]);
+ mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-
Quoted 1 line
group2asid[MLX5_VDPA_DATAVQ_GROUP]);
Quoted 14 lines
drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, + unsigned int asid) +{ + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) + return 0; + + return dup_iotlb(mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Are you worried by the changes in this patch or about the possibility of having
Quoted 6 lines
The reason for this change is that I noticed if you create one mr in one asid
you could be blocked out from creating another one in a different asid due
tomr->initializedbeing true. To me that seemed problematic. Is it not?My feeling is that
mr.cshould be device agnostic. It needs to know nothing about the device details to work. But this patch seems to break the layer.
Quoted 8 lines
Quoted 2 lines
But the same logic was there before (with the exception of cvq not having an init flag anymore). So what am I missing here?
Nothing, I think you're right.
I think we can have this patch go first and tweak on top by moving CVQ aware logic into the net specific codes.
Is this anything more than a re-org? My plan is to move the cvq mr part from mlx5_vdpa_dev into mlx5_vdpa_net. Is there anything else that you were expecting here?
Thanks,
Dragos
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 156 lines · Dragos Tatulea
Quoted 154 lines · Jason Wang
Quoted 152 lines · Dragos Tatulea
Quoted 144 lines · Jason Wang
Quoted 136 lines · Dragos Tatulea
Quoted 117 lines · Jason Wang
Quoted 115 lines · Dragos Tatulea
The
mr->initializedflag 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. Themr->initializedwill 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_mrgot
split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spacesfor
control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++------ --- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +0
-0@@ -489,60 +489,103 @@ static void destroy_user_mr(struct
mlx5_vdpa_dev
*mvdev, structmlx5_vdpa_mr*mr}}
drivers/vdpa/mlx5/core/mr.c +1
-1-void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)drivers/vdpa/mlx5/core/mr.c +8
-0+{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev,unsigned
int asid){ struct mlx5_vdpa_mr *mr = &mvdev->mr;drivers/vdpa/mlx5/core/mr.c +7
-4-mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev,unsigned
int asid)drivers/vdpa/mlx5/core/mr.c +8
-2+{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, - struct vhost_iotlb *iotlb, unsignedint
asid)drivers/vdpa/mlx5/core/mr.c +3
-0+void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ + mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-Quoted 1 line
group2asid[MLX5_VDPA_CVQ_GROUP]);
+ mlx5_vdpa_destroy_mr_asid(mvdev, mvdev-
Quoted 1 line
group2asid[MLX5_VDPA_DATAVQ_GROUP]);
Quoted 14 lines
drivers/vdpa/mlx5/core/mr.c
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Are you worried by the changes in this patch or about the possibility of having
Quoted 6 lines
The reason for this change is that I noticed if you create one mr in one asid
you could be blocked out from creating another one in a different asid due
tomr->initializedbeing true. To me that seemed problematic. Is it not?Quoted 4 lines
My feeling is that
mr.cshould be device agnostic. It needs to know nothing about the device details to work. But this patch seems to break the layer.But the same logic was there before (with the exception of cvq not having an init flag anymore). So what am I missing here?
Quoted 6 lines
Quoted 5 lines
Nothing, I think you're right.
I think we can have this patch go first and tweak on top by moving CVQ aware logic into the net specific codes.
Is this anything more than a re-org?
No.
Quoted 4 lines
My plan is to move the cvq mr part from
mlx5_vdpa_devintomlx5_vdpa_net. Is there anything else that you were expecting here?
That's fine.
Thanks
Quoted 2 lines
Thanks,
Dragos
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
In reply to Jason WangQuoted 104 lines · Jason Wang
Quoted 90 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 2 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:
For this case, I guess we may need another way to support virtio-vdpa 1:1 mapping rather than overloading virtio device reset semantics, see:
https://www.mail-archive.com/[email protected]/msg953755.html
Quoted 3 lines
Conceptually, the address mapping is not a part of the abstraction for a virtio device now. So resetting the memory mapping during virtio device reset seems wrong.
where we want to keep memory mapping intact across virtio device reset for best live migration latency/downtime. I wonder would it work to reset the mapping in vhost-vdpa life cycle out of virtio reset, say introduce a .reset_map() op to restore 1:1 mapping within vhost_vdpa_remove_as() right after vhost_vdpa_iotlb_unmap()? Then we can move the iotlb reset logic to there without worry breaking virtio-vdpa.
Thanks,
-Siwei
Quoted 94 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 66 lines
drivers/vdpa/mlx5/core/mr.c +32
-20+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);
Quoted 9 lines
Quoted 5 lines
drivers/vdpa/mlx5/core/mr.c +0
-1return err; } --2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 119 lines · Si-Wei Liu
Quoted 104 lines · Jason Wang
Quoted 90 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 2 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:For this case, I guess we may need another way to support virtio-vdpa 1:1 mapping rather than overloading virtio device reset semantics, see:
https://www.mail-archive.com/[email protected]/msg953755.html
Quoted 3 lines
Conceptually, the address mapping is not a part of the abstraction for a virtio device now. So resetting the memory mapping during virtio device reset seems wrong.
Quoted 6 lines
where we want to keep memory mapping intact across virtio device reset for best live migration latency/downtime. I wonder would it work to reset the mapping in vhost-vdpa life cycle out of virtio reset, say introduce a .reset_map() op to restore 1:1 mapping within
vhost_vdpa_remove_as()right aftervhost_vdpa_iotlb_unmap()? Then we can move the iotlb reset logic to there without worry breaking virtio-vdpa.
It looks to me we don't need a new ops. We can simply do set_map() twice or do you mean it would be faster?
Thanks
Quoted 108 lines
Thanks,
-SiweiQuoted 103 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 69 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --Quoted 2 lines
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 119 lines · Jason Wang
Quoted 118 lines · Si-Wei Liu
Quoted 104 lines · Jason Wang
Quoted 90 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 2 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:For this case, I guess we may need another way to support virtio-vdpa 1:1 mapping rather than overloading virtio device reset semantics, see:
https://www.mail-archive.com/[email protected]/msg953755.html
Quoted 3 lines
Conceptually, the address mapping is not a part of the abstraction for a virtio device now. So resetting the memory mapping during virtio device reset seems wrong.
Quoted 8 lines
Quoted 6 lines
where we want to keep memory mapping intact across virtio device reset for best live migration latency/downtime. I wonder would it work to reset the mapping in vhost-vdpa life cycle out of virtio reset, say introduce a .reset_map() op to restore 1:1 mapping within
vhost_vdpa_remove_as()right aftervhost_vdpa_iotlb_unmap()? Then we can move the iotlb reset logic to there without worry breaking virtio-vdpa.It looks to me we don't need a new ops. We can simply do
set_map()twice
What does it mean, first set_map(0, -1ULL) with zero iotlb entry passed in to destroy all iotlb mappings previously added, and second set_map(0, -1ULL) to restore 1:1 DMA MR? But userspace (maybe a buggy one but doesn't do harm) apart from vhost-vdpa itself can do unmap twice anyway, this is supported today I think. Why there'll be such obscure distinction, or what's the benefit to treat second .set_map() as recreating 1:1 mapping?
Quoted 1 line
or do you mean it would be faster?
I think with .reset_map() we at least can avoid indefinite latency hiccup from destroying and recreating 1:1 mapping with the unwarranted 2rd unmap call. And .reset_map() should work with both .dma_map() and .set_map() APIs with clear semantics.
Regards,
-Siwei
Quoted 108 lines
Thanks
Quoted 105 lines
Thanks,
-SiweiQuoted 102 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 69 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --Quoted 2 lines
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 131 lines · Si-Wei Liu
Quoted 119 lines · Jason Wang
Quoted 118 lines · Si-Wei Liu
Quoted 104 lines · Jason Wang
Quoted 90 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 2 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:For this case, I guess we may need another way to support virtio-vdpa 1:1 mapping rather than overloading virtio device reset semantics, see:
https://www.mail-archive.com/[email protected]/msg953755.html
Quoted 3 lines
Conceptually, the address mapping is not a part of the abstraction for a virtio device now. So resetting the memory mapping during virtio device reset seems wrong.
Quoted 8 lines
Quoted 6 lines
where we want to keep memory mapping intact across virtio device reset for best live migration latency/downtime. I wonder would it work to reset the mapping in vhost-vdpa life cycle out of virtio reset, say introduce a .reset_map() op to restore 1:1 mapping within
vhost_vdpa_remove_as()right aftervhost_vdpa_iotlb_unmap()? Then we can move the iotlb reset logic to there without worry breaking virtio-vdpa.It looks to me we don't need a new ops. We can simply do
set_map()twice
Quoted 7 lines
What does it mean, first
set_map(0, -1ULL)with zero iotlb entry passed in to destroy all iotlb mappings previously added, and secondset_map(0, -1ULL)to restore 1:1 DMA MR? But userspace (maybe a buggy one but doesn't do harm) apart from vhost-vdpa itself can do unmap twice anyway, this is supported today I think. Why there'll be such obscure distinction, or what's the benefit to treat second .set_map() as recreating 1:1 mapping?
Ok, I think I miss some context. I agree that it's better to decouple memory mappings from the virtio reset. It helps to reduce the unnecessary memory transactions. It might require a new feature flag.
Regarding the method of restoring to 1:1 DMA MR, it might be dangerous for (buggy) vhost-vDPA devices. Since its userspace doesn't set up any mapping it can explore the kernel with that via CVQ?
Thanks
Quoted 118 lines
Quoted 2 lines
or do you mean it would be faster?
I think with .reset_map() we at least can avoid indefinite latency hiccup from destroying and recreating 1:1 mapping with the unwarranted 2rd unmap call. And .reset_map() should work with both .dma_map() and .set_map() APIs with clear semantics.
Regards,
-SiweiQuoted 108 lines
Thanks
Quoted 105 lines
Thanks,
-SiweiQuoted 102 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 69 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --Quoted 2 lines
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 137 lines · Jason Wang
Quoted 129 lines · Si-Wei Liu
Quoted 118 lines · Jason Wang
Quoted 117 lines · Si-Wei Liu
Quoted 104 lines · Jason Wang
Quoted 90 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 2 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:For this case, I guess we may need another way to support virtio-vdpa 1:1 mapping rather than overloading virtio device reset semantics, see:
https://www.mail-archive.com/[email protected]/msg953755.html
Quoted 3 lines
Conceptually, the address mapping is not a part of the abstraction for a virtio device now. So resetting the memory mapping during virtio device reset seems wrong.
Quoted 8 lines
Quoted 6 lines
where we want to keep memory mapping intact across virtio device reset for best live migration latency/downtime. I wonder would it work to reset the mapping in vhost-vdpa life cycle out of virtio reset, say introduce a .reset_map() op to restore 1:1 mapping within
vhost_vdpa_remove_as()right aftervhost_vdpa_iotlb_unmap()? Then we can move the iotlb reset logic to there without worry breaking virtio-vdpa.It looks to me we don't need a new ops. We can simply do
set_map()twiceQuoted 7 lines
What does it mean, first
set_map(0, -1ULL)with zero iotlb entry passed in to destroy all iotlb mappings previously added, and secondset_map(0, -1ULL)to restore 1:1 DMA MR? But userspace (maybe a buggy one but doesn't do harm) apart from vhost-vdpa itself can do unmap twice anyway, this is supported today I think. Why there'll be such obscure distinction, or what's the benefit to treat second .set_map() as recreating 1:1 mapping?
Quoted 3 lines
Ok, I think I miss some context. I agree that it's better to decouple memory mappings from the virtio reset. It helps to reduce the unnecessary memory transactions. It might require a new feature flag.
This I agreed. AFAICT QEMU would need to check this new feature flag to make sure memory mappings are kept intact across reset, otherwise for the sake of avoid breaking older kernels it has to recreate all the mappings after reset like how it is done today.
Quoted 3 lines
Regarding the method of restoring to 1:1 DMA MR, it might be dangerous for (buggy) vhost-vDPA devices. Since its userspace doesn't set up any mapping it can explore the kernel with that via CVQ?
Not sure I understand this proposal. The 1:1 DMA MR is first created at vdpa device add, and gets destroyed implicitly when the first .set_map or .dma_map call is made, which is only possible after the vhost-vdpa module is loaded and bound to vdpa devices. Naturally the DMA MR should be restored to how it was before when vhost-vdpa module is unloaded, or if anything the 1:1 DMA MR creation can be deferred to until virtio-vdpa is probed and bound to devices. Today vhost_vdpa_remove_as() as part of the vhost-vdpa unload code path already gets all mappings purged through vhost_vdpa_iotlb_unmap(0, -1ULL), and it should be pretty safe to restore DMA MR via .reset_map() right after. Not sure what's the concern here with buggy vhost-vdpa device?
Noted when vhost-vdpa is being unloaded there's even no chance to probe kernel through CVQ, as the virtio feature is not even negotiated at that point. And it is even trickier to wait for CVQ response from device indefinitely when trying to unload a module.
Regards,
-Siwei
Quoted 118 lines
Thanks
Quoted 115 lines
Quoted 1 line
or do you mean it would be faster?
I think with .reset_map() we at least can avoid indefinite latency hiccup from destroying and recreating 1:1 mapping with the unwarranted 2rd unmap call. And .reset_map() should work with both .dma_map() and .set_map() APIs with clear semantics.
Regards,
-SiweiQuoted 107 lines
Thanks
Quoted 105 lines
Thanks,
-SiweiQuoted 102 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 69 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --Quoted 2 lines
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 149 lines · Si-Wei Liu
Quoted 137 lines · Jason Wang
Quoted 129 lines · Si-Wei Liu
Quoted 118 lines · Jason Wang
Quoted 117 lines · Si-Wei Liu
Quoted 104 lines · Jason Wang
Quoted 90 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 2 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:For this case, I guess we may need another way to support virtio-vdpa 1:1 mapping rather than overloading virtio device reset semantics, see:
https://www.mail-archive.com/[email protected]/msg953755.html
Quoted 3 lines
Conceptually, the address mapping is not a part of the abstraction for a virtio device now. So resetting the memory mapping during virtio device reset seems wrong.
Quoted 8 lines
Quoted 6 lines
where we want to keep memory mapping intact across virtio device reset for best live migration latency/downtime. I wonder would it work to reset the mapping in vhost-vdpa life cycle out of virtio reset, say introduce a .reset_map() op to restore 1:1 mapping within
vhost_vdpa_remove_as()right aftervhost_vdpa_iotlb_unmap()? Then we can move the iotlb reset logic to there without worry breaking virtio-vdpa.It looks to me we don't need a new ops. We can simply do
set_map()twiceQuoted 7 lines
What does it mean, first
set_map(0, -1ULL)with zero iotlb entry passed in to destroy all iotlb mappings previously added, and secondset_map(0, -1ULL)to restore 1:1 DMA MR? But userspace (maybe a buggy one but doesn't do harm) apart from vhost-vdpa itself can do unmap twice anyway, this is supported today I think. Why there'll be such obscure distinction, or what's the benefit to treat second .set_map() as recreating 1:1 mapping?Quoted 3 lines
Ok, I think I miss some context. I agree that it's better to decouple memory mappings from the virtio reset. It helps to reduce the unnecessary memory transactions. It might require a new feature flag.
This I agreed. AFAICT QEMU would need to check this new feature flag to make sure memory mappings are kept intact across reset, otherwise for the sake of avoid breaking older kernels it has to recreate all the mappings after reset like how it is done today.
Quoted 7 lines
Quoted 3 lines
Regarding the method of restoring to 1:1 DMA MR, it might be dangerous for (buggy) vhost-vDPA devices. Since its userspace doesn't set up any mapping it can explore the kernel with that via CVQ?
Not sure I understand this proposal. The 1:1 DMA MR is first created at vdpa device add, and gets destroyed implicitly when the first .set_map or .dma_map call is made, which is only possible after the vhost-vdpa module is loaded and bound to vdpa devices.
So what happens if there's a buggy userspace that doesn't do any IOTLB setup?
Thanks
Quoted 9 lines
Naturally the DMA MR should
be restored to how it was before when vhost-vdpa module is unloaded, or if anything the 1:1 DMA MR creation can be deferred to until virtio-vdpa is probed and bound to devices. Todayvhost_vdpa_remove_as()as part of the vhost-vdpa unload code path already gets all mappings purged throughvhost_vdpa_iotlb_unmap(0, -1ULL), and it should be pretty safe to restore DMA MR via .reset_map() right after. Not sure what's the concern here with buggy vhost-vdpa device?
Quoted 126 lines
Noted when vhost-vdpa is being unloaded there's even no chance to probe kernel through CVQ, as the virtio feature is not even negotiated at that point. And it is even trickier to wait for CVQ response from device indefinitely when trying to unload a module.
Regards,
-SiweiQuoted 118 lines
Thanks
Quoted 115 lines
Quoted 1 line
or do you mean it would be faster?
I think with .reset_map() we at least can avoid indefinite latency hiccup from destroying and recreating 1:1 mapping with the unwarranted 2rd unmap call. And .reset_map() should work with both .dma_map() and .set_map() APIs with clear semantics.
Regards,
-SiweiQuoted 107 lines
Thanks
Quoted 105 lines
Thanks,
-SiweiQuoted 102 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 69 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --Quoted 2 lines
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 147 lines · Jason Wang
Quoted 146 lines · Si-Wei Liu
Quoted 135 lines · Jason Wang
Quoted 127 lines · Si-Wei Liu
Quoted 117 lines · Jason Wang
Quoted 116 lines · Si-Wei Liu
Quoted 104 lines · Jason Wang
Quoted 90 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 2 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:For this case, I guess we may need another way to support virtio-vdpa 1:1 mapping rather than overloading virtio device reset semantics, see:
https://www.mail-archive.com/[email protected]/msg953755.html
Quoted 3 lines
Conceptually, the address mapping is not a part of the abstraction for a virtio device now. So resetting the memory mapping during virtio device reset seems wrong.
Quoted 8 lines
Quoted 6 lines
where we want to keep memory mapping intact across virtio device reset for best live migration latency/downtime. I wonder would it work to reset the mapping in vhost-vdpa life cycle out of virtio reset, say introduce a .reset_map() op to restore 1:1 mapping within
vhost_vdpa_remove_as()right aftervhost_vdpa_iotlb_unmap()? Then we can move the iotlb reset logic to there without worry breaking virtio-vdpa.It looks to me we don't need a new ops. We can simply do
set_map()twiceQuoted 7 lines
What does it mean, first
set_map(0, -1ULL)with zero iotlb entry passed in to destroy all iotlb mappings previously added, and secondset_map(0, -1ULL)to restore 1:1 DMA MR? But userspace (maybe a buggy one but doesn't do harm) apart from vhost-vdpa itself can do unmap twice anyway, this is supported today I think. Why there'll be such obscure distinction, or what's the benefit to treat second .set_map() as recreating 1:1 mapping?Quoted 3 lines
Ok, I think I miss some context. I agree that it's better to decouple memory mappings from the virtio reset. It helps to reduce the unnecessary memory transactions. It might require a new feature flag.
This I agreed. AFAICT QEMU would need to check this new feature flag to make sure memory mappings are kept intact across reset, otherwise for the sake of avoid breaking older kernels it has to recreate all the mappings after reset like how it is done today.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Regarding the method of restoring to 1:1 DMA MR, it might be dangerous for (buggy) vhost-vDPA devices. Since its userspace doesn't set up any mapping it can explore the kernel with that via CVQ?
Not sure I understand this proposal. The 1:1 DMA MR is first created at vdpa device add, and gets destroyed implicitly when the first .set_map or .dma_map call is made, which is only possible after the vhost-vdpa module is loaded and bound to vdpa devices.
So what happens if there's a buggy userspace that doesn't do any IOTLB setup?
Then parent driver doesn't do anything in .reset_map() - as the DMA MR is still there. Parent driver should be able to tell apart if DMA MR has been destroyed or not by checking the internal state.
-Siwei
Quoted 136 lines
Thanks
Quoted 133 lines
Naturally the DMA MR should
be restored to how it was before when vhost-vdpa module is unloaded, or if anything the 1:1 DMA MR creation can be deferred to until virtio-vdpa is probed and bound to devices. Todayvhost_vdpa_remove_as()as part of the vhost-vdpa unload code path already gets all mappings purged throughvhost_vdpa_iotlb_unmap(0, -1ULL), and it should be pretty safe to restore DMA MR via .reset_map() right after. Not sure what's the concern here with buggy vhost-vdpa device?Noted when vhost-vdpa is being unloaded there's even no chance to probe kernel through CVQ, as the virtio feature is not even negotiated at that point. And it is even trickier to wait for CVQ response from device indefinitely when trying to unload a module.
Regards,
-SiweiQuoted 117 lines
Thanks
Quoted 115 lines
Quoted 1 line
or do you mean it would be faster?
I think with .reset_map() we at least can avoid indefinite latency hiccup from destroying and recreating 1:1 mapping with the unwarranted 2rd unmap call. And .reset_map() should work with both .dma_map() and .set_map() APIs with clear semantics.
Regards,
-SiweiQuoted 107 lines
Thanks
Quoted 105 lines
Thanks,
-SiweiQuoted 102 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 69 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --Quoted 2 lines
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Quoted 154 lines · Si-Wei Liu
Quoted 150 lines · Jason Wang
Quoted 149 lines · Si-Wei Liu
Quoted 135 lines · Jason Wang
Quoted 127 lines · Si-Wei Liu
Quoted 117 lines · Jason Wang
Quoted 116 lines · Si-Wei Liu
Quoted 104 lines · Jason Wang
Quoted 90 lines · Dragos Tatulea
The
mr->initializedflag 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->initializedwill 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_mrgot split into data and control vq functions which are now also ASID aware.Fixes 8fcd20c30704 ("vdpa/mlx5: Support different address spaces for control and data")Signed-off-by Dragos Tatulea <[email protected]>Reviewed-by Eugenio Pérez <[email protected]>Reviewed-by Gal Pressman <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 27 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -31,6 +31,7 @@ struct mlx5_vdpa_mr {struct list_head head;unsigned long num_directs;unsigned long num_klms; +/* state of dvq mr */ bool initialized;/* serialize mkey creation and destruction */ drivers/vdpa/mlx5/core/mr.c +28
-7@@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return ; + +prune_iotlb (mvdev); +} + +static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr; -mutex_lock (&mr->mkey_mtx); +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid) +return ; +if (!mr->initialized) - goto out; +return ; -prune_iotlb (mvdev);if (mr->user_mr)destroy_user_mr (mvdev, mr);else destroy_dma_mr (mvdev, mr); mr->initialized = false; -out: +} + +static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ +struct mlx5_vdpa_mr *mr = &mvdev->mr; + +mutex_lock (&mr->mkey_mtx); + +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid); +_mlx5_vdpa_destroy_cvq_mr (mvdev, asid); +mutex_unlock (&mr->mkey_mtx); } -static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, -struct vhost_iotlb *iotlb,unsigned int asid) +void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev) +{ +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ]); +mlx5_vdpa_destroy_mr_asid (mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ]);drivers/vdpa/mlx5/core/mr.c static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr · line 543
Quoted 10 lines
drivers/vdpa/mlx5/core/mr.c +10
-0+} + +static int _mlx5_vdpa_create_cvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) +{ +if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] != asid) +return 0 ; + +return dup_iotlb (mvdev, iotlb);This worries me as conceptually, there should be no difference between dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
Quoted 2 lines
One example is that, if we only do
dup_iotlb()but not try to create dma mr here, we will break virtio-vdpa:For this case, I guess we may need another way to support virtio-vdpa 1:1 mapping rather than overloading virtio device reset semantics, see:
https://www.mail-archive.com/[email protected]/msg953755.html
Quoted 3 lines
Conceptually, the address mapping is not a part of the abstraction for a virtio device now. So resetting the memory mapping during virtio device reset seems wrong.
Quoted 8 lines
Quoted 6 lines
where we want to keep memory mapping intact across virtio device reset for best live migration latency/downtime. I wonder would it work to reset the mapping in vhost-vdpa life cycle out of virtio reset, say introduce a .reset_map() op to restore 1:1 mapping within
vhost_vdpa_remove_as()right aftervhost_vdpa_iotlb_unmap()? Then we can move the iotlb reset logic to there without worry breaking virtio-vdpa.It looks to me we don't need a new ops. We can simply do
set_map()twiceQuoted 7 lines
What does it mean, first
set_map(0, -1ULL)with zero iotlb entry passed in to destroy all iotlb mappings previously added, and secondset_map(0, -1ULL)to restore 1:1 DMA MR? But userspace (maybe a buggy one but doesn't do harm) apart from vhost-vdpa itself can do unmap twice anyway, this is supported today I think. Why there'll be such obscure distinction, or what's the benefit to treat second .set_map() as recreating 1:1 mapping?Quoted 3 lines
Ok, I think I miss some context. I agree that it's better to decouple memory mappings from the virtio reset. It helps to reduce the unnecessary memory transactions. It might require a new feature flag.
This I agreed. AFAICT QEMU would need to check this new feature flag to make sure memory mappings are kept intact across reset, otherwise for the sake of avoid breaking older kernels it has to recreate all the mappings after reset like how it is done today.
Quoted 3 lines
Regarding the method of restoring to 1:1 DMA MR, it might be dangerous for (buggy) vhost-vDPA devices. Since its userspace doesn't set up any mapping it can explore the kernel with that via CVQ?
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Not sure I understand this proposal. The 1:1 DMA MR is first created at vdpa device add, and gets destroyed implicitly when the first .set_map or .dma_map call is made, which is only possible after the vhost-vdpa module is loaded and bound to vdpa devices.
So what happens if there's a buggy userspace that doesn't do any IOTLB setup?
Then parent driver doesn't do anything in .reset_map() - as the DMA MR is still there. Parent driver should be able to tell apart if DMA MR has been destroyed or not by checking the internal state.
Would you mind posting a patch to demonstrate this?
Thanks
Quoted 140 lines
-Siwei
Quoted 136 lines
Thanks
Quoted 133 lines
Naturally the DMA MR should
be restored to how it was before when vhost-vdpa module is unloaded, or if anything the 1:1 DMA MR creation can be deferred to until virtio-vdpa is probed and bound to devices. Todayvhost_vdpa_remove_as()as part of the vhost-vdpa unload code path already gets all mappings purged throughvhost_vdpa_iotlb_unmap(0, -1ULL), and it should be pretty safe to restore DMA MR via .reset_map() right after. Not sure what's the concern here with buggy vhost-vdpa device?Noted when vhost-vdpa is being unloaded there's even no chance to probe kernel through CVQ, as the virtio feature is not even negotiated at that point. And it is even trickier to wait for CVQ response from device indefinitely when trying to unload a module.
Regards,
-SiweiQuoted 117 lines
Thanks
Quoted 115 lines
Quoted 1 line
or do you mean it would be faster?
I think with .reset_map() we at least can avoid indefinite latency hiccup from destroying and recreating 1:1 mapping with the unwarranted 2rd unmap call. And .reset_map() should work with both .dma_map() and .set_map() APIs with clear semantics.
Regards,
-SiweiQuoted 107 lines
Thanks
Quoted 105 lines
Thanks,
-SiweiQuoted 102 lines
commit
6f5312f801836e6af9bcbb0bdb44dc423e129206Author: Eli Cohen <[email protected]> Date: Wed Jun 2 11:58:54 2021 +0300vdpa/mlx5: Add support for running with
virtio_vdpaIn order to support running vdpa using
vritio_vdpadriver, we need to create a different kind of MR, one that has 1:1 mapping, since the addresses referring to virtqueues are dma addresses.We create the 1:1 MR in
mlx5_vdpa_dev_add()only in case firmware supports the general capabilityumem_uid_0. The reason for that is that 1:1 MRs must be created with uid == 0 while virtqueue objects can be created with uid == 0 only when the firmware capability is on.If the
set_map()callback is called with new translations provided through iotlb, the driver will destroy the 1:1 MR and create a regular one.Signed-off-by Eli Cohen <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Jason Wang <[email protected]>Thanks
Quoted 69 lines
drivers/vdpa/mlx5/core/mr.c +32
-21+} + +static int _mlx5_vdpa_create_dvq_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb, +unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;int err; -if (mr->initialized) +if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] != asid)return 0 ; -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) - err =create_user_mr (mvdev, iotlb); -else - err =create_dma_mr (mvdev, mr); +if (mr->initialized) +return 0 ; -if (err) -return err; - } +if (iotlb) + err =create_user_mr (mvdev, iotlb); +else + err =create_dma_mr (mvdev, mr); -if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP ] == asid) { - err =dup_iotlb (mvdev, iotlb); -if (err) - goto out_err; - } +if (err) +return err; mr->initialized = true; + +return 0 ; +} + +static int _mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev, +struct vhost_iotlb *iotlb,unsigned int asid) +{ +int err; + + err =_mlx5_vdpa_create_dvq_mr (mvdev, iotlb, asid); +if (err) +return err; + + err =_mlx5_vdpa_create_cvq_mr (mvdev, iotlb, asid); +if (err) + goto out_err; +return 0 ; out_err: -if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP ] == asid) { -if (iotlb) -destroy_user_mr (mvdev, mr); -else -destroy_dma_mr (mvdev, mr); - } +_mlx5_vdpa_destroy_dvq_mr (mvdev, asid);return err; } --Quoted 2 lines
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
cover vdpa: decouple reset of iotlb mapping from device reset
In order to reduce needlessly high setup and teardown cost of iotlb mapping during live migration, it's crucial to decouple the vhost-vdpa iotlb abstraction from the virtio device life cycle, i.e. iotlb mappings should be left intact across virtio device reset [1]. For it to work, the on-chip IOMMU parent device should implement a separate .reset_map() operation callback to restore 1:1 DMA mapping without having to resort to the .reset() callback, which is mainly used to reset virtio specific device state. This new .reset_map() callback will be invoked only when the vhost-vdpa driver is to be removed and detached from the vdpa bus, such that other vdpa bus drivers, e.g. virtio-vdpa, can get back on 1:1 DMA mapping when they are attached. For the context, those on-chip IOMMU parent devices, create the 1:1 DMA mapping at vdpa device add, and they would implicitly destroy the 1:1 mapping when the first .set_map or .dma_map callback is invoked.
[1] Reducing vdpa migration downtime because of memory pin / maps
https://www.mail-archive.com/[email protected]/msg953755.html
---
Si-Wei Liu (4):
vdpa: introduce .reset_map operation callback vdpa/mlx5: implement .reset_map driver op
vhost-vdpa: should restore 1:1 dma mapping before detaching driver
vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 72 +++++++++++++++++++++----------------- drivers/vdpa/mlx5/net/mlx5_vnet.c | 18 +++++++--- drivers/vhost/vdpa.c | 33 ++++++++++++++++- include/linux/vdpa.h | 7 ++++ include/uapi/linux/vhost_types.h | 2 ++ 6 files changed, 95 insertions(+), 38 deletions(-)
Signature · 6 lines
1.8.3.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 1/4 vdpa: introduce .reset_map operation callback
--- include/linux/vdpa.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/vdpa.h +7 -0
@@ -314,6 +314,12 @@ struct vdpa_map_file {* @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) +* @reset_map: Reset device memory mapping (optional) +* Needed for device that using device +* specific DMA translation (on-chip IOMMU) +* @vdev: vdpa device +* @asid: address space identifier +* Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device
@@ -390,6 +396,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque);int (*dma_unmap)(struct vdpa_device *vdev,unsigned int asid,u64 iova,u64 size); +int (*reset_map)(struct vdpa_device *vdev,unsigned int asid);int (*set_group_asid)(struct vdpa_device *vdev,unsigned int group,unsigned int asid);struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev,u16 idx);
Signature · 6 lines
1.8.3.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 1/4] vdpa: introduce .reset_map operation callback
Quoted 11 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- include/linux/vdpa.h | 7 +++++++ 1 file changed, 7 insertions(+)include/linux/vdpa.h +0
-0
include/linux/vdpa.h struct vdpa_map_file { · line 319
Quoted 6 lines
include/linux/vdpa.h +3
-0@@ -314,6 +314,12 @@ struct vdpa_map_file {* @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) +* @reset_map: Reset device memory mapping (optional) +* Needed for device that using device +* specific DMA translation (on-chip IOMMU)
This exposes the device internal to the upper layer which is not optimal.
Btw, what's the difference between this and a simple
set_map(NULL)?
Thanks
Quoted 15 lines
include/linux/vdpa.h +4
-1+* @vdev: vdpa device +* @asid: address space identifier +* Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device @@ -390,6 +396,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque);int (*dma_unmap)(struct vdpa_device *vdev,unsigned int asid,u64 iova,u64 size); +int (*reset_map)(struct vdpa_device *vdev,unsigned int asid);int (*set_group_asid)(struct vdpa_device *vdev,unsigned int group,unsigned int asid);struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev,u16 idx); --
Quoted 2 lines
1.8.3.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 1/4] vdpa: introduce .reset_map operation callback
Quoted 6 lines · Jason Wang
Quoted 5 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- include/linux/vdpa.h | 7 +++++++ 1 file changed, 7 insertions(+)
Quoted 12 lines
include/linux/vdpa.h struct vdpa_map_file { · line 319
Quoted 11 lines
include/linux/vdpa.h +3
-0@@ -314,6 +314,12 @@ struct vdpa_map_file {* @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) +* @reset_map: Reset device memory mapping (optional) +* Needed for device that using device +* specific DMA translation (on-chip IOMMU) This exposes the device internal to the upper layer which is not optimal.
Not sure what does it mean by "device internal", but this op callback just follows existing convention to describe what vdpa parent this API targets.
* @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) :
:
* @dma_map: Map an area of PA to IOVA (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental map. :
:
* @dma_unmap: Unmap an area of IOVA (optional but * must be implemented with dma_map) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental unmap.
Quoted 3 lines
Btw, what's the difference between this and a simple
set_map(NULL)?
I don't think parent drivers support this today - they can accept non-NULL iotlb containing empty map entry, but not a NULL iotlb. The behavior is undefined or it even causes panic when a NULL iotlb is passed in. Further this doesn't work with .dma_map parent drivers.
The reason why a new op is needed or better is because it allows userspace to tell apart different reset behavior from the older kernel (via the F_IOTLB_PERSIST feature bit in patch 4), while this behavior could vary between parent drivers.
Regards,
-Siwei
Quoted 12 lines
Thanks
Quoted 9 lines
include/linux/vdpa.h +3
-0+* @vdev: vdpa device +* @asid: address space identifier +* Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device @@ -390,6 +396,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque); int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid,
Quoted 8 lines
Quoted 8 lines
include/linux/vdpa.h +1
-1u64 iova, u64 size); +int (*reset_map)(struct vdpa_device *vdev,unsigned int asid);int (*set_group_asid)(struct vdpa_device *vdev,unsigned int group,unsigned int asid);struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev,u16 idx); --1.8.3.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 1/4] vdpa: introduce .reset_map operation callback
Quoted 22 lines · Si-Wei Liu
Quoted 6 lines · Jason Wang
Quoted 5 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- include/linux/vdpa.h | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 12 lines
include/linux/vdpa.h struct vdpa_map_file { · line 319
Quoted 11 lines
include/linux/vdpa.h +3
-0@@ -314,6 +314,12 @@ struct vdpa_map_file {* @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) +* @reset_map: Reset device memory mapping (optional) +* Needed for device that using device +* specific DMA translation (on-chip IOMMU) This exposes the device internal to the upper layer which is not optimal.
Quoted 3 lines
Not sure what does it mean by "device internal", but this op callback just follows existing convention to describe what vdpa parent this API targets.
I meant the bus tries to hide the differences among vendors. So it needs to hide on-chip IOMMU stuff to the upper layer.
We can expose two dimensional IO mappings models but it looks like over engineering for this issue. More below.
Quoted 19 lines
* @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) : : * @dma_map: Map an area of PA to IOVA (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental map. : : * @dma_unmap: Unmap an area of IOVA (optional but * must be implemented with dma_map) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental unmap.
Quoted 7 lines
Quoted 3 lines
Btw, what's the difference between this and a simple
set_map(NULL)?I don't think parent drivers support this today - they can accept non-NULL iotlb containing empty map entry, but not a NULL iotlb. The behavior is undefined or it even causes panic when a NULL iotlb is passed in.
We can do this simple change if it can work.
Quoted 1 line
Further this doesn't work with .dma_map parent drivers.
Probably, but I'd remove dma_map as it doesn't have any real users except for the simulator.
Quoted 5 lines
The reason why a new op is needed or better is because it allows userspace to tell apart different reset behavior from the older kernel (via the
F_IOTLB_PERSISTfeature bit in patch 4), while this behavior could vary between parent drivers.
I'm ok with a new feature flag, but we need to first seek a way to reuse the existing API.
Thanks
Quoted 16 lines
Regards,
-SiweiQuoted 12 lines
Thanks
Quoted 9 lines
include/linux/vdpa.h +3
-0+* @vdev: vdpa device +* @asid: address space identifier +* Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device @@ -390,6 +396,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque); int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid,
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
include/linux/vdpa.h +1
-1u64 iova, u64 size); +int (*reset_map)(struct vdpa_device *vdev,unsigned int asid);int (*set_group_asid)(struct vdpa_device *vdev,unsigned int group,unsigned int asid);struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev,u16 idx); --1.8.3.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 1/4] vdpa: introduce .reset_map operation callback
Quoted 49 lines · Jason Wang
Quoted 21 lines · Si-Wei Liu
Quoted 6 lines · Jason Wang
Quoted 5 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- include/linux/vdpa.h | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 12 lines
include/linux/vdpa.h struct vdpa_map_file { · line 319
Quoted 11 lines
include/linux/vdpa.h +3
-0@@ -314,6 +314,12 @@ struct vdpa_map_file {* @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) +* @reset_map: Reset device memory mapping (optional) +* Needed for device that using device +* specific DMA translation (on-chip IOMMU) This exposes the device internal to the upper layer which is not optimal.
Quoted 3 lines
Not sure what does it mean by "device internal", but this op callback just follows existing convention to describe what vdpa parent this API targets.
I meant the bus tries to hide the differences among vendors. So it needs to hide on-chip IOMMU stuff to the upper layer.
We can expose two dimensional IO mappings models but it looks like over engineering for this issue. More below.
Quoted 18 lines
* @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) : : * @dma_map: Map an area of PA to IOVA (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental map. : : * @dma_unmap: Unmap an area of IOVA (optional but * must be implemented with dma_map) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental unmap.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Btw, what's the difference between this and a simple
set_map(NULL)?I don't think parent drivers support this today - they can accept non-NULL iotlb containing empty map entry, but not a NULL iotlb. The behavior is undefined or it even causes panic when a NULL iotlb is passed in.
We can do this simple change if it can work.
If we go with setting up 1:1 DMA mapping at virtio-vdpa .probe() and tearing it down at .release(), perhaps set_map(NULL) is not sufficient.
Quoted 4 lines
Quoted 2 lines
Further this doesn't work with .dma_map parent drivers.
Probably, but I'd remove
dma_mapas it doesn't have any real users except for the simulator.
OK, at a point there was suggestion to get this incremental API extended to support batching to be in par with or even replace .set_map, not sure if it's too soon to conclude. But I'm okay with the removal if need be.
Quoted 7 lines
Quoted 5 lines
The reason why a new op is needed or better is because it allows userspace to tell apart different reset behavior from the older kernel (via the
F_IOTLB_PERSISTfeature bit in patch 4), while this behavior could vary between parent drivers.I'm ok with a new feature flag, but we need to first seek a way to reuse the existing API.
A feature flag is needed anyway. I'm fine with reusing but guess I'd want to converge on the direction first.
Thanks,
-Siwei
Quoted 17 lines
Thanks
Quoted 14 lines
Regards,
-SiweiQuoted 11 lines
Thanks
Quoted 9 lines
include/linux/vdpa.h +3
-0+* @vdev: vdpa device +* @asid: address space identifier +* Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device @@ -390,6 +396,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque); int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/linux/vdpa.h +1
-1u64 iova, u64 size); +int (*reset_map)(struct vdpa_device *vdev,unsigned int asid);int (*set_group_asid)(struct vdpa_device *vdev,unsigned int group,unsigned int asid);struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev,u16 idx); --1.8.3.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH RFC 1/4] vdpa: introduce .reset_map operation callback
Quoted 64 lines · Si-Wei Liu
Quoted 49 lines · Jason Wang
Quoted 21 lines · Si-Wei Liu
Quoted 6 lines · Jason Wang
Quoted 5 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- include/linux/vdpa.h | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 12 lines
include/linux/vdpa.h struct vdpa_map_file { · line 319
Quoted 11 lines
include/linux/vdpa.h +3
-0@@ -314,6 +314,12 @@ struct vdpa_map_file {* @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) +* @reset_map: Reset device memory mapping (optional) +* Needed for device that using device +* specific DMA translation (on-chip IOMMU) This exposes the device internal to the upper layer which is not optimal.
Quoted 3 lines
Not sure what does it mean by "device internal", but this op callback just follows existing convention to describe what vdpa parent this API targets.
I meant the bus tries to hide the differences among vendors. So it needs to hide on-chip IOMMU stuff to the upper layer.
We can expose two dimensional IO mappings models but it looks like over engineering for this issue. More below.
Quoted 18 lines
* @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) : : * @dma_map: Map an area of PA to IOVA (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental map. : : * @dma_unmap: Unmap an area of IOVA (optional but * must be implemented with dma_map) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental unmap.Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Btw, what's the difference between this and a simple
set_map(NULL)?I don't think parent drivers support this today - they can accept non-NULL iotlb containing empty map entry, but not a NULL iotlb. The behavior is undefined or it even causes panic when a NULL iotlb is passed in.
We can do this simple change if it can work.
If we go with setting up 1:1 DMA mapping at virtio-vdpa .probe() and tearing it down at .release(), perhaps
set_map(NULL)is not sufficient.Quoted 1 line
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Further this doesn't work with .dma_map parent drivers.
Probably, but I'd remove
dma_mapas it doesn't have any real users except for the simulator.OK, at a point there was suggestion to get this incremental API extended to support batching to be in par with or even replace .set_map, not sure if it's too soon to conclude. But I'm okay with the removal if need be.
Yes, I think the right move in the long run is to delegate the batching to the parent driver. This allows drivers like mlx to add memory (like hotplugged memory) without the need of tearing down all the old maps.
Having said that, maybe we can work on top if we need to remove .dma_map for now.
Quoted 38 lines
Quoted 7 lines
Quoted 5 lines
The reason why a new op is needed or better is because it allows userspace to tell apart different reset behavior from the older kernel (via the
F_IOTLB_PERSISTfeature bit in patch 4), while this behavior could vary between parent drivers.I'm ok with a new feature flag, but we need to first seek a way to reuse the existing API.
A feature flag is needed anyway. I'm fine with reusing but guess I'd want to converge on the direction first.
Thanks,
-SiweiQuoted 25 lines
Thanks
Quoted 22 lines
Regards,
-SiweiQuoted 19 lines
Thanks
Quoted 17 lines
include/linux/vdpa.h +4
-1+* @vdev: vdpa device +* @asid: address space identifier +* Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device @@ -390,6 +396,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque);int (*dma_unmap)(struct vdpa_device *vdev,unsigned int asid,u64 iova,u64 size); +int (*reset_map)(struct vdpa_device *vdev,unsigned int asid);int (*set_group_asid)(struct vdpa_device *vdev,unsigned int group,unsigned int asid);struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev,u16 idx); --1.8.3.1
Re: [PATCH RFC 1/4] vdpa: introduce .reset_map operation callback
Quoted 65 lines · Eugenio Perez Martin
Quoted 64 lines · Si-Wei Liu
Quoted 48 lines · Jason Wang
Quoted 20 lines · Si-Wei Liu
Quoted 6 lines · Jason Wang
Quoted 5 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- include/linux/vdpa.h | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 12 lines
include/linux/vdpa.h struct vdpa_map_file { · line 319
Quoted 11 lines
include/linux/vdpa.h +3
-0@@ -314,6 +314,12 @@ struct vdpa_map_file {* @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) +* @reset_map: Reset device memory mapping (optional) +* Needed for device that using device +* specific DMA translation (on-chip IOMMU) This exposes the device internal to the upper layer which is not optimal.
Quoted 3 lines
Not sure what does it mean by "device internal", but this op callback just follows existing convention to describe what vdpa parent this API targets.
I meant the bus tries to hide the differences among vendors. So it needs to hide on-chip IOMMU stuff to the upper layer.
We can expose two dimensional IO mappings models but it looks like over engineering for this issue. More below.
Quoted 18 lines
* @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) : : * @dma_map: Map an area of PA to IOVA (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental map. : : * @dma_unmap: Unmap an area of IOVA (optional but * must be implemented with dma_map) * Needed for device that using device * specific DMA translation (on-chip IOMMU) * and preferring incremental unmap.Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Btw, what's the difference between this and a simple
set_map(NULL)?I don't think parent drivers support this today - they can accept non-NULL iotlb containing empty map entry, but not a NULL iotlb. The behavior is undefined or it even causes panic when a NULL iotlb is passed in.
We can do this simple change if it can work.
If we go with setting up 1:1 DMA mapping at virtio-vdpa .probe() and tearing it down at .release(), perhaps
set_map(NULL)is not sufficient.Quoted 3 lines
Quoted 1 line
Further this doesn't work with .dma_map parent drivers.
Probably, but I'd remove
dma_mapas it doesn't have any real users except for the simulator.
Quoted 7 lines
Quoted 3 lines
OK, at a point there was suggestion to get this incremental API extended to support batching to be in par with or even replace .set_map, not sure if it's too soon to conclude. But I'm okay with the removal if need be.
Yes, I think the right move in the long run is to delegate the batching to the parent driver. This allows drivers like mlx to add memory (like hotplugged memory) without the need of tearing down all the old maps.
Nods.
Quoted 3 lines
Having said that, maybe we can work on top if we need to remove .dma_map for now.
I guess for that sake I would keep .dma_map unless there's strong objection against it.
Thanks,
-Siwei
Quoted 28 lines
Quoted 28 lines
Quoted 7 lines
Quoted 5 lines
The reason why a new op is needed or better is because it allows userspace to tell apart different reset behavior from the older kernel (via the
F_IOTLB_PERSISTfeature bit in patch 4), while this behavior could vary between parent drivers.I'm ok with a new feature flag, but we need to first seek a way to reuse the existing API.
A feature flag is needed anyway. I'm fine with reusing but guess I'd want to converge on the direction first.
Thanks,
-SiweiQuoted 16 lines
Thanks
Quoted 14 lines
Regards,
-SiweiQuoted 11 lines
Thanks
Quoted 9 lines
include/linux/vdpa.h +3
-0+* @vdev: vdpa device +* @asid: address space identifier +* Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device @@ -390,6 +396,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque); int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/linux/vdpa.h +1
-1u64 iova, u64 size); +int (*reset_map)(struct vdpa_device *vdev,unsigned int asid);int (*set_group_asid)(struct vdpa_device *vdev,unsigned int group,unsigned int asid);struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev,u16 idx); --1.8.3.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 2/4 vdpa/mlx5: implement .reset_map driver op
In reply to Si-Wei LiuThis patch is based on top of the "vdpa/mlx5: Fixes for ASID handling" series [1].
[1] vdpa/mlx5: Fixes for ASID handling
https://lore.kernel.org/virtualization/[email protected]/
--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 72 +++++++++++++++++++++----------------- drivers/vdpa/mlx5/net/mlx5_vnet.c | 18 +++++++--- 3 files changed, 54 insertions(+), 37 deletions(-)
drivers/vdpa/mlx5/core/mlx5_vdpa.h +1 -0
@@ -123,6 +123,7 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, unsigned int asid);void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev);void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid); +int mlx5_vdpa_reset_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid);#define mlx5_vdpa_warn (__dev, format, ...) \ dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \
drivers/vdpa/mlx5/core/mr.c +40 -32
120 lines not on this page · raw message
drivers/vdpa/mlx5/net/mlx5_vnet.c +13 -5
@@ -2816,7 +2816,6 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)unregister_link_notifier (ndev);teardown_driver (ndev);clear_vqs_ready (ndev); -mlx5_vdpa_destroy_mr (&ndev->mvdev); ndev->mvdev.status =0 ; ndev->mvdev.suspended = false; ndev->cur_num_vqs =0 ;
@@ -2827,10 +2826,6 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)init_group_to_asid_map (mvdev); ++mvdev->generation; -if (MLX5_CAP_GEN (mvdev->mdev, umem_uid_0)) { -if (mlx5_vdpa_create_mr (mvdev,NULL ,0 )) -mlx5_vdpa_warn (mvdev,"create MR failed\n" ); - }up_write (&ndev->reslock);return 0 ;
@@ -2895,6 +2890,18 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, unsigned int asid,return err; } +static int mlx5_vdpa_reset_map (struct vdpa_device *vdev,unsigned int asid) +{ +struct mlx5_vdpa_dev *mvdev =to_mvdev (vdev); +struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev); +int err; + +down_write (&ndev->reslock); + err =mlx5_vdpa_reset_mr (mvdev, asid); +up_write (&ndev->reslock); +return err; +} +static struct device *mlx5_get_vq_dma_dev (struct vdpa_device *vdev,u16 idx) {struct mlx5_vdpa_dev *mvdev =to_mvdev (vdev);
@@ -3154,6 +3161,7 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev, u32 group, .set_config = mlx5_vdpa_set_config, .get_generation = mlx5_vdpa_get_generation, .set_map = mlx5_vdpa_set_map, + .reset_map = mlx5_vdpa_reset_map, .set_group_asid = mlx5_set_group_asid, .get_vq_dma_dev = mlx5_get_vq_dma_dev, .free = mlx5_vdpa_free,
Signature · 6 lines
1.8.3.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Dragos Tatulea
maintainerRe: [PATCH RFC 2/4] vdpa/mlx5: implement .reset_map driver op
Quoted 117 lines · Si-Wei Liu
This patch is based on top of the "vdpa/mlx5: Fixes for ASID handling" series [1].
[1] vdpa/mlx5: Fixes for ASID handling
https://lore.kernel.org/virtualization/[email protected]/Signed-off-by Si-Wei Liu <[email protected]>---
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 72 +++++++++++++++++++++---------------- -
drivers/vdpa/mlx5/net/mlx5_vnet.c | 18 +++++++---3 files changed, 54 insertions(+), 37 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +0
-0@@ -123,6 +123,7 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,struct vhost_iotlb *iotlb, unsigned int asid); void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);void
mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid);
+intmlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid);
#define mlx5_vdpa_warn(__dev, format,
...) \
dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format,__func__, __LINE__, \drivers/vdpa/mlx5/core/mr.c +0
-0@@ -489,21 +489,15 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev,struct
mlx5_vdpa_mr*mr
}
}
-static void_mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
+static void_mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev){
- if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid)
- return;
-
prune_iotlb(mvdev);
}
-static void_mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
+static void_mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev){
structmlx5_vdpa_mr*mr =&mvdev->mr;
- if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid)
- return;
-
if (!mr->initialized)
return;drivers/vdpa/mlx5/core/mr.c +0
-0@@ -521,8 +515,10 @@ void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid)
mutex_lock(&mr->mkey_mtx);
- _mlx5_vdpa_destroy_dvq_mr(mvdev, asid);
- _mlx5_vdpa_destroy_cvq_mr(mvdev, asid);
+ if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) + _mlx5_vdpa_destroy_dvq_mr(mvdev);
+ if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) + _mlx5_vdpa_destroy_cvq_mr(mvdev);
mutex_unlock(&mr->mkey_mtx);
}drivers/vdpa/mlx5/core/mr.c +0
-0@@ -534,25 +530,17 @@ void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev) }
static int _mlx5_vdpa_create_cvq_mr(structmlx5_vdpa_dev*mvdev, - structvhost_iotlb*iotlb, - unsigned int asid) + structvhost_iotlb*iotlb) {
- if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) - return 0;
-
returndup_iotlb(mvdev, iotlb);
}
static int _mlx5_vdpa_create_dvq_mr(structmlx5_vdpa_dev*mvdev, - structvhost_iotlb*iotlb, - unsigned int asid) + structvhost_iotlb*iotlb) {
structmlx5_vdpa_mr*mr =&mvdev->mr;
int err;
- if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) - return 0;
-
if (mr->initialized)
return 0;drivers/vdpa/mlx5/core/mr.c +0
-0@@ -574,20 +562,18 @@ static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, { int err;
- err =_mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); - if (err)
- return err;
-
- err =_mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid); - if (err)
- gotoout_err;
+ if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) {
Quoted 8 lines
+ err =
_mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); + if (err)
+ return err;
+ }
+ if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) { + err =_mlx5_vdpa_create_cvq_mr(mvdev, iotlb); + if (err)
+ return err;
I think you still need the goto here, when CVQ and DVQ fall in same asid and there's a CVQ mr creation error, you are left stuck with the DVQ mr.
Quoted 95 lines
+ }
return 0;drivers/vdpa/mlx5/core/mr.c +0
-5- -out_err: - _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); - - return err;}
int mlx5_vdpa_create_mr(structmlx5_vdpa_dev*mvdev, structvhost_iotlb*iotlb,drivers/vdpa/mlx5/core/mr.c +0
-0@@ -601,6 +587,28 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,struct vhost_iotlb *iotlb, return err; }drivers/vdpa/mlx5/core/mr.c +22
-0+int mlx5_vdpa_reset_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ + struct mlx5_vdpa_mr *mr = &mvdev->mr; + int err = 0; + + if (asid != 0) + return 0; + + mutex_lock(&mr->mkey_mtx); + if (!mr->user_mr) + goto out; + _mlx5_vdpa_destroy_dvq_mr(mvdev); + if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { + err = _mlx5_vdpa_create_dvq_mr(mvdev, NULL, 0); + if (err) + mlx5_vdpa_warn(mvdev, "create DMA MR failed\n"); + } +out: + mutex_unlock(&mr->mkey_mtx); + return err; +} +int mlx5_vdpa_handle_set_map(struct
mlx5_vdpa_dev*mvdev, structvhost_iotlb*iotlb,
bool*change_map, unsigned int asid) {drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-1@@ -2816,7 +2816,6 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev) unregister_link_notifier(ndev); teardown_driver(ndev); clear_vqs_ready(ndev); - mlx5_vdpa_destroy_mr(&ndev->mvdev); ndev->mvdev.status = 0; ndev->mvdev.suspended = false; ndev->cur_num_vqs = 0;@@ -2827,10 +2826,6 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev) init_group_to_asid_map(mvdev); ++mvdev->generation;
- if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
- if (mlx5_vdpa_create_mr(mvdev, NULL, 0)) - mlx5_vdpa_warn(mvdev, "create MR failed\n"); - }
up_write(&ndev->reslock);
return 0;drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0@@ -2895,6 +2890,18 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev,unsigned int asid, return err; }drivers/vdpa/mlx5/net/mlx5_vnet.c +12
-0+static int mlx5_vdpa_reset_map (struct vdpa_device *vdev,unsigned int asid) +{ + struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); + struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); + int err; + + down_write(&ndev->reslock); + err = mlx5_vdpa_reset_mr(mvdev, asid); + up_write(&ndev->reslock); + return err; +} +static struct device *mlx5_get_vq_dma_dev(struct
vdpa_device*vdev, u16 idx) {
structmlx5_vdpa_dev*mvdev =to_mvdev(vdev);drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-0@@ -3154,6 +3161,7 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev,u32 group, .set_config = mlx5_vdpa_set_config, .get_generation = mlx5_vdpa_get_generation, .set_map = mlx5_vdpa_set_map, + .reset_map = mlx5_vdpa_reset_map, .set_group_asid = mlx5_set_group_asid, .get_vq_dma_dev = mlx5_get_vq_dma_dev,
Quoted 1 line
.free =
mlx5_vdpa_free,
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 2/4] vdpa/mlx5: implement .reset_map driver op
Quoted 120 lines · Dragos Tatulea
Quoted 119 lines · Si-Wei Liu
This patch is based on top of the "vdpa/mlx5: Fixes for ASID handling" series [1].
[1] vdpa/mlx5: Fixes for ASID handling
https://lore.kernel.org/virtualization/[email protected]/Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 72 +++++++++++++++++++++----------------(quoted diff) +0
-1- drivers/vdpa/mlx5/net/mlx5_vnet.c | 18 +++++++--- 3 files changed, 54 insertions(+), 37 deletions(-)drivers/vdpa/mlx5/core/mlx5_vdpa.h +1
-0@@ -123,6 +123,7 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,struct vhost_iotlb *iotlb, unsigned int asid); void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev); void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid); +int mlx5_vdpa_reset_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid);#define mlx5_vdpa_warn(__dev, format,
...) \
dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format,__func__, __LINE__, \drivers/vdpa/mlx5/core/mr.c +0
-0@@ -489,21 +489,15 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev,struct
mlx5_vdpa_mr*mr
}
}-static void
_mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid)drivers/vdpa/mlx5/core/mr.c +1
-4+static void _mlx5_vdpa_destroy_cvq_mr (struct mlx5_vdpa_dev *mvdev) { - if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) - return; - prune_iotlb(mvdev); } -static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev, unsignedint asid)
drivers/vdpa/mlx5/core/mr.c +5
-5+static void _mlx5_vdpa_destroy_dvq_mr (struct mlx5_vdpa_dev *mvdev) { struct mlx5_vdpa_mr *mr = &mvdev->mr; - if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) - return; - if (!mr->initialized) return;@@ -521,8 +515,10 @@ void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid) mutex_lock(&mr->mkey_mtx); - _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); - _mlx5_vdpa_destroy_cvq_mr(mvdev, asid); + if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) + _mlx5_vdpa_destroy_dvq_mr(mvdev); + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) + _mlx5_vdpa_destroy_cvq_mr(mvdev); mutex_unlock(&mr->mkey_mtx);}
drivers/vdpa/mlx5/core/mr.c +5
-17@@ -534,25 +530,17 @@ void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev) } static int _mlx5_vdpa_create_cvq_mr(struct mlx5_vdpa_dev *mvdev, - struct vhost_iotlb *iotlb, - unsigned int asid) + struct vhost_iotlb *iotlb) { - if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) - return 0; - return dup_iotlb(mvdev, iotlb); } static int _mlx5_vdpa_create_dvq_mr(struct mlx5_vdpa_dev *mvdev, - struct vhost_iotlb *iotlb, - unsigned int asid) + struct vhost_iotlb *iotlb) { struct mlx5_vdpa_mr *mr = &mvdev->mr; int err; - if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) - return 0; - if (mr->initialized) return 0;@@ -574,20 +562,18 @@ static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, { int err; - err = _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); - if (err) - return err; - - err = _mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid); - if (err) - goto out_err; + if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) { + err = _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); + if (err)
Quoted 8 lines
drivers/vdpa/mlx5/core/mr.c static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, · line 573
Quoted 6 lines
drivers/vdpa/mlx5/core/mr.c +6
-0+ return err; + } + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) { + err = _mlx5_vdpa_create_cvq_mr(mvdev, iotlb); + if (err) + return err;I think you still need the goto here, when CVQ and DVQ fall in same asid and there's a CVQ mr creation error, you are left stuck with the DVQ mr.
Yes, you are right, I will fix this in v2. Thank you for spotting this!
-Siwei
Quoted 89 lines
Quoted 89 lines
drivers/vdpa/mlx5/core/mr.c +1
-5+ } return 0; - -out_err: - _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); - - return err; }int mlx5_vdpa_create_mr(struct
mlx5_vdpa_dev*mvdev, structvhost_iotlb
*iotlb,drivers/vdpa/mlx5/core/mr.c +22
-0@@ -601,6 +587,28 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,struct vhost_iotlb *iotlb, return err; } +int mlx5_vdpa_reset_mr (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +{ + struct mlx5_vdpa_mr *mr = &mvdev->mr; + int err = 0; + + if (asid != 0) + return 0; + + mutex_lock(&mr->mkey_mtx); + if (!mr->user_mr) + goto out; + _mlx5_vdpa_destroy_dvq_mr(mvdev); + if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { + err = _mlx5_vdpa_create_dvq_mr(mvdev, NULL, 0); + if (err) + mlx5_vdpa_warn(mvdev, "create DMA MR failed\n"); + } +out: + mutex_unlock(&mr->mkey_mtx); + return err; +} + int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,bool
*change_map, unsigned int asid) {drivers/vdpa/mlx5/net/mlx5_vnet.c +12
-5@@ -2816,7 +2816,6 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev) unregister_link_notifier(ndev); teardown_driver(ndev); clear_vqs_ready(ndev); - mlx5_vdpa_destroy_mr(&ndev->mvdev); ndev->mvdev.status = 0; ndev->mvdev.suspended = false; ndev->cur_num_vqs = 0;@@ -2827,10 +2826,6 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev) init_group_to_asid_map(mvdev); ++mvdev->generation; - if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { - if (mlx5_vdpa_create_mr(mvdev, NULL, 0)) - mlx5_vdpa_warn(mvdev, "create MR failed\n"); - } up_write(&ndev->reslock); return 0;@@ -2895,6 +2890,18 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev,unsigned int asid, return err; } +static int mlx5_vdpa_reset_map (struct vdpa_device *vdev,unsigned int asid) +{ + struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); + struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); + int err; + + down_write(&ndev->reslock); + err = mlx5_vdpa_reset_mr(mvdev, asid); + up_write(&ndev->reslock); + return err; +} + static struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx) {struct
mlx5_vdpa_dev*mvdev =to_mvdev(vdev);drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0@@ -3154,6 +3161,7 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev,
Quoted 8 lines
Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-0u32 group, .set_config = mlx5_vdpa_set_config, .get_generation = mlx5_vdpa_get_generation, .set_map = mlx5_vdpa_set_map, + .reset_map = mlx5_vdpa_reset_map, .set_group_asid = mlx5_set_group_asid, .get_vq_dma_dev = mlx5_get_vq_dma_dev,.free =
mlx5_vdpa_free,
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 3/4 vhost-vdpa: should restore 1:1 dma mapping before detaching driver
In reply to Si-Wei Liu--- drivers/vhost/vdpa.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/vhost/vdpa.c +17 -0
@@ -131,6 +131,15 @@ static struct vhost_vdpa_as *vhost_vdpa_find_alloc_as(struct vhost_vdpa *v,return vhost_vdpa_alloc_as (v, asid); } +static void vhost_vdpa_reset_map (struct vhost_vdpa *v,u32 asid) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +if (ops->reset_map) + ops->reset_map (vdpa, asid); +} +static int vhost_vdpa_remove_as (struct vhost_vdpa *v,u32 asid) {struct vhost_vdpa_as *as =asid_to_as (v, asid);
@@ -140,6 +149,14 @@ static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid)hlist_del (&as->hash_link);vhost_vdpa_iotlb_unmap (v, &as->iotlb,0ULL ,0ULL -1 , asid); +/* +* Devices with on-chip IOMMU need to restore iotlb +* to 1:1 identity mapping before vhost-vdpa is going +* to be removed and detached from the device. Give +* them a chance to do so, as this cannot be done +* efficiently via the whole-range unmap call above. +*/ +vhost_vdpa_reset_map (v, asid);kfree (as);return 0 ;
Signature · 6 lines
1.8.3.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 3/4] vhost-vdpa: should restore 1:1 dma mapping before detaching driver
Quoted 27 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vhost/vdpa.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)drivers/vhost/vdpa.c +9
-0@@ -131,6 +131,15 @@ static struct vhost_vdpa_as *vhost_vdpa_find_alloc_as(struct vhost_vdpa *v,return vhost_vdpa_alloc_as (v, asid); } +static void vhost_vdpa_reset_map (struct vhost_vdpa *v,u32 asid) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +if (ops->reset_map) + ops->reset_map (vdpa, asid); +} +static int vhost_vdpa_remove_as (struct vhost_vdpa *v,u32 asid) {struct vhost_vdpa_as *as =asid_to_as (v, asid);
drivers/vhost/vdpa.c static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) · line 158
Quoted 10 lines
drivers/vhost/vdpa.c +7
-0@@ -140,6 +149,14 @@ static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid)hlist_del (&as->hash_link);vhost_vdpa_iotlb_unmap (v, &as->iotlb,0ULL ,0ULL -1 , asid); +/* +* Devices with on-chip IOMMU need to restore iotlb +* to 1:1 identity mapping before vhost-vdpa is going +* to be removed and detached from the device. Give +* them a chance to do so, as this cannot be done +* efficiently via the whole-range unmap call above. +*/
Same question as before, if 1:1 is restored and the userspace doesn't do any IOTLB updating. It looks like a security issue? (Assuming IOVA is PA)
Thanks
Quoted 7 lines
drivers/vhost/vdpa.c +1
-1+vhost_vdpa_reset_map (v, asid);kfree (as);return 0 ; --1.8.3.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 3/4] vhost-vdpa: should restore 1:1 dma mapping before detaching driver
Quoted 28 lines · Jason Wang
Quoted 27 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vhost/vdpa.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)drivers/vhost/vdpa.c +9
-0@@ -131,6 +131,15 @@ static struct vhost_vdpa_as *vhost_vdpa_find_alloc_as(struct vhost_vdpa *v,return vhost_vdpa_alloc_as (v, asid); } +static void vhost_vdpa_reset_map (struct vhost_vdpa *v,u32 asid) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +if (ops->reset_map) + ops->reset_map (vdpa, asid); +} +static int vhost_vdpa_remove_as (struct vhost_vdpa *v,u32 asid) {struct vhost_vdpa_as *as =asid_to_as (v, asid);@@ -140,6 +149,14 @@ static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid)
Quoted 12 lines
drivers/vhost/vdpa.c static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) · line 158
Quoted 9 lines
drivers/vhost/vdpa.c +7
-0hlist_del (&as->hash_link);vhost_vdpa_iotlb_unmap (v, &as->iotlb,0ULL ,0ULL -1 , asid); +/* +* Devices with on-chip IOMMU need to restore iotlb +* to 1:1 identity mapping before vhost-vdpa is going +* to be removed and detached from the device. Give +* them a chance to do so, as this cannot be done +* efficiently via the whole-range unmap call above. +*/ Same question as before, if 1:1 is restored and the userspace doesn't do any IOTLB updating. It looks like a security issue? (Assuming IOVA is PA)
This is already flawed independent of this series. It was introduced from the two commits I referenced earlier in the other thread. Today userspace is already able to do so with device reset and don't do any IOTLB update. This series don't get it worse nor make it better.
FWIW as said earlier, to address this security issue properly we probably should set up 1:1 DMA mapping in virtio_vdpa_probe() on demand, and tears it down at virtio_vdpa_release_dev(). Question is, was virtio-vdpa the only vdpa bus user that needs 1:1 DMA mapping, or it's the other way around that vhost-vdpa is the only exception among all vdpa bus drivers that don't want to start with 1:1 by default. This would help parent vdpa implementation for what kind of mapping it should start with upon creation.
Regards,
-Siwei
Quoted 10 lines
Thanks
Quoted 7 lines
drivers/vhost/vdpa.c +1
-1+vhost_vdpa_reset_map (v, asid);kfree (as);return 0 ; --1.8.3.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 4/4 vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
In reply to Si-Wei Liu--- drivers/vhost/vdpa.c | 16 +++++++++++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/vhost/vdpa.c +15 -1
@@ -406,6 +406,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)return ops->resume; } +static bool vhost_vdpa_has_persistent_map (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return (!ops->set_map && !ops->dma_map) || ops->reset_map; +} +static long vhost_vdpa_get_features (struct vhost_vdpa *v,u64 __user *featurep) {struct vdpa_device *vdpa = v->vdpa;
@@ -697,7 +705,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,return -EFAULT ;if (features & ~(VHOST_VDPA_BACKEND_FEATURES |BIT_ULL (VHOST_BACKEND_F_SUSPEND ) | -BIT_ULL (VHOST_BACKEND_F_RESUME ))) +BIT_ULL (VHOST_BACKEND_F_RESUME ) | +BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST )))return -EOPNOTSUPP ;if ((features &BIT_ULL (VHOST_BACKEND_F_SUSPEND )) && !vhost_vdpa_can_suspend (v))
@@ -705,6 +714,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,if ((features &BIT_ULL (VHOST_BACKEND_F_RESUME )) && !vhost_vdpa_can_resume (v))return -EOPNOTSUPP ; +if ((features &BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST )) && + !vhost_vdpa_has_persistent_map (v)) +return -EOPNOTSUPP ;vhost_set_backend_features (&v->vdev, features);return 0 ; }
@@ -758,6 +770,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, features |=BIT_ULL (VHOST_BACKEND_F_SUSPEND );if (vhost_vdpa_can_resume (v)) features |=BIT_ULL (VHOST_BACKEND_F_RESUME ); +if (vhost_vdpa_has_persistent_map (v)) + features |=BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST );if (copy_to_user (featurep, &features,sizeof (features))) r = -EFAULT ;break ;
include/uapi/linux/vhost_types.h +2 -0
@@ -181,5 +181,7 @@ struct vhost_vdpa_iova_range {#define VHOST_BACKEND_F_SUSPEND 0x4/* Device can be resumed */ #define VHOST_BACKEND_F_RESUME 0x5 +/* IOTLB don't flush memory mapping across device reset */ +#define VHOST_BACKEND_F_IOTLB_PERSIST 0x6#endif
Signature · 6 lines
1.8.3.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 4/4] vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
Quoted 12 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vhost/vdpa.c | 16 +++++++++++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-)drivers/vhost/vdpa.c +0
-0
drivers/vhost/vdpa.c static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v) · line 414
Quoted 9 lines
drivers/vhost/vdpa.c +6
-0@@ -406,6 +406,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)return ops->resume; } +static bool vhost_vdpa_has_persistent_map (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return (!ops->set_map && !ops->dma_map) || ops->reset_map;
So this means the IOTLB/IOMMU mappings have already been decoupled from the vdpa reset. So it should have been noticed by the userspace. I guess we can just fix the simulator and mlx5 then we are fine?
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 4/4] vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
Quoted 15 lines · Jason Wang
Quoted 14 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vhost/vdpa.c | 16 +++++++++++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-)drivers/vhost/vdpa.c +0
-0@@ -406,6 +406,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)return ops->resume; }
Quoted 8 lines
drivers/vhost/vdpa.c static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v) · line 414
Quoted 6 lines
drivers/vhost/vdpa.c +6
-0+static bool vhost_vdpa_has_persistent_map (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return (!ops->set_map && !ops->dma_map) || ops->reset_map;So this means the IOTLB/IOMMU mappings have already been decoupled from the vdpa reset.
Not in the sense of API, it' been coupled since day one from the implementations of every on-chip IOMMU parent driver, namely mlx5_vdpa and vdpa_sim. Because of that, later on the (improper) support for virtio-vdpa, from commit 6f5312f80183 ("vdpa/mlx5: Add support for running with virtio_vdpa") and 6c3d329e6486 ("vdpa_sim: get rid of DMA ops") misused the .reset() op to realize 1:1 mapping, rendering strong coupling between device reset and reset of iotlb mappings. This series try to rectify that implementation deficiency, while keep userspace continuing to work with older kernel behavior.
Quoted 1 line
So it should have been noticed by the userspace.
Yes, userspace had noticed this no-chip IOMMU discrepancy since day one I suppose. Unfortunately there's already code in userspace with this assumption in mind that proactively tears down and sets up iotlb mapping around vdpa device reset...
Quoted 1 line
I guess we can just fix the simulator and mlx5 then we are fine?
Only IF we don't care about running new QEMU on older kernels with flawed on-chip iommu behavior around reset. But that's a big IF...
Regards,
-Siwei
Quoted 3 lines
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 4/4] vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
Quoted 37 lines · Si-Wei Liu
Quoted 15 lines · Jason Wang
Quoted 14 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vhost/vdpa.c | 16 +++++++++++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-)drivers/vhost/vdpa.c +0
-0@@ -406,6 +406,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)return ops->resume; }Quoted 8 lines
drivers/vhost/vdpa.c static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v) · line 414
Quoted 6 lines
drivers/vhost/vdpa.c +6
-0+static bool vhost_vdpa_has_persistent_map (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return (!ops->set_map && !ops->dma_map) || ops->reset_map;So this means the IOTLB/IOMMU mappings have already been decoupled from the vdpa reset.
Not in the sense of API, it' been coupled since day one from the implementations of every on-chip IOMMU parent driver, namely
mlx5_vdpaandvdpa_sim. Because of that, later on the (improper) support for virtio-vdpa, from commit6f5312f80183("vdpa/mlx5: Add support for running withvirtio_vdpa") and6c3d329e6486("vdpa_sim: get rid of DMA ops") misused the .reset() op to realize 1:1 mapping, rendering strong coupling between device reset and reset of iotlb mappings. This series try to rectify that implementation deficiency, while keep userspace continuing to work with older kernel behavior.
Quoted 8 lines
Quoted 1 line
So it should have been noticed by the userspace.
Yes, userspace had noticed this no-chip IOMMU discrepancy since day one I suppose. Unfortunately there's already code in userspace with this assumption in mind that proactively tears down and sets up iotlb mapping around vdpa device reset...
Quoted 1 line
I guess we can just fix the simulator and mlx5 then we are fine?
Only IF we don't care about running new QEMU on older kernels with flawed on-chip iommu behavior around reset. But that's a big IF...
So what I meant is:
Userspace doesn't know whether the vendor specific mappings (set_map) are required or not. And in the implementation of vhost_vdpa, if platform IOMMU is used, the mappings are decoupled from the reset. So if the Qemu works with parents with platform IOMMU it means Qemu can work if we just decouple vendor specific mappings from the parents that uses set_map.
Thanks
Quoted 7 lines
Regards,
-SiweiQuoted 3 lines
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 4/4] vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
Quoted 45 lines · Jason Wang
Quoted 36 lines · Si-Wei Liu
Quoted 15 lines · Jason Wang
Quoted 14 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vhost/vdpa.c | 16 +++++++++++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-)drivers/vhost/vdpa.c +0
-0@@ -406,6 +406,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)return ops->resume; }Quoted 8 lines
drivers/vhost/vdpa.c static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v) · line 414
Quoted 6 lines
drivers/vhost/vdpa.c +6
-0+static bool vhost_vdpa_has_persistent_map (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return (!ops->set_map && !ops->dma_map) || ops->reset_map;So this means the IOTLB/IOMMU mappings have already been decoupled from the vdpa reset.
Not in the sense of API, it' been coupled since day one from the implementations of every on-chip IOMMU parent driver, namely
mlx5_vdpaandvdpa_sim. Because of that, later on the (improper) support for virtio-vdpa, from commit6f5312f80183("vdpa/mlx5: Add support for running withvirtio_vdpa") and6c3d329e6486("vdpa_sim: get rid of DMA ops") misused the .reset() op to realize 1:1 mapping, rendering strong coupling between device reset and reset of iotlb mappings. This series try to rectify that implementation deficiency, while keep userspace continuing to work with older kernel behavior.Quoted 8 lines
Quoted 1 line
So it should have been noticed by the userspace.
Yes, userspace had noticed this no-chip IOMMU discrepancy since day one I suppose. Unfortunately there's already code in userspace with this assumption in mind that proactively tears down and sets up iotlb mapping around vdpa device reset...
Quoted 1 line
I guess we can just fix the simulator and mlx5 then we are fine?
Only IF we don't care about running new QEMU on older kernels with flawed on-chip iommu behavior around reset. But that's a big IF...
Quoted 8 lines
So what I meant is:
Userspace doesn't know whether the vendor specific mappings (
set_map) are required or not. And in the implementation ofvhost_vdpa, if platform IOMMU is used, the mappings are decoupled from the reset. So if the Qemu works with parents with platform IOMMU it means Qemu can work if we just decouple vendor specific mappings from the parents that usesset_map.
I was aware of this, and if you may notice I don't even offer a way backward to retain/emulate the flawed vhost-iotlb reset behavior for older userspace - I consider it more of a bug in .set_map driver implementation of its own rather than what the vhost-vdpa iotlb abstraction wishes to expose to userspace in the first place.
If you ever look into QEMU's vhost_vdpa_reset_status() function, you may see memory_listener_unregister() will be called to evict all of the existing iotlb mappings right after vhost_vdpa_reset_device() across device reset, and later on at vhost_vdpa_dev_start(), memory_listener_register() will set up all iotlb mappings again. In an ideal world without this on-chip iommu deficiency QEMU should not have to behave this way - this is what I mentioned earlier that userspace had already noticed the discrepancy and it has to "proactively tear down and set up iotlb mapping around vdpa device reset". Apparently from functionality perspective this trick works completely fine with platform IOMMU, however, it's sub-optimal in the performance perspective.
We can't simply fix QEMU by moving this memory_listener_unregister() call out of the reset path unconditionally, as we don't want to break the already-functioning older kernel even though it's suboptimal in performance. Instead, to keep new QEMU continuing to work on top of the existing or older kernels, QEMU has to check this IOTLB_PERSIST feature flag to decide whether it is safe not to bother flushing and setting up iotlb across reset. For the platform IOMMU case, vdpa parent driver won't implement either the .set_map or .dma_map op, so it should be covered in the vhost_vdpa_has_persistent_map() check I suppose.
Thanks,
-Siwei
Quoted 6 lines
Thanks
Quoted 4 lines
Regards,
-SiweiQuoted 2 lines
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 4/4] vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
Quoted 57 lines · Si-Wei Liu
Quoted 45 lines · Jason Wang
Quoted 36 lines · Si-Wei Liu
Quoted 15 lines · Jason Wang
Quoted 14 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vhost/vdpa.c | 16 +++++++++++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-)drivers/vhost/vdpa.c +0
-0@@ -406,6 +406,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)return ops->resume; }Quoted 8 lines
drivers/vhost/vdpa.c static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v) · line 414
Quoted 6 lines
drivers/vhost/vdpa.c +6
-0+static bool vhost_vdpa_has_persistent_map (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return (!ops->set_map && !ops->dma_map) || ops->reset_map;So this means the IOTLB/IOMMU mappings have already been decoupled from the vdpa reset.
Not in the sense of API, it' been coupled since day one from the implementations of every on-chip IOMMU parent driver, namely
mlx5_vdpaandvdpa_sim. Because of that, later on the (improper) support for virtio-vdpa, from commit6f5312f80183("vdpa/mlx5: Add support for running withvirtio_vdpa") and6c3d329e6486("vdpa_sim: get rid of DMA ops") misused the .reset() op to realize 1:1 mapping, rendering strong coupling between device reset and reset of iotlb mappings. This series try to rectify that implementation deficiency, while keep userspace continuing to work with older kernel behavior.Quoted 8 lines
Quoted 1 line
So it should have been noticed by the userspace.
Yes, userspace had noticed this no-chip IOMMU discrepancy since day one I suppose. Unfortunately there's already code in userspace with this assumption in mind that proactively tears down and sets up iotlb mapping around vdpa device reset...
Quoted 1 line
I guess we can just fix the simulator and mlx5 then we are fine?
Only IF we don't care about running new QEMU on older kernels with flawed on-chip iommu behavior around reset. But that's a big IF...
Quoted 8 lines
So what I meant is:
Userspace doesn't know whether the vendor specific mappings (
set_map) are required or not. And in the implementation ofvhost_vdpa, if platform IOMMU is used, the mappings are decoupled from the reset. So if the Qemu works with parents with platform IOMMU it means Qemu can work if we just decouple vendor specific mappings from the parents that usesset_map.
Quoted 5 lines
I was aware of this, and if you may notice I don't even offer a way backward to retain/emulate the flawed vhost-iotlb reset behavior for older userspace - I consider it more of a bug in .set_map driver implementation of its own rather than what the vhost-vdpa iotlb abstraction wishes to expose to userspace in the first place.
That's my understanding as well.
Quoted 12 lines
If you ever look into QEMU's
vhost_vdpa_reset_status()function, you may seememory_listener_unregister()will be called to evict all of the existing iotlb mappings right aftervhost_vdpa_reset_device()across device reset, and later on atvhost_vdpa_dev_start(),memory_listener_register()will set up all iotlb mappings again. In an ideal world without this on-chip iommu deficiency QEMU should not have to behave this way - this is what I mentioned earlier that userspace had already noticed the discrepancy and it has to "proactively tear down and set up iotlb mapping around vdpa device reset". Apparently from functionality perspective this trick works completely fine with platform IOMMU, however, it's sub-optimal in the performance perspective.
Right.
Quoted 5 lines
We can't simply fix QEMU by moving this
memory_listener_unregister()call out of the reset path unconditionally, as we don't want to break the already-functioning older kernel even though it's suboptimal in performance.
I'm not sure how things can be broken in this case? Or why it is specific to parent with set_map.
Quoted 6 lines
Instead, to keep new QEMU continuing to work on top of the existing or older kernels, QEMU has to check this
IOTLB_PERSISTfeature flag to decide whether it is safe not to bother flushing and setting up iotlb across reset. For the platform IOMMU case, vdpa parent driver won't implement either the .set_map or .dma_map op, so it should be covered in thevhost_vdpa_has_persistent_map()check I suppose.
Just to make sure we are at the same page.
From the userspace point of view, the IOTLB persists and vhost-vDPA doesn't reset the IOTLB during vDPA reset. But we have are two levels of the coupling in other places:
1) Qemu level: memory listener is coupled with DRIVER_OK/reset
2) vDPA parent level: mlx5 build/destroy MR during DRIVER_OK/reset
If I understand you correctly, since we've coupled in 1), Qemu can't be aware of whether the mapping is coupled with reset or not? If we simply decouple in 1), memory mappigns might be lost during vDPA rset.
Thanks
Quoted 11 lines
Thanks,
-SiweiQuoted 6 lines
Thanks
Quoted 4 lines
Regards,
-SiweiQuoted 2 lines
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH RFC 4/4] vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
Quoted 74 lines · Jason Wang
Quoted 55 lines · Si-Wei Liu
Quoted 44 lines · Jason Wang
Quoted 35 lines · Si-Wei Liu
Quoted 15 lines · Jason Wang
Quoted 14 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>--- drivers/vhost/vdpa.c | 16 +++++++++++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-)drivers/vhost/vdpa.c +0
-0@@ -406,6 +406,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)return ops->resume; }Quoted 8 lines
drivers/vhost/vdpa.c static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v) · line 414
Quoted 6 lines
drivers/vhost/vdpa.c +6
-0+static bool vhost_vdpa_has_persistent_map (const struct vhost_vdpa *v) +{ +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; + +return (!ops->set_map && !ops->dma_map) || ops->reset_map;So this means the IOTLB/IOMMU mappings have already been decoupled from the vdpa reset.
Not in the sense of API, it' been coupled since day one from the implementations of every on-chip IOMMU parent driver, namely
mlx5_vdpaandvdpa_sim. Because of that, later on the (improper) support for virtio-vdpa, from commit6f5312f80183("vdpa/mlx5: Add support for running withvirtio_vdpa") and6c3d329e6486("vdpa_sim: get rid of DMA ops") misused the .reset() op to realize 1:1 mapping, rendering strong coupling between device reset and reset of iotlb mappings. This series try to rectify that implementation deficiency, while keep userspace continuing to work with older kernel behavior.Quoted 8 lines
Quoted 1 line
So it should have been noticed by the userspace.
Yes, userspace had noticed this no-chip IOMMU discrepancy since day one I suppose. Unfortunately there's already code in userspace with this assumption in mind that proactively tears down and sets up iotlb mapping around vdpa device reset...
Quoted 1 line
I guess we can just fix the simulator and mlx5 then we are fine?
Only IF we don't care about running new QEMU on older kernels with flawed on-chip iommu behavior around reset. But that's a big IF...
Quoted 8 lines
So what I meant is:
Userspace doesn't know whether the vendor specific mappings (
set_map) are required or not. And in the implementation ofvhost_vdpa, if platform IOMMU is used, the mappings are decoupled from the reset. So if the Qemu works with parents with platform IOMMU it means Qemu can work if we just decouple vendor specific mappings from the parents that usesset_map.Quoted 5 lines
I was aware of this, and if you may notice I don't even offer a way backward to retain/emulate the flawed vhost-iotlb reset behavior for older userspace - I consider it more of a bug in .set_map driver implementation of its own rather than what the vhost-vdpa iotlb abstraction wishes to expose to userspace in the first place.
That's my understanding as well.
Quoted 11 lines
If you ever look into QEMU's
vhost_vdpa_reset_status()function, you may seememory_listener_unregister()will be called to evict all of the existing iotlb mappings right aftervhost_vdpa_reset_device()across device reset, and later on atvhost_vdpa_dev_start(),memory_listener_register()will set up all iotlb mappings again. In an ideal world without this on-chip iommu deficiency QEMU should not have to behave this way - this is what I mentioned earlier that userspace had already noticed the discrepancy and it has to "proactively tear down and set up iotlb mapping around vdpa device reset". Apparently from functionality perspective this trick works completely fine with platform IOMMU, however, it's sub-optimal in the performance perspective.
Quoted 7 lines
Right.
Quoted 4 lines
We can't simply fix QEMU by moving this
memory_listener_unregister()call out of the reset path unconditionally, as we don't want to break the already-functioning older kernel even though it's suboptimal in performance.I'm not sure how things can be broken in this case?
Things won't be broken if we don't care about performance, for example reboot a large memory VM (translated to device reset internally) will freeze the guest and introduce extra reboot delay unnecessarily. If we want to fix the performance by remove memory_listener_unregister() unconditionally and we don't have such a flag to distinguish, we will break network connectivity entirely after reset - as all mappings are purged during reset on older parent driver.
Quoted 1 line
Or why it is specific to parent with
set_map.
As if without the .reset_map op and corresponding driver implementation (in correct way), there's no appropriate means for on-chip iommu parent driver to persist iotlb mappings across reset, isn't it? If the driver deliberately removes it from .reset, they don't support 1:1 DMA mapping for virtio-vdpa on the other hand, for instance.
Quoted 13 lines
Quoted 7 lines
Instead, to keep new QEMU continuing to work on top of the existing or older kernels, QEMU has to check this
IOTLB_PERSISTfeature flag to decide whether it is safe not to bother flushing and setting up iotlb across reset. For the platform IOMMU case, vdpa parent driver won't implement either the .set_map or .dma_map op, so it should be covered in thevhost_vdpa_has_persistent_map()check I suppose.Just to make sure we are at the same page.
From the userspace point of view, the IOTLB persists and vhost-vDPA
doesn't reset the IOTLB during vDPA reset. But we have are two levels of the coupling in other places:
Quoted 5 lines
1) Qemu level: memory listener is coupled with DRIVER_OK/reset
2) vDPA parent level: mlx5 build/destroy MR during DRIVER_OK/resetIf I understand you correctly, since we've coupled in 1), Qemu can't be aware of whether the mapping is coupled with reset or not?
I suspect it had been already noticed by someone who wrote this QEMU code since day one, just that there's lack of a comment documenting it. Or any other reason why QEMU had to decouple it in the first place? It affects performance across the board for platform IOMMU vdpa providers as well.
Quoted 2 lines
If we
simply decouple in 1), memory mappigns might be lost during vDPA rset.
I would tend to say 1) is an inadvertent artifact or side effect of 2), as I do not see memory listeners are used like this in other QEMU subsystems, e.g. vhost, vfio. Consider this coupling in 1) had been in the play since day one with neither advanced vDPA features like SVQ nor equivalent deficiency in platform IOMMU vdpa providers, it's suspicious that mlx5 build/destroy MR during reset was the curlprit then.
Regards,
-Siwei
Quoted 12 lines
Thanks
Quoted 9 lines
Thanks,
-SiweiQuoted 6 lines
Thanks
Quoted 4 lines
Regards,
-SiweiQuoted 2 lines
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Dragos Tatulea
maintainerPATCH 2/2 vdpa/mlx5: Delete control vq iotlb in destroy_mr only when necessary
In reply to Dragos TatuleaFrom: Eugenio Pérez <[email protected]>
mlx5_vdpa_destroy_mr can be called from .set_map with data ASID after the control virtqueue ASID iotlb has been populated. The control vq iotlb must not be cleared, since it will not be populated again.
So call the ASID aware destroy function which makes sure that the right vq resource is destroyed.
--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + drivers/vdpa/mlx5/core/mr.c | 2 +- drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/vdpa/mlx5/core/mlx5_vdpa.h +1 -0
@@ -122,6 +122,7 @@ int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *ioint mlx5_vdpa_create_mr (struct mlx5_vdpa_dev *mvdev,struct vhost_iotlb *iotlb,unsigned int asid);void mlx5_vdpa_destroy_mr (struct mlx5_vdpa_dev *mvdev); +void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid);#define mlx5_vdpa_warn (__dev, format, ...) \ dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \
drivers/vdpa/mlx5/core/mr.c +1 -1
@@ -515,7 +515,7 @@ static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int mr->initialized = false; } -static void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) +void mlx5_vdpa_destroy_mr_asid (struct mlx5_vdpa_dev *mvdev,unsigned int asid) {struct mlx5_vdpa_mr *mr = &mvdev->mr;
drivers/vdpa/mlx5/net/mlx5_vnet.c +2 -2
@@ -2636,7 +2636,7 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, goto err_mr;teardown_driver (ndev); -mlx5_vdpa_destroy_mr (mvdev); +mlx5_vdpa_destroy_mr_asid (mvdev, asid); err =mlx5_vdpa_create_mr (mvdev, iotlb, asid);if (err) goto err_mr;
@@ -2652,7 +2652,7 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,return 0 ; err_setup: -mlx5_vdpa_destroy_mr (mvdev); +mlx5_vdpa_destroy_mr_asid (mvdev, asid); err_mr:return err; }
Signature · 6 lines
2.41.0 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 9 lines · Dragos Tatulea
This patch series is based on Eugenio's fix for handling CVQs in a different ASID [0].
The first patch is the actual fix.
The next 2 patches are fixing a possible issue that I found while implementing patch 1. The patches are ordered like this for clarity.
So what are we doing with this patchset? If we are merging anything for this release it has to happen now.
Quoted 13 lines
Dragos Tatulea (1):
vdpa/mlx5: Fixmr->initializedsemanticsEugenio Pérez (1):
vdpa/mlx5: Delete control vq iotlb indestroy_mronly when necessarydrivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 +- 3 files changed, 74 insertions(+), 29 deletions(-)Signature · 1 line
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Jason Wang
Acked-byQuoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Dragos Tatulea
This patch series is based on Eugenio's fix for handling CVQs in a different ASID [0].
The first patch is the actual fix.
Quoted 8 lines
Quoted 4 lines
The next 2 patches are fixing a possible issue that I found while implementing patch 1. The patches are ordered like this for clarity.
So what are we doing with this patchset? If we are merging anything for this release it has to happen now.
I think we can merge this and do optimization on top.
Thanks
Quoted 7 lines
Quoted 7 lines
Dragos Tatulea (1):
vdpa/mlx5: Fixmr->initializedsemanticsEugenio Pérez (1):
vdpa/mlx5: Delete control vq iotlb indestroy_mronly when necessary
Quoted 8 lines
Quoted 7 lines
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 +- 3 files changed, 74 insertions(+), 29 deletions(-)--
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Dragos Tatulea
maintainerQuoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Dragos Tatulea
This patch series is based on Eugenio's fix for handling CVQs in a different ASID [0].
The first patch is the actual fix.
The next 2 patches are fixing a possible issue that I found while implementing patch 1. The patches are ordered like this for clarity.
Quoted 7 lines
Quoted 2 lines
So what are we doing with this patchset? If we are merging anything for this release it has to happen now.
Jason mentioned that wanted an additional cleanup patch to move the cvq specific code to the net part of mlx5_vdpa. That's quite a refactoring though and would like to take my time to do an RFC for that first.
It would be good if this got merged now as it fixes an actual problem ...
Quoted 6 lines
Quoted 6 lines
Dragos Tatulea (1):
vdpa/mlx5: Fixmr->initializedsemanticsEugenio Pérez (1):
vdpa/mlx5: Delete control vq iotlb indestroy_mronly when necessary
Quoted 8 lines
Quoted 7 lines
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 + drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++++--------- drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 +-
3 files changed, 74 insertions(+), 29 deletions(-)Signature · 1 line
2.41.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization