vdpa-net: improve migration downtime through descriptor ASID and persistent IOTLB
cover vdpa-net: improve migration downtime through descriptor ASID and persistent IOTLB
This patch series contain several enhancements to SVQ live migration downtime for vDPA-net hardware device, specifically on mlx5_vdpa. Currently it is based off of Eugenio's RFC v2 .load_setup series [1] to utilize the shared facility and reduce frictions in merging or duplicating code if at all possible.
It's stacked up in particular order as below, as the optimization for one on the top has to depend on others on the bottom. Here's a breakdown for what each part does respectively:
Patch # | Feature / optimization
---------V-------------------------------------------------------------------
35 - 40 | trace events 34 | migrate_cancel bug fix 21 - 33 | (Un)map batching at stop-n-copy to further optimize LM down time 11 - 20 | persistent IOTLB [3] to improve LM down time 02 - 10 | SVQ descriptor ASID [2] to optimize SVQ switching 01 | dependent linux headers
V
Let's first define 2 sources of downtime that this work is concerned with:
* SVQ switching downtime (Downtime #1): downtime at the start of migration. Time spent on teardown and setup for SVQ mode switching, and this downtime is regarded as the maxium time for an individual vdpa-net device. No memory transfer is involved during SVQ switching, hence no .
* LM downtime (Downtime #2): aggregated downtime for all vdpa-net devices on resource teardown and setup in the last stop-n-copy phase on source host.
With each part of the optimizations applied bottom up, the effective outcome in terms of down time (in seconds) performance can be observed in this table:
| Downtime #1 | Downtime #2
--------------------+-------------------+-------------------
Baseline QEMU | 20s ~ 30s | 20s
| |
Iterative map | |
at destination[1] | 5s | 20s
| |
SVQ descriptor | |
ASID [2] | 2s | 5s
| |
| |
persistent IOTLB | 2s | 2s
[3] | |
| |
(Un)map batching | |
at stop-n-copy | 1.7s | 1.5s
before switchover | |(VM config: 128GB mem, 2 mlx5_vdpa devices, each w/ 4 data vqs)
Please find the details regarding each enhancement on the commit log.
Thanks,
-Siwei
[1] [RFC PATCH v2 00/10] Map memory at destination .load_setup in vDPA-net migration
https://lists.nongnu.org/archive/html/qemu-devel/2023-11/msg05711.html
[2] VHOST_BACKEND_F_DESC_ASID
https://lore.kernel.org/virtualization/[email protected]/
[3] VHOST_BACKEND_F_IOTLB_PERSIST
https://lore.kernel.org/virtualization/[email protected]/
---
Si-Wei Liu (40):
linux-headers: add vhost_types.h and vhost.h
vdpa: add vhost_vdpa_get_vring_desc_group
vdpa: probe descriptor group index for data vqs
vdpa: piggyback desc_group index when probing isolated cvq
vdpa: populate desc_group from net_vhost_vdpa_init
vhost: make svq work with gpa without iova translation
vdpa: move around vhost_vdpa_set_address_space_id
vdpa: add back vhost_vdpa_net_first_nc_vdpa
vdpa: no repeat setting shadow_data
vdpa: assign svq descriptors a separate ASID when possible
vdpa: factor out vhost_vdpa_last_dev
vdpa: check map_thread_enabled before join maps thread
vdpa: ref counting VhostVDPAShared
vdpa: convert iova_tree to ref count based
vdpa: add svq_switching and flush_map to header
vdpa: indicate SVQ switching via flag
vdpa: judge if map can be kept across reset
vdpa: unregister listener on last dev cleanup
vdpa: should avoid map flushing with persistent iotlb
vdpa: avoid mapping flush across reset
vdpa: vhost_vdpa_dma_batch_end_once rename
vdpa: factor out vhost_vdpa_map_batch_begin
vdpa: vhost_vdpa_dma_batch_begin_once rename
vdpa: factor out vhost_vdpa_dma_batch_end
vdpa: add asid to dma_batch_once API
vdpa: return int for dma_batch_once API
vdpa: add asid to all dma_batch call sites
vdpa: support iotlb_batch_asid
vdpa: expose API vhost_vdpa_dma_batch_once
vdpa: batch map/unmap op per svq pair basis
vdpa: batch map and unmap around cvq svq start/stop
vdpa: factor out vhost_vdpa_net_get_nc_vdpa
vdpa: batch multiple dma_unmap to a single call for vm stop
vdpa: fix network breakage after cancelling migration
vdpa: add vhost_vdpa_set_address_space_id trace
vdpa: add vhost_vdpa_get_vring_base trace for svq mode
vdpa: add vhost_vdpa_set_dev_vring_base trace for svq mode
vdpa: add trace events for eval_flush
vdpa: add trace events for vhost_vdpa_net_load_cmd
vdpa: add trace event for vhost_vdpa_net_load_mq
hw/virtio/trace-events | 9 +- hw/virtio/vhost-shadow-virtqueue.c | 35 ++- hw/virtio/vhost-vdpa.c | 156 +++++++--- include/hw/virtio/vhost-vdpa.h | 16 + include/standard-headers/linux/vhost_types.h | 13 + linux-headers/linux/vhost.h | 9 + net/trace-events | 8 + net/vhost-vdpa.c | 434 ++++++++++++++++++++++----- 8 files changed, 558 insertions(+), 122 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/40 linux-headers: add vhost_types.h and vhost.h
--- include/standard-headers/linux/vhost_types.h | 13 +++++++++++++ linux-headers/linux/vhost.h | 9 +++++++++ 2 files changed, 22 insertions(+)
include/standard-headers/linux/vhost_types.h +13 -0
@@ -185,5 +185,18 @@ struct vhost_vdpa_iova_range {* DRIVER_OK */ #define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 +/* Device can be resumed */ +#define VHOST_BACKEND_F_RESUME 0x5 +/* Device supports the driver enabling virtqueues both before and after +* DRIVER_OK +*/ +#define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 +/* Device may expose the virtqueue's descriptor area, driver area and +* device area to a different group for ASID binding than where its +* buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID. +*/ +#define VHOST_BACKEND_F_DESC_ASID 0x7 +/* IOTLB don't flush memory mapping across device reset */ +#define VHOST_BACKEND_F_IOTLB_PERSIST 0x8#endif
linux-headers/linux/vhost.h +9 -0
@@ -219,4 +219,13 @@*/ #define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) +/* Get the dedicated group for the descriptor table of a virtqueue: +* read index, write group in num. +* The virtqueue index is stored in the index field of vhost_vring_state. +* The group id for the descriptor table of this specific virtqueue +* is returned via num field of vhost_vring_state. +*/ +#define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \ + struct vhost_vring_state) +#endif
Signature · 1 line
1.8.3.1
Re: [PATCH 01/40] linux-headers: add vhost_types.h and vhost.h
Quoted 2 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>
This should be updated from scripts/update-linux-headers.sh.
Quoted 49 lines
--- include/standard-headers/linux/vhost_types.h | 13 +++++++++++++ linux-headers/linux/vhost.h | 9 +++++++++ 2 files changed, 22 insertions(+)include/standard-headers/linux/vhost_types.h +13
-0@@ -185,5 +185,18 @@ struct vhost_vdpa_iova_range {* DRIVER_OK */ #define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 +/* Device can be resumed */ +#define VHOST_BACKEND_F_RESUME 0x5 +/* Device supports the driver enabling virtqueues both before and after +* DRIVER_OK +*/ +#define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 +/* Device may expose the virtqueue's descriptor area, driver area and +* device area to a different group for ASID binding than where its +* buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID. +*/ +#define VHOST_BACKEND_F_DESC_ASID 0x7 +/* IOTLB don't flush memory mapping across device reset */ +#define VHOST_BACKEND_F_IOTLB_PERSIST 0x8#endif linux-headers/linux/vhost.h +9
-1@@ -219,4 +219,13 @@*/ #define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) +/* Get the dedicated group for the descriptor table of a virtqueue: +* read index, write group in num. +* The virtqueue index is stored in the index field of vhost_vring_state. +* The group id for the descriptor table of this specific virtqueue +* is returned via num field of vhost_vring_state. +*/ +#define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \ + struct vhost_vring_state) +#endif --1.8.3.1
Re: [PATCH 01/40] linux-headers: add vhost_types.h and vhost.h
In reply to Si-Wei LiuQuoted 2 lines · Si-Wei Liu
Signed-off-by Si-Wei Liu <[email protected]>
It's better to document which version did this commit sync to.
Thanks
Quoted 49 lines
--- include/standard-headers/linux/vhost_types.h | 13 +++++++++++++ linux-headers/linux/vhost.h | 9 +++++++++ 2 files changed, 22 insertions(+)include/standard-headers/linux/vhost_types.h +13
-0@@ -185,5 +185,18 @@ struct vhost_vdpa_iova_range {* DRIVER_OK */ #define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 +/* Device can be resumed */ +#define VHOST_BACKEND_F_RESUME 0x5 +/* Device supports the driver enabling virtqueues both before and after +* DRIVER_OK +*/ +#define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 +/* Device may expose the virtqueue's descriptor area, driver area and +* device area to a different group for ASID binding than where its +* buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID. +*/ +#define VHOST_BACKEND_F_DESC_ASID 0x7 +/* IOTLB don't flush memory mapping across device reset */ +#define VHOST_BACKEND_F_IOTLB_PERSIST 0x8#endif linux-headers/linux/vhost.h +9
-1@@ -219,4 +219,13 @@*/ #define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) +/* Get the dedicated group for the descriptor table of a virtqueue: +* read index, write group in num. +* The virtqueue index is stored in the index field of vhost_vring_state. +* The group id for the descriptor table of this specific virtqueue +* is returned via num field of vhost_vring_state. +*/ +#define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \ + struct vhost_vring_state) +#endif --1.8.3.1
PATCH 2/40 vdpa: add vhost_vdpa_get_vring_desc_group
In reply to Si-Wei LiuInternal API to get the descriptor group index for a specific virtqueue through the VHOST_VDPA_GET_VRING_DESC_GROUP ioctl.
--- net/vhost-vdpa.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
net/vhost-vdpa.c +19 -0
@@ -471,6 +471,25 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index,return state.num; } +static int64_t vhost_vdpa_get_vring_desc_group (int device_fd, +unsigned vq_index, +Error **errp) +{ +struct vhost_vring_state state = { + .index = vq_index, + }; +int r =ioctl (device_fd,VHOST_VDPA_GET_VRING_DESC_GROUP , &state); + +if (unlikely (r <0 )) { + r = -errno; +error_setg_errno (errp, errno,"Cannot get VQ %u descriptor group" , + vq_index); +return r; + } + +return state.num; +} +static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v,unsigned vq_group,unsigned asid_num)
Signature · 1 line
1.8.3.1
Re: [PATCH 02/40] vdpa: add vhost_vdpa_get_vring_desc_group
Quoted 5 lines · Si-Wei Liu
Internal API to get the descriptor group index for a specific virtqueue through the
VHOST_VDPA_GET_VRING_DESC_GROUPioctl.Signed-off-by Si-Wei Liu <[email protected]>
Thanks
Quoted 37 lines
--- net/vhost-vdpa.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)net/vhost-vdpa.c +19
-1@@ -471,6 +471,25 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index,return state.num; } +static int64_t vhost_vdpa_get_vring_desc_group (int device_fd, +unsigned vq_index, +Error **errp) +{ +struct vhost_vring_state state = { + .index = vq_index, + }; +int r =ioctl (device_fd,VHOST_VDPA_GET_VRING_DESC_GROUP , &state); + +if (unlikely (r <0 )) { + r = -errno; +error_setg_errno (errp, errno,"Cannot get VQ %u descriptor group" , + vq_index); +return r; + } + +return state.num; +} +static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v,unsigned vq_group,unsigned asid_num) --1.8.3.1
PATCH 3/40 vdpa: probe descriptor group index for data vqs
In reply to Si-Wei LiuGetting it ahead at initialization time instead of start time allows decision making independent of device status, while reducing failure possibility in starting device or during migration.
Adding function vhost_vdpa_probe_desc_group() for that end. This function will be used to probe the descriptor group for data vqs.
--- net/vhost-vdpa.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)
net/vhost-vdpa.c +89 -0
@@ -1688,6 +1688,95 @@ out:return r; } +static int vhost_vdpa_probe_desc_group (int device_fd,uint64_t features, +int vq_index,int64_t *desc_grpidx, +Error **errp) +{ +uint64_t backend_features; +int64_t vq_group, desc_group; +uint8_t saved_status =0 ; +uint8_t status =0 ; +int r; + +ERRP_GUARD (); + + r =ioctl (device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); +if (unlikely (r <0 )) { +error_setg_errno (errp, errno,"Cannot get vdpa backend_features" ); +return r; + } + +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) { +return 0 ; + } + +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_DESC_ASID ))) { +return 0 ; + } + + r =ioctl (device_fd,VHOST_VDPA_GET_STATUS , &saved_status); +if (unlikely (r)) { +error_setg_errno (errp, -r,"Cannot get device status" ); + goto out; + } + + r =ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status); +if (unlikely (r)) { +error_setg_errno (errp, -r,"Cannot reset device" ); + goto out; + } + + r =ioctl (device_fd,VHOST_SET_FEATURES , &features); +if (unlikely (r)) { +error_setg_errno (errp, errno,"Cannot set features" ); + } + + status =VIRTIO_CONFIG_S_ACKNOWLEDGE | +VIRTIO_CONFIG_S_DRIVER | +VIRTIO_CONFIG_S_FEATURES_OK ; + + r =ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status); +if (unlikely (r)) { +error_setg_errno (errp, -r,"Cannot set device status" ); + goto out; + } + + vq_group =vhost_vdpa_get_vring_group (device_fd, vq_index, errp); +if (unlikely (vq_group <0 )) { +if (vq_group != -ENOTSUP ) { + r = vq_group; + goto out; + } + +/* +* The kernel report VHOST_BACKEND_F_IOTLB_ASID if the vdpa frontend +* support ASID even if the parent driver does not. +*/ +error_free (*errp); + *errp =NULL ; + r =0 ; + goto out; + } + + desc_group =vhost_vdpa_get_vring_desc_group (device_fd, vq_index, + errp); +if (unlikely (desc_group <0 )) { + r = desc_group; + goto out; + }else if (desc_group != vq_group) { + *desc_grpidx = desc_group; + } + r =1 ; + +out: + status =0 ; +ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status); +if (saved_status) { +ioctl (device_fd,VHOST_VDPA_SET_STATUS , &saved_status); + } +return r; +} + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name,
Signature · 1 line
1.8.3.1
Re: [PATCH 03/40] vdpa: probe descriptor group index for data vqs
Quoted 41 lines · Si-Wei Liu
Getting it ahead at initialization time instead of start time allows decision making independent of device status, while reducing failure possibility in starting device or during migration.
Adding function
vhost_vdpa_probe_desc_group()for that end. This function will be used to probe the descriptor group for data vqs.Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)net/vhost-vdpa.c +20
-0@@ -1688,6 +1688,95 @@ out:return r; } +static int vhost_vdpa_probe_desc_group (int device_fd,uint64_t features, +int vq_index,int64_t *desc_grpidx, +Error **errp) +{ +uint64_t backend_features; +int64_t vq_group, desc_group; +uint8_t saved_status =0 ; +uint8_t status =0 ; +int r; + +ERRP_GUARD (); + + r =ioctl (device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); +if (unlikely (r <0 )) { +error_setg_errno (errp, errno,"Cannot get vdpa backend_features" ); +return r; + } + +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) { +return 0 ;
net/vhost-vdpa.c out: · line 1720
Quoted 10 lines
net/vhost-vdpa.c +10
-0+ } + +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_DESC_ASID ))) { +return 0 ; + } + + r =ioctl (device_fd,VHOST_VDPA_GET_STATUS , &saved_status); +if (unlikely (r)) { +error_setg_errno (errp, -r,"Cannot get device status" ); + goto out;
Nit, we could return here directly, can't we?
net/vhost-vdpa.c out: · line 1731
Quoted 11 lines
net/vhost-vdpa.c +11
-0+ } + + r =ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status); +if (unlikely (r)) { +error_setg_errno (errp, -r,"Cannot reset device" ); + goto out; + } + + r =ioctl (device_fd,VHOST_SET_FEATURES , &features); +if (unlikely (r)) { +error_setg_errno (errp, errno,"Cannot set features" );
missing goto out?
Quoted 38 lines
net/vhost-vdpa.c +38
-0+ } + + status =VIRTIO_CONFIG_S_ACKNOWLEDGE | +VIRTIO_CONFIG_S_DRIVER | +VIRTIO_CONFIG_S_FEATURES_OK ; + + r =ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status); +if (unlikely (r)) { +error_setg_errno (errp, -r,"Cannot set device status" ); + goto out; + } + + vq_group =vhost_vdpa_get_vring_group (device_fd, vq_index, errp); +if (unlikely (vq_group <0 )) { +if (vq_group != -ENOTSUP ) { + r = vq_group; + goto out; + } + +/* +* The kernel report VHOST_BACKEND_F_IOTLB_ASID if the vdpa frontend +* support ASID even if the parent driver does not. +*/ +error_free (*errp); + *errp =NULL ; + r =0 ; + goto out; + } + + desc_group =vhost_vdpa_get_vring_desc_group (device_fd, vq_index, + errp); +if (unlikely (desc_group <0 )) { + r = desc_group; + goto out; + }else if (desc_group != vq_group) { + *desc_grpidx = desc_group; + } + r =1 ;
net/vhost-vdpa.c out: · line 1779
Quoted 10 lines
net/vhost-vdpa.c +10
-0+ +out: + status =0 ; +ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status); +if (saved_status) { +ioctl (device_fd,VHOST_VDPA_SET_STATUS , &saved_status); + } +return r; +} +
It is invalid to add static functions without a caller, I think the compiler will complain about this.
Quoted 7 lines
net/vhost-vdpa.c +0
-1static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, --1.8.3.1
Re: [PATCH 03/40] vdpa: probe descriptor group index for data vqs
In reply to Si-Wei LiuQuoted 42 lines · Si-Wei Liu
Getting it ahead at initialization time instead of start time allows decision making independent of device status, while reducing failure possibility in starting device or during migration.
Adding function
vhost_vdpa_probe_desc_group()for that end. This function will be used to probe the descriptor group for data vqs.Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)net/vhost-vdpa.c +21
-0@@ -1688,6 +1688,95 @@ out:return r; } +static int vhost_vdpa_probe_desc_group (int device_fd,uint64_t features, +int vq_index,int64_t *desc_grpidx, +Error **errp) +{ +uint64_t backend_features; +int64_t vq_group, desc_group; +uint8_t saved_status =0 ; +uint8_t status =0 ; +int r; + +ERRP_GUARD (); + + r =ioctl (device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); +if (unlikely (r <0 )) { +error_setg_errno (errp, errno,"Cannot get vdpa backend_features" ); +return r; + } + +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) { +return 0 ; + }
net/vhost-vdpa.c out: · line 1721
Quoted 10 lines
net/vhost-vdpa.c +10
-0+ +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_DESC_ASID ))) { +return 0 ; + } + + r =ioctl (device_fd,VHOST_VDPA_GET_STATUS , &saved_status); +if (unlikely (r)) { +error_setg_errno (errp, -r,"Cannot get device status" ); + goto out; + }
I wonder what's the reason for the status being saved and restored?
We don't do this in vhost_vdpa_probe_cvq_isolation().
Thanks
PATCH 4/40 vdpa: piggyback desc_group index when probing isolated cvq
In reply to Si-Wei LiuSame as the previous commit, but do it for cvq instead of data vqs.
--- net/vhost-vdpa.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
net/vhost-vdpa.c +17 -4
@@ -1601,16 +1601,19 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { };/** -* Probe if CVQ is isolated +* Probe if CVQ is isolated, and piggyback its descriptor group +* index if supported * * @device_fd The vdpa device fd * @features Features offered by the device. * @cvq_index The control vq pair index +* @desc_grpidx The CVQ's descriptor group index to return * -* Returns <0 in case of failure, 0 if false and 1 if true. +* Returns <0 in case of failure, 0 if false and 1 if true (isolated). */ static int vhost_vdpa_probe_cvq_isolation (int device_fd,uint64_t features, -int cvq_index,Error **errp) +int cvq_index,int64_t *desc_grpidx, +Error **errp) {uint64_t backend_features;int64_t cvq_group;
@@ -1667,6 +1670,13 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, goto out; } +if (backend_features &BIT_ULL (VHOST_BACKEND_F_DESC_ASID )) { +int64_t desc_group =vhost_vdpa_get_vring_desc_group (device_fd, + cvq_index, errp); +if (likely (desc_group >=0 ) && desc_group != cvq_group) + *desc_grpidx = desc_group; + } +for (int i =0 ; i < cvq_index; ++i) {int64_t group =vhost_vdpa_get_vring_group (device_fd, i, errp);if (unlikely (group <0 )) {
@@ -1685,6 +1695,8 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, out: status =0 ;ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status); + status =VIRTIO_CONFIG_S_ACKNOWLEDGE |VIRTIO_CONFIG_S_DRIVER ; +ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status);return r; }
@@ -1791,6 +1803,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, Error **errp) {NetClientState *nc =NULL ; +int64_t desc_group =-1 ;VhostVDPAState *s;int ret =0 ;assert (name);
@@ -1802,7 +1815,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, }else { cvq_isolated =vhost_vdpa_probe_cvq_isolation (vdpa_device_fd, features, queue_pair_index *2 , - errp); + &desc_group, errp);if (unlikely (cvq_isolated <0 )) {return NULL ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 04/40] vdpa: piggyback desc_group index when probing isolated cvq
Quoted 50 lines · Si-Wei Liu
Same as the previous commit, but do it for cvq instead of data vqs.
Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)net/vhost-vdpa.c +13
-3@@ -1601,16 +1601,19 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { };/** -* Probe if CVQ is isolated +* Probe if CVQ is isolated, and piggyback its descriptor group +* index if supported * * @device_fd The vdpa device fd * @features Features offered by the device. * @cvq_index The control vq pair index +* @desc_grpidx The CVQ's descriptor group index to return * -* Returns <0 in case of failure, 0 if false and 1 if true. +* Returns <0 in case of failure, 0 if false and 1 if true (isolated). */ static int vhost_vdpa_probe_cvq_isolation (int device_fd,uint64_t features, -int cvq_index,Error **errp) +int cvq_index,int64_t *desc_grpidx, +Error **errp) {uint64_t backend_features;int64_t cvq_group;@@ -1667,6 +1670,13 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, goto out; } +if (backend_features &BIT_ULL (VHOST_BACKEND_F_DESC_ASID )) { +int64_t desc_group =vhost_vdpa_get_vring_desc_group (device_fd, + cvq_index, errp); +if (likely (desc_group >=0 ) && desc_group != cvq_group) + *desc_grpidx = desc_group; + } +for (int i =0 ; i < cvq_index; ++i) {int64_t group =vhost_vdpa_get_vring_group (device_fd, i, errp);if (unlikely (group <0 )) {
net/vhost-vdpa.c static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, · line 1698
Quoted 4 lines
net/vhost-vdpa.c +1
-0@@ -1685,6 +1695,8 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, out: status =0 ;ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status); + status =VIRTIO_CONFIG_S_ACKNOWLEDGE |VIRTIO_CONFIG_S_DRIVER ;
Is this a bug fix or I don't see the connection with the descriptor group.
Thanks
Quoted 24 lines
net/vhost-vdpa.c +3
-2+ioctl (device_fd,VHOST_VDPA_SET_STATUS , &status);return r; }@@ -1791,6 +1803,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, Error **errp) {NetClientState *nc =NULL ; +int64_t desc_group =-1 ;VhostVDPAState *s;int ret =0 ;assert (name);@@ -1802,7 +1815,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, }else { cvq_isolated =vhost_vdpa_probe_cvq_isolation (vdpa_device_fd, features, queue_pair_index *2 , - errp); + &desc_group, errp);if (unlikely (cvq_isolated <0 )) {return NULL ; } --1.8.3.1
PATCH 5/40 vdpa: populate desc_group from net_vhost_vdpa_init
In reply to Si-Wei LiuAdd the desc_group field to struct vhost_vdpa, and get it populated when the corresponding vq is initialized at net_vhost_vdpa_init. If the vq does not have descriptor group capability, or it doesn't have a dedicated ASID group to host descriptors other than the data buffers, desc_group will be set to a negative value -1.
--- include/hw/virtio/vhost-vdpa.h | 1 + net/vhost-vdpa.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
include/hw/virtio/vhost-vdpa.h +1 -0
@@ -87,6 +87,7 @@ typedef struct vhost_vdpa {Error *migration_blocker;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];IOMMUNotifier n; +int64_t desc_group; } VhostVDPA;int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range);
net/vhost-vdpa.c +13 -2
@@ -1855,11 +1855,22 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);if (ret) { -qemu_del_net_client (nc); -return NULL ; + goto err; } +if (is_datapath) { + ret =vhost_vdpa_probe_desc_group (vdpa_device_fd, features, +0 , &desc_group, errp); +if (unlikely (ret <0 )) { + goto err; + } + } + s->vhost_vdpa.desc_group = desc_group;return nc; + +err: +qemu_del_net_client (nc); +return NULL ; }static int vhost_vdpa_get_features (int fd,uint64_t *features,Error **errp)
Signature · 1 line
1.8.3.1
Re: [PATCH 05/40] vdpa: populate desc_group from net_vhost_vdpa_init
Quoted 8 lines · Si-Wei Liu
Add the
desc_groupfield to structvhost_vdpa, and get it populated when the corresponding vq is initialized atnet_vhost_vdpa_init. If the vq does not have descriptor group capability, or it doesn't have a dedicated ASID group to host descriptors other than the data buffers,desc_groupwill be set to a negative value -1.
We should use a defined constant. As always, I don't have a good name though :). DESC_GROUP_SAME_AS_BUFFERS_GROUP?
Quoted 29 lines
Signed-off-by Si-Wei Liu <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + net/vhost-vdpa.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -87,6 +87,7 @@ typedef struct vhost_vdpa {Error *migration_blocker;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];IOMMUNotifier n; +int64_t desc_group; } VhostVDPA;int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range);net/vhost-vdpa.c +1
-2@@ -1855,11 +1855,22 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);if (ret) { -qemu_del_net_client (nc); -return NULL ; + goto err;
net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1868
Quoted 10 lines
net/vhost-vdpa.c +8
-0} +if (is_datapath) { + ret =vhost_vdpa_probe_desc_group (vdpa_device_fd, features, +0 , &desc_group, errp); +if (unlikely (ret <0 )) { + goto err; + } + } + s->vhost_vdpa.desc_group = desc_group;
Why not do the probe at the same time as the CVQ isolation probe? It would save all the effort to restore the previous device status, not to mention not needed to initialize and reset the device so many times for the probing. The error unwinding is not needed here that way.
I think the most controversial part is how to know the right vring group. When I sent the CVQ probe, I delegated that to the device startup and we decide it would be weird to have CVQ isolated only in the MQ case but not in the SQ case. I think we could do the same here for the sake of making the series simpler: just checking the actual isolation of vring descriptor group, and then move to save the actual vring group at initialization if it saves significant time.
Does it make sense to you?
Thanks!
Quoted 11 lines
net/vhost-vdpa.c +4
-1return nc; + +err: +qemu_del_net_client (nc); +return NULL ; }static int vhost_vdpa_get_features (int fd,uint64_t *features,Error **errp) --1.8.3.1
Re: [PATCH 05/40] vdpa: populate desc_group from net_vhost_vdpa_init
Quoted 45 lines · Eugenio Perez Martin
Quoted 8 lines · Si-Wei Liu
Add the
desc_groupfield to structvhost_vdpa, and get it populated when the corresponding vq is initialized atnet_vhost_vdpa_init. If the vq does not have descriptor group capability, or it doesn't have a dedicated ASID group to host descriptors other than the data buffers,desc_groupwill be set to a negative value -1.We should use a defined constant. As always, I don't have a good name though :).
DESC_GROUP_SAME_AS_BUFFERS_GROUP?Quoted 31 lines
Signed-off-by Si-Wei Liu <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + net/vhost-vdpa.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -87,6 +87,7 @@ typedef struct vhost_vdpa {Error *migration_blocker;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];IOMMUNotifier n; +int64_t desc_group; } VhostVDPA;int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range);net/vhost-vdpa.c +1
-2@@ -1855,11 +1855,22 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);if (ret) { -qemu_del_net_client (nc); -return NULL ; + goto err; }
Quoted 3 lines
net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1863
Quoted 3 lines
net/vhost-vdpa.c +3
-0+if (is_datapath) { + ret =vhost_vdpa_probe_desc_group (vdpa_device_fd, features, +0 , &desc_group, errp);
Also, it is always checking for the vring group of the first virtqueue of the vdpa parent device, isn't it? The 3rd parameter should be queue_pair_index*2.
Even with queue_pair_index*2., we're also assuming tx queue will have the same vring group as rx. While I think this is a valid assumption, maybe it is better to probe it at initialization and act as if the device does not have VHOST_BACKEND_F_DESC_ASID if we find otherwise?
Thanks!
Quoted 34 lines
net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1868
Quoted 5 lines
net/vhost-vdpa.c +5
-0+if (unlikely (ret <0 )) { + goto err; + } + } + s->vhost_vdpa.desc_group = desc_group;Why not do the probe at the same time as the CVQ isolation probe? It would save all the effort to restore the previous device status, not to mention not needed to initialize and reset the device so many times for the probing. The error unwinding is not needed here that way.
I think the most controversial part is how to know the right vring group. When I sent the CVQ probe, I delegated that to the device startup and we decide it would be weird to have CVQ isolated only in the MQ case but not in the SQ case. I think we could do the same here for the sake of making the series simpler: just checking the actual isolation of vring descriptor group, and then move to save the actual vring group at initialization if it saves significant time.
Does it make sense to you?
Thanks!
Quoted 11 lines
net/vhost-vdpa.c +4
-1return nc; + +err: +qemu_del_net_client (nc); +return NULL ; }static int vhost_vdpa_get_features (int fd,uint64_t *features,Error **errp) --1.8.3.1
Re: [PATCH 05/40] vdpa: populate desc_group from net_vhost_vdpa_init
In reply to Si-Wei LiuQuoted 31 lines · Si-Wei Liu
Add the
desc_groupfield to structvhost_vdpa, and get it populated when the corresponding vq is initialized atnet_vhost_vdpa_init. If the vq does not have descriptor group capability, or it doesn't have a dedicated ASID group to host descriptors other than the data buffers,desc_groupwill be set to a negative value -1.Signed-off-by Si-Wei Liu <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + net/vhost-vdpa.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -87,6 +87,7 @@ typedef struct vhost_vdpa {Error *migration_blocker;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];IOMMUNotifier n; +int64_t desc_group; } VhostVDPA;int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range);net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1858
Quoted 6 lines
net/vhost-vdpa.c +1
-2@@ -1855,11 +1855,22 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);if (ret) { -qemu_del_net_client (nc); -return NULL ; + goto err;
This part of introducing the "err" label looks more like a cleanup.
Others look good.
Thanks
Quoted 21 lines
net/vhost-vdpa.c +12
-1} +if (is_datapath) { + ret =vhost_vdpa_probe_desc_group (vdpa_device_fd, features, +0 , &desc_group, errp); +if (unlikely (ret <0 )) { + goto err; + } + } + s->vhost_vdpa.desc_group = desc_group;return nc; + +err: +qemu_del_net_client (nc); +return NULL ; }static int vhost_vdpa_get_features (int fd,uint64_t *features,Error **errp) --1.8.3.1
PATCH 6/40 vhost: make svq work with gpa without iova translation
In reply to Si-Wei LiuMake vhost_svq_vring_write_descs able to work with GPA directly without going through iova tree for translation. This will be needed in the next few patches where the SVQ has dedicated address space to host its virtqueues. Instead of having to translate qemu's VA to IOVA via the iova tree, with dedicated or isolated address space for SVQ descriptors, the IOVA is exactly same as the guest GPA space where translation would not be needed any more.
--- hw/virtio/vhost-shadow-virtqueue.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
hw/virtio/vhost-shadow-virtqueue.c +23 -12
@@ -136,8 +136,8 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq,* Return true if success, false otherwise and print error. */ static bool vhost_svq_vring_write_descs (VhostShadowVirtqueue *svq,hwaddr *sg, -const struct iovec *iovec,size_t num, -bool more_descs,bool write) +const struct iovec *iovec,hwaddr *addr, +size_t num,bool more_descs,bool write) {uint16_t i = svq->free_head, last = svq->free_head;unsigned n;
@@ -149,8 +149,15 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,return true; } - ok =vhost_svq_translate_addr (svq, sg, iovec, num); -if (unlikely (!ok)) { +if (svq->iova_tree) { + ok =vhost_svq_translate_addr (svq, sg, iovec, num); +if (unlikely (!ok)) { +return false; + } + }else if (!addr) { +qemu_log_mask (LOG_GUEST_ERROR , +"No translation found for vaddr 0x%p\n" , + iovec[0 ].iov_base);return false; }
@@ -161,7 +168,7 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, }else { descs[i].flags = flags; } - descs[i].addr =cpu_to_le64 (sg[n]); + descs[i].addr =cpu_to_le64 (svq->iova_tree ? sg[n] : addr[n]); descs[i].len =cpu_to_le32 (iovec[n].iov_len); last = i;
@@ -173,9 +180,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, }static bool vhost_svq_add_split (VhostShadowVirtqueue *svq, -const struct iovec *out_sg,size_t out_num, -const struct iovec *in_sg,size_t in_num, -unsigned *head) +const struct iovec *out_sg,hwaddr *out_addr, +size_t out_num, +const struct iovec *in_sg,hwaddr *in_addr, +size_t in_num,unsigned *head) {unsigned avail_idx;vring_avail_t *avail = svq->vring.avail;
@@ -191,13 +199,14 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,return false; } - ok =vhost_svq_vring_write_descs (svq, sgs, out_sg, out_num, in_num >0 , - false); + ok =vhost_svq_vring_write_descs (svq, sgs, out_sg, out_addr, out_num, + in_num >0 , false);if (unlikely (!ok)) {return false; } - ok =vhost_svq_vring_write_descs (svq, sgs, in_sg, in_num, false, true); + ok =vhost_svq_vring_write_descs (svq, sgs, in_sg, in_addr, in_num, + false, true);if (unlikely (!ok)) {return false; }
@@ -258,7 +267,9 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,return -ENOSPC ; } - ok =vhost_svq_add_split (svq, out_sg, out_num, in_sg, in_num, &qemu_head); + ok =vhost_svq_add_split (svq, out_sg, elem ? elem->out_addr :NULL , + out_num, in_sg, elem ? elem->in_addr :NULL , + in_num, &qemu_head);if (unlikely (!ok)) {return -EINVAL ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 06/40] vhost: make svq work with gpa without iova translation
Quoted 90 lines · Si-Wei Liu
Make
vhost_svq_vring_write_descsable to work with GPA directly without going through iova tree for translation. This will be needed in the next few patches where the SVQ has dedicated address space to host its virtqueues. Instead of having to translate qemu's VA to IOVA via the iova tree, with dedicated or isolated address space for SVQ descriptors, the IOVA is exactly same as the guest GPA space where translation would not be needed any more.Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-shadow-virtqueue.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)hw/virtio/vhost-shadow-virtqueue.c +20
-11@@ -136,8 +136,8 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq,* Return true if success, false otherwise and print error. */ static bool vhost_svq_vring_write_descs (VhostShadowVirtqueue *svq,hwaddr *sg, -const struct iovec *iovec,size_t num, -bool more_descs,bool write) +const struct iovec *iovec,hwaddr *addr, +size_t num,bool more_descs,bool write) {uint16_t i = svq->free_head, last = svq->free_head;unsigned n;@@ -149,8 +149,15 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,return true; } - ok =vhost_svq_translate_addr (svq, sg, iovec, num); -if (unlikely (!ok)) { +if (svq->iova_tree) { + ok =vhost_svq_translate_addr (svq, sg, iovec, num); +if (unlikely (!ok)) { +return false; + } + }else if (!addr) { +qemu_log_mask (LOG_GUEST_ERROR , +"No translation found for vaddr 0x%p\n" , + iovec[0 ].iov_base);return false; }@@ -161,7 +168,7 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, }else { descs[i].flags = flags; } - descs[i].addr =cpu_to_le64 (sg[n]); + descs[i].addr =cpu_to_le64 (svq->iova_tree ? sg[n] : addr[n]); descs[i].len =cpu_to_le32 (iovec[n].iov_len); last = i;@@ -173,9 +180,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, }static bool vhost_svq_add_split (VhostShadowVirtqueue *svq, -const struct iovec *out_sg,size_t out_num, -const struct iovec *in_sg,size_t in_num, -unsigned *head) +const struct iovec *out_sg,hwaddr *out_addr, +size_t out_num, +const struct iovec *in_sg,hwaddr *in_addr, +size_t in_num,unsigned *head) {unsigned avail_idx;vring_avail_t *avail = svq->vring.avail;@@ -191,13 +199,14 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,return false; } - ok =vhost_svq_vring_write_descs (svq, sgs, out_sg, out_num, in_num >0 , - false); + ok =vhost_svq_vring_write_descs (svq, sgs, out_sg, out_addr, out_num, + in_num >0 , false);if (unlikely (!ok)) {return false; } - ok =vhost_svq_vring_write_descs (svq, sgs, in_sg, in_num, false, true); + ok =vhost_svq_vring_write_descs (svq, sgs, in_sg, in_addr, in_num, + false, true);if (unlikely (!ok)) {return false; }
hw/virtio/vhost-shadow-virtqueue.c int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, · line 272
Quoted 7 lines
hw/virtio/vhost-shadow-virtqueue.c +3
-1@@ -258,7 +267,9 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,return -ENOSPC ; } - ok =vhost_svq_add_split (svq, out_sg, out_num, in_sg, in_num, &qemu_head); + ok =vhost_svq_add_split (svq, out_sg, elem ? elem->out_addr :NULL , + out_num, in_sg, elem ? elem->in_addr :NULL , + in_num, &qemu_head);
This function is using in_sg and out_sg intentionally as CVQ buffers do not use VirtQueueElement addressing. You can check calls at net/vhost-vdpa.c for more info. The right place for this change is actually vhost_svq_add_element, and I suggest checking for svq->iova_tree as the rest of the patch.
Apart from that,
Thanks!
Quoted 6 lines
hw/virtio/vhost-shadow-virtqueue.c +0
-1if (unlikely (!ok)) {return -EINVAL ; } --1.8.3.1
Re: [PATCH 06/40] vhost: make svq work with gpa without iova translation
In reply to Si-Wei LiuQuoted 31 lines · Si-Wei Liu
Make
vhost_svq_vring_write_descsable to work with GPA directly without going through iova tree for translation. This will be needed in the next few patches where the SVQ has dedicated address space to host its virtqueues. Instead of having to translate qemu's VA to IOVA via the iova tree, with dedicated or isolated address space for SVQ descriptors, the IOVA is exactly same as the guest GPA space where translation would not be needed any more.Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-shadow-virtqueue.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)hw/virtio/vhost-shadow-virtqueue.c +2
-2@@ -136,8 +136,8 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq,* Return true if success, false otherwise and print error. */ static bool vhost_svq_vring_write_descs (VhostShadowVirtqueue *svq,hwaddr *sg, -const struct iovec *iovec,size_t num, -bool more_descs,bool write) +const struct iovec *iovec,hwaddr *addr, +size_t num,bool more_descs,bool write) {uint16_t i = svq->free_head, last = svq->free_head;unsigned n;
hw/virtio/vhost-shadow-virtqueue.c static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, · line 156
Quoted 10 lines
hw/virtio/vhost-shadow-virtqueue.c +5
-2@@ -149,8 +149,15 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,return true; } - ok =vhost_svq_translate_addr (svq, sg, iovec, num); -if (unlikely (!ok)) { +if (svq->iova_tree) { + ok =vhost_svq_translate_addr (svq, sg, iovec, num); +if (unlikely (!ok)) { +return false; + }
So the idea is when shadow virtqueue can work directly for GPA, there won't be an iova_tree here?
If yes, I think we need a comment around iova_tree or here to explain this.
hw/virtio/vhost-shadow-virtqueue.c static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, · line 171
Quoted 13 lines
hw/virtio/vhost-shadow-virtqueue.c +5
-1+ }else if (!addr) { +qemu_log_mask (LOG_GUEST_ERROR , +"No translation found for vaddr 0x%p\n" , + iovec[0 ].iov_base);return false; }@@ -161,7 +168,7 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, }else { descs[i].flags = flags; } - descs[i].addr =cpu_to_le64 (sg[n]); + descs[i].addr =cpu_to_le64 (svq->iova_tree ? sg[n] : addr[n]);
Or maybe a helper and do the switch there with the comments.
Thanks
Quoted 49 lines
hw/virtio/vhost-shadow-virtqueue.c +11
-8descs[i].len =cpu_to_le32 (iovec[n].iov_len); last = i;@@ -173,9 +180,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, }static bool vhost_svq_add_split (VhostShadowVirtqueue *svq, -const struct iovec *out_sg,size_t out_num, -const struct iovec *in_sg,size_t in_num, -unsigned *head) +const struct iovec *out_sg,hwaddr *out_addr, +size_t out_num, +const struct iovec *in_sg,hwaddr *in_addr, +size_t in_num,unsigned *head) {unsigned avail_idx;vring_avail_t *avail = svq->vring.avail;@@ -191,13 +199,14 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,return false; } - ok =vhost_svq_vring_write_descs (svq, sgs, out_sg, out_num, in_num >0 , - false); + ok =vhost_svq_vring_write_descs (svq, sgs, out_sg, out_addr, out_num, + in_num >0 , false);if (unlikely (!ok)) {return false; } - ok =vhost_svq_vring_write_descs (svq, sgs, in_sg, in_num, false, true); + ok =vhost_svq_vring_write_descs (svq, sgs, in_sg, in_addr, in_num, + false, true);if (unlikely (!ok)) {return false; }@@ -258,7 +267,9 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,return -ENOSPC ; } - ok =vhost_svq_add_split (svq, out_sg, out_num, in_sg, in_num, &qemu_head); + ok =vhost_svq_add_split (svq, out_sg, elem ? elem->out_addr :NULL , + out_num, in_sg, elem ? elem->in_addr :NULL , + in_num, &qemu_head);if (unlikely (!ok)) {return -EINVAL ; } --1.8.3.1
PATCH 7/40 vdpa: move around vhost_vdpa_set_address_space_id
In reply to Si-Wei LiuMove it a few lines ahead to make function call easier for those before it. No funtional change involved.
--- net/vhost-vdpa.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
net/vhost-vdpa.c +18 -18
@@ -335,6 +335,24 @@ static void vdpa_net_migration_state_notifier(Notifier *notifier, void *data) } } +static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v, +unsigned vq_group, +unsigned asid_num) +{ +struct vhost_vring_state asid = { + .index = vq_group, + .num = asid_num, + }; +int r; + + r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid); +if (unlikely (r <0 )) { +error_report ("Can't set vq group %u asid %u, errno=%d (%s)" , + asid.index, asid.num, errno,g_strerror (errno)); + } +return r; +} +static void vhost_vdpa_net_data_start_first (VhostVDPAState *s) {struct vhost_vdpa *v = &s->vhost_vdpa;
@@ -490,24 +508,6 @@ static int64_t vhost_vdpa_get_vring_desc_group(int device_fd,return state.num; } -static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v, -unsigned vq_group, -unsigned asid_num) -{ -struct vhost_vring_state asid = { - .index = vq_group, - .num = asid_num, - }; -int r; - - r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid); -if (unlikely (r <0 )) { -error_report ("Can't set vq group %u asid %u, errno=%d (%s)" , - asid.index, asid.num, errno,g_strerror (errno)); - } -return r; -} -static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) {VhostIOVATree *tree = v->shared->iova_tree;
Signature · 1 line
1.8.3.1
Re: [PATCH 07/40] vdpa: move around vhost_vdpa_set_address_space_id
Quoted 5 lines · Si-Wei Liu
Move it a few lines ahead to make function call easier for those before it. No funtional change involved.
Signed-off-by Si-Wei Liu <[email protected]>
Quoted 61 lines
--- net/vhost-vdpa.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)net/vhost-vdpa.c +18
-19@@ -335,6 +335,24 @@ static void vdpa_net_migration_state_notifier(Notifier *notifier, void *data) } } +static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v, +unsigned vq_group, +unsigned asid_num) +{ +struct vhost_vring_state asid = { + .index = vq_group, + .num = asid_num, + }; +int r; + + r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid); +if (unlikely (r <0 )) { +error_report ("Can't set vq group %u asid %u, errno=%d (%s)" , + asid.index, asid.num, errno,g_strerror (errno)); + } +return r; +} +static void vhost_vdpa_net_data_start_first (VhostVDPAState *s) {struct vhost_vdpa *v = &s->vhost_vdpa;@@ -490,24 +508,6 @@ static int64_t vhost_vdpa_get_vring_desc_group(int device_fd,return state.num; } -static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v, -unsigned vq_group, -unsigned asid_num) -{ -struct vhost_vring_state asid = { - .index = vq_group, - .num = asid_num, - }; -int r; - - r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid); -if (unlikely (r <0 )) { -error_report ("Can't set vq group %u asid %u, errno=%d (%s)" , - asid.index, asid.num, errno,g_strerror (errno)); - } -return r; -} -static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) {VhostIOVATree *tree = v->shared->iova_tree; --1.8.3.1
Re: [PATCH 07/40] vdpa: move around vhost_vdpa_set_address_space_id
In reply to Si-Wei LiuQuoted 3 lines · Si-Wei Liu
Move it a few lines ahead to make function call easier for those before it. No funtional change involved.
Typo for functional.
Quoted 2 lines
Signed-off-by Si-Wei Liu <[email protected]>
Thanks
Quoted 61 lines
--- net/vhost-vdpa.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)net/vhost-vdpa.c +18
-19@@ -335,6 +335,24 @@ static void vdpa_net_migration_state_notifier(Notifier *notifier, void *data) } } +static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v, +unsigned vq_group, +unsigned asid_num) +{ +struct vhost_vring_state asid = { + .index = vq_group, + .num = asid_num, + }; +int r; + + r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid); +if (unlikely (r <0 )) { +error_report ("Can't set vq group %u asid %u, errno=%d (%s)" , + asid.index, asid.num, errno,g_strerror (errno)); + } +return r; +} +static void vhost_vdpa_net_data_start_first (VhostVDPAState *s) {struct vhost_vdpa *v = &s->vhost_vdpa;@@ -490,24 +508,6 @@ static int64_t vhost_vdpa_get_vring_desc_group(int device_fd,return state.num; } -static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v, -unsigned vq_group, -unsigned asid_num) -{ -struct vhost_vring_state asid = { - .index = vq_group, - .num = asid_num, - }; -int r; - - r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid); -if (unlikely (r <0 )) { -error_report ("Can't set vq group %u asid %u, errno=%d (%s)" , - asid.index, asid.num, errno,g_strerror (errno)); - } -return r; -} -static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) {VhostIOVATree *tree = v->shared->iova_tree; --1.8.3.1
PATCH 8/40 vdpa: add back vhost_vdpa_net_first_nc_vdpa
In reply to Si-Wei LiuPrevious commits had it removed. Now adding it back because this function will be needed by next patches.
--- net/vhost-vdpa.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
net/vhost-vdpa.c +13 -2
@@ -287,6 +287,16 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf,return size; } + +/** From any vdpa net client, get the netclient of the first queue pair */ +static VhostVDPAState *vhost_vdpa_net_first_nc_vdpa (VhostVDPAState *s) +{ +NICState *nic =qemu_get_nic (s->nc.peer); +NetClientState *nc0 =qemu_get_peer (nic->ncs,0 ); + +return DO_UPCAST (VhostVDPAState, nc, nc0); +} +static void vhost_vdpa_net_log_global_enable (VhostVDPAState *s,bool enable) {struct vhost_vdpa *v = &s->vhost_vdpa;
@@ -566,7 +576,7 @@ dma_map_err:static int vhost_vdpa_net_cvq_start (NetClientState *nc) { -VhostVDPAState *s; +VhostVDPAState *s, *s0;struct vhost_vdpa *v;int64_t cvq_group;int r;
@@ -577,7 +587,8 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) s =DO_UPCAST (VhostVDPAState, nc, nc); v = &s->vhost_vdpa; - v->shadow_vqs_enabled = v->shared->shadow_data; + s0 =vhost_vdpa_net_first_nc_vdpa (s); + v->shadow_vqs_enabled = s0->vhost_vdpa.shadow_vqs_enabled; s->vhost_vdpa.address_space_id =VHOST_VDPA_GUEST_PA_ASID ;if (v->shared->shadow_data) {
Signature · 1 line
1.8.3.1
Re: [PATCH 08/40] vdpa: add back vhost_vdpa_net_first_nc_vdpa
Quoted 14 lines · Si-Wei Liu
Previous commits had it removed. Now adding it back because this function will be needed by next patches.
Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf, · line 290
Quoted 4 lines
net/vhost-vdpa.c +1
-0@@ -287,6 +287,16 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf,return size; } +
Extra newline.
Quoted 22 lines
net/vhost-vdpa.c +10
-1+/** From any vdpa net client, get the netclient of the first queue pair */ +static VhostVDPAState *vhost_vdpa_net_first_nc_vdpa (VhostVDPAState *s) +{ +NICState *nic =qemu_get_nic (s->nc.peer); +NetClientState *nc0 =qemu_get_peer (nic->ncs,0 ); + +return DO_UPCAST (VhostVDPAState, nc, nc0); +} +static void vhost_vdpa_net_log_global_enable (VhostVDPAState *s,bool enable) {struct vhost_vdpa *v = &s->vhost_vdpa;@@ -566,7 +576,7 @@ dma_map_err:static int vhost_vdpa_net_cvq_start (NetClientState *nc) { -VhostVDPAState *s; +VhostVDPAState *s, *s0;struct vhost_vdpa *v;int64_t cvq_group;int r;
net/vhost-vdpa.c static int vhost_vdpa_net_cvq_start(NetClientState *nc) · line 592
Quoted 7 lines
net/vhost-vdpa.c +2
-1@@ -577,7 +587,8 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) s =DO_UPCAST (VhostVDPAState, nc, nc); v = &s->vhost_vdpa; - v->shadow_vqs_enabled = v->shared->shadow_data; + s0 =vhost_vdpa_net_first_nc_vdpa (s); + v->shadow_vqs_enabled = s0->vhost_vdpa.shadow_vqs_enabled; s->vhost_vdpa.address_space_id =VHOST_VDPA_GUEST_PA_ASID ;
I'm wondering if shared->shadow_data is more correct now.
Either way:
Thanks!
Quoted 6 lines
net/vhost-vdpa.c +0
-1if (v->shared->shadow_data) { --1.8.3.1
Re: [PATCH 08/40] vdpa: add back vhost_vdpa_net_first_nc_vdpa
In reply to Si-Wei LiuQuoted 3 lines · Si-Wei Liu
Previous commits had it removed. Now adding it back because this function will be needed by next patches.
Need some description to explain why. Because it should not be needed as we have a "parent" structure now, anything that is common could be stored there?
Thanks
PATCH 9/40 vdpa: no repeat setting shadow_data
In reply to Si-Wei LiuSince shadow_data is now shared in the parent data struct, it just needs to be set only once by the first vq. This change will make shadow_data independent of svq enabled state, which can be optionally turned off when SVQ descritors and device driver areas are all isolated to a separate address space.
--- net/vhost-vdpa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/vhost-vdpa.c +1 -2
@@ -387,13 +387,12 @@ static int vhost_vdpa_net_data_start(NetClientState *nc)if (s->always_svq ||migration_is_setup_or_active (migrate_get_current ()->state)) { v->shadow_vqs_enabled = true; - v->shared->shadow_data = true; }else { v->shadow_vqs_enabled = false; - v->shared->shadow_data = false; }if (v->index ==0 ) { + v->shared->shadow_data = v->shadow_vqs_enabled;vhost_vdpa_net_data_start_first (s);return 0 ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 09/40] vdpa: no repeat setting shadow_data
Quoted 5 lines · Si-Wei Liu
Since
shadow_datais now shared in the parent data struct, it just needs to be set only once by the first vq. This change will makeshadow_dataindependent of svq enabled state, which can be optionally turned off when SVQ descritors and device
descri *p* tors typo.
Quoted 3 lines
driver areas are all isolated to a separate address space.
Signed-off-by Si-Wei Liu <[email protected]>
Can you send this separately so we make this series smaller?
Apart from the typo,
Thanks!
Quoted 26 lines
--- net/vhost-vdpa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/vhost-vdpa.c +1
-3@@ -387,13 +387,12 @@ static int vhost_vdpa_net_data_start(NetClientState *nc)if (s->always_svq ||migration_is_setup_or_active (migrate_get_current ()->state)) { v->shadow_vqs_enabled = true; - v->shared->shadow_data = true; }else { v->shadow_vqs_enabled = false; - v->shared->shadow_data = false; }if (v->index ==0 ) { + v->shared->shadow_data = v->shadow_vqs_enabled;vhost_vdpa_net_data_start_first (s);return 0 ; } --1.8.3.1
Re: [PATCH 09/40] vdpa: no repeat setting shadow_data
In reply to Si-Wei LiuQuoted 5 lines · Si-Wei Liu
Since
shadow_datais now shared in the parent data struct, it just needs to be set only once by the first vq. This change will makeshadow_dataindependent of svq enabled state, which can be optionally turned off when SVQ descritors and device
Typo for descriptors.
Quoted 3 lines
driver areas are all isolated to a separate address space.
Signed-off-by Si-Wei Liu <[email protected]>
Thanks
Quoted 26 lines
--- net/vhost-vdpa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/vhost-vdpa.c +1
-3@@ -387,13 +387,12 @@ static int vhost_vdpa_net_data_start(NetClientState *nc)if (s->always_svq ||migration_is_setup_or_active (migrate_get_current ()->state)) { v->shadow_vqs_enabled = true; - v->shared->shadow_data = true; }else { v->shadow_vqs_enabled = false; - v->shared->shadow_data = false; }if (v->index ==0 ) { + v->shared->shadow_data = v->shadow_vqs_enabled;vhost_vdpa_net_data_start_first (s);return 0 ; } --1.8.3.1
PATCH 10/40 vdpa: assign svq descriptors a separate ASID when possible
In reply to Si-Wei LiuWhen backend supports the VHOST_BACKEND_F_DESC_ASID feature and all the data vqs can support one or more descriptor group to host SVQ vrings and descriptors, we assign them a different ASID than where its buffers reside in guest memory address space. With this dedicated ASID for SVQs, the IOVA for what vdpa device may care effectively becomes the GPA, thus there's no need to translate IOVA address. For this reason, shadow_data can be turned off accordingly. It doesn't mean the SVQ is not enabled, but just that the translation is not needed from iova tree perspective.
We can reuse CVQ's address space ID to host SVQ descriptors because both CVQ and SVQ are emulated in the same QEMU process, which will share the same VA address space.
--- hw/virtio/vhost-vdpa.c | 5 ++++- net/vhost-vdpa.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 5 deletions(-)
hw/virtio/vhost-vdpa.c +4 -1
@@ -627,6 +627,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)uint64_t qemu_backend_features =0x1ULL <<VHOST_BACKEND_F_IOTLB_MSG_V2 |0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH |0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID | +0x1ULL <<VHOST_BACKEND_F_DESC_ASID |0x1ULL <<VHOST_BACKEND_F_SUSPEND ;int ret;
@@ -1249,7 +1250,9 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) goto err; } -vhost_svq_start (svq, dev->vdev, vq, v->shared->iova_tree); +vhost_svq_start (svq, dev->vdev, vq, + v->desc_group >=0 && v->address_space_id ? +NULL : v->shared->iova_tree); ok =vhost_vdpa_svq_map_rings (dev, svq, &addr, &err);if (unlikely (!ok)) { goto err_map;
net/vhost-vdpa.c +53 -4
98 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH 10/40] vdpa: assign svq descriptors a separate ASID when possible
Quoted 35 lines · Si-Wei Liu
When backend supports the
VHOST_BACKEND_F_DESC_ASIDfeature and all the data vqs can support one or more descriptor group to host SVQ vrings and descriptors, we assign them a different ASID than where its buffers reside in guest memory address space. With this dedicated ASID for SVQs, the IOVA for what vdpa device may care effectively becomes the GPA, thus there's no need to translate IOVA address. For this reason,shadow_datacan be turned off accordingly. It doesn't mean the SVQ is not enabled, but just that the translation is not needed from iova tree perspective.We can reuse CVQ's address space ID to host SVQ descriptors because both CVQ and SVQ are emulated in the same QEMU process, which will share the same VA address space.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 5 ++++- net/vhost-vdpa.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 5 deletions(-)hw/virtio/vhost-vdpa.c +1
-0@@ -627,6 +627,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)uint64_t qemu_backend_features =0x1ULL <<VHOST_BACKEND_F_IOTLB_MSG_V2 |0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH |0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID | +0x1ULL <<VHOST_BACKEND_F_DESC_ASID |0x1ULL <<VHOST_BACKEND_F_SUSPEND ;int ret;
hw/virtio/vhost-vdpa.c static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) · line 1254
Quoted 6 lines
hw/virtio/vhost-vdpa.c +2
-1@@ -1249,7 +1250,9 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) goto err; } -vhost_svq_start (svq, dev->vdev, vq, v->shared->iova_tree); + vhost_svq_start(svq, dev->vdev, vq, + v->desc_group >= 0 && v->address_space_id ?
v->address_space_id != VHOST_VDPA_GUEST_PA_ASID?
Quoted 9 lines
hw/virtio/vhost-vdpa.c +1
-0+ NULL : v->shared->iova_tree); ok =vhost_vdpa_svq_map_rings (dev, svq, &addr, &err);if (unlikely (!ok)) { goto err_map;net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, · line 374
Quoted 9 lines
net/vhost-vdpa.c +2
-0@@ -366,20 +366,50 @@ static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v,static void vhost_vdpa_net_data_start_first (VhostVDPAState *s) {struct vhost_vdpa *v = &s->vhost_vdpa; +int r;migration_add_notifier (&s->migration_state, vdpa_net_migration_state_notifier); +if (!v->shadow_vqs_enabled) {
&& VHOST_BACKEND_F_DESC_ASID feature is acked?
Quoted 5 lines
net/vhost-vdpa.c +5
-0+if (v->desc_group >=0 && + v->address_space_id !=VHOST_VDPA_GUEST_PA_ASID ) { +vhost_vdpa_set_address_space_id (v, v->desc_group, +VHOST_VDPA_GUEST_PA_ASID ); + s->vhost_vdpa.address_space_id =VHOST_VDPA_GUEST_PA_ASID ;
net/vhost-vdpa.c static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, · line 388
Quoted 10 lines
net/vhost-vdpa.c +5
-1+ } +return ; + } +/* iova_tree may be initialized by vhost_vdpa_net_load_setup */ -if (v->shadow_vqs_enabled && !v->shared->iova_tree) { +if (!v->shared->iova_tree) { v->shared->iova_tree =vhost_iova_tree_new (v->shared->iova_range.first, v->shared->iova_range.last); }
Maybe not so popular opinion, but I would add a previous patch modifying:
if (v->shadow_vqs_enabled && !v->shared->iova_tree) {
iova_tree = new()
}
---
to:
if (!v->shadow_vqs_enabled) {
return
}
if (!v->shared->iova_tree) {
iova_tree = new()
}
---
Quoted 5 lines
net/vhost-vdpa.c +5
-0+ +if (s->always_svq || v->desc_group <0 ) { +return ; + } +
net/vhost-vdpa.c static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, · line 403
Quoted 10 lines
net/vhost-vdpa.c +10
-0+ r =vhost_vdpa_set_address_space_id (v, v->desc_group, +VHOST_VDPA_NET_CVQ_ASID ); +if (unlikely (r <0 )) { +/* The other data vqs should also fall back to using the same ASID */ + s->vhost_vdpa.address_space_id =VHOST_VDPA_GUEST_PA_ASID ; +return ; + } + +/* No translation needed on data SVQ when descriptor group is used */ + s->vhost_vdpa.address_space_id =VHOST_VDPA_NET_CVQ_ASID ;
I'm not sure "address_space_id" is a good name for this member anymore. If any, I think we can add a comment explaining that it only applies to descs vring if VHOST_BACKEND_F_DESC_ASID is acked and all the needed conditions are met.
Also, maybe it is better to define a new constant VHOST_VDPA_NET_VRING_DESCS_ASID, set it to VHOST_VDPA_NET_CVQ_ASID, and explain why it is ok to reuse that ASID?
Quoted 18 lines
net/vhost-vdpa.c +6
-0+ s->vhost_vdpa.shared->shadow_data = false; +return ; }static int vhost_vdpa_net_data_start (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +VhostVDPAState *s0 =vhost_vdpa_net_first_nc_vdpa (s); +struct vhost_vdpa *v = &s->vhost_vdpa;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );@@ -397,6 +427,18 @@ static int vhost_vdpa_net_data_start(NetClientState *nc)return 0 ; } +if (v->desc_group >=0 && v->desc_group != s0->vhost_vdpa.desc_group) { +unsigned asid;
net/vhost-vdpa.c static int vhost_vdpa_net_data_start(NetClientState *nc) · line 441
Quoted 10 lines
net/vhost-vdpa.c +10
-0+ asid = v->shadow_vqs_enabled ? + s0->vhost_vdpa.address_space_id :VHOST_VDPA_GUEST_PA_ASID ; +if (asid != s->vhost_vdpa.address_space_id) { +vhost_vdpa_set_address_space_id (v, v->desc_group, asid); + } + s->vhost_vdpa.address_space_id = asid; + }else { + s->vhost_vdpa.address_space_id = s0->vhost_vdpa.address_space_id; + } +
Ok, here I see how all vqs are configured so I think some of my previous comments are not 100% valid.
However I think we can improve this, as this omits the case where two vrings different from s0 vring have the same vring descriptor group. But I guess we can always optimize on top.
Quoted 13 lines
net/vhost-vdpa.c +5
-1return 0 ; }@@ -603,13 +645,19 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc)return 0 ; } -if (!s->cvq_isolated) { +if (!s->cvq_isolated && v->desc_group <0 ) { +if (s0->vhost_vdpa.shadow_vqs_enabled && + s0->vhost_vdpa.desc_group >=0 && + s0->vhost_vdpa.address_space_id) { + v->shadow_vqs_enabled = false;
net/vhost-vdpa.c static int vhost_vdpa_net_cvq_start(NetClientState *nc) · line 660
Quoted 10 lines
net/vhost-vdpa.c +4
-2+ }return 0 ; } - cvq_group =vhost_vdpa_get_vring_group (v->shared->device_fd, + cvq_group = s->cvq_isolated ? +vhost_vdpa_get_vring_group (v->shared->device_fd, v->dev->vq_index_end -1 , - &err); + &err) : v->desc_group;
I'm not sure if we can happily set v->desc_group if !s->cvq_isolated. If CVQ buffers share its group with data queues, but its vring is effectively isolated, we are setting all the dataplane buffers to the ASID of the CVQ descriptors, isn't it?
net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1891
Quoted 8 lines
net/vhost-vdpa.c +1
-0if (unlikely (cvq_group <0 )) {error_report_err (err);return cvq_group;@@ -1840,6 +1888,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->always_svq = svq; s->migration_state.notify =NULL ; s->vhost_vdpa.shadow_vqs_enabled = svq; + s->vhost_vdpa.address_space_id =VHOST_VDPA_GUEST_PA_ASID ;
Isn't this overridden at each vhost_vdpa_net_*_start?
Quoted 6 lines
net/vhost-vdpa.c +0
-1if (queue_pair_index ==0 ) {vhost_vdpa_net_valid_svq_features (features, &s->vhost_vdpa.migration_blocker); --1.8.3.1
Re: [PATCH 10/40] vdpa: assign svq descriptors a separate ASID when possible
In reply to Si-Wei LiuQuoted 35 lines · Si-Wei Liu
When backend supports the
VHOST_BACKEND_F_DESC_ASIDfeature and all the data vqs can support one or more descriptor group to host SVQ vrings and descriptors, we assign them a different ASID than where its buffers reside in guest memory address space. With this dedicated ASID for SVQs, the IOVA for what vdpa device may care effectively becomes the GPA, thus there's no need to translate IOVA address. For this reason,shadow_datacan be turned off accordingly. It doesn't mean the SVQ is not enabled, but just that the translation is not needed from iova tree perspective.We can reuse CVQ's address space ID to host SVQ descriptors because both CVQ and SVQ are emulated in the same QEMU process, which will share the same VA address space.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 5 ++++- net/vhost-vdpa.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 5 deletions(-)hw/virtio/vhost-vdpa.c +1
-0@@ -627,6 +627,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)uint64_t qemu_backend_features =0x1ULL <<VHOST_BACKEND_F_IOTLB_MSG_V2 |0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH |0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID | +0x1ULL <<VHOST_BACKEND_F_DESC_ASID |0x1ULL <<VHOST_BACKEND_F_SUSPEND ;int ret;
hw/virtio/vhost-vdpa.c static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) · line 1255
Quoted 7 lines
hw/virtio/vhost-vdpa.c +3
-1@@ -1249,7 +1250,9 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) goto err; } -vhost_svq_start (svq, dev->vdev, vq, v->shared->iova_tree); +vhost_svq_start (svq, dev->vdev, vq, + v->desc_group >=0 && v->address_space_id ? +NULL : v->shared->iova_tree);
Nit: it might be a little bit more clear if we use a helper to check like vhost_svq_needs _iova_tree()
Quoted 24 lines
hw/virtio/vhost-vdpa.c +0
-0ok =vhost_vdpa_svq_map_rings (dev, svq, &addr, &err);if (unlikely (!ok)) { goto err_map;net/vhost-vdpa.c +9
-0@@ -366,20 +366,50 @@ static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v,static void vhost_vdpa_net_data_start_first (VhostVDPAState *s) {struct vhost_vdpa *v = &s->vhost_vdpa; +int r;migration_add_notifier (&s->migration_state, vdpa_net_migration_state_notifier); +if (!v->shadow_vqs_enabled) { +if (v->desc_group >=0 && + v->address_space_id !=VHOST_VDPA_GUEST_PA_ASID ) { +vhost_vdpa_set_address_space_id (v, v->desc_group, +VHOST_VDPA_GUEST_PA_ASID ); + s->vhost_vdpa.address_space_id =VHOST_VDPA_GUEST_PA_ASID ; + } +return ;
net/vhost-vdpa.c static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, · line 390
Quoted 10 lines
net/vhost-vdpa.c +5
-1+ } +/* iova_tree may be initialized by vhost_vdpa_net_load_setup */ -if (v->shadow_vqs_enabled && !v->shared->iova_tree) { +if (!v->shared->iova_tree) { v->shared->iova_tree =vhost_iova_tree_new (v->shared->iova_range.first, v->shared->iova_range.last); } + +if (s->always_svq || v->desc_group <0 ) {
I think the always_svq mode deserves a TODO there since it can utilize the desc_group actually?
net/vhost-vdpa.c static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, · line 395
Quoted 5 lines
net/vhost-vdpa.c +5
-0+return ; + } + + r =vhost_vdpa_set_address_space_id (v, v->desc_group, +VHOST_VDPA_NET_CVQ_ASID );
Any reason why we only set the descriptor group for the first nc?
(This seems implies the device has one descriptor group for all virtqueue which might not be true)
Quoted 22 lines
net/vhost-vdpa.c +12
-0+if (unlikely (r <0 )) { +/* The other data vqs should also fall back to using the same ASID */ + s->vhost_vdpa.address_space_id =VHOST_VDPA_GUEST_PA_ASID ; +return ; + } + +/* No translation needed on data SVQ when descriptor group is used */ + s->vhost_vdpa.address_space_id =VHOST_VDPA_NET_CVQ_ASID ; + s->vhost_vdpa.shared->shadow_data = false; +return ; }static int vhost_vdpa_net_data_start (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +VhostVDPAState *s0 =vhost_vdpa_net_first_nc_vdpa (s); +struct vhost_vdpa *v = &s->vhost_vdpa;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );@@ -397,6 +427,18 @@ static int vhost_vdpa_net_data_start(NetClientState *nc)return 0 ;
net/vhost-vdpa.c static int vhost_vdpa_net_data_start(NetClientState *nc) · line 437
Quoted 10 lines
net/vhost-vdpa.c +8
-0} +if (v->desc_group >=0 && v->desc_group != s0->vhost_vdpa.desc_group) { +unsigned asid; + asid = v->shadow_vqs_enabled ? + s0->vhost_vdpa.address_space_id :VHOST_VDPA_GUEST_PA_ASID ; +if (asid != s->vhost_vdpa.address_space_id) { +vhost_vdpa_set_address_space_id (v, v->desc_group, asid); + } + s->vhost_vdpa.address_space_id = asid;
Can we unify the logic for nc0 and others here?
Then we don't need the trick in start_fisrt().
Quoted 8 lines
net/vhost-vdpa.c +4
-0+ }else { + s->vhost_vdpa.address_space_id = s0->vhost_vdpa.address_space_id; + } +return 0 ; }
net/vhost-vdpa.c static int vhost_vdpa_net_cvq_start(NetClientState *nc) · line 650
Quoted 7 lines
net/vhost-vdpa.c +3
-1@@ -603,13 +645,19 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc)return 0 ; } -if (!s->cvq_isolated) { +if (!s->cvq_isolated && v->desc_group <0 ) { + if (s0->vhost_vdpa.shadow_vqs_enabled && + s0->vhost_vdpa.desc_group >= 0 &&
I think we should fail if v->desc_group < 0 but s0->vhost_vdpa.desc_group >= 0 ?
net/vhost-vdpa.c static int vhost_vdpa_net_cvq_start(NetClientState *nc) · line 651
Quoted 1 line
net/vhost-vdpa.c +1
-0+ s0->vhost_vdpa.address_space_id) {
If this is a check for VHOST_VDPA_GUEST_PA_ASID, let's explicitly check it against the macro here.
But it's not clear to me the logic here:
It looks to me like the code tries to work when CVQ is not isolated, is this intended? This makes the logic rather complicated here.
Thanks
Quoted 25 lines
net/vhost-vdpa.c +6
-3+ v->shadow_vqs_enabled = false; + }return 0 ; } - cvq_group =vhost_vdpa_get_vring_group (v->shared->device_fd, + cvq_group = s->cvq_isolated ? +vhost_vdpa_get_vring_group (v->shared->device_fd, v->dev->vq_index_end -1 , - &err); + &err) : v->desc_group;if (unlikely (cvq_group <0 )) {error_report_err (err);return cvq_group;@@ -1840,6 +1888,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->always_svq = svq; s->migration_state.notify =NULL ; s->vhost_vdpa.shadow_vqs_enabled = svq; + s->vhost_vdpa.address_space_id =VHOST_VDPA_GUEST_PA_ASID ;if (queue_pair_index ==0 ) {vhost_vdpa_net_valid_svq_features (features, &s->vhost_vdpa.migration_blocker); --1.8.3.1
PATCH 11/40 vdpa: factor out vhost_vdpa_last_dev
In reply to Si-Wei LiuGeneralize duplicated condition check for the last vq of vdpa device to a common function.
--- hw/virtio/vhost-vdpa.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
hw/virtio/vhost-vdpa.c +7 -2
@@ -593,6 +593,11 @@ static bool vhost_vdpa_first_dev(struct vhost_dev *dev)return v->index ==0 ; } +static bool vhost_vdpa_last_dev (struct vhost_dev *dev) +{ +return dev->vq_index + dev->nvqs == dev->vq_index_end; +} +static int vhost_vdpa_get_dev_features (struct vhost_dev *dev,uint64_t *features) {
@@ -1432,7 +1437,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) goto out_stop; } -if (dev->vq_index + dev->nvqs != dev->vq_index_end) { +if (!vhost_vdpa_last_dev (dev)) {return 0 ; }
@@ -1467,7 +1472,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -if (dev->vq_index + dev->nvqs != dev->vq_index_end) { +if (!vhost_vdpa_last_dev (dev)) {return ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 11/40] vdpa: factor out vhost_vdpa_last_dev
Quoted 5 lines · Si-Wei Liu
Generalize duplicated condition check for the last vq of vdpa device to a common function.
Signed-off-by Si-Wei Liu <[email protected]>
We can also send this separately,
Quoted 41 lines
--- hw/virtio/vhost-vdpa.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)hw/virtio/vhost-vdpa.c +7
-3@@ -593,6 +593,11 @@ static bool vhost_vdpa_first_dev(struct vhost_dev *dev)return v->index ==0 ; } +static bool vhost_vdpa_last_dev (struct vhost_dev *dev) +{ +return dev->vq_index + dev->nvqs == dev->vq_index_end; +} +static int vhost_vdpa_get_dev_features (struct vhost_dev *dev,uint64_t *features) {@@ -1432,7 +1437,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) goto out_stop; } -if (dev->vq_index + dev->nvqs != dev->vq_index_end) { +if (!vhost_vdpa_last_dev (dev)) {return 0 ; }@@ -1467,7 +1472,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -if (dev->vq_index + dev->nvqs != dev->vq_index_end) { +if (!vhost_vdpa_last_dev (dev)) {return ; } --1.8.3.1
Re: [PATCH 11/40] vdpa: factor out vhost_vdpa_last_dev
In reply to Si-Wei LiuQuoted 5 lines · Si-Wei Liu
Generalize duplicated condition check for the last vq of vdpa device to a common function.
Signed-off-by Si-Wei Liu <[email protected]>
Thanks
Quoted 41 lines
--- hw/virtio/vhost-vdpa.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)hw/virtio/vhost-vdpa.c +7
-3@@ -593,6 +593,11 @@ static bool vhost_vdpa_first_dev(struct vhost_dev *dev)return v->index ==0 ; } +static bool vhost_vdpa_last_dev (struct vhost_dev *dev) +{ +return dev->vq_index + dev->nvqs == dev->vq_index_end; +} +static int vhost_vdpa_get_dev_features (struct vhost_dev *dev,uint64_t *features) {@@ -1432,7 +1437,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) goto out_stop; } -if (dev->vq_index + dev->nvqs != dev->vq_index_end) { +if (!vhost_vdpa_last_dev (dev)) {return 0 ; }@@ -1467,7 +1472,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -if (dev->vq_index + dev->nvqs != dev->vq_index_end) { +if (!vhost_vdpa_last_dev (dev)) {return ; } --1.8.3.1
PATCH 12/40 vdpa: check map_thread_enabled before join maps thread
In reply to Si-Wei LiuThe next patches will also register memory listener on demand, hence the need to differentiate the map_thread case from the rest.
--- hw/virtio/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +1 -1
@@ -1450,7 +1450,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)if (!v->shared->listener_registered) {memory_listener_register (&v->shared->listener, dev->vdev->dma_as); v->shared->listener_registered = true; - }else { + }else if (v->shared->map_thread_enabled) { ok =vhost_vdpa_join_maps_thread (v->shared);if (unlikely (!ok)) { goto out_stop;
Signature · 1 line
1.8.3.1
PATCH 13/40 vdpa: ref counting VhostVDPAShared
In reply to Si-Wei LiuSubsequent patches attempt to release VhostVDPAShared resources, for example iova tree to free and memory listener to unregister, in vdpa_dev_cleanup(). Instead of checking against the vq index, which is not always available in all of the callers, counting the usage by reference. Then it'll be easy to free resource upon the last deref.
--- include/hw/virtio/vhost-vdpa.h | 2 ++ net/vhost-vdpa.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-)
include/hw/virtio/vhost-vdpa.h +2 -0
@@ -70,6 +70,8 @@ typedef struct vhost_vdpa_shared {/* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */ bool shadow_data; + +unsigned refcnt; } VhostVDPAShared; typedef struct vhost_vdpa {
net/vhost-vdpa.c +10 -4
@@ -236,11 +236,11 @@ static void vhost_vdpa_cleanup(NetClientState *nc)g_free (s->vhost_net); s->vhost_net =NULL ; } -if (s->vhost_vdpa.index !=0 ) { -return ; +if (--s->vhost_vdpa.shared->refcnt ==0 ) { +qemu_close (s->vhost_vdpa.shared->device_fd); +g_free (s->vhost_vdpa.shared); } -qemu_close (s->vhost_vdpa.shared->device_fd); -g_free (s->vhost_vdpa.shared); + s->vhost_vdpa.shared =NULL ; }/** Dummy SetSteeringEBPF to support RSS for vhost-vdpa backend */
@@ -1896,6 +1896,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shared->device_fd = vdpa_device_fd; s->vhost_vdpa.shared->iova_range = iova_range; s->vhost_vdpa.shared->shadow_data = svq; + s->vhost_vdpa.shared->refcnt++; }else if (!is_datapath) { s->cvq_cmd_out_buffer = mmap(NULL, vhost_vdpa_net_cvq_cmd_page_len(), PROT_READ | PROT_WRITE,
@@ -1910,6 +1911,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, }if (queue_pair_index !=0 ) { s->vhost_vdpa.shared = shared; + s->vhost_vdpa.shared->refcnt++; } ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);
@@ -1928,6 +1930,10 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,return nc; err: +if (--s->vhost_vdpa.shared->refcnt ==0 ) { +g_free (s->vhost_vdpa.shared); + } + s->vhost_vdpa.shared =NULL ;qemu_del_net_client (nc);return NULL ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 13/40] vdpa: ref counting VhostVDPAShared
Quoted 32 lines · Si-Wei Liu
Subsequent patches attempt to release VhostVDPAShared resources, for example iova tree to free and memory listener to unregister, in
vdpa_dev_cleanup(). Instead of checking against the vq index, which is not always available in all of the callers, counting the usage by reference. Then it'll be easy to free resource upon the last deref.Signed-off-by Si-Wei Liu <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 2 ++ net/vhost-vdpa.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-)include/hw/virtio/vhost-vdpa.h +2
-0@@ -70,6 +70,8 @@ typedef struct vhost_vdpa_shared {/* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */ bool shadow_data; + +unsigned refcnt; } VhostVDPAShared; typedef struct vhost_vdpa {net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c static void vhost_vdpa_cleanup(NetClientState *nc) · line 242
Quoted 9 lines
net/vhost-vdpa.c +3
-2@@ -236,11 +236,11 @@ static void vhost_vdpa_cleanup(NetClientState *nc)g_free (s->vhost_net); s->vhost_net =NULL ; } -if (s->vhost_vdpa.index !=0 ) { -return ; +if (--s->vhost_vdpa.shared->refcnt ==0 ) { +qemu_close (s->vhost_vdpa.shared->device_fd); +g_free (s->vhost_vdpa.shared); }
I'd suggest having a get and put helper, then we can check and do cleanup in the put when refcnt is zero.
Thanks
Quoted 36 lines
net/vhost-vdpa.c +7
-3-qemu_close (s->vhost_vdpa.shared->device_fd); -g_free (s->vhost_vdpa.shared); + s->vhost_vdpa.shared =NULL ; }/** Dummy SetSteeringEBPF to support RSS for vhost-vdpa backend */ @@ -1896,6 +1896,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shared->device_fd = vdpa_device_fd; s->vhost_vdpa.shared->iova_range = iova_range; s->vhost_vdpa.shared->shadow_data = svq; + s->vhost_vdpa.shared->refcnt++; }else if (!is_datapath) { s->cvq_cmd_out_buffer = mmap(NULL, vhost_vdpa_net_cvq_cmd_page_len(), PROT_READ | PROT_WRITE,@@ -1910,6 +1911,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, }if (queue_pair_index !=0 ) { s->vhost_vdpa.shared = shared; + s->vhost_vdpa.shared->refcnt++; } ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);@@ -1928,6 +1930,10 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,return nc; err: +if (--s->vhost_vdpa.shared->refcnt ==0 ) { +g_free (s->vhost_vdpa.shared); + } + s->vhost_vdpa.shared =NULL ;qemu_del_net_client (nc);return NULL ; } --1.8.3.1
PATCH 14/40 vdpa: convert iova_tree to ref count based
In reply to Si-Wei LiuSo that it can be freed from vhost_vdpa_cleanup on the last deref. The next few patches will try to make iova tree life cycle not depend on memory listener, and there's possiblity to keep iova tree around when memory mapping is not changed across device reset.
--- net/vhost-vdpa.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
net/vhost-vdpa.c +2 -7
@@ -238,6 +238,8 @@ static void vhost_vdpa_cleanup(NetClientState *nc) }if (--s->vhost_vdpa.shared->refcnt ==0 ) {qemu_close (s->vhost_vdpa.shared->device_fd); +g_clear_pointer (&s->vhost_vdpa.shared->iova_tree, + vhost_iova_tree_delete);g_free (s->vhost_vdpa.shared); } s->vhost_vdpa.shared =NULL ;
@@ -461,19 +463,12 @@ static int vhost_vdpa_net_data_load(NetClientState *nc)static void vhost_vdpa_net_client_stop (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); -struct vhost_dev *dev;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );if (s->vhost_vdpa.index ==0 ) {migration_remove_notifier (&s->migration_state); } - - dev = s->vhost_vdpa.dev; -if (dev->vq_index + dev->nvqs == dev->vq_index_end) { -g_clear_pointer (&s->vhost_vdpa.shared->iova_tree, - vhost_iova_tree_delete); - } }static int vhost_vdpa_net_load_setup (NetClientState *nc,NICState *nic)
Signature · 1 line
1.8.3.1
Re: [PATCH 14/40] vdpa: convert iova_tree to ref count based
Quoted 8 lines · Si-Wei Liu
So that it can be freed from
vhost_vdpa_cleanupon the last deref. The next few patches will try to make iova tree life cycle not depend on memory listener, and there's possiblity to keep iova tree around when memory mapping is not changed across device reset.
Title and commit description does not match with the patch, I guess it is because the reference count was at iova_tree some time in the past but you decided to move to VhostVDPAShared.
But this code should be merged with previous patches, because we have an asymmetry here and some bug will arise if the guest reset the
device: allocating at device start, but freeing at cleanup instead of stop.
Quoted 41 lines
Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)net/vhost-vdpa.c +2
-8@@ -238,6 +238,8 @@ static void vhost_vdpa_cleanup(NetClientState *nc) }if (--s->vhost_vdpa.shared->refcnt ==0 ) {qemu_close (s->vhost_vdpa.shared->device_fd); +g_clear_pointer (&s->vhost_vdpa.shared->iova_tree, + vhost_iova_tree_delete);g_free (s->vhost_vdpa.shared); } s->vhost_vdpa.shared =NULL ;@@ -461,19 +463,12 @@ static int vhost_vdpa_net_data_load(NetClientState *nc)static void vhost_vdpa_net_client_stop (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); -struct vhost_dev *dev;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );if (s->vhost_vdpa.index ==0 ) {migration_remove_notifier (&s->migration_state); } - - dev = s->vhost_vdpa.dev; -if (dev->vq_index + dev->nvqs == dev->vq_index_end) { -g_clear_pointer (&s->vhost_vdpa.shared->iova_tree, - vhost_iova_tree_delete); - } }static int vhost_vdpa_net_load_setup (NetClientState *nc,NICState *nic) --1.8.3.1
Re: [PATCH 14/40] vdpa: convert iova_tree to ref count based
In reply to Si-Wei LiuQuoted 18 lines · Si-Wei Liu
So that it can be freed from
vhost_vdpa_cleanupon the last deref. The next few patches will try to make iova tree life cycle not depend on memory listener, and there's possiblity to keep iova tree around when memory mapping is not changed across device reset.Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c static void vhost_vdpa_cleanup(NetClientState *nc) · line 242
Quoted 5 lines
net/vhost-vdpa.c +2
-0@@ -238,6 +238,8 @@ static void vhost_vdpa_cleanup(NetClientState *nc) }if (--s->vhost_vdpa.shared->refcnt ==0 ) {qemu_close (s->vhost_vdpa.shared->device_fd); +g_clear_pointer (&s->vhost_vdpa.shared->iova_tree, + vhost_iova_tree_delete);
Could be part of the put() as well.
Thanks
Quoted 26 lines
net/vhost-vdpa.c +0
-8g_free (s->vhost_vdpa.shared); } s->vhost_vdpa.shared =NULL ;@@ -461,19 +463,12 @@ static int vhost_vdpa_net_data_load(NetClientState *nc)static void vhost_vdpa_net_client_stop (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); -struct vhost_dev *dev;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );if (s->vhost_vdpa.index ==0 ) {migration_remove_notifier (&s->migration_state); } - - dev = s->vhost_vdpa.dev; -if (dev->vq_index + dev->nvqs == dev->vq_index_end) { -g_clear_pointer (&s->vhost_vdpa.shared->iova_tree, - vhost_iova_tree_delete); - } }static int vhost_vdpa_net_load_setup (NetClientState *nc,NICState *nic) --1.8.3.1
PATCH 15/40 vdpa: add svq_switching and flush_map to header
In reply to Si-Wei LiuWill be used in next patches.
--- include/hw/virtio/vhost-vdpa.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/hw/virtio/vhost-vdpa.h +6 -0
@@ -72,6 +72,12 @@ typedef struct vhost_vdpa_shared {bool shadow_data;unsigned refcnt; + +/* SVQ switching is in progress? 1: turn on SVQ, -1: turn off SVQ */ +int svq_switching; + +/* Flush mappings on reset due to shared address space */ +bool flush_map; } VhostVDPAShared; typedef struct vhost_vdpa {
Signature · 1 line
1.8.3.1
Re: [PATCH 15/40] vdpa: add svq_switching and flush_map to header
Quoted 13 lines · Si-Wei Liu
Will be used in next patches.
Signed-off-by Si-Wei Liu <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 6 ++++++ 1 file changed, 6 insertions(+)include/hw/virtio/vhost-vdpa.h +0
-0
include/hw/virtio/vhost-vdpa.h typedef struct vhost_vdpa_shared { · line 77
Quoted 6 lines
include/hw/virtio/vhost-vdpa.h +3
-0@@ -72,6 +72,12 @@ typedef struct vhost_vdpa_shared {bool shadow_data;unsigned refcnt; + +/* SVQ switching is in progress? 1: turn on SVQ, -1: turn off SVQ */ +int svq_switching;
Nit: just curious about any reason why 0, 1 or true false is not used?
Thanks
Quoted 9 lines
include/hw/virtio/vhost-vdpa.h +3
-1+ +/* Flush mappings on reset due to shared address space */ +bool flush_map; } VhostVDPAShared; typedef struct vhost_vdpa { --1.8.3.1
PATCH 16/40 vdpa: indicate SVQ switching via flag
In reply to Si-Wei Liusvq_switching indicates the case where SVQ mode change is on going. Positive (1) means switching from the normal passthrough mode to SVQ mode, and negative (-1) meaning switch SVQ back to the passthrough; zero (0) indicates that there's no SVQ mode switch taking place.
--- net/vhost-vdpa.c | 2 ++ 1 file changed, 2 insertions(+)
net/vhost-vdpa.c +2 -0
@@ -320,6 +320,7 @@ static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enable) data_queue_pairs = n->multiqueue ? n->max_queue_pairs :1 ; cvq =virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ ) ? n->max_ncs - n->max_queue_pairs :0 ; + v->shared->svq_switching = enable ?1 :-1 ;/* * TODO: vhost_net_stop does suspend, get_base and reset. We can be smarter * in the future and resume the device if read-only operations between
@@ -332,6 +333,7 @@ static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enable)if (unlikely (r <0 )) {error_report ("unable to start vhost net: %s(%d)" ,g_strerror (-r), -r); } + v->shared->svq_switching =0 ; }static void vdpa_net_migration_state_notifier (Notifier *notifier,void *data)
Signature · 1 line
1.8.3.1
Re: [PATCH 16/40] vdpa: indicate SVQ switching via flag
Quoted 6 lines · Si-Wei Liu
svq_switchingindicates the case where SVQ mode change is on going. Positive (1) means switching from the normal passthrough mode to SVQ mode, and negative (-1) meaning switch SVQ back to the passthrough; zero (0) indicates that there's no SVQ mode switch taking place.
Ok, so the previous patch forgot to describe the zero(0).
And it looks to me we'd better use enum instead of the magic number here.
Thanks
Quoted 29 lines
Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 2 ++ 1 file changed, 2 insertions(+)net/vhost-vdpa.c +2
-1@@ -320,6 +320,7 @@ static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enable) data_queue_pairs = n->multiqueue ? n->max_queue_pairs :1 ; cvq =virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ ) ? n->max_ncs - n->max_queue_pairs :0 ; + v->shared->svq_switching = enable ?1 :-1 ;/* * TODO: vhost_net_stop does suspend, get_base and reset. We can be smarter * in the future and resume the device if read-only operations between @@ -332,6 +333,7 @@ static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enable)if (unlikely (r <0 )) {error_report ("unable to start vhost net: %s(%d)" ,g_strerror (-r), -r); } + v->shared->svq_switching =0 ; }static void vdpa_net_migration_state_notifier (Notifier *notifier,void *data) --1.8.3.1
PATCH 17/40 vdpa: judge if map can be kept across reset
In reply to Si-Wei LiuThe descriptor group for SVQ ASID allows the guest memory mapping to retain across SVQ switching, same as how isolated CVQ can do with a different ASID than the guest GPA space. Introduce an evaluation function to judge whether to flush or keep iotlb maps based on virtqueue's descriptor group and cvq isolation capability.
Have to hook the evaluation function to NetClient's .poll op as .vhost_reset_status runs ahead of .stop, and .vhost_dev_start don't have access to the vhost-vdpa net's information.
--- net/vhost-vdpa.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
net/vhost-vdpa.c +40 -0
@@ -504,12 +504,36 @@ static int vhost_vdpa_net_load_cleanup(NetClientState *nc, NICState *nic) n->parent_obj.status & VIRTIO_CONFIG_S_DRIVER_OK); } +static void vhost_vdpa_net_data_eval_flush (NetClientState *nc,bool stop) +{ +VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; + +if (!stop) { +return ; + } + +if (s->vhost_vdpa.index ==0 ) { +if (s->always_svq) { + v->shared->flush_map = true; + }else if (!v->shared->svq_switching || v->desc_group >=0 ) { + v->shared->flush_map = false; + }else { + v->shared->flush_map = true; + } + }else if (!s->always_svq && v->shared->svq_switching && + v->desc_group <0 ) { + v->shared->flush_map = true; + } +} +static NetClientInfo net_vhost_vdpa_info = { .type =NET_CLIENT_DRIVER_VHOST_VDPA , .size =sizeof (VhostVDPAState), .receive = vhost_vdpa_receive, .start = vhost_vdpa_net_data_start, .load = vhost_vdpa_net_data_load, + .poll = vhost_vdpa_net_data_eval_flush, .stop = vhost_vdpa_net_client_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
@@ -1368,12 +1392,28 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)return 0 ; } +static void vhost_vdpa_net_cvq_eval_flush (NetClientState *nc,bool stop) +{ +VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; + +if (!stop) { +return ; + } + +if (!v->shared->flush_map && !v->shared->svq_switching && + !s->cvq_isolated && v->desc_group <0 ) { + v->shared->flush_map = true; + } +} +static NetClientInfo net_vhost_vdpa_cvq_info = { .type =NET_CLIENT_DRIVER_VHOST_VDPA , .size =sizeof (VhostVDPAState), .receive = vhost_vdpa_receive, .start = vhost_vdpa_net_cvq_start, .load = vhost_vdpa_net_cvq_load, + .poll = vhost_vdpa_net_cvq_eval_flush, .stop = vhost_vdpa_net_cvq_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
Signature · 1 line
1.8.3.1
Re: [PATCH 17/40] vdpa: judge if map can be kept across reset
Quoted 26 lines · Si-Wei Liu
The descriptor group for SVQ ASID allows the guest memory mapping to retain across SVQ switching, same as how isolated CVQ can do with a different ASID than the guest GPA space. Introduce an evaluation function to judge whether to flush or keep iotlb maps based on virtqueue's descriptor group and cvq isolation capability.
Have to hook the evaluation function to NetClient's .poll op as .vhost_reset_status runs ahead of .stop, and .vhost_dev_start don't have access to the vhost-vdpa net's information.
Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)net/vhost-vdpa.c +2
-0@@ -504,12 +504,36 @@ static int vhost_vdpa_net_load_cleanup(NetClientState *nc, NICState *nic) n->parent_obj.status & VIRTIO_CONFIG_S_DRIVER_OK); } +static void vhost_vdpa_net_data_eval_flush (NetClientState *nc,bool stop) +{
net/vhost-vdpa.c static int vhost_vdpa_net_load_cleanup(NetClientState *nc, NICState *nic) · line 518
Quoted 10 lines
net/vhost-vdpa.c +10
-0+VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; + +if (!stop) { +return ; + } + +if (s->vhost_vdpa.index ==0 ) { +if (s->always_svq) { + v->shared->flush_map = true;
Why do we need to reset the map in the case of always_svq?
net/vhost-vdpa.c static int vhost_vdpa_net_load_cleanup(NetClientState *nc, NICState *nic) · line 529
Quoted 11 lines
net/vhost-vdpa.c +11
-0+ }else if (!v->shared->svq_switching || v->desc_group >=0 ) { + v->shared->flush_map = false; + }else { + v->shared->flush_map = true; + } + }else if (!s->always_svq && v->shared->svq_switching && + v->desc_group <0 ) { + v->shared->flush_map = true; + } +} +
I'm wondering, since we have the reference count for the memory listener already, why not adding one refcnt if _start detect it can keep the memory maps?
Quoted 42 lines
net/vhost-vdpa.c +17
-1static NetClientInfo net_vhost_vdpa_info = { .type =NET_CLIENT_DRIVER_VHOST_VDPA , .size =sizeof (VhostVDPAState), .receive = vhost_vdpa_receive, .start = vhost_vdpa_net_data_start, .load = vhost_vdpa_net_data_load, + .poll = vhost_vdpa_net_data_eval_flush, .stop = vhost_vdpa_net_client_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,@@ -1368,12 +1392,28 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)return 0 ; } +static void vhost_vdpa_net_cvq_eval_flush (NetClientState *nc,bool stop) +{ +VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; + +if (!stop) { +return ; + } + +if (!v->shared->flush_map && !v->shared->svq_switching && + !s->cvq_isolated && v->desc_group <0 ) { + v->shared->flush_map = true; + } +} +static NetClientInfo net_vhost_vdpa_cvq_info = { .type =NET_CLIENT_DRIVER_VHOST_VDPA , .size =sizeof (VhostVDPAState), .receive = vhost_vdpa_receive, .start = vhost_vdpa_net_cvq_start, .load = vhost_vdpa_net_cvq_load, + .poll = vhost_vdpa_net_cvq_eval_flush, .stop = vhost_vdpa_net_cvq_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, --1.8.3.1
Re: [PATCH 17/40] vdpa: judge if map can be kept across reset
In reply to Si-Wei LiuQuoted 6 lines · Si-Wei Liu
The descriptor group for SVQ ASID allows the guest memory mapping to retain across SVQ switching, same as how isolated CVQ can do with a different ASID than the guest GPA space. Introduce an evaluation function to judge whether to flush or keep iotlb maps based on virtqueue's descriptor group and cvq isolation capability.
I may miss something, but is there any reason we can't judge during initialization?
We know the device capability so it should not depend on any runtime configuration.
Thanks
Quoted 83 lines
Have to hook the evaluation function to NetClient's .poll op as .vhost_reset_status runs ahead of .stop, and .vhost_dev_start don't have access to the vhost-vdpa net's information.
Signed-off-by Si-Wei Liu <[email protected]>--- net/vhost-vdpa.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)net/vhost-vdpa.c +40
-1@@ -504,12 +504,36 @@ static int vhost_vdpa_net_load_cleanup(NetClientState *nc, NICState *nic) n->parent_obj.status & VIRTIO_CONFIG_S_DRIVER_OK); } +static void vhost_vdpa_net_data_eval_flush (NetClientState *nc,bool stop) +{ +VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; + +if (!stop) { +return ; + } + +if (s->vhost_vdpa.index ==0 ) { +if (s->always_svq) { + v->shared->flush_map = true; + }else if (!v->shared->svq_switching || v->desc_group >=0 ) { + v->shared->flush_map = false; + }else { + v->shared->flush_map = true; + } + }else if (!s->always_svq && v->shared->svq_switching && + v->desc_group <0 ) { + v->shared->flush_map = true; + } +} +static NetClientInfo net_vhost_vdpa_info = { .type =NET_CLIENT_DRIVER_VHOST_VDPA , .size =sizeof (VhostVDPAState), .receive = vhost_vdpa_receive, .start = vhost_vdpa_net_data_start, .load = vhost_vdpa_net_data_load, + .poll = vhost_vdpa_net_data_eval_flush, .stop = vhost_vdpa_net_client_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,@@ -1368,12 +1392,28 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)return 0 ; } +static void vhost_vdpa_net_cvq_eval_flush (NetClientState *nc,bool stop) +{ +VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; + +if (!stop) { +return ; + } + +if (!v->shared->flush_map && !v->shared->svq_switching && + !s->cvq_isolated && v->desc_group <0 ) { + v->shared->flush_map = true; + } +} +static NetClientInfo net_vhost_vdpa_cvq_info = { .type =NET_CLIENT_DRIVER_VHOST_VDPA , .size =sizeof (VhostVDPAState), .receive = vhost_vdpa_receive, .start = vhost_vdpa_net_cvq_start, .load = vhost_vdpa_net_cvq_load, + .poll = vhost_vdpa_net_cvq_eval_flush, .stop = vhost_vdpa_net_cvq_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, --1.8.3.1
PATCH 18/40 vdpa: unregister listener on last dev cleanup
In reply to Si-Wei LiuSo that the free of iova tree struct can be safely deferred to until the last vq referencing it goes away.
--- hw/virtio/vhost-vdpa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +4 -1
@@ -815,7 +815,10 @@ static int vhost_vdpa_cleanup(struct vhost_dev *dev) }vhost_vdpa_host_notifiers_uninit (dev, dev->nvqs); -memory_listener_unregister (&v->shared->listener); +if (vhost_vdpa_last_dev (dev) && v->shared->listener_registered) { +memory_listener_unregister (&v->shared->listener); + v->shared->listener_registered = false; + }vhost_vdpa_svq_cleanup (dev); dev->opaque =NULL ;
Signature · 1 line
1.8.3.1
Re: [PATCH 18/40] vdpa: unregister listener on last dev cleanup
Quoted 4 lines · Si-Wei Liu
So that the free of iova tree struct can be safely deferred to until the last vq referencing it goes away.
I think this patch message went out of sync too.
Quoted 10 lines
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)hw/virtio/vhost-vdpa.c +0
-0
hw/virtio/vhost-vdpa.c static int vhost_vdpa_cleanup(struct vhost_dev *dev) · line 821
Quoted 8 lines
hw/virtio/vhost-vdpa.c +4
-1@@ -815,7 +815,10 @@ static int vhost_vdpa_cleanup(struct vhost_dev *dev) }vhost_vdpa_host_notifiers_uninit (dev, dev->nvqs); -memory_listener_unregister (&v->shared->listener); +if (vhost_vdpa_last_dev (dev) && v->shared->listener_registered) { +memory_listener_unregister (&v->shared->listener); + v->shared->listener_registered = false; + }
I think this version is more correct, but it should not matter as the device cleanup implies the device will not be used anymore, isn't it? Or am I missing something?
Quoted 6 lines
hw/virtio/vhost-vdpa.c +0
-1vhost_vdpa_svq_cleanup (dev); dev->opaque =NULL ; --1.8.3.1
Re: [PATCH 18/40] vdpa: unregister listener on last dev cleanup
In reply to Si-Wei LiuQuoted 14 lines · Si-Wei Liu
So that the free of iova tree struct can be safely deferred to until the last vq referencing it goes away.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)hw/virtio/vhost-vdpa.c +0
-0
hw/virtio/vhost-vdpa.c static int vhost_vdpa_cleanup(struct vhost_dev *dev) · line 821
Quoted 8 lines
hw/virtio/vhost-vdpa.c +4
-1@@ -815,7 +815,10 @@ static int vhost_vdpa_cleanup(struct vhost_dev *dev) }vhost_vdpa_host_notifiers_uninit (dev, dev->nvqs); -memory_listener_unregister (&v->shared->listener); +if (vhost_vdpa_last_dev (dev) && v->shared->listener_registered) { +memory_listener_unregister (&v->shared->listener); + v->shared->listener_registered = false; + }
Can we move this to the put() (refcnt decreasing helper) of shared?
Thanks
Quoted 6 lines
hw/virtio/vhost-vdpa.c +0
-1vhost_vdpa_svq_cleanup (dev); dev->opaque =NULL ; --1.8.3.1
PATCH 19/40 vdpa: should avoid map flushing with persistent iotlb
In reply to Si-Wei LiuToday memory listener is unregistered in vhost_vdpa_reset_status unconditionally, due to which all the maps will be flushed away from the iotlb. However, map flush is not always needed, and doing it from performance hot path may have innegligible latency impact that affects VM reboot time or brown out period during live migration.
Leverage the IOTLB_PERSIST backend featuae, which ensures durable iotlb maps and not disappearing even across reset. When it is supported, we may conditionally keep the maps for cases where the guest memory mapping doesn't change. Prepare a function so that the next patch will be able to use it to keep the maps.
--- hw/virtio/trace-events | 1 + hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)
hw/virtio/trace-events +1 -0
@@ -66,6 +66,7 @@ vhost_vdpa_set_owner(void *dev) "dev: %p" vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint64_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64 vhost_vdpa_get_iova_range(void *dev, uint64_t first, uint64_t last) "dev: %p first: 0x%"PRIx64" last: 0x%"PRIx64 vhost_vdpa_set_config_call(void *dev, int fd)"dev: %p fd: %d" +vhost_vdpa_maybe_flush_map(void *dev, bool reg, bool flush, bool persist) "dev: %p registered: %d flush_map: %d iotlb_persistent: %d" # virtio.c virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned out_num) "elem %p size %zd in_num %u out_num %u"
hw/virtio/vhost-vdpa.c +20 -0
@@ -1471,6 +1471,26 @@ out_stop:return ok ?0 :-1 ; } +static void vhost_vdpa_maybe_flush_map (struct vhost_dev *dev) +{ +struct vhost_vdpa *v = dev->opaque; + +trace_vhost_vdpa_maybe_flush_map (dev, v->shared->listener_registered, + v->shared->flush_map, + !!(dev->backend_cap & +BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST ))); + +if (!v->shared->listener_registered) { +return ; + } + +if (!(dev->backend_cap &BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST )) || + v->shared->flush_map) { +memory_listener_unregister (&v->shared->listener); + v->shared->listener_registered = false; + } +} +static void vhost_vdpa_reset_status (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque;
Signature · 1 line
1.8.3.1
Re: [PATCH 19/40] vdpa: should avoid map flushing with persistent iotlb
Quoted 37 lines · Si-Wei Liu
Today memory listener is unregistered in
vhost_vdpa_reset_statusunconditionally, due to which all the maps will be flushed away from the iotlb. However, map flush is not always needed, and doing it from performance hot path may have innegligible latency impact that affects VM reboot time or brown out period during live migration.Leverage the
IOTLB_PERSISTbackend featuae, which ensures durable iotlb maps and not disappearing even across reset. When it is supported, we may conditionally keep the maps for cases where the guest memory mapping doesn't change. Prepare a function so that the next patch will be able to use it to keep the maps.Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/trace-events | 1 + hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)hw/virtio/trace-events +1
-0@@ -66,6 +66,7 @@ vhost_vdpa_set_owner(void *dev) "dev: %p" vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint64_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64 vhost_vdpa_get_iova_range(void *dev, uint64_t first, uint64_t last) "dev: %p first: 0x%"PRIx64" last: 0x%"PRIx64 vhost_vdpa_set_config_call(void *dev, int fd)"dev: %p fd: %d" +vhost_vdpa_maybe_flush_map(void *dev, bool reg, bool flush, bool persist) "dev: %p registered: %d flush_map: %d iotlb_persistent: %d" # virtio.c virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned out_num) "elem %p size %zd in_num %u out_num %u"hw/virtio/vhost-vdpa.c +0
-0
hw/virtio/vhost-vdpa.c out_stop: · line 1474
Quoted 4 lines
hw/virtio/vhost-vdpa.c +1
-0@@ -1471,6 +1471,26 @@ out_stop:return ok ?0 :-1 ; } +static void vhost_vdpa_maybe_flush_map (struct vhost_dev *dev)
Nit: Not a native speaker, but it looks likevhost_vdpa_may_flush_map() is better.
Quoted 7 lines
hw/virtio/vhost-vdpa.c +7
-0+{ +struct vhost_vdpa *v = dev->opaque; + +trace_vhost_vdpa_maybe_flush_map (dev, v->shared->listener_registered, + v->shared->flush_map, + !!(dev->backend_cap & +BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST )));
hw/virtio/vhost-vdpa.c out_stop: · line 1491
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ +if (!v->shared->listener_registered) { +return ; + } + +if (!(dev->backend_cap &BIT_ULL (VHOST_BACKEND_F_IOTLB_PERSIST )) || + v->shared->flush_map) { +memory_listener_unregister (&v->shared->listener); + v->shared->listener_registered = false; + }
Others look good.
Thanks
Quoted 8 lines
hw/virtio/vhost-vdpa.c +2
-1+} +static void vhost_vdpa_reset_status (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; --1.8.3.1
PATCH 20/40 vdpa: avoid mapping flush across reset
In reply to Si-Wei LiuLeverage the IOTLB_PERSIST and DESC_ASID features to achieve a slightly light weight reset path, without resorting to suspend and resume. Not as best but it offers significant time saving too, which should somehow play its role in live migration down time reduction by large.
It benefits two cases:
- normal virtio reset in the VM, e.g. guest reboot, don't have to tear down all iotlb mapping and set up again.
- SVQ switching, in which data vq's descriptor table and vrings are moved to a different ASID than where its buffers reside. Along with the use of persistent iotlb, it would save substantial time from pinning and mapping unneccessarily when moving descriptors on to or out of shadow mode.
--- hw/virtio/vhost-vdpa.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/virtio/vhost-vdpa.c +2 -5
@@ -633,6 +633,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH |0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID |0x1ULL <<VHOST_BACKEND_F_DESC_ASID | +0x1ULL <<VHOST_BACKEND_F_IOTLB_PERSIST |0x1ULL <<VHOST_BACKEND_F_SUSPEND ;int ret;
@@ -1493,8 +1494,6 @@ static void vhost_vdpa_maybe_flush_map(struct vhost_dev *dev)static void vhost_vdpa_reset_status (struct vhost_dev *dev) { -struct vhost_vdpa *v = dev->opaque; -if (!vhost_vdpa_last_dev (dev)) {return ; }
@@ -1502,9 +1501,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev)vhost_vdpa_reset_device (dev);vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_ACKNOWLEDGE |VIRTIO_CONFIG_S_DRIVER ); -memory_listener_unregister (&v->shared->listener); - v->shared->listener_registered = false; - +vhost_vdpa_maybe_flush_map (dev); } static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base,
Signature · 1 line
1.8.3.1
Re: [PATCH 20/40] vdpa: avoid mapping flush across reset
Quoted 17 lines · Si-Wei Liu
Leverage the
IOTLB_PERSISTandDESC_ASIDfeatures to achieve a slightly light weight reset path, without resorting to suspend and resume. Not as best but it offers significant time saving too, which should somehow play its role in live migration down time reduction by large.It benefits two cases:
- normal virtio reset in the VM, e.g. guest reboot, don't have to tear down all iotlb mapping and set up again.
- SVQ switching, in which data vq's descriptor table and vrings are moved to a different ASID than where its buffers reside. Along with the use of persistent iotlb, it would save substantial time from pinning and mapping unneccessarily when moving descriptors on to or out of shadow mode.
Quoted 1 line
Signed-off-by Si-Wei Liu <[email protected]>
Looks good to me.
Thanks
Quoted 39 lines
--- hw/virtio/vhost-vdpa.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/virtio/vhost-vdpa.c +2
-6@@ -633,6 +633,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH |0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID |0x1ULL <<VHOST_BACKEND_F_DESC_ASID | +0x1ULL <<VHOST_BACKEND_F_IOTLB_PERSIST |0x1ULL <<VHOST_BACKEND_F_SUSPEND ;int ret;@@ -1493,8 +1494,6 @@ static void vhost_vdpa_maybe_flush_map(struct vhost_dev *dev)static void vhost_vdpa_reset_status (struct vhost_dev *dev) { -struct vhost_vdpa *v = dev->opaque; -if (!vhost_vdpa_last_dev (dev)) {return ; }@@ -1502,9 +1501,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev)vhost_vdpa_reset_device (dev);vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_ACKNOWLEDGE |VIRTIO_CONFIG_S_DRIVER ); -memory_listener_unregister (&v->shared->listener); - v->shared->listener_registered = false; - +vhost_vdpa_maybe_flush_map (dev); } static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, --1.8.3.1
PATCH 21/40 vdpa: vhost_vdpa_dma_batch_end_once rename
In reply to Si-Wei LiuNo functional changes. Rename only.
--- hw/virtio/vhost-vdpa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/virtio/vhost-vdpa.c +3 -3
@@ -191,7 +191,7 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) s->iotlb_batch_begin_sent = true; } -static void vhost_vdpa_dma_end_batch (VhostVDPAShared *s) +static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) {struct vhost_msg_v2 msg = {};int fd = s->device_fd;
@@ -229,7 +229,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener) {VhostVDPAShared *s =container_of (listener, VhostVDPAShared, listener); -vhost_vdpa_dma_end_batch (s); +vhost_vdpa_dma_batch_end_once (s); }static void vhost_vdpa_iommu_map_notify (IOMMUNotifier *n,IOMMUTLBEntry *iotlb)
@@ -1367,7 +1367,7 @@ static void *vhost_vdpa_load_map(void *opaque)vhost_vdpa_iotlb_batch_begin_once (shared);break ;case VHOST_IOTLB_BATCH_END : -vhost_vdpa_dma_end_batch (shared); +vhost_vdpa_dma_batch_end_once (shared);break ;default :error_report ("Invalid IOTLB msg type %d" , msg->iotlb.type);
Signature · 1 line
1.8.3.1
Re: [PATCH 21/40] vdpa: vhost_vdpa_dma_batch_end_once rename
Quoted 31 lines · Si-Wei Liu
No functional changes. Rename only.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/virtio/vhost-vdpa.c +2
-2@@ -191,7 +191,7 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) s->iotlb_batch_begin_sent = true; } -static void vhost_vdpa_dma_end_batch (VhostVDPAShared *s) +static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) {struct vhost_msg_v2 msg = {};int fd = s->device_fd;@@ -229,7 +229,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener) {VhostVDPAShared *s =container_of (listener, VhostVDPAShared, listener); -vhost_vdpa_dma_end_batch (s); +vhost_vdpa_dma_batch_end_once (s); }static void vhost_vdpa_iommu_map_notify (IOMMUNotifier *n,IOMMUTLBEntry *iotlb)
hw/virtio/vhost-vdpa.c static void *vhost_vdpa_load_map(void *opaque) · line 1370
Quoted 5 lines
hw/virtio/vhost-vdpa.c +1
-1@@ -1367,7 +1367,7 @@ static void *vhost_vdpa_load_map(void *opaque)vhost_vdpa_iotlb_batch_begin_once (shared);break ;case VHOST_IOTLB_BATCH_END : -vhost_vdpa_dma_end_batch (shared); +vhost_vdpa_dma_batch_end_once (shared);
It's better to explain why having a "_once" suffix is better here.
Thanks
Quoted 6 lines
hw/virtio/vhost-vdpa.c +0
-1break ;default :error_report ("Invalid IOTLB msg type %d" , msg->iotlb.type); --1.8.3.1
Re: [PATCH 21/40] vdpa: vhost_vdpa_dma_batch_end_once rename
Quoted 31 lines · Jason Wang
Quoted 29 lines · Si-Wei Liu
No functional changes. Rename only.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/virtio/vhost-vdpa.c +2
-2@@ -191,7 +191,7 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) s->iotlb_batch_begin_sent = true; } -static void vhost_vdpa_dma_end_batch (VhostVDPAShared *s) +static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) {struct vhost_msg_v2 msg = {};int fd = s->device_fd;@@ -229,7 +229,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener) {VhostVDPAShared *s =container_of (listener, VhostVDPAShared, listener); -vhost_vdpa_dma_end_batch (s); +vhost_vdpa_dma_batch_end_once (s); }
Quoted 9 lines
hw/virtio/vhost-vdpa.c static void *vhost_vdpa_load_map(void *opaque) · line 1370
Quoted 7 lines
hw/virtio/vhost-vdpa.c +1
-1static void vhost_vdpa_iommu_map_notify (IOMMUNotifier *n,IOMMUTLBEntry *iotlb)@@ -1367,7 +1367,7 @@ static void *vhost_vdpa_load_map(void *opaque)vhost_vdpa_iotlb_batch_begin_once (shared);break ;case VHOST_IOTLB_BATCH_END : -vhost_vdpa_dma_end_batch (shared); +vhost_vdpa_dma_batch_end_once (shared);It's better to explain why having a "
_once" suffix is better here.
Ok, if it's for symmetry for host_vdpa_iotlb_batch_begin_once(), I think it makes sense.
But it's better to document this in the change log.
Thanks
Quoted 9 lines
Thanks
Quoted 6 lines
hw/virtio/vhost-vdpa.c +0
-1break ;default :error_report ("Invalid IOTLB msg type %d" , msg->iotlb.type); --1.8.3.1
PATCH 22/40 vdpa: factor out vhost_vdpa_map_batch_begin
In reply to Si-Wei LiuRefactoring only. No functional change.
--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-)
hw/virtio/trace-events +1 -1
@@ -32,7 +32,7 @@ vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 -vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d"
hw/virtio/vhost-vdpa.c +16 -9
@@ -161,7 +161,7 @@ int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova,return ret; } -static void vhost_vdpa_iotlb_batch_begin_once (VhostVDPAShared *s) +static bool vhost_vdpa_map_batch_begin (VhostVDPAShared *s) {int fd = s->device_fd;struct vhost_msg_v2 msg = {
@@ -169,26 +169,33 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) .iotlb.type = VHOST_IOTLB_BATCH_BEGIN, }; -if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || - s->iotlb_batch_begin_sent) { -return ; - } -if (s->map_thread_enabled && !qemu_thread_is_self (&s->map_thread)) { struct vhost_msg_v2 *new_msg = g_new(struct vhost_msg_v2, 1); *new_msg = msg;g_async_queue_push (s->map_queue, new_msg); -return ; +return false; } -trace_vhost_vdpa_listener_begin_batch (s, fd, msg.type, msg.iotlb.type); +trace_vhost_vdpa_map_batch_begin (s, fd, msg.type, msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno)); } - s->iotlb_batch_begin_sent = true; +return true; +} + +static void vhost_vdpa_iotlb_batch_begin_once (VhostVDPAShared *s) +{ +if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || + s->iotlb_batch_begin_sent) { +return ; + } + +if (vhost_vdpa_map_batch_begin (s)) { + s->iotlb_batch_begin_sent = true; + } }static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s)
Signature · 1 line
1.8.3.1
Re: [PATCH 22/40] vdpa: factor out vhost_vdpa_map_batch_begin
Quoted 4 lines · Si-Wei Liu
Refactoring only. No functional change.
Signed-off-by Si-Wei Liu <[email protected]>
Thanks
Quoted 76 lines
--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-)hw/virtio/trace-events +1
-1@@ -32,7 +32,7 @@ vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 -vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d"hw/virtio/vhost-vdpa.c +16
-10@@ -161,7 +161,7 @@ int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova,return ret; } -static void vhost_vdpa_iotlb_batch_begin_once (VhostVDPAShared *s) +static bool vhost_vdpa_map_batch_begin (VhostVDPAShared *s) {int fd = s->device_fd;struct vhost_msg_v2 msg = {@@ -169,26 +169,33 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) .iotlb.type = VHOST_IOTLB_BATCH_BEGIN, }; -if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || - s->iotlb_batch_begin_sent) { -return ; - } -if (s->map_thread_enabled && !qemu_thread_is_self (&s->map_thread)) { struct vhost_msg_v2 *new_msg = g_new(struct vhost_msg_v2, 1); *new_msg = msg;g_async_queue_push (s->map_queue, new_msg); -return ; +return false; } -trace_vhost_vdpa_listener_begin_batch (s, fd, msg.type, msg.iotlb.type); +trace_vhost_vdpa_map_batch_begin (s, fd, msg.type, msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno)); } - s->iotlb_batch_begin_sent = true; +return true; +} + +static void vhost_vdpa_iotlb_batch_begin_once (VhostVDPAShared *s) +{ +if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || + s->iotlb_batch_begin_sent) { +return ; + } + +if (vhost_vdpa_map_batch_begin (s)) { + s->iotlb_batch_begin_sent = true; + } }static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) --1.8.3.1
PATCH 23/40 vdpa: vhost_vdpa_dma_batch_begin_once rename
In reply to Si-Wei LiuNo functional changes. Rename only.
--- hw/virtio/vhost-vdpa.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/virtio/vhost-vdpa.c +4 -4
@@ -186,7 +186,7 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s)return true; } -static void vhost_vdpa_iotlb_batch_begin_once (VhostVDPAShared *s) +static void vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || s->iotlb_batch_begin_sent) {
@@ -411,7 +411,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, iova = mem_region.iova; } -vhost_vdpa_iotlb_batch_begin_once (s); +vhost_vdpa_dma_batch_begin_once (s); ret =vhost_vdpa_dma_map (s,VHOST_VDPA_GUEST_PA_ASID , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {
@@ -493,7 +493,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, iova = result->iova;vhost_iova_tree_remove (s->iova_tree, *result); } -vhost_vdpa_iotlb_batch_begin_once (s); +vhost_vdpa_dma_batch_begin_once (s);/* * The unmap ioctl doesn't accept a full 64-bit. need to check it */
@@ -1371,7 +1371,7 @@ static void *vhost_vdpa_load_map(void *opaque) msg->iotlb.size);break ;case VHOST_IOTLB_BATCH_BEGIN : -vhost_vdpa_iotlb_batch_begin_once (shared); +vhost_vdpa_dma_batch_begin_once (shared);break ;case VHOST_IOTLB_BATCH_END :vhost_vdpa_dma_batch_end_once (shared);
Signature · 1 line
1.8.3.1
Re: [PATCH 23/40] vdpa: vhost_vdpa_dma_batch_begin_once rename
Quoted 40 lines · Si-Wei Liu
No functional changes. Rename only.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/virtio/vhost-vdpa.c +3
-3@@ -186,7 +186,7 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s)return true; } -static void vhost_vdpa_iotlb_batch_begin_once (VhostVDPAShared *s) +static void vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || s->iotlb_batch_begin_sent) {@@ -411,7 +411,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, iova = mem_region.iova; } -vhost_vdpa_iotlb_batch_begin_once (s); +vhost_vdpa_dma_batch_begin_once (s); ret =vhost_vdpa_dma_map (s,VHOST_VDPA_GUEST_PA_ASID , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {@@ -493,7 +493,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, iova = result->iova;vhost_iova_tree_remove (s->iova_tree, *result); } -vhost_vdpa_iotlb_batch_begin_once (s); +vhost_vdpa_dma_batch_begin_once (s);/* * The unmap ioctl doesn't accept a full 64-bit. need to check it */
hw/virtio/vhost-vdpa.c static void *vhost_vdpa_load_map(void *opaque) · line 1374
Quoted 5 lines
hw/virtio/vhost-vdpa.c +1
-1@@ -1371,7 +1371,7 @@ static void *vhost_vdpa_load_map(void *opaque) msg->iotlb.size);break ;case VHOST_IOTLB_BATCH_BEGIN : -vhost_vdpa_iotlb_batch_begin_once (shared); +vhost_vdpa_dma_batch_begin_once (shared);
Nit: "iotlb" seems to be better than "dma" as there's no guarantee that the underlayer device is using DMA (e.g simulator or VDUSE).
Thanks
Quoted 6 lines
hw/virtio/vhost-vdpa.c +0
-1break ;case VHOST_IOTLB_BATCH_END :vhost_vdpa_dma_batch_end_once (shared); --1.8.3.1
PATCH 24/40 vdpa: factor out vhost_vdpa_dma_batch_end
In reply to Si-Wei LiuRefactoring only. No functional change.
--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-)
hw/virtio/trace-events +1 -1
@@ -33,7 +33,7 @@ vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 -vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d" vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64
hw/virtio/vhost-vdpa.c +18 -12
@@ -198,19 +198,11 @@ static void vhost_vdpa_dma_batch_begin_once(VhostVDPAShared *s) } } -static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) +static bool vhost_vdpa_dma_batch_end (VhostVDPAShared *s) {struct vhost_msg_v2 msg = {};int fd = s->device_fd; -if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) { -return ; - } - -if (!s->iotlb_batch_begin_sent) { -return ; - } - msg.type =VHOST_IOTLB_MSG_V2 ; msg.iotlb.type =VHOST_IOTLB_BATCH_END ;
@@ -220,16 +212,30 @@ static void vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s) *new_msg = msg;g_async_queue_push (s->map_queue, new_msg); -return ; +return false; } -trace_vhost_vdpa_listener_commit (s, fd, msg.type, msg.iotlb.type); +trace_vhost_vdpa_dma_batch_end (s, fd, msg.type, msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno)); } +return true; +} + +static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) +{ +if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) { +return ; + } + +if (!s->iotlb_batch_begin_sent) { +return ; + } - s->iotlb_batch_begin_sent = false; +if (vhost_vdpa_dma_batch_end (s)) { + s->iotlb_batch_begin_sent = false; + } }static void vhost_vdpa_listener_commit (MemoryListener *listener)
Signature · 1 line
1.8.3.1
Re: [PATCH 24/40] vdpa: factor out vhost_vdpa_dma_batch_end
Quoted 27 lines · Si-Wei Liu
Refactoring only. No functional change.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-)hw/virtio/trace-events +1
-1@@ -33,7 +33,7 @@ vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 -vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d" vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64hw/virtio/vhost-vdpa.c +0
-0
hw/virtio/vhost-vdpa.c static void vhost_vdpa_dma_batch_begin_once(VhostVDPAShared *s) · line 202
Quoted 6 lines
hw/virtio/vhost-vdpa.c +1
-1@@ -198,19 +198,11 @@ static void vhost_vdpa_dma_batch_begin_once(VhostVDPAShared *s) } } -static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) +static bool vhost_vdpa_dma_batch_end (VhostVDPAShared *s) {
I had the same comment for using "iotlb" instead of "dma".
Others look good.
Thanks
PATCH 25/40 vdpa: add asid to dma_batch_once API
In reply to Si-Wei LiuSo that DMA batching API can operate on other ASID than 0.
--- hw/virtio/trace-events | 4 ++-- hw/virtio/vhost-vdpa.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
hw/virtio/trace-events +2 -2
@@ -32,8 +32,8 @@ vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 -vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 -vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type, uint32_t asid) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8" asid: %"PRIu32 +vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type, uint32_t asid) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8" asid: %"PRIu32 vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d" vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64
hw/virtio/vhost-vdpa.c +8 -6
@@ -161,11 +161,12 @@ int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova,return ret; } -static bool vhost_vdpa_map_batch_begin (VhostVDPAShared *s) +static bool vhost_vdpa_map_batch_begin (VhostVDPAShared *s,uint32_t asid) {int fd = s->device_fd;struct vhost_msg_v2 msg = { .type =VHOST_IOTLB_MSG_V2 , + .asid = asid, .iotlb.type =VHOST_IOTLB_BATCH_BEGIN , };
@@ -178,7 +179,7 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s)return false; } -trace_vhost_vdpa_map_batch_begin (s, fd, msg.type, msg.iotlb.type); +trace_vhost_vdpa_map_batch_begin (s, fd, msg.type, msg.iotlb.type, msg.asid);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno));
@@ -193,17 +194,18 @@ static void vhost_vdpa_dma_batch_begin_once(VhostVDPAShared *s)return ; } -if (vhost_vdpa_map_batch_begin (s)) { +if (vhost_vdpa_map_batch_begin (s,0 )) { s->iotlb_batch_begin_sent = true; } } -static bool vhost_vdpa_dma_batch_end (VhostVDPAShared *s) +static bool vhost_vdpa_dma_batch_end (VhostVDPAShared *s,uint32_t asid) {struct vhost_msg_v2 msg = {};int fd = s->device_fd; msg.type =VHOST_IOTLB_MSG_V2 ; + msg.asid = asid; msg.iotlb.type =VHOST_IOTLB_BATCH_END ;if (s->map_thread_enabled && !qemu_thread_is_self (&s->map_thread)) {
@@ -215,7 +217,7 @@ static bool vhost_vdpa_dma_batch_end(VhostVDPAShared *s)return false; } -trace_vhost_vdpa_dma_batch_end (s, fd, msg.type, msg.iotlb.type); +trace_vhost_vdpa_dma_batch_end (s, fd, msg.type, msg.iotlb.type, msg.asid);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno));
@@ -233,7 +235,7 @@ static void vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s)return ; } -if (vhost_vdpa_dma_batch_end (s)) { +if (vhost_vdpa_dma_batch_end (s,0 )) { s->iotlb_batch_begin_sent = false; } }
Signature · 1 line
1.8.3.1
Re: [PATCH 25/40] vdpa: add asid to dma_batch_once API
Quoted 53 lines · Si-Wei Liu
So that DMA batching API can operate on other ASID than 0.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/trace-events | 4 ++-- hw/virtio/vhost-vdpa.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)hw/virtio/trace-events +2
-2@@ -32,8 +32,8 @@ vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 -vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 -vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type, uint32_t asid) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8" asid: %"PRIu32 +vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type, uint32_t asid) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8" asid: %"PRIu32 vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d" vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64hw/virtio/vhost-vdpa.c +3
-2@@ -161,11 +161,12 @@ int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova,return ret; } -static bool vhost_vdpa_map_batch_begin (VhostVDPAShared *s) +static bool vhost_vdpa_map_batch_begin (VhostVDPAShared *s,uint32_t asid) {int fd = s->device_fd;struct vhost_msg_v2 msg = { .type =VHOST_IOTLB_MSG_V2 , + .asid = asid, .iotlb.type =VHOST_IOTLB_BATCH_BEGIN , };@@ -178,7 +179,7 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s)return false; } -trace_vhost_vdpa_map_batch_begin (s, fd, msg.type, msg.iotlb.type); +trace_vhost_vdpa_map_batch_begin (s, fd, msg.type, msg.iotlb.type, msg.asid);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno));@@ -193,17 +194,18 @@ static void vhost_vdpa_dma_batch_begin_once(VhostVDPAShared *s)return ;
hw/virtio/vhost-vdpa.c static void vhost_vdpa_dma_batch_begin_once(VhostVDPAShared *s) · line 202
Quoted 10 lines
hw/virtio/vhost-vdpa.c +2
-2} -if (vhost_vdpa_map_batch_begin (s)) { +if (vhost_vdpa_map_batch_begin (s,0 )) { s->iotlb_batch_begin_sent = true; } } -static bool vhost_vdpa_dma_batch_end (VhostVDPAShared *s) +static bool vhost_vdpa_dma_batch_end (VhostVDPAShared *s,uint32_t asid)
Maybe adding the asid parameter is not needed? We already have it in s->asid by the end of the series, and kernel will also complain if wrong asid is send.
Actually, dma_map and dma_unmap have the asid parameter because maps out of batch, but I think there are no IOTLB operation out of batch by the end of the series, isn't it?
Thanks!
Quoted 30 lines
hw/virtio/vhost-vdpa.c +3
-3{struct vhost_msg_v2 msg = {};int fd = s->device_fd; msg.type =VHOST_IOTLB_MSG_V2 ; + msg.asid = asid; msg.iotlb.type =VHOST_IOTLB_BATCH_END ;if (s->map_thread_enabled && !qemu_thread_is_self (&s->map_thread)) {@@ -215,7 +217,7 @@ static bool vhost_vdpa_dma_batch_end(VhostVDPAShared *s)return false; } -trace_vhost_vdpa_dma_batch_end (s, fd, msg.type, msg.iotlb.type); +trace_vhost_vdpa_dma_batch_end (s, fd, msg.type, msg.iotlb.type, msg.asid);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno));@@ -233,7 +235,7 @@ static void vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s)return ; } -if (vhost_vdpa_dma_batch_end (s)) { +if (vhost_vdpa_dma_batch_end (s,0 )) { s->iotlb_batch_begin_sent = false; } } --1.8.3.1
Re: [PATCH 25/40] vdpa: add asid to dma_batch_once API
In reply to Si-Wei LiuQuoted 29 lines · Si-Wei Liu
So that DMA batching API can operate on other ASID than 0.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/trace-events | 4 ++-- hw/virtio/vhost-vdpa.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)hw/virtio/trace-events +2
-2@@ -32,8 +32,8 @@ vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 -vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 -vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type, uint32_t asid) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8" asid: %"PRIu32 +vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type, uint32_t asid) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8" asid: %"PRIu32 vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d" vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64hw/virtio/vhost-vdpa.c +0
-0
hw/virtio/vhost-vdpa.c int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova, · line 169
Quoted 10 lines
hw/virtio/vhost-vdpa.c +2
-1@@ -161,11 +161,12 @@ int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova,return ret; } -static bool vhost_vdpa_map_batch_begin (VhostVDPAShared *s) +static bool vhost_vdpa_map_batch_begin (VhostVDPAShared *s,uint32_t asid) {int fd = s->device_fd;struct vhost_msg_v2 msg = { .type =VHOST_IOTLB_MSG_V2 , + .asid = asid,
I wonder if we need a check if vhost doesn't support ASID but asid is not zero?
Thanks
PATCH 26/40 vdpa: return int for dma_batch_once API
In reply to Si-Wei LiuReturn zero for success for now. Prepare for non-zero return in the next few patches.
--- hw/virtio/vhost-vdpa.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
hw/virtio/vhost-vdpa.c +9 -5
@@ -187,16 +187,18 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s, uint32_t asid)return true; } -static void vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s) +static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || s->iotlb_batch_begin_sent) { -return ; +return 0 ; }if (vhost_vdpa_map_batch_begin (s,0 )) { s->iotlb_batch_begin_sent = true; } + +return 0 ; }static bool vhost_vdpa_dma_batch_end (VhostVDPAShared *s,uint32_t asid)
@@ -225,19 +227,21 @@ static bool vhost_vdpa_dma_batch_end(VhostVDPAShared *s, uint32_t asid)return true; } -static void vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) +static int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) { -return ; +return 0 ; }if (!s->iotlb_batch_begin_sent) { -return ; +return 0 ; }if (vhost_vdpa_dma_batch_end (s,0 )) { s->iotlb_batch_begin_sent = false; } + +return 0 ; }static void vhost_vdpa_listener_commit (MemoryListener *listener)
Signature · 1 line
1.8.3.1
PATCH 27/40 vdpa: add asid to all dma_batch call sites
In reply to Si-Wei LiuWill allow other callers to specifcy asid when calling the dma_batch API.
--- hw/virtio/vhost-vdpa.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
hw/virtio/vhost-vdpa.c +9 -9
@@ -187,14 +187,14 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s, uint32_t asid)return true; } -static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s) +static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || s->iotlb_batch_begin_sent) {return 0 ; } -if (vhost_vdpa_map_batch_begin (s,0 )) { +if (vhost_vdpa_map_batch_begin (s, asid)) { s->iotlb_batch_begin_sent = true; }
@@ -227,7 +227,7 @@ static bool vhost_vdpa_dma_batch_end(VhostVDPAShared *s, uint32_t asid)return true; } -static int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s) +static int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ;
@@ -237,7 +237,7 @@ static int vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s)return 0 ; } -if (vhost_vdpa_dma_batch_end (s,0 )) { +if (vhost_vdpa_dma_batch_end (s, asid)) { s->iotlb_batch_begin_sent = false; }
@@ -248,7 +248,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener) {VhostVDPAShared *s =container_of (listener, VhostVDPAShared, listener); -vhost_vdpa_dma_batch_end_once (s); +vhost_vdpa_dma_batch_end_once (s,VHOST_VDPA_GUEST_PA_ASID ); }static void vhost_vdpa_iommu_map_notify (IOMMUNotifier *n,IOMMUTLBEntry *iotlb)
@@ -423,7 +423,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, iova = mem_region.iova; } -vhost_vdpa_dma_batch_begin_once (s); +vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); ret =vhost_vdpa_dma_map (s,VHOST_VDPA_GUEST_PA_ASID , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {
@@ -505,7 +505,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, iova = result->iova;vhost_iova_tree_remove (s->iova_tree, *result); } -vhost_vdpa_dma_batch_begin_once (s); +vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID );/* * The unmap ioctl doesn't accept a full 64-bit. need to check it */
@@ -1383,10 +1383,10 @@ static void *vhost_vdpa_load_map(void *opaque) msg->iotlb.size);break ;case VHOST_IOTLB_BATCH_BEGIN : -vhost_vdpa_dma_batch_begin_once (shared); +vhost_vdpa_dma_batch_begin_once (shared, msg->asid);break ;case VHOST_IOTLB_BATCH_END : -vhost_vdpa_dma_batch_end_once (shared); +vhost_vdpa_dma_batch_end_once (shared, msg->asid);break ;default :error_report ("Invalid IOTLB msg type %d" , msg->iotlb.type);
Signature · 1 line
1.8.3.1
PATCH 28/40 vdpa: support iotlb_batch_asid
In reply to Si-Wei LiuThen it's possible to specify ASID when calling the DMA batching API. If the ASID to work on doesn't align with the ASID for ongoing transaction, the API will fail the request and return negative, and the transaction will remain intact as if no failed request ever had occured.
--- hw/virtio/vhost-vdpa.c | 25 +++++++++++++++++++------ include/hw/virtio/vhost-vdpa.h | 1 + net/vhost-vdpa.c | 1 + 3 files changed, 21 insertions(+), 6 deletions(-)
hw/virtio/vhost-vdpa.c +19 -6
@@ -189,15 +189,25 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s, uint32_t asid)static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) { -if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || - s->iotlb_batch_begin_sent) { +if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ; } -if (vhost_vdpa_map_batch_begin (s, asid)) { - s->iotlb_batch_begin_sent = true; +if (s->iotlb_batch_begin_sent && s->iotlb_batch_asid != asid) { +return -1 ; + } + +if (s->iotlb_batch_begin_sent) { +return 0 ; } +if (!vhost_vdpa_map_batch_begin (s, asid)) { +return 0 ; + } + + s->iotlb_batch_begin_sent = true; + s->iotlb_batch_asid = asid; +return 0 ; }
@@ -237,10 +247,13 @@ static int vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s, uint32_t asid)return 0 ; } -if (vhost_vdpa_dma_batch_end (s, asid)) { - s->iotlb_batch_begin_sent = false; +if (!vhost_vdpa_dma_batch_end (s, asid)) { +return 0 ; } + s->iotlb_batch_begin_sent = false; + s->iotlb_batch_asid =-1 ; +return 0 ; }
include/hw/virtio/vhost-vdpa.h +1 -0
@@ -61,6 +61,7 @@ typedef struct vhost_vdpa_shared {bool map_thread_enabled;bool iotlb_batch_begin_sent; +uint32_t iotlb_batch_asid;/* * The memory listener has been registered, so DMA maps have been sent to
net/vhost-vdpa.c +1 -0
@@ -1933,6 +1933,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shared->device_fd = vdpa_device_fd; s->vhost_vdpa.shared->iova_range = iova_range; s->vhost_vdpa.shared->shadow_data = svq; + s->vhost_vdpa.shared->iotlb_batch_asid =-1 ; s->vhost_vdpa.shared->refcnt++; }else if (!is_datapath) { s->cvq_cmd_out_buffer = mmap(NULL, vhost_vdpa_net_cvq_cmd_page_len(),
Signature · 1 line
1.8.3.1
Re: [PATCH 28/40] vdpa: support iotlb_batch_asid
Quoted 50 lines · Si-Wei Liu
Then it's possible to specify ASID when calling the DMA batching API. If the ASID to work on doesn't align with the ASID for ongoing transaction, the API will fail the request and return negative, and the transaction will remain intact as if no failed request ever had occured.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 25 +++++++++++++++++++------ include/hw/virtio/vhost-vdpa.h | 1 + net/vhost-vdpa.c | 1 + 3 files changed, 21 insertions(+), 6 deletions(-)hw/virtio/vhost-vdpa.c +14
-4@@ -189,15 +189,25 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s, uint32_t asid)static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) { -if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || - s->iotlb_batch_begin_sent) { +if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ; } -if (vhost_vdpa_map_batch_begin (s, asid)) { - s->iotlb_batch_begin_sent = true; +if (s->iotlb_batch_begin_sent && s->iotlb_batch_asid != asid) { +return -1 ; + } + +if (s->iotlb_batch_begin_sent) { +return 0 ; } +if (!vhost_vdpa_map_batch_begin (s, asid)) { +return 0 ; + } + + s->iotlb_batch_begin_sent = true; + s->iotlb_batch_asid = asid; +return 0 ; }@@ -237,10 +247,13 @@ static int vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s, uint32_t asid)return 0 ;
hw/virtio/vhost-vdpa.c static int vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s, uint32_t asid) · line 255
Quoted 10 lines
hw/virtio/vhost-vdpa.c +4
-2} -if (vhost_vdpa_dma_batch_end (s, asid)) { - s->iotlb_batch_begin_sent = false; +if (!vhost_vdpa_dma_batch_end (s, asid)) { +return 0 ; } + s->iotlb_batch_begin_sent = false; + s->iotlb_batch_asid =-1 ;
If we define -1 as "not in batch", iotlb_batch_begin_sent is redundant. Can we "#define IOTLB_NOT_IN_BATCH -1" and remove iotlb_batch_begin_sent?
Quoted 31 lines
hw/virtio/vhost-vdpa.c +1
-0+return 0 ; }include/hw/virtio/vhost-vdpa.h +1
-0@@ -61,6 +61,7 @@ typedef struct vhost_vdpa_shared {bool map_thread_enabled;bool iotlb_batch_begin_sent; +uint32_t iotlb_batch_asid;/* * The memory listener has been registered, so DMA maps have been sent to net/vhost-vdpa.c +1
-1@@ -1933,6 +1933,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shared->device_fd = vdpa_device_fd; s->vhost_vdpa.shared->iova_range = iova_range; s->vhost_vdpa.shared->shadow_data = svq; + s->vhost_vdpa.shared->iotlb_batch_asid =-1 ; s->vhost_vdpa.shared->refcnt++; }else if (!is_datapath) { s->cvq_cmd_out_buffer = mmap(NULL, vhost_vdpa_net_cvq_cmd_page_len(), --1.8.3.1
Re: [PATCH 28/40] vdpa: support iotlb_batch_asid
In reply to Si-Wei LiuQuoted 81 lines · Si-Wei Liu
Then it's possible to specify ASID when calling the DMA batching API. If the ASID to work on doesn't align with the ASID for ongoing transaction, the API will fail the request and return negative, and the transaction will remain intact as if no failed request ever had occured.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 25 +++++++++++++++++++------ include/hw/virtio/vhost-vdpa.h | 1 + net/vhost-vdpa.c | 1 + 3 files changed, 21 insertions(+), 6 deletions(-)hw/virtio/vhost-vdpa.c +19
-6@@ -189,15 +189,25 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s, uint32_t asid)static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) { -if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) || - s->iotlb_batch_begin_sent) { +if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ; } -if (vhost_vdpa_map_batch_begin (s, asid)) { - s->iotlb_batch_begin_sent = true; +if (s->iotlb_batch_begin_sent && s->iotlb_batch_asid != asid) { +return -1 ; + } + +if (s->iotlb_batch_begin_sent) { +return 0 ; } +if (!vhost_vdpa_map_batch_begin (s, asid)) { +return 0 ; + } + + s->iotlb_batch_begin_sent = true; + s->iotlb_batch_asid = asid; +return 0 ; }@@ -237,10 +247,13 @@ static int vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s, uint32_t asid)return 0 ; } -if (vhost_vdpa_dma_batch_end (s, asid)) { - s->iotlb_batch_begin_sent = false; +if (!vhost_vdpa_dma_batch_end (s, asid)) { +return 0 ; } + s->iotlb_batch_begin_sent = false; + s->iotlb_batch_asid =-1 ; +return 0 ; }include/hw/virtio/vhost-vdpa.h +1
-0@@ -61,6 +61,7 @@ typedef struct vhost_vdpa_shared {bool map_thread_enabled;bool iotlb_batch_begin_sent; +uint32_t iotlb_batch_asid;/* * The memory listener has been registered, so DMA maps have been sent to net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1936
Quoted 4 lines
net/vhost-vdpa.c +1
-0@@ -1933,6 +1933,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shared->device_fd = vdpa_device_fd; s->vhost_vdpa.shared->iova_range = iova_range; s->vhost_vdpa.shared->shadow_data = svq; + s->vhost_vdpa.shared->iotlb_batch_asid =-1 ;
This seems a trick, uAPI defines asid as:
__u32 asid;
So technically -1U is a legal value.
Thanks
Quoted 6 lines
net/vhost-vdpa.c +0
-1s->vhost_vdpa.shared->refcnt++; }else if (!is_datapath) { s->cvq_cmd_out_buffer = mmap(NULL, vhost_vdpa_net_cvq_cmd_page_len(), --1.8.3.1
PATCH 29/40 vdpa: expose API vhost_vdpa_dma_batch_once
In reply to Si-Wei LiuSo that the batching API can be called from other file externally than the local.
--- hw/virtio/vhost-vdpa.c | 21 +++++++++++++++------ include/hw/virtio/vhost-vdpa.h | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-)
hw/virtio/vhost-vdpa.c +15 -6
@@ -187,7 +187,7 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s, uint32_t asid)return true; } -static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) +int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ;
@@ -237,7 +237,7 @@ static bool vhost_vdpa_dma_batch_end(VhostVDPAShared *s, uint32_t asid)return true; } -static int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid) +int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ;
@@ -436,7 +436,12 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, iova = mem_region.iova; } -vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); + ret =vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); +if (unlikely (ret)) { +error_report ("Can't batch mapping on asid 0 (%p)" , s); + goto fail_map; + } + ret =vhost_vdpa_dma_map (s,VHOST_VDPA_GUEST_PA_ASID , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {
@@ -518,7 +523,11 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, iova = result->iova;vhost_iova_tree_remove (s->iova_tree, *result); } -vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); + ret =vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); +if (ret) { +error_report ("Can't batch mapping on asid 0 (%p)" , s); + } +/* * The unmap ioctl doesn't accept a full 64-bit. need to check it */
@@ -1396,10 +1405,10 @@ static void *vhost_vdpa_load_map(void *opaque) msg->iotlb.size);break ;case VHOST_IOTLB_BATCH_BEGIN : -vhost_vdpa_dma_batch_begin_once (shared, msg->asid); + r =vhost_vdpa_dma_batch_begin_once (shared, msg->asid);break ;case VHOST_IOTLB_BATCH_END : -vhost_vdpa_dma_batch_end_once (shared, msg->asid); + r =vhost_vdpa_dma_batch_end_once (shared, msg->asid);break ;default :error_report ("Invalid IOTLB msg type %d" , msg->iotlb.type);
include/hw/virtio/vhost-vdpa.h +3 -0
@@ -106,6 +106,9 @@ int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t asid, hwaddr iova, hwaddr size, void *vaddr, bool readonly);int vhost_vdpa_dma_unmap (VhostVDPAShared *s,uint32_t asid,hwaddr iova,hwaddr size); +int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid); +int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid); +int vhost_vdpa_load_setup (VhostVDPAShared *s,AddressSpace *dma_as);int vhost_vdpa_load_cleanup (VhostVDPAShared *s,bool vhost_will_start);
Signature · 1 line
1.8.3.1
Re: [PATCH 29/40] vdpa: expose API vhost_vdpa_dma_batch_once
Quoted 33 lines · Si-Wei Liu
So that the batching API can be called from other file externally than the local.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 21 +++++++++++++++------ include/hw/virtio/vhost-vdpa.h | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-)hw/virtio/vhost-vdpa.c +2
-2@@ -187,7 +187,7 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s, uint32_t asid)return true; } -static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) +int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ;@@ -237,7 +237,7 @@ static bool vhost_vdpa_dma_batch_end(VhostVDPAShared *s, uint32_t asid)return true; } -static int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid) +int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ;
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 441
Quoted 7 lines
hw/virtio/vhost-vdpa.c +3
-1@@ -436,7 +436,12 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, iova = mem_region.iova; } -vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); + ret =vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); +if (unlikely (ret)) { +error_report ("Can't batch mapping on asid 0 (%p)" , s);
Can we move this error to vhost_vdpa_dma_batch_begin_once?
That way we avoid duplicating the error message later in the patch and we can tell the expected ASID.
Quoted 49 lines
hw/virtio/vhost-vdpa.c +10
-3+ goto fail_map; + } + ret =vhost_vdpa_dma_map (s,VHOST_VDPA_GUEST_PA_ASID , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {@@ -518,7 +523,11 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, iova = result->iova;vhost_iova_tree_remove (s->iova_tree, *result); } -vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); + ret =vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); +if (ret) { +error_report ("Can't batch mapping on asid 0 (%p)" , s); + } +/* * The unmap ioctl doesn't accept a full 64-bit. need to check it */ @@ -1396,10 +1405,10 @@ static void *vhost_vdpa_load_map(void *opaque) msg->iotlb.size);break ;case VHOST_IOTLB_BATCH_BEGIN : -vhost_vdpa_dma_batch_begin_once (shared, msg->asid); + r =vhost_vdpa_dma_batch_begin_once (shared, msg->asid);break ;case VHOST_IOTLB_BATCH_END : -vhost_vdpa_dma_batch_end_once (shared, msg->asid); + r =vhost_vdpa_dma_batch_end_once (shared, msg->asid);break ;default :error_report ("Invalid IOTLB msg type %d" , msg->iotlb.type);include/hw/virtio/vhost-vdpa.h +3
-1@@ -106,6 +106,9 @@ int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t asid, hwaddr iova, hwaddr size, void *vaddr, bool readonly);int vhost_vdpa_dma_unmap (VhostVDPAShared *s,uint32_t asid,hwaddr iova,hwaddr size); +int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid); +int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid); +int vhost_vdpa_load_setup (VhostVDPAShared *s,AddressSpace *dma_as);int vhost_vdpa_load_cleanup (VhostVDPAShared *s,bool vhost_will_start); --1.8.3.1
Re: [PATCH 29/40] vdpa: expose API vhost_vdpa_dma_batch_once
In reply to Si-Wei LiuQuoted 33 lines · Si-Wei Liu
So that the batching API can be called from other file externally than the local.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 21 +++++++++++++++------ include/hw/virtio/vhost-vdpa.h | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-)hw/virtio/vhost-vdpa.c +2
-2@@ -187,7 +187,7 @@ static bool vhost_vdpa_map_batch_begin(VhostVDPAShared *s, uint32_t asid)return true; } -static int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) +int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ;@@ -237,7 +237,7 @@ static bool vhost_vdpa_dma_batch_end(VhostVDPAShared *s, uint32_t asid)return true; } -static int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid) +int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid) {if (!(s->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) {return 0 ;
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 444
Quoted 10 lines
hw/virtio/vhost-vdpa.c +6
-1@@ -436,7 +436,12 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, iova = mem_region.iova; } -vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); + ret =vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); +if (unlikely (ret)) { +error_report ("Can't batch mapping on asid 0 (%p)" , s); + goto fail_map; + } +
This seems like another patch.
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_del(MemoryListener *listener, · line 529
Quoted 12 lines
hw/virtio/vhost-vdpa.c +4
-1ret =vhost_vdpa_dma_map (s,VHOST_VDPA_GUEST_PA_ASID , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {@@ -518,7 +523,11 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, iova = result->iova;vhost_iova_tree_remove (s->iova_tree, *result); } -vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); + ret =vhost_vdpa_dma_batch_begin_once (s,VHOST_VDPA_GUEST_PA_ASID ); +if (ret) { +error_report ("Can't batch mapping on asid 0 (%p)" , s); + }
And this as well.
Quoted 5 lines
hw/virtio/vhost-vdpa.c +1
-0+/* * The unmap ioctl doesn't accept a full 64-bit. need to check it */
hw/virtio/vhost-vdpa.c static void *vhost_vdpa_load_map(void *opaque) · line 1411
Quoted 9 lines
hw/virtio/vhost-vdpa.c +2
-2@@ -1396,10 +1405,10 @@ static void *vhost_vdpa_load_map(void *opaque) msg->iotlb.size);break ;case VHOST_IOTLB_BATCH_BEGIN : -vhost_vdpa_dma_batch_begin_once (shared, msg->asid); + r =vhost_vdpa_dma_batch_begin_once (shared, msg->asid);break ;case VHOST_IOTLB_BATCH_END : -vhost_vdpa_dma_batch_end_once (shared, msg->asid); + r =vhost_vdpa_dma_batch_end_once (shared, msg->asid);
And these.
Thanks
Quoted 20 lines
hw/virtio/vhost-vdpa.c +0
-0break ;default :error_report ("Invalid IOTLB msg type %d" , msg->iotlb.type);include/hw/virtio/vhost-vdpa.h +3
-1@@ -106,6 +106,9 @@ int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t asid, hwaddr iova, hwaddr size, void *vaddr, bool readonly);int vhost_vdpa_dma_unmap (VhostVDPAShared *s,uint32_t asid,hwaddr iova,hwaddr size); +int vhost_vdpa_dma_batch_begin_once (VhostVDPAShared *s,uint32_t asid); +int vhost_vdpa_dma_batch_end_once (VhostVDPAShared *s,uint32_t asid); +int vhost_vdpa_load_setup (VhostVDPAShared *s,AddressSpace *dma_as);int vhost_vdpa_load_cleanup (VhostVDPAShared *s,bool vhost_will_start); --1.8.3.1
PATCH 30/40 vdpa: batch map/unmap op per svq pair basis
In reply to Si-Wei LiuCoalesce multiple map or unmap operations to just one so that all mapping setup or teardown can occur in a single DMA batch.
--- hw/virtio/vhost-vdpa.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/virtio/vhost-vdpa.c +5 -0
@@ -1288,6 +1288,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev)return true; } +vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id);for (i =0 ; i < v->shadow_vqs->len; ++i) {VirtQueue *vq =virtio_get_queue (dev->vdev, dev->vq_index + i);VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, i);
@@ -1315,6 +1316,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) goto err_set_addr; } } +vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id);return true;
@@ -1323,6 +1325,7 @@ err_set_addr: err_map:vhost_svq_stop (g_ptr_array_index (v->shadow_vqs, i)); +vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id); err:error_reportf_err (err,"Cannot setup SVQ %u: " , i);
@@ -1343,6 +1346,7 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)return ; } +vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id);for (unsigned i =0 ; i < v->shadow_vqs->len; ++i) {VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, i);
@@ -1352,6 +1356,7 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)event_notifier_cleanup (&svq->hdev_kick);event_notifier_cleanup (&svq->hdev_call); } +vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id); }static void vhost_vdpa_suspend (struct vhost_dev *dev)
Signature · 1 line
1.8.3.1
Re: [PATCH 30/40] vdpa: batch map/unmap op per svq pair basis
Quoted 6 lines · Si-Wei Liu
Coalesce multiple map or unmap operations to just one so that all mapping setup or teardown can occur in a single DMA batch.
Signed-off-by Si-Wei Liu <[email protected]>
Thanks
PATCH 31/40 vdpa: batch map and unmap around cvq svq start/stop
In reply to Si-Wei LiuCoalesce map or unmap operations to exact one DMA
batch to reduce potential impact on performance.
--- net/vhost-vdpa.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/vhost-vdpa.c +7 -1
@@ -715,10 +715,11 @@ out: v->shared->iova_range.last); } +vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id); r =vhost_vdpa_cvq_map_buf (&s->vhost_vdpa, s->cvq_cmd_out_buffer,vhost_vdpa_net_cvq_cmd_page_len (), false);if (unlikely (r <0 )) { -return r; + goto err; } r = vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->status,
@@ -727,18 +728,23 @@ out:vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->cvq_cmd_out_buffer); } +err: +vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id);return r; }static void vhost_vdpa_net_cvq_stop (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );if (s->vhost_vdpa.shadow_vqs_enabled) { +vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id);vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->cvq_cmd_out_buffer);vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->status); +vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id); }vhost_vdpa_net_client_stop (nc);
Signature · 1 line
1.8.3.1
Re: [PATCH 31/40] vdpa: batch map and unmap around cvq svq start/stop
Quoted 5 lines · Si-Wei Liu
Coalesce map or unmap operations to exact one DMA
batch to reduce potential impact on performance.Signed-off-by Si-Wei Liu <[email protected]>
Thanks
PATCH 32/40 vdpa: factor out vhost_vdpa_net_get_nc_vdpa
In reply to Si-Wei LiuIntroduce new API. No functional change on existing API.
--- net/vhost-vdpa.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/vhost-vdpa.c +9 -4
@@ -290,13 +290,18 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf, } -/** From any vdpa net client, get the netclient of the first queue pair */ -static VhostVDPAState *vhost_vdpa_net_first_nc_vdpa (VhostVDPAState *s) +/** From any vdpa net client, get the netclient of the i-th queue pair */ +static VhostVDPAState *vhost_vdpa_net_get_nc_vdpa (VhostVDPAState *s,int i) {NICState *nic =qemu_get_nic (s->nc.peer); -NetClientState *nc0 =qemu_get_peer (nic->ncs,0 ); +NetClientState *nc_i =qemu_get_peer (nic->ncs, i); + +return DO_UPCAST (VhostVDPAState, nc, nc_i); +} -return DO_UPCAST (VhostVDPAState, nc, nc0); +static VhostVDPAState *vhost_vdpa_net_first_nc_vdpa (VhostVDPAState *s) +{ +return vhost_vdpa_net_get_nc_vdpa (s,0 ); }static void vhost_vdpa_net_log_global_enable (VhostVDPAState *s,bool enable)
Signature · 1 line
1.8.3.1
Re: [PATCH 32/40] vdpa: factor out vhost_vdpa_net_get_nc_vdpa
Quoted 4 lines · Si-Wei Liu
Introduce new API. No functional change on existing API.
Signed-off-by Si-Wei Liu <[email protected]>
Thanks
PATCH 33/40 vdpa: batch multiple dma_unmap to a single call for vm stop
In reply to Si-Wei LiuShould help live migration downtime on source host. Below are the coalesced dma_unmap time series on 2 queue pair config (no dedicated descriptor group ASID for SVQ).
[email protected]:vhost_vdpa_reset_device dev: 0x55c933926890 [email protected]:vhost_vdpa_add_status dev: 0x55c933926890 status: 0x3 [email protected]:vhost_vdpa_flush_map dev: 0x55c933926890 doit: 1 svq_flush: 0 persist: 1 [email protected]:vhost_vdpa_set_config_call dev: 0x55c933926890 fd: -1 [email protected]:vhost_vdpa_iotlb_begin_batch vdpa:0x7fa2aa895190 fd: 16 msg_type: 2 type: 5 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16 msg_type: 2 asid: 0 iova: 0x1000 size: 0x2000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16 msg_type: 2 asid: 0 iova: 0x3000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16 msg_type: 2 asid: 0 iova: 0x4000 size: 0x2000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16 msg_type: 2 asid: 0 iova: 0x6000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16 msg_type: 2 asid: 0 iova: 0x7000 size: 0x2000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16 msg_type: 2 asid: 0 iova: 0x9000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16 msg_type: 2 asid: 0 iova: 0xa000 size: 0x2000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16 msg_type: 2 asid: 0 iova: 0xc000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16 msg_type: 2 asid: 0 iova: 0xf000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16 msg_type: 2 asid: 0 iova: 0x10000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16 msg_type: 2 asid: 0 iova: 0xd000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16 msg_type: 2 asid: 0 iova: 0xe000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_iotlb_end_batch vdpa:0x7fa2aa895190 fd: 16 msg_type: 2 type: 6 [email protected]:vhost_vdpa_get_vq_index dev: 0x55c933925de0 idx: 0 vq idx: 0 [email protected]:vhost_vdpa_get_vq_index dev: 0x55c933925de0 idx: 1 vq idx: 1 [email protected]:vhost_vdpa_get_vq_index dev: 0x55c9339262e0 idx: 2 vq idx: 2 [email protected]:vhost_vdpa_get_vq_index dev: 0x55c9339262e0 idx: 3 vq idx: 3
--- hw/virtio/vhost-vdpa.c | 7 +-- include/hw/virtio/vhost-vdpa.h | 3 ++ net/vhost-vdpa.c | 112 +++++++++++++++++++++++++++-------------- 3 files changed, 80 insertions(+), 42 deletions(-)
hw/virtio/vhost-vdpa.c +2 -5
@@ -1162,8 +1162,8 @@ static void vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr addr)vhost_iova_tree_remove (v->shared->iova_tree, *result); } -static void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, -const VhostShadowVirtqueue *svq) +void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, +const VhostShadowVirtqueue *svq) {struct vhost_vdpa *v = dev->opaque;struct vhost_vring_addr svq_addr;
@@ -1346,17 +1346,14 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)return ; } -vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id);for (unsigned i =0 ; i < v->shadow_vqs->len; ++i) {VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, i);vhost_svq_stop (svq); -vhost_vdpa_svq_unmap_rings (dev, svq);event_notifier_cleanup (&svq->hdev_kick);event_notifier_cleanup (&svq->hdev_call); } -vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id); }static void vhost_vdpa_suspend (struct vhost_dev *dev)
include/hw/virtio/vhost-vdpa.h +3 -0
@@ -112,6 +112,9 @@ int vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s, uint32_t asid);int vhost_vdpa_load_setup (VhostVDPAShared *s,AddressSpace *dma_as);int vhost_vdpa_load_cleanup (VhostVDPAShared *s,bool vhost_will_start); +void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, +const VhostShadowVirtqueue *svq); + typedef struct vdpa_iommu { VhostVDPAShared *dev_shared; IOMMUMemoryRegion *iommu_mr;
net/vhost-vdpa.c +75 -37
147 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH 33/40] vdpa: batch multiple dma_unmap to a single call for vm stop
Quoted 171 lines · Si-Wei Liu
Should help live migration downtime on source host. Below are the coalesced
dma_unmaptime series on 2 queue pair config (no dedicated descriptor group ASID for SVQ).[email protected]:vhost_vdpa_reset_device dev:
0x55c933926890[email protected]:vhost_vdpa_add_status dev:0x55c933926890status:0x3[email protected]:vhost_vdpa_flush_map dev:0x55c933926890doit: 1svq_flush: 0 persist: 1 [email protected]:vhost_vdpa_set_config_call dev:0x55c933926890fd: -1 [email protected]:vhost_vdpa_iotlb_begin_batch vdpa:0x7fa2aa895190 fd: 16msg_type: 2 type: 5 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16msg_type: 2 asid: 0 iova:0x1000size:0x2000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16msg_type: 2 asid: 0 iova:0x3000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16msg_type: 2 asid: 0 iova:0x4000size:0x2000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16msg_type: 2 asid: 0 iova:0x6000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16msg_type: 2 asid: 0 iova:0x7000size:0x2000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16msg_type: 2 asid: 0 iova:0x9000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16msg_type: 2 asid: 0 iova:0xa000size:0x2000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16msg_type: 2 asid: 0 iova:0xc000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16msg_type: 2 asid: 0 iova:0xf000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16msg_type: 2 asid: 0 iova:0x10000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16msg_type: 2 asid: 0 iova:0xd000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16msg_type: 2 asid: 0 iova:0xe000size:0x1000type: 3 [email protected]:vhost_vdpa_iotlb_end_batch vdpa:0x7fa2aa895190 fd: 16msg_type: 2 type: 6 [email protected]:vhost_vdpa_get_vq_index dev:0x55c933925de0idx: 0 vq idx: 0 [email protected]:vhost_vdpa_get_vq_index dev:0x55c933925de0idx: 1 vq idx: 1 [email protected]:vhost_vdpa_get_vq_index dev:0x55c9339262e0idx: 2 vq idx: 2 [email protected]:vhost_vdpa_get_vq_index dev:0x55c9339262e0idx: 3 vq idx: 3Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 7 +-- include/hw/virtio/vhost-vdpa.h | 3 ++ net/vhost-vdpa.c | 112 +++++++++++++++++++++++++++-------------- 3 files changed, 80 insertions(+), 42 deletions(-)hw/virtio/vhost-vdpa.c +2
-5@@ -1162,8 +1162,8 @@ static void vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr addr)vhost_iova_tree_remove (v->shared->iova_tree, *result); } -static void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, -const VhostShadowVirtqueue *svq) +void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, +const VhostShadowVirtqueue *svq) {struct vhost_vdpa *v = dev->opaque;struct vhost_vring_addr svq_addr;@@ -1346,17 +1346,14 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)return ; } -vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id);for (unsigned i =0 ; i < v->shadow_vqs->len; ++i) {VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, i);vhost_svq_stop (svq); -vhost_vdpa_svq_unmap_rings (dev, svq);event_notifier_cleanup (&svq->hdev_kick);event_notifier_cleanup (&svq->hdev_call); } -vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id); }static void vhost_vdpa_suspend (struct vhost_dev *dev)include/hw/virtio/vhost-vdpa.h +3
-0@@ -112,6 +112,9 @@ int vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s, uint32_t asid);int vhost_vdpa_load_setup (VhostVDPAShared *s,AddressSpace *dma_as);int vhost_vdpa_load_cleanup (VhostVDPAShared *s,bool vhost_will_start); +void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, +const VhostShadowVirtqueue *svq); + typedef struct vdpa_iommu { VhostVDPAShared *dev_shared; IOMMUMemoryRegion *iommu_mr;net/vhost-vdpa.c +65
-0@@ -29,6 +29,7 @@#include "migration/migration.h" #include "migration/misc.h" #include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-vdpa.h" /* Todo:need to add the multiqueue support here */ typedef struct VhostVDPAState {@@ -467,15 +468,89 @@ static int vhost_vdpa_net_data_load(NetClientState *nc)return 0 ; } +static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) +{ +VhostIOVATree *tree = v->shared->iova_tree; +DMAMap needle = { +/* +* No need to specify size or to look for more translations since +* this contiguous chunk was allocated by us. +*/ + .translated_addr = (hwaddr )(uintptr_t )addr, + }; +const DMAMap *map =vhost_iova_tree_find_iova (tree, &needle); +int r; + +if (unlikely (!map)) { +error_report ("Cannot locate expected map" ); +return ; + } + + r =vhost_vdpa_dma_unmap (v->shared, v->address_space_id, map->iova, + map->size +1 ); +if (unlikely (r !=0 )) { +error_report ("Device cannot unmap: %s(%d)" ,g_strerror (r), r); + } + +vhost_iova_tree_remove (tree, *map); +} +static void vhost_vdpa_net_client_stop (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; +struct vhost_vdpa *last_vi =NULL ; +bool has_cvq = v->dev->vq_index_end %2 ; +int nvqp;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );if (s->vhost_vdpa.index ==0 ) {migration_remove_notifier (&s->migration_state); } + +if (v->dev->vq_index + v->dev->nvqs != v->dev->vq_index_end) { +return ; + } + + nvqp = (v->dev->vq_index_end +1 ) /2 ; +for (int i =0 ; i < nvqp; ++i) { +VhostVDPAState *s_i =vhost_vdpa_net_get_nc_vdpa (s, i); +struct vhost_vdpa *v_i = &s_i->vhost_vdpa; + +if (!v_i->shadow_vqs_enabled) { +continue ; + } +if (!last_vi) { +vhost_vdpa_dma_batch_begin_once (v_i->shared, + v_i->address_space_id); + last_vi = v_i; + }else if (last_vi->address_space_id != v_i->address_space_id) { +vhost_vdpa_dma_batch_end_once (last_vi->shared, + last_vi->address_space_id); +vhost_vdpa_dma_batch_begin_once (v_i->shared, + v_i->address_space_id); + last_vi = v_i; + } + +for (unsigned j =0 ; j < v_i->shadow_vqs->len; ++j) { +VhostShadowVirtqueue *svq =g_ptr_array_index (v_i->shadow_vqs, j); + +vhost_vdpa_svq_unmap_rings (v_i->dev, svq); + } + } +if (has_cvq) { +if (last_vi) {
net/vhost-vdpa.c static int vhost_vdpa_net_data_load(NetClientState *nc) · line 553
Quoted 10 lines
net/vhost-vdpa.c +10
-0+assert (last_vi->address_space_id == v->address_space_id); + } +vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->cvq_cmd_out_buffer); +vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->status); + } +if (last_vi) { +vhost_vdpa_dma_batch_end_once (last_vi->shared, + last_vi->address_space_id); + last_vi =NULL ; + }
Since we've delayed the guest unmap memory to _cleanup, why not delay these unmaps to cleanup too?
Quoted 59 lines
net/vhost-vdpa.c +0
-38}static int vhost_vdpa_net_load_setup (NetClientState *nc,NICState *nic)@@ -585,33 +660,6 @@ static int64_t vhost_vdpa_get_vring_desc_group(int device_fd,return state.num; } -static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) -{ -VhostIOVATree *tree = v->shared->iova_tree; -DMAMap needle = { -/* -* No need to specify size or to look for more translations since -* this contiguous chunk was allocated by us. -*/ - .translated_addr = (hwaddr )(uintptr_t )addr, - }; -const DMAMap *map =vhost_iova_tree_find_iova (tree, &needle); -int r; - -if (unlikely (!map)) { -error_report ("Cannot locate expected map" ); -return ; - } - - r =vhost_vdpa_dma_unmap (v->shared, v->address_space_id, map->iova, - map->size +1 ); -if (unlikely (r !=0 )) { -error_report ("Device cannot unmap: %s(%d)" ,g_strerror (r), r); - } - -vhost_iova_tree_remove (tree, *map); -} -/** Map CVQ buffer. */ static int vhost_vdpa_cvq_map_buf (struct vhost_vdpa *v,void *buf,size_t size,bool write)@@ -740,18 +788,8 @@ err:static void vhost_vdpa_net_cvq_stop (NetClientState *nc) { -VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); -struct vhost_vdpa *v = &s->vhost_vdpa; -assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -if (s->vhost_vdpa.shadow_vqs_enabled) { -vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id); -vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->cvq_cmd_out_buffer); -vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->status); -vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id); - } -vhost_vdpa_net_client_stop (nc); } --1.8.3.1
Re: [PATCH 33/40] vdpa: batch multiple dma_unmap to a single call for vm stop
In reply to Si-Wei LiuQuoted 4 lines · Si-Wei Liu
Should help live migration downtime on source host. Below are the coalesced
dma_unmaptime series on 2 queue pair config (no dedicated descriptor group ASID for SVQ).
It's better to explain how we can batch into a single call (e.g do we batch at the level of a whole device?)
Quoted 116 lines
[email protected]:vhost_vdpa_reset_device dev:
0x55c933926890[email protected]:vhost_vdpa_add_status dev:0x55c933926890status:0x3[email protected]:vhost_vdpa_flush_map dev:0x55c933926890doit: 1svq_flush: 0 persist: 1 [email protected]:vhost_vdpa_set_config_call dev:0x55c933926890fd: -1 [email protected]:vhost_vdpa_iotlb_begin_batch vdpa:0x7fa2aa895190 fd: 16msg_type: 2 type: 5 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16msg_type: 2 asid: 0 iova:0x1000size:0x2000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16msg_type: 2 asid: 0 iova:0x3000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16msg_type: 2 asid: 0 iova:0x4000size:0x2000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa895190 fd: 16msg_type: 2 asid: 0 iova:0x6000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16msg_type: 2 asid: 0 iova:0x7000size:0x2000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16msg_type: 2 asid: 0 iova:0x9000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16msg_type: 2 asid: 0 iova:0xa000size:0x2000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa84c190 fd: 16msg_type: 2 asid: 0 iova:0xc000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16msg_type: 2 asid: 0 iova:0xf000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16msg_type: 2 asid: 0 iova:0x10000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16msg_type: 2 asid: 0 iova:0xd000size:0x1000type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa:0x7fa2aa6b6190 fd: 16msg_type: 2 asid: 0 iova:0xe000size:0x1000type: 3 [email protected]:vhost_vdpa_iotlb_end_batch vdpa:0x7fa2aa895190 fd: 16msg_type: 2 type: 6 [email protected]:vhost_vdpa_get_vq_index dev:0x55c933925de0idx: 0 vq idx: 0 [email protected]:vhost_vdpa_get_vq_index dev:0x55c933925de0idx: 1 vq idx: 1 [email protected]:vhost_vdpa_get_vq_index dev:0x55c9339262e0idx: 2 vq idx: 2 [email protected]:vhost_vdpa_get_vq_index dev:0x55c9339262e0idx: 3 vq idx: 3Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/vhost-vdpa.c | 7 +-- include/hw/virtio/vhost-vdpa.h | 3 ++ net/vhost-vdpa.c | 112 +++++++++++++++++++++++++++-------------- 3 files changed, 80 insertions(+), 42 deletions(-)hw/virtio/vhost-vdpa.c +2
-5@@ -1162,8 +1162,8 @@ static void vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr addr)vhost_iova_tree_remove (v->shared->iova_tree, *result); } -static void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, -const VhostShadowVirtqueue *svq) +void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, +const VhostShadowVirtqueue *svq) {struct vhost_vdpa *v = dev->opaque;struct vhost_vring_addr svq_addr;@@ -1346,17 +1346,14 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)return ; } -vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id);for (unsigned i =0 ; i < v->shadow_vqs->len; ++i) {VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, i);vhost_svq_stop (svq); -vhost_vdpa_svq_unmap_rings (dev, svq);event_notifier_cleanup (&svq->hdev_kick);event_notifier_cleanup (&svq->hdev_call); } -vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id); }static void vhost_vdpa_suspend (struct vhost_dev *dev)include/hw/virtio/vhost-vdpa.h +3
-0@@ -112,6 +112,9 @@ int vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s, uint32_t asid);int vhost_vdpa_load_setup (VhostVDPAShared *s,AddressSpace *dma_as);int vhost_vdpa_load_cleanup (VhostVDPAShared *s,bool vhost_will_start); +void vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev, +const VhostShadowVirtqueue *svq); + typedef struct vdpa_iommu { VhostVDPAShared *dev_shared; IOMMUMemoryRegion *iommu_mr;net/vhost-vdpa.c +23
-0@@ -29,6 +29,7 @@#include "migration/migration.h" #include "migration/misc.h" #include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-vdpa.h" /* Todo:need to add the multiqueue support here */ typedef struct VhostVDPAState {@@ -467,15 +468,89 @@ static int vhost_vdpa_net_data_load(NetClientState *nc)return 0 ; } +static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) +{ +VhostIOVATree *tree = v->shared->iova_tree; +DMAMap needle = { +/* +* No need to specify size or to look for more translations since +* this contiguous chunk was allocated by us. +*/ + .translated_addr = (hwaddr )(uintptr_t )addr, + }; +const DMAMap *map =vhost_iova_tree_find_iova (tree, &needle); +int r; + +if (unlikely (!map)) { +error_report ("Cannot locate expected map" ); +return ; + } + + r =vhost_vdpa_dma_unmap (v->shared, v->address_space_id, map->iova, + map->size +1 ); +if (unlikely (r !=0 )) { +error_report ("Device cannot unmap: %s(%d)" ,g_strerror (r), r);
net/vhost-vdpa.c static int vhost_vdpa_net_data_load(NetClientState *nc) · line 502
Quoted 10 lines
net/vhost-vdpa.c +7
-0+ } + +vhost_iova_tree_remove (tree, *map); +} +static void vhost_vdpa_net_client_stop (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; +struct vhost_vdpa *last_vi =NULL ;
Nit: just curious what did "vi" mean here?
Quoted 41 lines
net/vhost-vdpa.c +35
-0+bool has_cvq = v->dev->vq_index_end %2 ; +int nvqp;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );if (s->vhost_vdpa.index ==0 ) {migration_remove_notifier (&s->migration_state); } + +if (v->dev->vq_index + v->dev->nvqs != v->dev->vq_index_end) { +return ; + } + + nvqp = (v->dev->vq_index_end +1 ) /2 ; +for (int i =0 ; i < nvqp; ++i) { +VhostVDPAState *s_i =vhost_vdpa_net_get_nc_vdpa (s, i); +struct vhost_vdpa *v_i = &s_i->vhost_vdpa; + +if (!v_i->shadow_vqs_enabled) { +continue ; + } +if (!last_vi) { +vhost_vdpa_dma_batch_begin_once (v_i->shared, + v_i->address_space_id); + last_vi = v_i; + }else if (last_vi->address_space_id != v_i->address_space_id) { +vhost_vdpa_dma_batch_end_once (last_vi->shared, + last_vi->address_space_id); +vhost_vdpa_dma_batch_begin_once (v_i->shared, + v_i->address_space_id); + last_vi = v_i; + } + +for (unsigned j =0 ; j < v_i->shadow_vqs->len; ++j) { +VhostShadowVirtqueue *svq =g_ptr_array_index (v_i->shadow_vqs, j); + +vhost_vdpa_svq_unmap_rings (v_i->dev, svq); + } + } +if (has_cvq) { +if (last_vi) {
net/vhost-vdpa.c static int vhost_vdpa_net_data_load(NetClientState *nc) · line 553
Quoted 10 lines
net/vhost-vdpa.c +10
-0+assert (last_vi->address_space_id == v->address_space_id); + } +vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->cvq_cmd_out_buffer); +vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->status); + } +if (last_vi) { +vhost_vdpa_dma_batch_end_once (last_vi->shared, + last_vi->address_space_id); + last_vi =NULL ; + }
The logic looks rather complicated, can we simplify it by:
batch_begin_once()unmap()batch_end_once()
?
Thanks
Quoted 59 lines
net/vhost-vdpa.c +0
-38}static int vhost_vdpa_net_load_setup (NetClientState *nc,NICState *nic)@@ -585,33 +660,6 @@ static int64_t vhost_vdpa_get_vring_desc_group(int device_fd,return state.num; } -static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) -{ -VhostIOVATree *tree = v->shared->iova_tree; -DMAMap needle = { -/* -* No need to specify size or to look for more translations since -* this contiguous chunk was allocated by us. -*/ - .translated_addr = (hwaddr )(uintptr_t )addr, - }; -const DMAMap *map =vhost_iova_tree_find_iova (tree, &needle); -int r; - -if (unlikely (!map)) { -error_report ("Cannot locate expected map" ); -return ; - } - - r =vhost_vdpa_dma_unmap (v->shared, v->address_space_id, map->iova, - map->size +1 ); -if (unlikely (r !=0 )) { -error_report ("Device cannot unmap: %s(%d)" ,g_strerror (r), r); - } - -vhost_iova_tree_remove (tree, *map); -} -/** Map CVQ buffer. */ static int vhost_vdpa_cvq_map_buf (struct vhost_vdpa *v,void *buf,size_t size,bool write)@@ -740,18 +788,8 @@ err:static void vhost_vdpa_net_cvq_stop (NetClientState *nc) { -VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); -struct vhost_vdpa *v = &s->vhost_vdpa; -assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -if (s->vhost_vdpa.shadow_vqs_enabled) { -vhost_vdpa_dma_batch_begin_once (v->shared, v->address_space_id); -vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->cvq_cmd_out_buffer); -vhost_vdpa_cvq_unmap_buf (&s->vhost_vdpa, s->status); -vhost_vdpa_dma_batch_end_once (v->shared, v->address_space_id); - } -vhost_vdpa_net_client_stop (nc); } --1.8.3.1
PATCH 34/40 vdpa: fix network breakage after cancelling migration
In reply to Si-Wei LiuFix an issue where cancellation of ongoing migration ends up with no network connectivity.
When canceling migration, SVQ will be switched back to the passthrough mode, but the right call fd is not programed to the device and the svq's own call fd is still used. At the point of this transitioning period, the shadow_vqs_enabled hadn't been set back to false yet, causing the installation of call fd inadvertently bypassed.
--- hw/virtio/vhost-vdpa.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +6 -1
@@ -1647,7 +1647,12 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev,/* Remember last call fd because we can switch to SVQ anytime. */ vhost_svq_set_svq_call_fd (svq, file->fd); -if (v->shadow_vqs_enabled) { +/* +* In the event of SVQ switching to off, shadow_vqs_enabled has +* not been set to false yet, but the underlying call fd will +* switch back to the guest notifier for passthrough VQs. +*/ +if (v->shadow_vqs_enabled && v->shared->svq_switching >=0 ) {return 0 ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 34/40] vdpa: fix network breakage after cancelling migration
Quoted 11 lines · Si-Wei Liu
Fix an issue where cancellation of ongoing migration ends up with no network connectivity.
When canceling migration, SVQ will be switched back to the passthrough mode, but the right call fd is not programed to the device and the svq's own call fd is still used. At the point of this transitioning period, the
shadow_vqs_enabledhadn't been set back to false yet, causing the installation of call fd inadvertently bypassed.
Quoted 2 lines
Fixes a8ac88585da1 ("vhost: Add Shadow VirtQueue call forwarding capabilities")Cc Eugenio Pérez <[email protected]>
Let's cc stable and post this as an independent patch.
Quoted 2 lines
Signed-off-by Si-Wei Liu <[email protected]>
Thanks
PATCH 35/40 vdpa: add vhost_vdpa_set_address_space_id trace
In reply to Si-Wei LiuFor better debuggability and observability.
--- net/trace-events | 3 +++ net/vhost-vdpa.c | 3 +++ 2 files changed, 6 insertions(+)
net/trace-events +3 -0
@@ -23,3 +23,6 @@ colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int hdlen, in # filter-rewriter.c colo_filter_rewriter_pkt_info(const char *func, const char *src, const char *dst, uint32_t seq, uint32_t ack, uint32_t flag) "%s: src/dst: %s/%s p: seq/ack=%u/%u flags=0x%x" colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" + +# vhost-vdpa.c +vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u"
net/vhost-vdpa.c +3 -0
@@ -30,6 +30,7 @@#include "migration/misc.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-vdpa.h" +#include "trace.h" /* Todo:need to add the multiqueue support here */ typedef struct VhostVDPAState {
@@ -365,6 +366,8 @@ static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, };int r; +trace_vhost_vdpa_set_address_space_id (v, vq_group, asid_num); + r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid);if (unlikely (r <0 )) { error_report("Can't set vq group %u asid %u, errno=%d (%s)",
Signature · 1 line
1.8.3.1
Re: [PATCH 35/40] vdpa: add vhost_vdpa_set_address_space_id trace
Quoted 4 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>
Quoted 40 lines
--- net/trace-events | 3 +++ net/vhost-vdpa.c | 3 +++ 2 files changed, 6 insertions(+)net/trace-events +3
-0@@ -23,3 +23,6 @@ colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int hdlen, in # filter-rewriter.c colo_filter_rewriter_pkt_info(const char *func, const char *src, const char *dst, uint32_t seq, uint32_t ack, uint32_t flag) "%s: src/dst: %s/%s p: seq/ack=%u/%u flags=0x%x" colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" + +# vhost-vdpa.c +vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u"net/vhost-vdpa.c +3
-1@@ -30,6 +30,7 @@#include "migration/misc.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-vdpa.h" +#include "trace.h" /* Todo:need to add the multiqueue support here */ typedef struct VhostVDPAState {@@ -365,6 +366,8 @@ static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, };int r; +trace_vhost_vdpa_set_address_space_id (v, vq_group, asid_num); + r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid);if (unlikely (r <0 )) { error_report("Can't set vq group %u asid %u, errno=%d (%s)", --1.8.3.1
Re: [PATCH 35/40] vdpa: add vhost_vdpa_set_address_space_id trace
In reply to Si-Wei LiuQuoted 14 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>--- net/trace-events | 3 +++ net/vhost-vdpa.c | 3 +++ 2 files changed, 6 insertions(+)net/trace-events +0
-0
net/trace-events colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int hdlen, in · line 28
Quoted 6 lines
net/trace-events +3
-0@@ -23,3 +23,6 @@ colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int hdlen, in # filter-rewriter.c colo_filter_rewriter_pkt_info(const char *func, const char *src, const char *dst, uint32_t seq, uint32_t ack, uint32_t flag) "%s: src/dst: %s/%s p: seq/ack=%u/%u flags=0x%x" colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" + +# vhost-vdpa.c +vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u"
So pointer is not user friendly, how about using the name of the netclient?
Thanks
Quoted 24 lines
net/vhost-vdpa.c +3
-1@@ -30,6 +30,7 @@#include "migration/misc.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-vdpa.h" +#include "trace.h" /* Todo:need to add the multiqueue support here */ typedef struct VhostVDPAState {@@ -365,6 +366,8 @@ static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, };int r; +trace_vhost_vdpa_set_address_space_id (v, vq_group, asid_num); + r =ioctl (v->shared->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid);if (unlikely (r <0 )) { error_report("Can't set vq group %u asid %u, errno=%d (%s)", --1.8.3.1
PATCH 36/40 vdpa: add vhost_vdpa_get_vring_base trace for svq mode
In reply to Si-Wei LiuFor better debuggability and observability.
--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
hw/virtio/trace-events +1 -1
@@ -58,7 +58,7 @@ vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int r vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64 vhost_vdpa_set_vring_num(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" vhost_vdpa_set_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" -vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" +vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_set_vring_kick(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64
hw/virtio/vhost-vdpa.c +2 -1
@@ -1607,6 +1607,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev,if (v->shadow_vqs_enabled) { ring->num =virtio_queue_get_last_avail_idx (dev->vdev, ring->index); +trace_vhost_vdpa_get_vring_base (dev, ring->index, ring->num, true);return 0 ; }
@@ -1619,7 +1620,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, } ret =vhost_vdpa_call (dev,VHOST_GET_VRING_BASE , ring); -trace_vhost_vdpa_get_vring_base (dev, ring->index, ring->num); +trace_vhost_vdpa_get_vring_base (dev, ring->index, ring->num, false);return ret; }
Signature · 1 line
1.8.3.1
Re: [PATCH 36/40] vdpa: add vhost_vdpa_get_vring_base trace for svq mode
Quoted 4 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>
Quoted 42 lines
--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)hw/virtio/trace-events +1
-1@@ -58,7 +58,7 @@ vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int r vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64 vhost_vdpa_set_vring_num(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" vhost_vdpa_set_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" -vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" +vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_set_vring_kick(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64hw/virtio/vhost-vdpa.c +2
-2@@ -1607,6 +1607,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev,if (v->shadow_vqs_enabled) { ring->num =virtio_queue_get_last_avail_idx (dev->vdev, ring->index); +trace_vhost_vdpa_get_vring_base (dev, ring->index, ring->num, true);return 0 ; }@@ -1619,7 +1620,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, } ret =vhost_vdpa_call (dev,VHOST_GET_VRING_BASE , ring); -trace_vhost_vdpa_get_vring_base (dev, ring->index, ring->num); +trace_vhost_vdpa_get_vring_base (dev, ring->index, ring->num, false);return ret; } --1.8.3.1
Re: [PATCH 36/40] vdpa: add vhost_vdpa_get_vring_base trace for svq mode
In reply to Si-Wei LiuQuoted 14 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)hw/virtio/trace-events +0
-0
hw/virtio/trace-events vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int r · line 61
Quoted 5 lines
hw/virtio/trace-events +1
-1@@ -58,7 +58,7 @@ vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int r vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64 vhost_vdpa_set_vring_num(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" vhost_vdpa_set_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" -vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" +vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d"
In the future, it might be better to use the name of VirtIODevice as well as vq index instead of pointer. But consider %p has been used, so
Thanks
PATCH 37/40 vdpa: add vhost_vdpa_set_dev_vring_base trace for svq mode
In reply to Si-Wei LiuFor better debuggability and observability.
--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)
hw/virtio/trace-events +1 -1
@@ -57,7 +57,7 @@ vhost_vdpa_dev_start(void *dev, bool started) "dev: %p started: %d" vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int refcnt, int fd, void *log) "dev: %p base: 0x%"PRIx64" size: %llu refcnt: %d fd: %d log: %p" vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64 vhost_vdpa_set_vring_num(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" -vhost_vdpa_set_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" +vhost_vdpa_set_dev_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_set_vring_kick(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d"
hw/virtio/vhost-vdpa.c +4 -1
@@ -1043,7 +1043,10 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config,static int vhost_vdpa_set_dev_vring_base (struct vhost_dev *dev,struct vhost_vring_state *ring) { -trace_vhost_vdpa_set_vring_base (dev, ring->index, ring->num); +struct vhost_vdpa *v = dev->opaque; + +trace_vhost_vdpa_set_dev_vring_base (dev, ring->index, ring->num, + v->shadow_vqs_enabled);return vhost_vdpa_call (dev,VHOST_SET_VRING_BASE , ring); }
Signature · 1 line
1.8.3.1
Re: [PATCH 37/40] vdpa: add vhost_vdpa_set_dev_vring_base trace for svq mode
Quoted 4 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>
Quoted 37 lines
--- hw/virtio/trace-events | 2 +- hw/virtio/vhost-vdpa.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)hw/virtio/trace-events +1
-1@@ -57,7 +57,7 @@ vhost_vdpa_dev_start(void *dev, bool started) "dev: %p started: %d" vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int refcnt, int fd, void *log) "dev: %p base: 0x%"PRIx64" size: %llu refcnt: %d fd: %d log: %p" vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64 vhost_vdpa_set_vring_num(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" -vhost_vdpa_set_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" +vhost_vdpa_set_dev_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_set_vring_kick(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d"hw/virtio/vhost-vdpa.c +4
-2@@ -1043,7 +1043,10 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config,static int vhost_vdpa_set_dev_vring_base (struct vhost_dev *dev,struct vhost_vring_state *ring) { -trace_vhost_vdpa_set_vring_base (dev, ring->index, ring->num); +struct vhost_vdpa *v = dev->opaque; + +trace_vhost_vdpa_set_dev_vring_base (dev, ring->index, ring->num, + v->shadow_vqs_enabled);return vhost_vdpa_call (dev,VHOST_SET_VRING_BASE , ring); } --1.8.3.1
Re: [PATCH 37/40] vdpa: add vhost_vdpa_set_dev_vring_base trace for svq mode
In reply to Si-Wei LiuQuoted 4 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>
Thanks
PATCH 38/40 vdpa: add trace events for eval_flush
In reply to Si-Wei LiuFor better debuggability and observability.
--- net/trace-events | 2 ++ net/vhost-vdpa.c | 7 +++++++ 2 files changed, 9 insertions(+)
net/trace-events +2 -0
@@ -26,3 +26,5 @@ colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" # vhost-vdpa.c vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u" +vhost_vdpa_net_data_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" +vhost_vdpa_net_cvq_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d"
net/vhost-vdpa.c +7 -0
@@ -608,6 +608,9 @@ static void vhost_vdpa_net_data_eval_flush(NetClientState *nc, bool stop) v->desc_group < 0) { v->shared->flush_map = true; } +trace_vhost_vdpa_net_data_eval_flush (v, s->vhost_vdpa.index, + v->shared->svq_switching, + v->shared->flush_map); }static NetClientInfo net_vhost_vdpa_info = {
@@ -1457,6 +1460,10 @@ static void vhost_vdpa_net_cvq_eval_flush(NetClientState *nc, bool stop) !s->cvq_isolated && v->desc_group < 0) { v->shared->flush_map = true; } + +trace_vhost_vdpa_net_cvq_eval_flush (v, s->vhost_vdpa.index, + v->shared->svq_switching, + v->shared->flush_map); }static NetClientInfo net_vhost_vdpa_cvq_info = {
Signature · 1 line
1.8.3.1
Re: [PATCH 38/40] vdpa: add trace events for eval_flush
net/vhost-vdpa.c static void vhost_vdpa_net_cvq_eval_flush(NetClientState *nc, bool stop)
Quoted 34 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>--- net/trace-events | 2 ++ net/vhost-vdpa.c | 7 +++++++ 2 files changed, 9 insertions(+)net/trace-events +2
-0@@ -26,3 +26,5 @@ colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" # vhost-vdpa.c vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u" +vhost_vdpa_net_data_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" +vhost_vdpa_net_cvq_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d"net/vhost-vdpa.c +3
-0@@ -608,6 +608,9 @@ static void vhost_vdpa_net_data_eval_flush(NetClientState *nc, bool stop) v->desc_group < 0) { v->shared->flush_map = true; } +trace_vhost_vdpa_net_data_eval_flush (v, s->vhost_vdpa.index, + v->shared->svq_switching, + v->shared->flush_map); }static NetClientInfo net_vhost_vdpa_info = {@@ -1457,6 +1460,10 @@ static void vhost_vdpa_net_cvq_eval_flush(NetClientState *nc, bool stop)
For even better debuggability and observability.
Is it better to squash this into the patch into vhost_vdpa_net_cvq_eval_flush()?
Thanks
Quoted 13 lines
net/vhost-vdpa.c +4
-1!s->cvq_isolated && v->desc_group < 0) { v->shared->flush_map = true; } + +trace_vhost_vdpa_net_cvq_eval_flush (v, s->vhost_vdpa.index, + v->shared->svq_switching, + v->shared->flush_map); }static NetClientInfo net_vhost_vdpa_cvq_info = { --1.8.3.1
PATCH 39/40 vdpa: add trace events for vhost_vdpa_net_load_cmd
In reply to Si-Wei LiuFor better debuggability and observability.
--- net/trace-events | 2 ++ net/vhost-vdpa.c | 2 ++ 2 files changed, 4 insertions(+)
net/trace-events +2 -0
@@ -28,3 +28,5 @@ colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u" vhost_vdpa_net_data_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" vhost_vdpa_net_cvq_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" +vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d" +vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d"
net/vhost-vdpa.c +2 -0
@@ -885,6 +885,7 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s,assert (data_size <vhost_vdpa_net_cvq_cmd_page_len () -sizeof (ctrl)); cmd_size =sizeof (ctrl) + data_size; +trace_vhost_vdpa_net_load_cmd (s, class, cmd, data_num, data_size);if (vhost_svq_available_slots (svq) <2 ||iov_size (out_cursor,1 ) < cmd_size) {/*
@@ -916,6 +917,7 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, r =vhost_vdpa_net_cvq_add (s, &out,1 , &in,1 );if (unlikely (r <0 )) { +trace_vhost_vdpa_net_load_cmd_retval (s, class, cmd, r);return r; }
Signature · 1 line
1.8.3.1
Re: [PATCH 39/40] vdpa: add trace events for vhost_vdpa_net_load_cmd
Quoted 4 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>
Quoted 38 lines
--- net/trace-events | 2 ++ net/vhost-vdpa.c | 2 ++ 2 files changed, 4 insertions(+)net/trace-events +2
-0@@ -28,3 +28,5 @@ colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u" vhost_vdpa_net_data_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" vhost_vdpa_net_cvq_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" +vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d" +vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d"net/vhost-vdpa.c +2
-1@@ -885,6 +885,7 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s,assert (data_size <vhost_vdpa_net_cvq_cmd_page_len () -sizeof (ctrl)); cmd_size =sizeof (ctrl) + data_size; +trace_vhost_vdpa_net_load_cmd (s, class, cmd, data_num, data_size);if (vhost_svq_available_slots (svq) <2 ||iov_size (out_cursor,1 ) < cmd_size) {/* @@ -916,6 +917,7 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, r =vhost_vdpa_net_cvq_add (s, &out,1 , &in,1 );if (unlikely (r <0 )) { +trace_vhost_vdpa_net_load_cmd_retval (s, class, cmd, r);return r; } --1.8.3.1
PATCH 40/40 vdpa: add trace event for vhost_vdpa_net_load_mq
In reply to Si-Wei LiuFor better debuggability and observability.
--- net/trace-events | 1 + net/vhost-vdpa.c | 2 ++ 2 files changed, 3 insertions(+)
net/trace-events +1 -0
@@ -30,3 +30,4 @@ vhost_vdpa_net_data_eval_flush(void *s, int qindex, int svq_switch, bool svq_flu vhost_vdpa_net_cvq_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d" vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d" +vhost_vdpa_net_load_mq(void *s, int ncurqps) "vdpa state: %p current_qpairs: %d"
net/vhost-vdpa.c +2 -0
@@ -1109,6 +1109,8 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,return 0 ; } +trace_vhost_vdpa_net_load_mq (s, n->curr_queue_pairs); + mq.virtqueue_pairs =cpu_to_le16 (n->curr_queue_pairs);const struct iovec data = { .iov_base = &mq,
Signature · 1 line
1.8.3.1
Re: [PATCH 40/40] vdpa: add trace event for vhost_vdpa_net_load_mq
Quoted 4 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>
Quoted 30 lines
--- net/trace-events | 1 + net/vhost-vdpa.c | 2 ++ 2 files changed, 3 insertions(+)net/trace-events +1
-0@@ -30,3 +30,4 @@ vhost_vdpa_net_data_eval_flush(void *s, int qindex, int svq_switch, bool svq_flu vhost_vdpa_net_cvq_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d" vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d" +vhost_vdpa_net_load_mq(void *s, int ncurqps) "vdpa state: %p current_qpairs: %d"net/vhost-vdpa.c +2
-1@@ -1109,6 +1109,8 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,return 0 ; } +trace_vhost_vdpa_net_load_mq (s, n->curr_queue_pairs); + mq.virtqueue_pairs =cpu_to_le16 (n->curr_queue_pairs);const struct iovec data = { .iov_base = &mq, --1.8.3.1
Re: [PATCH 40/40] vdpa: add trace event for vhost_vdpa_net_load_mq
In reply to Si-Wei LiuQuoted 14 lines · Si-Wei Liu
For better debuggability and observability.
Signed-off-by Si-Wei Liu <[email protected]>--- net/trace-events | 1 + net/vhost-vdpa.c | 2 ++ 2 files changed, 3 insertions(+)net/trace-events +0
-0
net/trace-events vhost_vdpa_net_data_eval_flush(void *s, int qindex, int svq_switch, bool svq_flu · line 33
Quoted 4 lines
net/trace-events +1
-0@@ -30,3 +30,4 @@ vhost_vdpa_net_data_eval_flush(void *s, int qindex, int svq_switch, bool svq_flu vhost_vdpa_net_cvq_eval_flush(void *s, int qindex, int svq_switch, bool svq_flush) "vhost_vdpa: %p qp: %d svq_switch: %d flush_map: %d" vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d" vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d" +vhost_vdpa_net_load_mq(void *s, int ncurqps) "vdpa state: %p current_qpairs: %d"
Similarly, I think nc->name looks better than the plain pointer here?
Thanks
Quoted 16 lines
net/vhost-vdpa.c +2
-1@@ -1109,6 +1109,8 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,return 0 ; } +trace_vhost_vdpa_net_load_mq (s, n->curr_queue_pairs); + mq.virtqueue_pairs =cpu_to_le16 (n->curr_queue_pairs);const struct iovec data = { .iov_base = &mq, --1.8.3.1
Quoted 12 lines · Si-Wei Liu
This patch series contain several enhancements to SVQ live migration downtime for vDPA-net hardware device, specifically on
mlx5_vdpa. Currently it is based off of Eugenio's RFC v2 .load_setup series [1] to utilize the shared facility and reduce frictions in merging or duplicating code if at all possible.It's stacked up in particular order as below, as the optimization for one on the top has to depend on others on the bottom. Here's a breakdown for what each part does respectively:
Patch # | Feature / optimization
---------V-------------------------------------------------------------------
Quoted 8 lines
35 - 40 | trace events 34 | migrate_cancel bug fix 21 - 33 | (Un)map batching at stop-n-copy to further optimize LM down time 11 - 20 | persistent IOTLB [3] to improve LM down time 02 - 10 | SVQ descriptor ASID [2] to optimize SVQ switching 01 | dependent linux headersV
Hi Si-Wei,
Thanks for the series, I think it contains great additions for the live migration solution!
It is pretty large though. Do you think it would be feasible to split out the fixes and the tracing patches in a separated series? That would allow the reviews to focus on the downtime reduction. I think I acked all of them.
Maybe we can even create a third series for the vring asid? I think we should note an increase on performance using svq so it justifies by itself too.
Quoted 32 lines
Let's first define 2 sources of downtime that this work is concerned with:
* SVQ switching downtime (Downtime #1): downtime at the start of migration. Time spent on teardown and setup for SVQ mode switching, and this downtime is regarded as the maxium time for an individual vdpa-net device. No memory transfer is involved during SVQ switching, hence no .
* LM downtime (Downtime #2): aggregated downtime for all vdpa-net devices on resource teardown and setup in the last stop-n-copy phase on source host.
With each part of the optimizations applied bottom up, the effective outcome in terms of down time (in seconds) performance can be observed in this table:
| Downtime #1 | Downtime #2
--------------------+-------------------+-------------------Baseline QEMU | 20s ~ 30s | 20s | | Iterative map | | at destination[1] | 5s | 20s | | SVQ descriptor | | ASID [2] | 2s | 5s | | | | persistent IOTLB | 2s | 2s [3] | | | | (Un)map batching | | at stop-n-copy | 1.7s | 1.5s before switchover | |
Quoted 2 lines
(VM config: 128GB mem, 2
mlx5_vdpadevices, each w/ 4 data vqs)
Thanks for all the profiling, it looks promising!
Quoted 70 lines
Please find the details regarding each enhancement on the commit log.
Thanks,
-Siwei[1] [RFC PATCH v2 00/10] Map memory at destination .load_setup in vDPA-net migration
https://lists.nongnu.org/archive/html/qemu-devel/2023-11/msg05711.html
[2]VHOST_BACKEND_F_DESC_ASID
https://lore.kernel.org/virtualization/[email protected]/
[3]VHOST_BACKEND_F_IOTLB_PERSIST
https://lore.kernel.org/virtualization/[email protected]/---
Si-Wei Liu (40):
linux-headers: addvhost_types.handvhost.h
vdpa: addvhost_vdpa_get_vring_desc_group
vdpa: probe descriptor group index for data vqs
vdpa: piggybackdesc_groupindex when probing isolated cvq
vdpa: populatedesc_groupfromnet_vhost_vdpa_init
vhost: make svq work with gpa without iova translation
vdpa: move aroundvhost_vdpa_set_address_space_id
vdpa: add backvhost_vdpa_net_first_nc_vdpa
vdpa: no repeat settingshadow_data
vdpa: assign svq descriptors a separate ASID when possible
vdpa: factor outvhost_vdpa_last_dev
vdpa: checkmap_thread_enabledbefore join maps thread
vdpa: ref counting VhostVDPAShared
vdpa: convertiova_treeto ref count based
vdpa: addsvq_switchingandflush_mapto header
vdpa: indicate SVQ switching via flag
vdpa: judge if map can be kept across reset
vdpa: unregister listener on last dev cleanup
vdpa: should avoid map flushing with persistent iotlb
vdpa: avoid mapping flush across reset
vdpa:vhost_vdpa_dma_batch_end_oncerename
vdpa: factor outvhost_vdpa_map_batch_begin
vdpa:vhost_vdpa_dma_batch_begin_oncerename
vdpa: factor outvhost_vdpa_dma_batch_end
vdpa: add asid todma_batch_onceAPI
vdpa: return int fordma_batch_onceAPI
vdpa: add asid to alldma_batchcall sites
vdpa: supportiotlb_batch_asid
vdpa: expose APIvhost_vdpa_dma_batch_once
vdpa: batch map/unmap op per svq pair basis
vdpa: batch map and unmap around cvq svq start/stop
vdpa: factor outvhost_vdpa_net_get_nc_vdpa
vdpa: batch multipledma_unmapto a single call for vm stop
vdpa: fix network breakage after cancelling migration
vdpa: addvhost_vdpa_set_address_space_idtrace
vdpa: addvhost_vdpa_get_vring_basetrace for svq mode
vdpa: addvhost_vdpa_set_dev_vring_basetrace for svq mode
vdpa: add trace events foreval_flush
vdpa: add trace events forvhost_vdpa_net_load_cmd
vdpa: add trace event forvhost_vdpa_net_load_mqhw/virtio/trace-events | 9 +- hw/virtio/vhost-shadow-virtqueue.c | 35 ++- hw/virtio/vhost-vdpa.c | 156 +++++++--- include/hw/virtio/vhost-vdpa.h | 16 + include/standard-headers/linux/vhost_types.h | 13 + linux-headers/linux/vhost.h | 9 + net/trace-events | 8 + net/vhost-vdpa.c | 434 ++++++++++++++++++++++----- 8 files changed, 558 insertions(+), 122 deletions(-)--
1.8.3.1
Quoted 52 lines · Si-Wei Liu
This patch series contain several enhancements to SVQ live migration downtime for vDPA-net hardware device, specifically on
mlx5_vdpa. Currently it is based off of Eugenio's RFC v2 .load_setup series [1] to utilize the shared facility and reduce frictions in merging or duplicating code if at all possible.It's stacked up in particular order as below, as the optimization for one on the top has to depend on others on the bottom. Here's a breakdown for what each part does respectively:
Patch # | Feature / optimization
---------V-------------------------------------------------------------------35 - 40 | trace events 34 | migrate_cancel bug fix 21 - 33 | (Un)map batching at stop-n-copy to further optimize LM down time 11 - 20 | persistent IOTLB [3] to improve LM down time 02 - 10 | SVQ descriptor ASID [2] to optimize SVQ switching 01 | dependent linux headersV
Let's first define 2 sources of downtime that this work is concerned with:
* SVQ switching downtime (Downtime #1): downtime at the start of migration. Time spent on teardown and setup for SVQ mode switching, and this downtime is regarded as the maxium time for an individual vdpa-net device. No memory transfer is involved during SVQ switching, hence no .
* LM downtime (Downtime #2): aggregated downtime for all vdpa-net devices on resource teardown and setup in the last stop-n-copy phase on source host.
With each part of the optimizations applied bottom up, the effective outcome in terms of down time (in seconds) performance can be observed in this table:
| Downtime #1 | Downtime #2
--------------------+-------------------+-------------------Baseline QEMU | 20s ~ 30s | 20s | | Iterative map | | at destination[1] | 5s | 20s | | SVQ descriptor | | ASID [2] | 2s | 5s | | | | persistent IOTLB | 2s | 2s [3] | | | | (Un)map batching | | at stop-n-copy | 1.7s | 1.5s before switchover | |
Quoted 1 line
(VM config: 128GB mem, 2
mlx5_vdpadevices, each w/ 4 data vqs)
This looks promising!
But the series looks a little bit huge, can we split them into 2 or 3 series?
It helps to speed up the reviewing and merging.
Thanks
Quoted 71 lines
Please find the details regarding each enhancement on the commit log.
Thanks,
-Siwei[1] [RFC PATCH v2 00/10] Map memory at destination .load_setup in vDPA-net migration
https://lists.nongnu.org/archive/html/qemu-devel/2023-11/msg05711.html
[2]VHOST_BACKEND_F_DESC_ASID
https://lore.kernel.org/virtualization/[email protected]/
[3]VHOST_BACKEND_F_IOTLB_PERSIST
https://lore.kernel.org/virtualization/[email protected]/---
Si-Wei Liu (40):
linux-headers: addvhost_types.handvhost.h
vdpa: addvhost_vdpa_get_vring_desc_group
vdpa: probe descriptor group index for data vqs
vdpa: piggybackdesc_groupindex when probing isolated cvq
vdpa: populatedesc_groupfromnet_vhost_vdpa_init
vhost: make svq work with gpa without iova translation
vdpa: move aroundvhost_vdpa_set_address_space_id
vdpa: add backvhost_vdpa_net_first_nc_vdpa
vdpa: no repeat settingshadow_data
vdpa: assign svq descriptors a separate ASID when possible
vdpa: factor outvhost_vdpa_last_dev
vdpa: checkmap_thread_enabledbefore join maps thread
vdpa: ref counting VhostVDPAShared
vdpa: convertiova_treeto ref count based
vdpa: addsvq_switchingandflush_mapto header
vdpa: indicate SVQ switching via flag
vdpa: judge if map can be kept across reset
vdpa: unregister listener on last dev cleanup
vdpa: should avoid map flushing with persistent iotlb
vdpa: avoid mapping flush across reset
vdpa:vhost_vdpa_dma_batch_end_oncerename
vdpa: factor outvhost_vdpa_map_batch_begin
vdpa:vhost_vdpa_dma_batch_begin_oncerename
vdpa: factor outvhost_vdpa_dma_batch_end
vdpa: add asid todma_batch_onceAPI
vdpa: return int fordma_batch_onceAPI
vdpa: add asid to alldma_batchcall sites
vdpa: supportiotlb_batch_asid
vdpa: expose APIvhost_vdpa_dma_batch_once
vdpa: batch map/unmap op per svq pair basis
vdpa: batch map and unmap around cvq svq start/stop
vdpa: factor outvhost_vdpa_net_get_nc_vdpa
vdpa: batch multipledma_unmapto a single call for vm stop
vdpa: fix network breakage after cancelling migration
vdpa: addvhost_vdpa_set_address_space_idtrace
vdpa: addvhost_vdpa_get_vring_basetrace for svq mode
vdpa: addvhost_vdpa_set_dev_vring_basetrace for svq mode
vdpa: add trace events foreval_flush
vdpa: add trace events forvhost_vdpa_net_load_cmd
vdpa: add trace event forvhost_vdpa_net_load_mqhw/virtio/trace-events | 9 +- hw/virtio/vhost-shadow-virtqueue.c | 35 ++- hw/virtio/vhost-vdpa.c | 156 +++++++--- include/hw/virtio/vhost-vdpa.h | 16 + include/standard-headers/linux/vhost_types.h | 13 + linux-headers/linux/vhost.h | 9 + net/trace-events | 8 + net/vhost-vdpa.c | 434 ++++++++++++++++++++++----- 8 files changed, 558 insertions(+), 122 deletions(-)--
1.8.3.1