Move memory listener register to vhost_vdpa_init
v2 cover Move memory listener register to vhost_vdpa_init
Current memory operations like pinning may take a lot of time at the destination. Currently they are done after the source of the migration is stopped, and before the workload is resumed at the destination. This is a period where neigher traffic can flow, nor the VM workload can continue (downtime).
We can do better as we know the memory layout of the guest RAM at the destination from the moment that all devices are initializaed. So moving that operation allows QEMU to communicate the kernel the maps while the workload is still running in the source, so Linux can start mapping them.
As a small drawback, there is a time in the initialization where QEMU cannot respond to QMP etc. By some testing, this time is about 0.2seconds. This may be further reduced (or increased) depending on the vdpa driver and the platform hardware, and it is dominated by the cost of memory pinning.
This matches the time that we move out of the called downtime window. The downtime is measured as checking the trace timestamp from the moment the source suspend the device to the moment the destination starts the eight and last virtqueue pair. For a 39G guest, it goes from ~2.2526 secs to 2.0949.
Future directions on top of this series may include to move more things ahead of the migration time, like set DRIVER_OK or perform actual iterative migration of virtio-net devices.
Comments are welcome.
This series is a different approach of series [1]. As the title does not reflect the changes anymore, please refer to the previous one to know the series history.
This series is based on [2], it must be applied after it.
v2:
* Move the memory listener registration to vhost_vdpa_set_owner function.
* Move the iova_tree allocation to net_vhost_vdpa_init.
v1 at https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg02136.html .
[1] https://patchwork.kernel.org/project/qemu-devel/cover/[email protected]/
[2] https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg05910.html
Eugenio Pérez (7):
vdpa: check for iova tree initialized at net_client_start
vdpa: reorder vhost_vdpa_set_backend_cap
vdpa: set backend capabilities at vhost_vdpa_init
vdpa: add listener_registered
vdpa: reorder listener assignment
vdpa: move iova_tree allocation to net_vhost_vdpa_init
vdpa: move memory listener register to vhost_vdpa_init
hw/virtio/vhost-vdpa.c | 98 ++++++++++++++++++++++------------ include/hw/virtio/vhost-vdpa.h | 22 +++++++- net/vhost-vdpa.c | 34 ++---------- 3 files changed, 88 insertions(+), 66 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 6/7 vdpa: move iova_tree allocation to net_vhost_vdpa_init
As we are moving to keep the mapping through all the vdpa device life instead of resetting it at VirtIO reset, we need to move all its dependencies to the initialization too. In particular devices with x-svq=on need a valid iova_tree from the beginning.
Simplify the code also consolidating the two creation points: the first data vq in case of SVQ active and CVQ start in case only CVQ uses it.
--- include/hw/virtio/vhost-vdpa.h | 16 ++++++++++++++- net/vhost-vdpa.c | 36 +++------------------------------- 2 files changed, 18 insertions(+), 34 deletions(-)
include/hw/virtio/vhost-vdpa.h +15 -1
@@ -37,7 +37,21 @@ typedef struct vhost_vdpa_shared {struct vhost_vdpa_iova_range iova_range; QLIST_HEAD(, vdpa_iommu) iommu_list; -/* IOVA mapping used by the Shadow Virtqueue */ +/* +* IOVA mapping used by the Shadow Virtqueue +* +* It is shared among all ASID for simplicity, whether CVQ shares ASID with +* guest or not: +* - Memory listener need access to guest's memory addresses allocated in +* the IOVA tree. +* - There should be plenty of IOVA address space for both ASID not to +* worry about collisions between them. Guest's translations are still +* validated with virtio virtqueue_pop so there is no risk for the guest +* to access memory that it shouldn't. +* +* To allocate a iova tree per ASID is doable but it complicates the code +* and it is not worth it for the moment. +*/ VhostIOVATree *iova_tree;/* Copy of backend features */
net/vhost-vdpa.c +3 -33
@@ -232,6 +232,7 @@ static void vhost_vdpa_cleanup(NetClientState *nc)return ; }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); }
@@ -329,16 +330,8 @@ static void vdpa_net_migration_state_notifier(Notifier *notifier, void *data)static void vhost_vdpa_net_data_start_first (VhostVDPAState *s) { -struct vhost_vdpa *v = &s->vhost_vdpa; -migration_add_notifier (&s->migration_state, vdpa_net_migration_state_notifier); - -/* iova_tree may be initialized by vhost_vdpa_net_load_setup */ -if (v->shadow_vqs_enabled && !v->shared->iova_tree) { - v->shared->iova_tree =vhost_iova_tree_new (v->shared->iova_range.first, - v->shared->iova_range.last); - } }static int vhost_vdpa_net_data_start (NetClientState *nc)
@@ -383,19 +376,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 NetClientInfo net_vhost_vdpa_info = {
@@ -557,24 +543,6 @@ out:return 0 ; } -/* -* If other vhost_vdpa already have an iova_tree, reuse it for simplicity, -* whether CVQ shares ASID with guest or not, because: -* - Memory listener need access to guest's memory addresses allocated in -* the IOVA tree. -* - There should be plenty of IOVA address space for both ASID not to -* worry about collisions between them. Guest's translations are still -* validated with virtio virtqueue_pop so there is no risk for the guest -* to access memory that it shouldn't. -* -* To allocate a iova tree per ASID is doable but it complicates the code -* and it is not worth it for the moment. -*/ -if (!v->shared->iova_tree) { - v->shared->iova_tree =vhost_iova_tree_new (v->shared->iova_range.first, - v->shared->iova_range.last); - } - 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 )) {
@@ -1674,6 +1642,8 @@ 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->iova_tree =vhost_iova_tree_new (iova_range.first, + iova_range.last); }else if (!is_datapath) { s->cvq_cmd_out_buffer = mmap(NULL, vhost_vdpa_net_cvq_cmd_page_len(), PROT_READ | PROT_WRITE,
Signature · 1 line
2.43.0
PATCH v2 2/7 vdpa: reorder vhost_vdpa_set_backend_cap
In reply to Eugenio PérezIt will be used directly by vhost_vdpa_init.
--- hw/virtio/vhost-vdpa.c | 60 +++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-)
hw/virtio/vhost-vdpa.c +30 -30
@@ -580,6 +580,36 @@ static void vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v) v->shadow_vqs =g_steal_pointer (&shadow_vqs); } +static int vhost_vdpa_set_backend_cap (struct vhost_dev *dev) +{ +struct vhost_vdpa *v = dev->opaque; + +uint64_t features; +uint64_t f =0x1ULL <<VHOST_BACKEND_F_IOTLB_MSG_V2 | +0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH | +0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID | +0x1ULL <<VHOST_BACKEND_F_SUSPEND ; +int r; + +if (vhost_vdpa_call (dev,VHOST_GET_BACKEND_FEATURES , &features)) { +return -EFAULT ; + } + + features &= f; + +if (vhost_vdpa_first_dev (dev)) { + r =vhost_vdpa_call (dev,VHOST_SET_BACKEND_FEATURES , &features); +if (r) { +return -EFAULT ; + } + } + + dev->backend_cap = features; + v->shared->backend_cap = features; + +return 0 ; +} +static int vhost_vdpa_init (struct vhost_dev *dev,void *opaque,Error **errp) {struct vhost_vdpa *v = opaque;
@@ -827,36 +857,6 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,return vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_FEATURES_OK ); } -static int vhost_vdpa_set_backend_cap (struct vhost_dev *dev) -{ -struct vhost_vdpa *v = dev->opaque; - -uint64_t features; -uint64_t f =0x1ULL <<VHOST_BACKEND_F_IOTLB_MSG_V2 | -0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH | -0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID | -0x1ULL <<VHOST_BACKEND_F_SUSPEND ; -int r; - -if (vhost_vdpa_call (dev,VHOST_GET_BACKEND_FEATURES , &features)) { -return -EFAULT ; - } - - features &= f; - -if (vhost_vdpa_first_dev (dev)) { - r =vhost_vdpa_call (dev,VHOST_SET_BACKEND_FEATURES , &features); -if (r) { -return -EFAULT ; - } - } - - dev->backend_cap = features; - v->shared->backend_cap = features; - -return 0 ; -} -static int vhost_vdpa_get_device_id (struct vhost_dev *dev,uint32_t *device_id) {
Signature · 1 line
2.43.0
PATCH v2 3/7 vdpa: set backend capabilities at vhost_vdpa_init
In reply to Eugenio PérezThe backend does not reset them until the vdpa file descriptor is closed so there is no harm in doing it only once.
This allows the destination of a live migration to premap memory in batches, using VHOST_BACKEND_F_IOTLB_BATCH.
--- hw/virtio/vhost-vdpa.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +6 -1
@@ -620,6 +620,12 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) v->dev = dev; dev->opaque = opaque ; v->shared->listener = vhost_vdpa_memory_listener; + + ret =vhost_vdpa_set_backend_cap (dev); +if (unlikely (ret !=0 )) { +return ret; + } +vhost_vdpa_init_svq (dev, v);error_propagate (&dev->migration_blocker, v->migration_blocker);
@@ -1506,7 +1512,6 @@ const VhostOps vdpa_ops = { .vhost_set_vring_kick = vhost_vdpa_set_vring_kick, .vhost_set_vring_call = vhost_vdpa_set_vring_call, .vhost_get_features = vhost_vdpa_get_features, - .vhost_set_backend_cap = vhost_vdpa_set_backend_cap, .vhost_set_owner = vhost_vdpa_set_owner, .vhost_set_vring_endian = NULL, .vhost_backend_memslots_limit = vhost_vdpa_memslots_limit,
Signature · 1 line
2.43.0
PATCH v2 4/7 vdpa: add listener_registered
In reply to Eugenio PérezCheck if the listener has been registered or not, so it needs to be registered again at start.
--- hw/virtio/vhost-vdpa.c | 7 ++++++- include/hw/virtio/vhost-vdpa.h | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +6 -1
@@ -1331,7 +1331,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) "IOMMU and try again");return -1 ; } -memory_listener_register (&v->shared->listener, dev->vdev->dma_as); +if (!v->shared->listener_registered) { +memory_listener_register (&v->shared->listener, dev->vdev->dma_as); + v->shared->listener_registered = true; + }return vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_DRIVER_OK ); }
@@ -1351,6 +1354,8 @@ static void vhost_vdpa_reset_status(struct vhost_dev *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; + } static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base,
include/hw/virtio/vhost-vdpa.h +6 -0
@@ -45,6 +45,12 @@ typedef struct vhost_vdpa_shared {bool iotlb_batch_begin_sent; +/* +* The memory listener has been registered, so DMA maps have been sent to +* the device. +*/ +bool listener_registered; +/* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */ bool shadow_data; } VhostVDPAShared;
Signature · 1 line
2.43.0
PATCH v2 7/7 vdpa: move memory listener register to vhost_vdpa_init
In reply to Eugenio PérezCurrent memory operations like pinning may take a lot of time at the destination. Currently they are done after the source of the migration is stopped, and before the workload is resumed at the destination. This is a period where neigher traffic can flow, nor the VM workload can continue (downtime).
We can do better as we know the memory layout of the guest RAM at the destination from the moment that all devices are initializaed. So moving that operation allows QEMU to communicate the kernel the maps while the workload is still running in the source, so Linux can start mapping them.
As a small drawback, there is a time in the initialization where QEMU cannot respond to QMP etc. By some testing, this time is about 0.2seconds. This may be further reduced (or increased) depending on the vdpa driver and the platform hardware, and it is dominated by the cost of memory pinning.
This matches the time that we move out of the called downtime window. The downtime is measured as checking the trace timestamp from the moment the source suspend the device to the moment the destination starts the eight and last virtqueue pair. For a 39G guest, it goes from ~2.2526 secs to 2.0949.
--
v2:
Move the memory listener registration to vhost_vdpa_set_owner function. In case of hotplug the vdpa device, the memory is already set up, and leaving memory listener register call in the init function made maps occur before set owner call.
To be 100% safe, let's put it right after set_owner call.
--- hw/virtio/vhost-vdpa.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +21 -1
@@ -1331,6 +1331,11 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) "IOMMU and try again");return -1 ; } +if (v->shared->listener_registered && + dev->vdev->dma_as != v->shared->listener.address_space) { +memory_listener_unregister (&v->shared->listener); + v->shared->listener_registered = false; + }if (!v->shared->listener_registered) {memory_listener_register (&v->shared->listener, dev->vdev->dma_as); v->shared->listener_registered = true;
@@ -1480,12 +1485,27 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev,static int vhost_vdpa_set_owner (struct vhost_dev *dev) { +int r; +struct vhost_vdpa *v; +if (!vhost_vdpa_first_dev (dev)) {return 0 ; }trace_vhost_vdpa_set_owner (dev); -return vhost_vdpa_call (dev,VHOST_SET_OWNER ,NULL ); + r =vhost_vdpa_call (dev,VHOST_SET_OWNER ,NULL ); +if (unlikely (r <0 )) { +return r; + } + +/* +* Being optimistic and listening address space memory. If the device +* uses vIOMMU, it is changed at vhost_vdpa_dev_start. +*/ + v = dev->opaque; +memory_listener_register (&v->shared->listener, &address_space_memory); + v->shared->listener_registered = true; +return 0 ; } static int vhost_vdpa_vq_get_addr(struct vhost_dev *dev,
Signature · 1 line
2.43.0
PATCH v2 1/7 vdpa: check for iova tree initialized at net_client_start
In reply to Eugenio PérezTo map the guest memory while it is migrating we need to create the iova_tree, as long as the destination uses x-svq=on. Checking to not override it.
The function vhost_vdpa_net_client_stop clear it if the device is stopped. If the guest starts the device again, the iova tree is recreated by vhost_vdpa_net_data_start_first or vhost_vdpa_net_cvq_start if needed, so old behavior is kept.
--- net/vhost-vdpa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/vhost-vdpa.c +3 -1
@@ -333,7 +333,9 @@ static void vhost_vdpa_net_data_start_first(VhostVDPAState *s)migration_add_notifier (&s->migration_state, vdpa_net_migration_state_notifier); -if (v->shadow_vqs_enabled) { + +/* iova_tree may be initialized by vhost_vdpa_net_load_setup */ +if (v->shadow_vqs_enabled && !v->shared->iova_tree) { v->shared->iova_tree =vhost_iova_tree_new (v->shared->iova_range.first, v->shared->iova_range.last); }
Signature · 1 line
2.43.0
PATCH v2 5/7 vdpa: reorder listener assignment
In reply to Eugenio PérezSince commit f6fe3e333f ("vdpa: move memory listener to vhost_vdpa_shared") this piece of code repeatedly assign shared->listener members. This was not a problem as it was not used until device start.
However next patches move the listener registration to this vhost_vdpa_init function. When the listener is registered it is added to an embedded linked list, so setting its members again will cause memory corruption to the linked list node.
Do the right thing and only set it in the first vdpa device.
--- hw/virtio/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +1 -1
@@ -619,7 +619,6 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) v->dev = dev; dev->opaque = opaque ; - v->shared->listener = vhost_vdpa_memory_listener; ret =vhost_vdpa_set_backend_cap (dev);if (unlikely (ret !=0 )) {
@@ -661,6 +660,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_ACKNOWLEDGE |VIRTIO_CONFIG_S_DRIVER ); + v->shared->listener = vhost_vdpa_memory_listener;return 0 ; }
Signature · 1 line
2.43.0
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
In reply to Eugenio PérezHi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Regards,
-Siwei
Quoted 117 lines · Eugenio Pérez
As we are moving to keep the mapping through all the vdpa device life instead of resetting it at VirtIO reset, we need to move all its dependencies to the initialization too. In particular devices with x-svq=on need a valid
iova_treefrom the beginning.Simplify the code also consolidating the two creation points: the first data vq in case of SVQ active and CVQ start in case only CVQ uses it.
Suggested-by Si-Wei Liu <[email protected]>Signed-off-by Eugenio Pérez <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 16 ++++++++++++++- net/vhost-vdpa.c | 36 +++------------------------------- 2 files changed, 18 insertions(+), 34 deletions(-)include/hw/virtio/vhost-vdpa.h +15
-1@@ -37,7 +37,21 @@ typedef struct vhost_vdpa_shared {struct vhost_vdpa_iova_range iova_range; QLIST_HEAD(, vdpa_iommu) iommu_list; -/* IOVA mapping used by the Shadow Virtqueue */ +/* +* IOVA mapping used by the Shadow Virtqueue +* +* It is shared among all ASID for simplicity, whether CVQ shares ASID with +* guest or not: +* - Memory listener need access to guest's memory addresses allocated in +* the IOVA tree. +* - There should be plenty of IOVA address space for both ASID not to +* worry about collisions between them. Guest's translations are still +* validated with virtio virtqueue_pop so there is no risk for the guest +* to access memory that it shouldn't. +* +* To allocate a iova tree per ASID is doable but it complicates the code +* and it is not worth it for the moment. +*/ VhostIOVATree *iova_tree;/* Copy of backend features */ net/vhost-vdpa.c +1
-33@@ -232,6 +232,7 @@ static void vhost_vdpa_cleanup(NetClientState *nc)return ; }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); }@@ -329,16 +330,8 @@ static void vdpa_net_migration_state_notifier(Notifier *notifier, void *data)static void vhost_vdpa_net_data_start_first (VhostVDPAState *s) { -struct vhost_vdpa *v = &s->vhost_vdpa; -migration_add_notifier (&s->migration_state, vdpa_net_migration_state_notifier); - -/* iova_tree may be initialized by vhost_vdpa_net_load_setup */ -if (v->shadow_vqs_enabled && !v->shared->iova_tree) { - v->shared->iova_tree =vhost_iova_tree_new (v->shared->iova_range.first, - v->shared->iova_range.last); - } }static int vhost_vdpa_net_data_start (NetClientState *nc)@@ -383,19 +376,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 NetClientInfo net_vhost_vdpa_info = {@@ -557,24 +543,6 @@ out:return 0 ; } -/* -* If other vhost_vdpa already have an iova_tree, reuse it for simplicity, -* whether CVQ shares ASID with guest or not, because: -* - Memory listener need access to guest's memory addresses allocated in -* the IOVA tree. -* - There should be plenty of IOVA address space for both ASID not to -* worry about collisions between them. Guest's translations are still -* validated with virtio virtqueue_pop so there is no risk for the guest -* to access memory that it shouldn't. -* -* To allocate a iova tree per ASID is doable but it complicates the code -* and it is not worth it for the moment. -*/ -if (!v->shared->iova_tree) { - v->shared->iova_tree =vhost_iova_tree_new (v->shared->iova_range.first, - v->shared->iova_range.last); - } - 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 )) {
net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1649
Quoted 8 lines
net/vhost-vdpa.c +2
-0@@ -1674,6 +1642,8 @@ 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->iova_tree =vhost_iova_tree_new (iova_range.first, + iova_range.last); }else if (!is_datapath) { s->cvq_cmd_out_buffer = mmap(NULL, vhost_vdpa_net_cvq_cmd_page_len(), PROT_READ | PROT_WRITE,
+ qemu-system-x86_64 -no-user-config -nodefaults -machine type=pc-q35-8.0,dump-guest-core=off,accel=kvm,kernel_irqchip=split -cpu EPYC -smp 8,sockets=1,cores=8,threads=1 -m size=128G,slots=8,maxmem=256G -qmp unix:/tmp/q,server,nowait -serial mon:stdio -display vnc=:37 -drive file=/usr/share/OVMF/OVMF_CODE.pure-efi.fd,index=0,if=pflash,format=raw,readonly=on -drive file=/usr/share/OVMF/OVMF_VARS.pure-efi.fd,index=1,if=pflash,format=raw -drive id=disk0,if=none,format=qcow2,file=/root/vdpa/tools/images/VM-el7.9-uefi-x86_64.qcow2 -device virtio-blk-pci,drive=disk0 -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0,x-svq=on -device virtio-net-pci,netdev=vhost-vdpa0,id=vdpa0,bootindex=-1,page-per-vq=on,mac=e4:11:c6:d3:45:f0,ctrl_vq=on,mq=on,ctrl_vlan=off,vectors=6,host_mtu=9000,disable-legacy=on -msg timestamp=on --trace events=/tmp/e [email protected]:vhost_vdpa_init dev: 0x556d459e6e00, common dev: 0x556d45c75140 vdpa: 0x7f991c860190
[email protected]:vhost_vdpa_add_status dev: 0x556d459e6e00 status: 0x3
[email protected]:vhost_vdpa_set_owner dev: 0x556d459e6e00
[email protected]:vhost_vdpa_get_features dev: 0x556d459e6e00 features: 0x300c3182b
[email protected]:vhost_vdpa_memslots_limit dev: 0x556d459e6e00 = 0x7fffffff
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_get_device_id dev: 0x556d459e6e00 device_id 1
[email protected]:vhost_vdpa_init dev: 0x556d45c5e670, common dev: 0x556d45c75140 vdpa: 0x7f991c6d7190
[email protected]:vhost_vdpa_get_features dev: 0x556d45c5e670 features: 0x300c3182b
[email protected]:vhost_vdpa_memslots_limit dev: 0x556d45c5e670 = 0x7fffffff
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d45c5e670 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d45c5e670 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_get_device_id dev: 0x556d45c5e670 device_id 1
[email protected]:vhost_vdpa_init dev: 0x556d45c5eb90, common dev: 0x556d45c75140 vdpa: 0x7f991c68e190
[email protected]:vhost_vdpa_get_features dev: 0x556d45c5eb90 features: 0x300c3182b
[email protected]:vhost_vdpa_memslots_limit dev: 0x556d45c5eb90 = 0x7fffffff
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d45c5eb90 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_get_device_id dev: 0x556d45c5eb90 device_id 1
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0x0 llend 0x80000000 vaddr: 0x7f7903e00000 read-only: 0
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x1000 size: 0x80000000 uaddr: 0x7f7903e00000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0x100000000 llend 0x2080000000 vaddr: 0x7f7983e00000 read-only: 0
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x80001000 size: 0x1f80000000 uaddr: 0x7f7983e00000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0xfeda0000 llend 0xfedc0000 vaddr: 0x7f7903ea0000 read-only: 0
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x2000001000 size: 0x20000 uaddr: 0x7f7903ea0000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0xfeda0000 llend 0xfedbffff
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x1000 size: 0x20000 type: 3
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_set_config dev: 0x556d459e6e00 offset: 0 size: 6 flags: 0x0
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0
[email protected]:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0x0 llend 0x7fffffff
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x2000001000 size: 0x80000000 type: 3
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0x0 llend 0xc0000 vaddr: 0x7f7903e00000 read-only: 0
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x1000 size: 0xc0000 uaddr: 0x7f7903e00000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0xc0000 llend 0xe0000 vaddr: 0x7f7902e00000 read-only: 1
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xc1000 size: 0x20000 uaddr: 0x7f7902e00000 perm: 0x1 type: 2
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0xe0000 llend 0x100000 vaddr: 0x7f9908200000 read-only: 1
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xe1000 size: 0x20000 uaddr: 0x7f9908200000 perm: 0x1 type: 2
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0x100000 llend 0x80000000 vaddr: 0x7f7903f00000 read-only: 0
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x101000 size: 0x7ff00000 uaddr: 0x7f7903f00000 perm: 0x3 type: 2
2024-02-02T06:20:49.080706Z qemu-system-x86_64: failed to write, fd=16, errno=14 (Bad address) 2024-02-02T06:20:49.080732Z qemu-system-x86_64: vhost vdpa map fail! 2024-02-02T06:20:49.080742Z qemu-system-x86_64: vhost-vdpa: DMA mapping failed, unable to continue
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6 [email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0xc0000000 llend 0xc0040000 vaddr: 0x7f7902c00000 read-only: 1 [email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x101000 size: 0x40000 uaddr: 0x7f7902c00000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6 [email protected]:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0xc0000000 llend 0xc003ffff [email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x101000 size: 0x40000 type: 3 [email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f990bb79460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f990bb79460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f990bb79460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f990bb79460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f990bb79460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f990bb79460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f990bb79460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f990bb79460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_set_features dev: 0x556d459e6e00 features: 0x300000008
[email protected]:vhost_vdpa_add_status dev: 0x556d459e6e00 status: 0x8
[email protected]:vhost_vdpa_set_mem_table dev: 0x556d459e6e00 nregions: 3 padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x556d459e6e00 0: guest_phys_addr: 0x0 memory_size: 0xc0000 userspace_addr: 0x7f7903e00000 flags_padding: 0x0 [email protected]:vhost_vdpa_dump_regions dev: 0x556d459e6e00 1: guest_phys_addr: 0x100000 memory_size: 0x7ff00000 userspace_addr: 0x7f7903f00000 flags_padding: 0x0 [email protected]:vhost_vdpa_dump_regions dev: 0x556d459e6e00 2: guest_phys_addr: 0x100000000 memory_size: 0x1f80000000 userspace_addr: 0x7f7983e00000 flags_padding: 0x0 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_set_vring_num dev: 0x556d459e6e00 index: 0 num: 256
[email protected]:vhost_vdpa_vq_get_addr dev: 0x556d459e6e00 vq: 0x556d459e7080 desc_user_addr: 0x7e459000 avail_user_addr: 0x7e45a000 used_user_addr: 0x7e45b000 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_set_vring_num dev: 0x556d459e6e00 index: 1 num: 256
[email protected]:vhost_vdpa_vq_get_addr dev: 0x556d459e6e00 vq: 0x556d459e7100 desc_user_addr: 0x7e45d000 avail_user_addr: 0x7e45e000 used_user_addr: 0x7e45f000 [email protected]:vhost_vdpa_dev_start dev: 0x556d459e6e00 started: 1
[email protected]:vhost_vdpa_set_vring_base dev: 0x556d459e6e00 index: 0 num: 0
[email protected]:vhost_vdpa_set_vring_kick dev: 0x556d459e6e00 index: 0 fd: 49
[email protected]:vhost_vdpa_set_vring_call dev: 0x556d459e6e00 index: 0 fd: 50
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x101000 size: 0x2000 uaddr: 0x7f991c831000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x103000 size: 0x1000 uaddr: 0x7f991ca0b000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_set_vring_addr dev: 0x556d459e6e00 index: 0 flags: 0x0 desc_user_addr: 0x101000 used_user_addr: 0x103000 avail_user_addr: 0x102000 log_guest_addr: 0x0 [email protected]:vhost_vdpa_set_vring_base dev: 0x556d459e6e00 index: 1 num: 0
[email protected]:vhost_vdpa_set_vring_kick dev: 0x556d459e6e00 index: 1 fd: 51
[email protected]:vhost_vdpa_set_vring_call dev: 0x556d459e6e00 index: 1 fd: 52
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x104000 size: 0x2000 uaddr: 0x7f991c82f000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x106000 size: 0x1000 uaddr: 0x7f991c82e000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_set_vring_addr dev: 0x556d459e6e00 index: 1 flags: 0x0 desc_user_addr: 0x104000 used_user_addr: 0x106000 avail_user_addr: 0x105000 log_guest_addr: 0x0 [email protected]:vhost_vdpa_add_status dev: 0x556d459e6e00 status: 0x4
[email protected]:vhost_vdpa_set_config_call dev: 0x556d459e6e00 fd: 45
[email protected]:vhost_vdpa_set_vring_ready dev: 0x556d459e6e00, idx: 0, r: 0
[email protected]:vhost_vdpa_set_vring_ready dev: 0x556d459e6e00, idx: 1, r: 0
[email protected]:vhost_vdpa_dev_start dev: 0x556d459e6e00 started: 0
[email protected]:vhost_vdpa_suspend dev: 0x556d459e6e00
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x101000 size: 0x2000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x103000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x104000 size: 0x2000 type: 3 [email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x106000 size: 0x1000 type: 3 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_reset_device dev: 0x556d459e6e00
[email protected]:vhost_vdpa_add_status dev: 0x556d459e6e00 status: 0x3
[email protected]:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0x0 llend 0xbffff
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x1000 size: 0xc0000 type: 3 [email protected]:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0xc0000 llend 0xdffff
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xc1000 size: 0x20000 type: 3 [email protected]:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0xe0000 llend 0xfffff
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xe1000 size: 0x20000 type: 3 [email protected]:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0x100000 llend 0x7fffffff [email protected]:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0x100000000 llend 0x207fffffff [email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x80001000 size: 0x1f80000000 type: 3 [email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_set_config_call dev: 0x556d459e6e00 fd: -1
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d45c5e670 idx: 2 vq idx: 2
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d45c5e670 idx: 3 vq idx: 3
[email protected]:vhost_vdpa_set_features dev: 0x556d459e6e00 features: 0x300c3180b
[email protected]:vhost_vdpa_add_status dev: 0x556d459e6e00 status: 0x8
[email protected]:vhost_vdpa_set_mem_table dev: 0x556d459e6e00 nregions: 3 padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x556d459e6e00 0: guest_phys_addr: 0x0 memory_size: 0xc0000 userspace_addr: 0x7f7903e00000 flags_padding: 0x0 [email protected]:vhost_vdpa_dump_regions dev: 0x556d459e6e00 1: guest_phys_addr: 0x100000 memory_size: 0x7ff00000 userspace_addr: 0x7f7903f00000 flags_padding: 0x0 [email protected]:vhost_vdpa_dump_regions dev: 0x556d459e6e00 2: guest_phys_addr: 0x100000000 memory_size: 0x1f80000000 userspace_addr: 0x7f7983e00000 flags_padding: 0x0 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_set_vring_num dev: 0x556d459e6e00 index: 0 num: 256
[email protected]:vhost_vdpa_vq_get_addr dev: 0x556d459e6e00 vq: 0x556d459e7080 desc_user_addr: 0x1ed88d2000 avail_user_addr: 0x1ed88d3000 used_user_addr: 0x1ed88d3240 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d459e6e00 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_set_vring_num dev: 0x556d459e6e00 index: 1 num: 256
[email protected]:vhost_vdpa_vq_get_addr dev: 0x556d459e6e00 vq: 0x556d459e7100 desc_user_addr: 0x1ed88d4000 avail_user_addr: 0x1ed88d5000 used_user_addr: 0x1ed88d5240 [email protected]:vhost_vdpa_dev_start dev: 0x556d459e6e00 started: 1
[email protected]:vhost_vdpa_set_vring_base dev: 0x556d459e6e00 index: 0 num: 0
[email protected]:vhost_vdpa_set_vring_kick dev: 0x556d459e6e00 index: 0 fd: 69
[email protected]:vhost_vdpa_set_vring_call dev: 0x556d459e6e00 index: 0 fd: 70
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x1000 size: 0x2000 uaddr: 0x7f991c831000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x3000 size: 0x1000 uaddr: 0x7f991ca0b000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_set_vring_addr dev: 0x556d459e6e00 index: 0 flags: 0x0 desc_user_addr: 0x1000 used_user_addr: 0x3000 avail_user_addr: 0x2000 log_guest_addr: 0x0 [email protected]:vhost_vdpa_set_vring_base dev: 0x556d459e6e00 index: 1 num: 0
[email protected]:vhost_vdpa_set_vring_kick dev: 0x556d459e6e00 index: 1 fd: 71
[email protected]:vhost_vdpa_set_vring_call dev: 0x556d459e6e00 index: 1 fd: 72
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x4000 size: 0x2000 uaddr: 0x7f991c82f000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x6000 size: 0x1000 uaddr: 0x7f991c82e000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_set_vring_addr dev: 0x556d459e6e00 index: 1 flags: 0x0 desc_user_addr: 0x4000 used_user_addr: 0x6000 avail_user_addr: 0x5000 log_guest_addr: 0x0 [email protected]:vhost_vdpa_set_config_call dev: 0x556d459e6e00 fd: 65
[email protected]:vhost_vdpa_get_vq_index dev: 0x556d45c5e670 idx: 2 vq idx: 2
[email protected]:vhost_vdpa_set_vring_num dev: 0x556d45c5e670 index: 2 num: 256
[email protected]:vhost_vdpa_vq_get_addr dev: 0x556d45c5e670 vq: 0x556d45c5e8f0 desc_user_addr: 0x1ed88d6000 avail_user_addr: 0x1ed88d7000 used_user_addr: 0x1ed88d7240 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d45c5e670 idx: 3 vq idx: 3
[email protected]:vhost_vdpa_set_vring_num dev: 0x556d45c5e670 index: 3 num: 256
[email protected]:vhost_vdpa_vq_get_addr dev: 0x556d45c5e670 vq: 0x556d45c5e970 desc_user_addr: 0x1ed8920000 avail_user_addr: 0x1ed8921000 used_user_addr: 0x1ed8921240 [email protected]:vhost_vdpa_dev_start dev: 0x556d45c5e670 started: 1
[email protected]:vhost_vdpa_set_vring_base dev: 0x556d45c5e670 index: 2 num: 0
[email protected]:vhost_vdpa_set_vring_kick dev: 0x556d45c5e670 index: 2 fd: 76
[email protected]:vhost_vdpa_set_vring_call dev: 0x556d45c5e670 index: 2 fd: 77
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x7000 size: 0x2000 uaddr: 0x7f991c82c000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x9000 size: 0x1000 uaddr: 0x7f991c82b000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_set_vring_addr dev: 0x556d45c5e670 index: 2 flags: 0x0 desc_user_addr: 0x7000 used_user_addr: 0x9000 avail_user_addr: 0x8000 log_guest_addr: 0x0 [email protected]:vhost_vdpa_set_vring_base dev: 0x556d45c5e670 index: 3 num: 0
[email protected]:vhost_vdpa_set_vring_kick dev: 0x556d45c5e670 index: 3 fd: 78
[email protected]:vhost_vdpa_set_vring_call dev: 0x556d45c5e670 index: 3 fd: 79
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xa000 size: 0x2000 uaddr: 0x7f991c829000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xc000 size: 0x1000 uaddr: 0x7f991c828000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_set_vring_addr dev: 0x556d45c5e670 index: 3 flags: 0x0 desc_user_addr: 0xa000 used_user_addr: 0xc000 avail_user_addr: 0xb000 log_guest_addr: 0x0 [email protected]:vhost_vdpa_set_config_call dev: 0x556d45c5e670 fd: 65
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xd000 size: 0x1000 uaddr: 0x7f991ca19000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xe000 size: 0x1000 uaddr: 0x7f991ca18000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_get_vq_index dev: 0x556d45c5eb90 idx: 4 vq idx: 4
[email protected]:vhost_vdpa_set_vring_num dev: 0x556d45c5eb90 index: 4 num: 64
[email protected]:vhost_vdpa_vq_get_addr dev: 0x556d45c5eb90 vq: 0x556d45c5ee10 desc_user_addr: 0x1ed9feb000 avail_user_addr: 0x1ed9feb400 used_user_addr: 0x1ed9feb4c0 [email protected]:vhost_vdpa_dev_start dev: 0x556d45c5eb90 started: 1
[email protected]:vhost_vdpa_set_vring_base dev: 0x556d45c5eb90 index: 4 num: 0
[email protected]:vhost_vdpa_set_vring_kick dev: 0x556d45c5eb90 index: 4 fd: 82
[email protected]:vhost_vdpa_set_vring_call dev: 0x556d45c5eb90 index: 4 fd: 83
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xf000 size: 0x1000 uaddr: 0x7f991c827000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x10000 size: 0x1000 uaddr: 0x7f991c826000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_set_vring_addr dev: 0x556d45c5eb90 index: 4 flags: 0x0 desc_user_addr: 0xf000 used_user_addr: 0x10000 avail_user_addr: 0xf400 log_guest_addr: 0x0 [email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0x0 llend 0xc0000 vaddr: 0x7f7903e00000 read-only: 0 [email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x11000 size: 0xc0000 uaddr: 0x7f7903e00000 perm: 0x3 type: 2 [email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0xc0000 llend 0xe0000 vaddr: 0x7f7902e00000 read-only: 1 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xd1000 size: 0x20000 uaddr: 0x7f7902e00000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0xe0000 llend 0x100000 vaddr: 0x7f9908200000 read-only: 1 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0xf1000 size: 0x20000 uaddr: 0x7f9908200000 perm: 0x1 type: 2 [email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0x100000 llend 0x80000000 vaddr: 0x7f7903f00000 read-only: 0 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x111000 size: 0x7ff00000 uaddr: 0x7f7903f00000 perm: 0x3 type: 2
2024-02-02T06:20:59.064167Z qemu-system-x86_64: failed to write, fd=16, errno=14 (Bad address) 2024-02-02T06:20:59.064187Z qemu-system-x86_64: vhost vdpa map fail! 2024-02-02T06:20:59.064198Z qemu-system-x86_64: vhost-vdpa: DMA mapping failed, unable to continue [email protected]:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0x100000000 llend 0x2080000000 vaddr: 0x7f7983e00000 read-only: 0 [email protected]:vhost_vdpa_dma_map vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 asid: 0 iova: 0x111000 size: 0x1f80000000 uaddr: 0x7f7983e00000 perm: 0x3 type: 2 2024-02-02T06:20:59.064215Z qemu-system-x86_64: failed to write, fd=16, errno=14 (Bad address) 2024-02-02T06:20:59.064232Z qemu-system-x86_64: vhost vdpa map fail! 2024-02-02T06:20:59.064244Z qemu-system-x86_64: vhost-vdpa: DMA mapping failed, unable to continue
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x556d45c75140 fd: 16 msg_type: 2 type: 6 [email protected]:vhost_vdpa_add_status dev: 0x556d45c5eb90 status: 0x4 [email protected]:vhost_vdpa_set_config_call dev: 0x556d45c5eb90 fd: 65 [email protected]:vhost_vdpa_set_vring_ready dev: 0x556d45c5eb90, idx: 4, r: 0 [email protected]:vhost_vdpa_set_vring_ready dev: 0x556d45c5eb90, idx: 0, r: 0 [email protected]:vhost_vdpa_set_vring_ready dev: 0x556d45c5eb90, idx: 1, r: 0 [email protected]:vhost_vdpa_set_vring_ready dev: 0x556d45c5eb90, idx: 2, r: 0 [email protected]:vhost_vdpa_set_vring_ready dev: 0x556d45c5eb90, idx: 3, r: 0 [email protected]:vhost_vdpa_get_config dev: 0x556d459e6e00 config: 0x7f9908b73460 config_len: 12 [email protected]:vhost_vdpa_dump_config dev: 0x556d459e6e00 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
Quoted 11 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Regards,
-Siwei
Eugenio were you able to reproduce? Siwei did you have time to look into this? Can't merge patches which are known to break things ...
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
Quoted 11 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Quoted 6 lines
Quoted 2 lines
Regards,
-SiweiEugenio were you able to reproduce? Siwei did you have time to look into this? Can't merge patches which are known to break things ...
Sorry for the lack of news, I'll try to reproduce this week. Meanwhile this patch should not be merged, as you mention.
Thanks!
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
In reply to Michael S. TsirkinHi Michael,
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Quoted 4 lines
Quoted 2 lines
Regards,
-SiweiEugenio were you able to reproduce? Siwei did you have time to look into this?
Didn't get a chance to look into the detail yet in the past week, but thought it may have something to do with the (internals of) iova tree range allocation and the lookup routine. It started to fall apart at the first vhost_vdpa_dma_unmap call showing up in the trace events, where it should've gotten IOVA=0x2000001000, but an incorrect IOVA address 0x1000 was ended up returning from the iova tree lookup routine.
HVA GPA IOVA
-------------------------------------------------------------------------------------------------------------------------
Map
[0x7f7903e00000, 0x7f7983e00000) [0x0, 0x80000000) [0x1000, 0x80000000) [0x7f7983e00000, 0x7f9903e00000) [0x100000000, 0x2080000000) [0x80001000, 0x2000001000) [0x7f7903ea0000, 0x7f7903ec0000) [0xfeda0000, 0xfedc0000) [0x2000001000, 0x2000021000)
Unmap
[0x7f7903ea0000, 0x7f7903ec0000) [0xfeda0000, 0xfedc0000) [0x1000, 0x20000) ??? shouldn't it be [0x2000001000, 0x2000021000) ???
PS, I will be taking off from today and for the next two weeks. Will try to help out looking more closely after I get back.
-Siwei
Quoted 1 line
Can't merge patches which are known to break things ...
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
In reply to Eugenio Perez MartinHi Eugenio,
Just to answer the question you had in the sync meeting as I've just tried, it seems that the issue is also reproducible even with VGA device and VNC display removed, and also reproducible with 8G mem size. You already knew that I can only repro with x-svq=on.
Regards,
-Siwei
Quoted 21 lines · Eugenio Perez Martin
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Quoted 5 lines
Quoted 2 lines
Regards,
-SiweiEugenio were you able to reproduce? Siwei did you have time to look into this? Can't merge patches which are known to break things ...
Sorry for the lack of news, I'll try to reproduce this week. Meanwhile this patch should not be merged, as you mention.
Thanks!
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
In reply to Si-Wei LiuQuoted 34 lines · Si-Wei Liu
Hi Michael,
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Quoted 4 lines
Quoted 2 lines
Regards,
-SiweiEugenio were you able to reproduce? Siwei did you have time to look into this?
Didn't get a chance to look into the detail yet in the past week, but thought it may have something to do with the (internals of) iova tree range allocation and the lookup routine. It started to fall apart at the first
vhost_vdpa_dma_unmapcall showing up in the trace events, where it should've gotten IOVA=0x2000001000, but an incorrect IOVA address0x1000was ended up returning from the iova tree lookup routine.HVA GPA IOVA
-------------------------------------------------------------------------------------------------------------------------
Map
[0x7f7903e00000,0x7f7983e00000) [0x0,0x80000000) [0x1000,0x80000000)
[0x7f7983e00000,0x7f9903e00000) [0x100000000,0x2080000000)
[0x80001000,0x2000001000)
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000)
[0x2000001000,0x2000021000)
Quoted 6 lines
Unmap
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000) [0x1000,0x20000) ???shouldn't it be [0x2000001000,
0x2000021000) ???
Yes, I'm still not able to reproduce. In particular, I don't know how how the memory listener adds a region and then release a region with a different size. I'm talking about these log entries:
1706854838.154394:vhost_vdpa_listener_region_add vdpa: 0x556d45c75140 iova 0x0 llend 0x80000000 vaddr: 0x7f7903e00000 read-only: 0 452:vhost_vdpa_listener_region_del vdpa: 0x556d45c75140 iova 0x0 llend 0x7fffffff
Is it possible for you to also trace the skipped regions? We should add a debug trace there too...
Thanks!
Quoted 6 lines
PS, I will be taking off from today and for the next two weeks. Will try to help out looking more closely after I get back.
-Siwei
Quoted 1 line
Can't merge patches which are known to break things ...
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
Quoted 34 lines · Eugenio Perez Martin
Quoted 33 lines · Si-Wei Liu
Hi Michael,
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Quoted 4 lines
Quoted 2 lines
Regards,
-SiweiEugenio were you able to reproduce? Siwei did you have time to look into this?
Didn't get a chance to look into the detail yet in the past week, but thought it may have something to do with the (internals of) iova tree range allocation and the lookup routine. It started to fall apart at the first
vhost_vdpa_dma_unmapcall showing up in the trace events, where it should've gotten IOVA=0x2000001000, but an incorrect IOVA address0x1000was ended up returning from the iova tree lookup routine.HVA GPA IOVA
-------------------------------------------------------------------------------------------------------------------------
Map
[0x7f7903e00000,0x7f7983e00000) [0x0,0x80000000) [0x1000,0x80000000)
[0x7f7983e00000,0x7f9903e00000) [0x100000000,0x2080000000)
[0x80001000,0x2000001000)
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000)
[0x2000001000,0x2000021000)
Quoted 6 lines
Quoted 6 lines
Unmap
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000) [0x1000,0x20000) ???shouldn't it be [0x2000001000,
0x2000021000) ???
It looks the SVQ iova tree lookup routine vhost_iova_tree_find_iova(), which is called from vhost_vdpa_listener_region_del(), can't properly deal with overlapped region. Specifically, q35's mch_realize() has the following:
579 memory_region_init_alias(&mch->open_high_smram, OBJECT(mch), "smram-open-high", 580 mch->ram_memory, MCH_HOST_BRIDGE_SMRAM_C_BASE, 581 MCH_HOST_BRIDGE_SMRAM_C_SIZE);
582 memory_region_add_subregion_overlap(mch->system_memory, 0xfeda0000, 583 &mch->open_high_smram, 1);
584 memory_region_set_enabled(&mch->open_high_smram, false);
#0 0x0000564c30bf6980 in iova_tree_find_address_iterator (key=0x564c331cf8e0, value=0x564c331cf8e0, data=0x7fffb6d749b0) at ../util/iova-tree.c:96
#1 0x00007f5f66479654 in g_tree_foreach () at /lib64/libglib-2.0.so.0
#2 0x0000564c30bf6b53 in iova_tree_find_iova (tree=<optimized out>, map=map@entry=0x7fffb6d74a00) at ../util/iova-tree.c:114
#3 0x0000564c309da0a9 in vhost_iova_tree_find_iova (tree=<optimized out>, map=map@entry=0x7fffb6d74a00) at ../hw/virtio/vhost-iova-tree.c:70
#4 0x0000564c3085e49d in vhost_vdpa_listener_region_del (listener=0x564c331024c8, section=0x7fffb6d74aa0) at ../hw/virtio/vhost-vdpa.c:444
#5 0x0000564c309f4931 in address_space_update_topology_pass (as=as@entry=0x564c31ab1840 <address_space_memory>, old_view=old_view@entry=0x564c33364cc0, new_view=new_view@entry=0x564c333640f0, adding=adding@entry=false) at ../system/memory.c:977 #6 0x0000564c309f4dcd in address_space_set_flatview (as=0x564c31ab1840 <address_space_memory>) at ../system/memory.c:1079
#7 0x0000564c309f86d0 in memory_region_transaction_commit () at ../system/memory.c:1132
#8 0x0000564c309f86d0 in memory_region_transaction_commit () at ../system/memory.c:1117
#9 0x0000564c307cce64 in mch_realize (d=<optimized out>, errp=<optimized out>) at ../hw/pci-host/q35.c:584
However, it looks like iova_tree_find_address_iterator() only check if the translated address (HVA) falls in to the range when trying to locate the desired IOVA, causing the first DMAMap that happens to overlap in the translated address (HVA) space to be returned prematurely:
89 static gboolean iova_tree_find_address_iterator(gpointer key, gpointer value, 90 gpointer data) 91 {
:
:
99 if (map->translated_addr + map->size < needle->translated_addr || 100 needle->translated_addr + needle->size < map->translated_addr) { 101 return false;
102 }
103
104 args->result = map;
105 return true;
106 }
In the QEMU trace file, it reveals that the first DMAMap as below gets returned incorrectly instead the second, the latter of which is what the actual IOVA corresponds to:
HVA GPA IOVA
[0x7f7903e00000, 0x7f7983e00000) [0x0, 0x80000000) [0x1000, 0x80001000)
[0x7f7903ea0000, 0x7f7903ec0000) [0xfeda0000, 0xfedc0000) [0x2000001000, 0x2000021000)
Maybe other than check the HVA range, we should also match GPA, or at least the size should exactly match?
Quoted 8 lines
Yes, I'm still not able to reproduce. In particular, I don't know how how the memory listener adds a region and then release a region with a different size. I'm talking about these log entries:
1706854838.154394:vhost_vdpa_listener_region_add vdpa:
0x556d45c75140iova0x0llend0x80000000vaddr:0x7f7903e00000read-only: 0 452:vhost_vdpa_listener_region_del vdpa:0x556d45c75140iova0x0llend0x7fffffff
Didn't see a different size here, though if you referred to the discrepancy in the traces around llend, I thought the two between _add() and _del() would have to be interpreted differently due to:
3d1e4d34 "vhost_vdpa: fix the input in trace_vhost_vdpa_listener_region_del()"
Regards,
-Siwei
Quoted 10 lines
Is it possible for you to also trace the skipped regions? We should add a debug trace there too...
Thanks!
Quoted 5 lines
PS, I will be taking off from today and for the next two weeks. Will try to help out looking more closely after I get back.
-Siwei
Quoted 1 line
Can't merge patches which are known to break things ...
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
Quoted 103 lines · Si-Wei Liu
Quoted 34 lines · Eugenio Perez Martin
Quoted 33 lines · Si-Wei Liu
Hi Michael,
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Quoted 4 lines
Quoted 2 lines
Regards,
-SiweiEugenio were you able to reproduce? Siwei did you have time to look into this?
Didn't get a chance to look into the detail yet in the past week, but thought it may have something to do with the (internals of) iova tree range allocation and the lookup routine. It started to fall apart at the first
vhost_vdpa_dma_unmapcall showing up in the trace events, where it should've gotten IOVA=0x2000001000, but an incorrect IOVA address0x1000was ended up returning from the iova tree lookup routine.HVA GPA IOVA
-------------------------------------------------------------------------------------------------------------------------
Map
[0x7f7903e00000,0x7f7983e00000) [0x0,0x80000000) [0x1000,0x80000000)
[0x7f7983e00000,0x7f9903e00000) [0x100000000,0x2080000000)
[0x80001000,0x2000001000)
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000)
[0x2000001000,0x2000021000)Quoted 6 lines
Quoted 6 lines
Unmap
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000) [0x1000,0x20000) ???shouldn't it be [0x2000001000,
0x2000021000) ???It looks the SVQ iova tree lookup routine
vhost_iova_tree_find_iova(), which is called fromvhost_vdpa_listener_region_del(), can't properly deal with overlapped region. Specifically, q35'smch_realize()has the following:579 memory_region_init_alias(&mch->open_high_smram, OBJECT(mch),
"smram-open-high",
580mch->ram_memory,MCH_HOST_BRIDGE_SMRAM_C_BASE,
581MCH_HOST_BRIDGE_SMRAM_C_SIZE);
582 memory_region_add_subregion_overlap(mch->system_memory,0xfeda0000,
583&mch->open_high_smram, 1);
584memory_region_set_enabled(&mch->open_high_smram, false);#0
0x0000564c30bf6980iniova_tree_find_address_iterator(key=0x564c331cf8e0, value=0x564c331cf8e0, data=0x7fffb6d749b0) at../util/iova-tree.c:96
#10x00007f5f66479654ing_tree_foreach() at/lib64/libglib-2.0.so.0#20x0000564c30bf6b53iniova_tree_find_iova(tree=<optimized out>, map=map@entry=0x7fffb6d74a00) at../util/iova-tree.c:114
#30x0000564c309da0a9invhost_iova_tree_find_iova(tree=<optimized out>, map=map@entry=0x7fffb6d74a00) at../hw/virtio/vhost-iova-tree.c:70#40x0000564c3085e49dinvhost_vdpa_listener_region_del(listener=0x564c331024c8, section=0x7fffb6d74aa0) at../hw/virtio/vhost-vdpa.c:444
#50x0000564c309f4931inaddress_space_update_topology_pass(as=as@entry=0x564c31ab1840 <address_space_memory>, old_view=old_view@entry=0x564c33364cc0, new_view=new_view@entry=0x564c333640f0, adding=adding@entry=false) at../system/memory.c:977
#60x0000564c309f4dcdinaddress_space_set_flatview(as=0x564c31ab1840 <address_space_memory>) at../system/memory.c:1079
#70x0000564c309f86d0inmemory_region_transaction_commit() at../system/memory.c:1132
#80x0000564c309f86d0inmemory_region_transaction_commit() at../system/memory.c:1117
#90x0000564c307cce64inmch_realize(d=<optimized out>, errp=<optimized out>) at../hw/pci-host/q35.c:584However, it looks like
iova_tree_find_address_iterator()only check if the translated address (HVA) falls in to the range when trying to locate the desired IOVA, causing the first DMAMap that happens to overlap in the translated address (HVA) space to be returned prematurely:89 static gboolean iova_tree_find_address_iterator(gpointer key,
gpointer value,
90 gpointer data)
91 {
:
:
99 if (map->translated_addr+map->size<needle->translated_addr||
100needle->translated_addr+needle->size<map->translated_addr) {
101 return false;
102 }
103
104args->result= map;
105 return true;
106 }
Quoted 8 lines
In the QEMU trace file, it reveals that the first DMAMap as below gets returned incorrectly instead the second, the latter of which is what the actual IOVA corresponds to:
HVA GPA IOVA
[0x7f7903e00000,0x7f7983e00000) [0x0,0x80000000) [0x1000,0x80001000)
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000) [0x2000001000,0x2000021000)
I think the analysis is totally accurate as no code expects to unmap / map overlapping regions. In particular, vdpa kernel does not expect it either.
Since it is issued at _realize, it should be ok to unmap all the region range and then map the right range again, even if that implies a lot of unpin / pin.
Quoted 4 lines
Maybe other than check the HVA range, we should also match GPA, or at least the size should exactly match?
The safe actions here would be to unmap all the memory chunk and then map the overlap memory? Or am I missing something?
Another thing I don't get, is this reproducible in previous versions? As far as I understand, this bug was never found before. I guess this path of q35's mch_realize is recent?
Thanks!
Quoted 28 lines
Quoted 8 lines
Yes, I'm still not able to reproduce. In particular, I don't know how how the memory listener adds a region and then release a region with a different size. I'm talking about these log entries:
1706854838.154394:vhost_vdpa_listener_region_add vdpa:
0x556d45c75140iova0x0llend0x80000000vaddr:0x7f7903e00000read-only: 0 452:vhost_vdpa_listener_region_del vdpa:0x556d45c75140iova0x0llend0x7fffffffDidn't see a different size here, though if you referred to the discrepancy in the traces around llend, I thought the two between
_add()and_del()would have to be interpreted differently due to:
3d1e4d34"vhost_vdpa: fix the input intrace_vhost_vdpa_listener_region_del()"Regards,
-SiweiQuoted 10 lines
Is it possible for you to also trace the skipped regions? We should add a debug trace there too...
Thanks!
Quoted 5 lines
PS, I will be taking off from today and for the next two weeks. Will try to help out looking more closely after I get back.
-Siwei
Quoted 1 line
Can't merge patches which are known to break things ...
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
Quoted 107 lines · Eugenio Perez Martin
Quoted 106 lines · Si-Wei Liu
Quoted 34 lines · Eugenio Perez Martin
Quoted 33 lines · Si-Wei Liu
Hi Michael,
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Quoted 4 lines
Quoted 2 lines
Regards,
-SiweiEugenio were you able to reproduce? Siwei did you have time to look into this?
Didn't get a chance to look into the detail yet in the past week, but thought it may have something to do with the (internals of) iova tree range allocation and the lookup routine. It started to fall apart at the first
vhost_vdpa_dma_unmapcall showing up in the trace events, where it should've gotten IOVA=0x2000001000, but an incorrect IOVA address0x1000was ended up returning from the iova tree lookup routine.HVA GPA IOVA
-------------------------------------------------------------------------------------------------------------------------
Map
[0x7f7903e00000,0x7f7983e00000) [0x0,0x80000000) [0x1000,0x80000000)
[0x7f7983e00000,0x7f9903e00000) [0x100000000,0x2080000000)
[0x80001000,0x2000001000)
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000)
[0x2000001000,0x2000021000)Quoted 6 lines
Quoted 6 lines
Unmap
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000) [0x1000,0x20000) ???shouldn't it be [0x2000001000,
0x2000021000) ???It looks the SVQ iova tree lookup routine
vhost_iova_tree_find_iova(), which is called fromvhost_vdpa_listener_region_del(), can't properly deal with overlapped region. Specifically, q35'smch_realize()has the following:579 memory_region_init_alias(&mch->open_high_smram, OBJECT(mch),
"smram-open-high",
580mch->ram_memory,MCH_HOST_BRIDGE_SMRAM_C_BASE,
581MCH_HOST_BRIDGE_SMRAM_C_SIZE);
582 memory_region_add_subregion_overlap(mch->system_memory,0xfeda0000,
583&mch->open_high_smram, 1);
584memory_region_set_enabled(&mch->open_high_smram, false);#0
0x0000564c30bf6980iniova_tree_find_address_iterator(key=0x564c331cf8e0, value=0x564c331cf8e0, data=0x7fffb6d749b0) at../util/iova-tree.c:96
#10x00007f5f66479654ing_tree_foreach() at/lib64/libglib-2.0.so.0#20x0000564c30bf6b53iniova_tree_find_iova(tree=<optimized out>, map=map@entry=0x7fffb6d74a00) at../util/iova-tree.c:114
#30x0000564c309da0a9invhost_iova_tree_find_iova(tree=<optimized out>, map=map@entry=0x7fffb6d74a00) at../hw/virtio/vhost-iova-tree.c:70#40x0000564c3085e49dinvhost_vdpa_listener_region_del(listener=0x564c331024c8, section=0x7fffb6d74aa0) at../hw/virtio/vhost-vdpa.c:444
#50x0000564c309f4931inaddress_space_update_topology_pass(as=as@entry=0x564c31ab1840 <address_space_memory>, old_view=old_view@entry=0x564c33364cc0, new_view=new_view@entry=0x564c333640f0, adding=adding@entry=false) at../system/memory.c:977
#60x0000564c309f4dcdinaddress_space_set_flatview(as=0x564c31ab1840 <address_space_memory>) at../system/memory.c:1079
#70x0000564c309f86d0inmemory_region_transaction_commit() at../system/memory.c:1132
#80x0000564c309f86d0inmemory_region_transaction_commit() at../system/memory.c:1117
#90x0000564c307cce64inmch_realize(d=<optimized out>, errp=<optimized out>) at../hw/pci-host/q35.c:584However, it looks like
iova_tree_find_address_iterator()only check if the translated address (HVA) falls in to the range when trying to locate the desired IOVA, causing the first DMAMap that happens to overlap in the translated address (HVA) space to be returned prematurely:89 static gboolean iova_tree_find_address_iterator(gpointer key,
gpointer value,
90 gpointer data)91 { : : 99 if (map->translated_addr + map->size < needle->translated_addr ||100
needle->translated_addr+needle->size<map->translated_addr) {
101 return false;
102 }
103
104args->result= map;
105 return true;
106 }In the QEMU trace file, it reveals that the first DMAMap as below gets returned incorrectly instead the second, the latter of which is what the actual IOVA corresponds to:
Quoted 7 lines
Quoted 4 lines
HVA GPA IOVA
[0x7f7903e00000,0x7f7983e00000) [0x0,0x80000000) [0x1000,0x80001000)
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000) [0x2000001000,0x2000021000)I think the analysis is totally accurate as no code expects to unmap / map overlapping regions. In particular, vdpa kernel does not expect it either.
Maybe I missed something, but I don't see how vdpa kernel prohibits this overlapping case? The same HVA gets remapped under a different GPA or IOVA range should be a valid use case it seems? For e.g. I don't see mapping failure when x-svq=on was removed from QEMU's vhost-vdpa arguments (where you can see in the attached trace, mch_realize with the exactly same overlapping region got remapped successfully, and then got unmapped right after).
Quoted 3 lines
Since it is issued at
_realize, it should be ok to unmap all the region range and then map the right range again, even if that implies a lot of unpin / pin.
You'll find out mch_realize() already did that - where line 582 is to create a mapping overlapped with entire range, while line 583 is to disable (unmap) this same mapping shortly after.
582 memory_region_add_subregion_overlap(mch->system_memory, 0xfeda0000,
583 &mch->open_high_smram, 1);
584 memory_region_set_enabled(&mch->open_high_smram, false);
So we don't have to add any special case to deal with these overlapping case (just use the GPA as the hint to help identify which iova range it tries to unmap), as the vdpa's memory listener now moves upfront to the earliest point of time at machine boot, the relevant SVQ code needs to be more flexible and tolerate to the extra churns for the rest of QEMU's subsystems to stabilize the guest memory layout.
Quoted 7 lines
Quoted 3 lines
Maybe other than check the HVA range, we should also match GPA, or at least the size should exactly match?
The safe actions here would be to unmap all the memory chunk and then map the overlap memory? Or am I missing something?
Another thing I don't get, is this reproducible in previous versions?
It is not reproducible without this series. I thought that may be because previously the vhost-vdpa's memory listener was registered at a later point of time, after all the overlapped regions are gone and the memory layout is completely stabilized. Now we move registration to the init time, then all the devils come out biting us.
Previous versions of this patch series we didn't get this far yet, when x-svq=on is specified.
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 2 lines
As far as I understand, this bug was never found before. I guess this path of q35's
mch_realizeis recent?
No, it's been there for quite a while.
Cheers,
-Siwei
Quoted 30 lines
Thanks!
Quoted 27 lines
Quoted 8 lines
Yes, I'm still not able to reproduce. In particular, I don't know how how the memory listener adds a region and then release a region with a different size. I'm talking about these log entries:
1706854838.154394:vhost_vdpa_listener_region_add vdpa:
0x556d45c75140iova0x0llend0x80000000vaddr:0x7f7903e00000read-only: 0 452:vhost_vdpa_listener_region_del vdpa:0x556d45c75140iova0x0llend0x7fffffffDidn't see a different size here, though if you referred to the discrepancy in the traces around llend, I thought the two between
_add()and_del()would have to be interpreted differently due to:
3d1e4d34"vhost_vdpa: fix the input intrace_vhost_vdpa_listener_region_del()"Regards,
-SiweiQuoted 10 lines
Is it possible for you to also trace the skipped regions? We should add a debug trace there too...
Thanks!
Quoted 5 lines
PS, I will be taking off from today and for the next two weeks. Will try to help out looking more closely after I get back.
-Siwei
Quoted 1 line
Can't merge patches which are known to break things ...
+ qemu-system-x86_64 -no-user-config -nodefaults -machine type=pc-q35-8.0,dump-guest-core=off,accel=kvm,kernel_irqchip=split -cpu EPYC -smp 8,sockets=1,cores=8,threads=1 -m size=8G,slots=8,maxmem=256G -qmp unix:/tmp/q,server,nowait -serial mon:stdio -drive file=/usr/share/OVMF/OVMF_CODE.pure-efi.fd,index=0,if=pflash,format=raw,readonly=on -drive file=/usr/share/OVMF/OVMF_VARS.pure-efi.fd,index=1,if=pflash,format=raw -drive id=disk0,if=none,format=qcow2,file=/root/vdpa/tools/images/VM-el7.9-uefi-x86_64.qcow2 -device virtio-blk-pci,drive=disk0 -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0, -device virtio-net-pci,netdev=vhost-vdpa0,id=vdpa0,bootindex=-1,page-per-vq=on,mac=e4:11:c6:d3:45:f0,ctrl_vq=on,mq=on,ctrl_vlan=off,vectors=6,host_mtu=9000,mrg_rxbuf=on,rx_queue_size=1024,disable-legacy=on -msg timestamp=on --trace events=/tmp/e [email protected]:vhost_vdpa_init dev: 0x5641ebbea650, common dev: 0x5641eb972fd0 vdpa: 0x7f6a968d7190
[email protected]:vhost_vdpa_get_features dev: 0x5641ebbea650 features: 0x300c3982b
[email protected]:vhost_vdpa_add_status dev: 0x5641ebbea650 status: 0x3
[email protected]:vhost_vdpa_set_owner dev: 0x5641ebbea650
[email protected]:vhost_vdpa_get_features dev: 0x5641ebbea650 features: 0x300c3982b
[email protected]:vhost_vdpa_memslots_limit dev: 0x5641ebbea650 = 0x7fffffff
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbea650 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_set_vring_call dev: 0x5641ebbea650 index: 0 fd: 17
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbea650 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_set_vring_call dev: 0x5641ebbea650 index: 1 fd: 18
[email protected]:vhost_vdpa_get_device_id dev: 0x5641ebbea650 device_id 1
[email protected]:vhost_vdpa_init dev: 0x5641ebbeab70, common dev: 0x5641eb972fd0 vdpa: 0x7f6a9688e190
[email protected]:vhost_vdpa_get_features dev: 0x5641ebbeab70 features: 0x300c3982b
[email protected]:vhost_vdpa_memslots_limit dev: 0x5641ebbeab70 = 0x7fffffff
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbeab70 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_set_vring_call dev: 0x5641ebbeab70 index: 0 fd: 19
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbeab70 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_set_vring_call dev: 0x5641ebbeab70 index: 1 fd: 20
[email protected]:vhost_vdpa_get_device_id dev: 0x5641ebbeab70 device_id 1
[email protected]:vhost_vdpa_init dev: 0x5641ebbeb090, common dev: 0x5641eb972fd0 vdpa: 0x7f6a96845190
[email protected]:vhost_vdpa_get_features dev: 0x5641ebbeb090 features: 0x300c3982b
[email protected]:vhost_vdpa_memslots_limit dev: 0x5641ebbeb090 = 0x7fffffff
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbeb090 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_set_vring_call dev: 0x5641ebbeb090 index: 0 fd: 21
[email protected]:vhost_vdpa_get_device_id dev: 0x5641ebbeb090 device_id 1
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x5641eb972fd0 iova 0x0 llend 0x80000000 vaddr: 0x7f687fe00000 read-only: 0
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 asid: 0 iova: 0x0 size: 0x80000000 uaddr: 0x7f687fe00000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x5641eb972fd0 iova 0x100000000 llend 0x280000000 vaddr: 0x7f68ffe00000 read-only: 0
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 asid: 0 iova: 0x100000000 size: 0x180000000 uaddr: 0x7f68ffe00000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x5641eb972fd0 iova 0xfeda0000 llend 0xfedc0000 vaddr: 0x7f687fea0000 read-only: 0
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 asid: 0 iova: 0xfeda0000 size: 0x20000 uaddr: 0x7f687fea0000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_listener_region_del vdpa: 0x5641eb972fd0 iova 0xfeda0000 llend 0xfedbffff
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 asid: 0 iova: 0xfeda0000 size: 0x20000 type: 3
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_set_config dev: 0x5641ebbea650 offset: 0 size: 6 flags: 0x0
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0
[email protected]:vhost_vdpa_listener_region_del vdpa: 0x5641eb972fd0 iova 0x0 llend 0x7fffffff
[email protected]:vhost_vdpa_listener_begin_batch vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 5
[email protected]:vhost_vdpa_dma_unmap vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 asid: 0 iova: 0x0 size: 0x80000000 type: 3
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x5641eb972fd0 iova 0x0 llend 0xc0000 vaddr: 0x7f687fe00000 read-only: 0
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 asid: 0 iova: 0x0 size: 0xc0000 uaddr: 0x7f687fe00000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_region_add vdpa: 0x5641eb972fd0 iova 0x100000 llend 0x80000000 vaddr: 0x7f687ff00000 read-only: 0
[email protected]:vhost_vdpa_dma_map vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 asid: 0 iova: 0x100000 size: 0x7ff00000 uaddr: 0x7f687ff00000 perm: 0x3 type: 2
[email protected]:vhost_vdpa_listener_commit vdpa_shared:0x5641eb972fd0 fd: 16 msg_type: 2 type: 6
[email protected]:vhost_vdpa_get_config dev: 0x5641ebbea650 config: 0x7f6a851ff460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
[email protected]:vhost_vdpa_get_config dev: 0x5641ebbea650 config: 0x7f6a851ff460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
[email protected]:vhost_vdpa_get_config dev: 0x5641ebbea650 config: 0x7f6a851ff460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
[email protected]:vhost_vdpa_get_config dev: 0x5641ebbea650 config: 0x7f6a851ff460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
[email protected]:vhost_vdpa_get_config dev: 0x5641ebbea650 config: 0x7f6a851ff460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
[email protected]:vhost_vdpa_get_config dev: 0x5641ebbea650 config: 0x7f6a851ff460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
[email protected]:vhost_vdpa_get_config dev: 0x5641ebbea650 config: 0x7f6a851ff460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
[email protected]:vhost_vdpa_get_config dev: 0x5641ebbea650 config: 0x7f6a851ff460 config_len: 12
[email protected]:vhost_vdpa_dump_config dev: 0x5641ebbea650 0000: e4 11 c6 d3 45 f0 01 00 02 00 28 23
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbea650 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_set_vring_call dev: 0x5641ebbea650 index: 0 fd: 43
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbea650 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_set_vring_call dev: 0x5641ebbea650 index: 1 fd: 44
[email protected]:vhost_vdpa_set_features dev: 0x5641ebbea650 features: 0x300000008
[email protected]:vhost_vdpa_add_status dev: 0x5641ebbea650 status: 0x8
[email protected]:vhost_vdpa_set_mem_table dev: 0x5641ebbea650 nregions: 3 padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x5641ebbea650 0: guest_phys_addr: 0x0 memory_size: 0xc0000 userspace_addr: 0x7f687fe00000 flags_padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x5641ebbea650 1: guest_phys_addr: 0x100000 memory_size: 0x7ff00000 userspace_addr: 0x7f687ff00000 flags_padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x5641ebbea650 2: guest_phys_addr: 0x100000000 memory_size: 0x180000000 userspace_addr: 0x7f68ffe00000 flags_padding: 0x0
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbea650 idx: 0 vq idx: 0
[email protected]:vhost_vdpa_set_vring_num dev: 0x5641ebbea650 index: 0 num: 256
[email protected]:vhost_vdpa_set_vring_base dev: 0x5641ebbea650 index: 0 num: 0
[email protected]:vhost_vdpa_vq_get_addr dev: 0x5641ebbea650 vq: 0x5641ebbea8d0 desc_user_addr: 0x7e45b000 avail_user_addr: 0x7e45c000 used_user_addr: 0x7e45d000
[email protected]:vhost_vdpa_set_vring_addr dev: 0x5641ebbea650 index: 0 flags: 0x0 desc_user_addr: 0x7e45b000 used_user_addr: 0x7e45d000 avail_user_addr: 0x7e45c000 log_guest_addr: 0x7e45d000
[email protected]:vhost_vdpa_set_vring_kick dev: 0x5641ebbea650 index: 0 fd: 46
[email protected]:vhost_vdpa_get_vq_index dev: 0x5641ebbea650 idx: 1 vq idx: 1
[email protected]:vhost_vdpa_set_vring_num dev: 0x5641ebbea650 index: 1 num: 256
[email protected]:vhost_vdpa_set_vring_base dev: 0x5641ebbea650 index: 1 num: 0
[email protected]:vhost_vdpa_vq_get_addr dev: 0x5641ebbea650 vq: 0x5641ebbea950 desc_user_addr: 0x7e45f000 avail_user_addr: 0x7e460000 used_user_addr: 0x7e461000
[email protected]:vhost_vdpa_set_vring_addr dev: 0x5641ebbea650 index: 1 flags: 0x0 desc_user_addr: 0x7e45f000 used_user_addr: 0x7e461000 avail_user_addr: 0x7e460000 log_guest_addr: 0x7e461000
[email protected]:vhost_vdpa_set_vring_kick dev: 0x5641ebbea650 index: 1 fd: 47
[email protected]:vhost_vdpa_dev_start dev: 0x5641ebbea650 started: 1
[email protected]:vhost_vdpa_set_mem_table dev: 0x5641ebbea650 nregions: 5 padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x5641ebbea650 0: guest_phys_addr: 0x0 memory_size: 0xc0000 userspace_addr: 0x7f687fe00000 flags_padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x5641ebbea650 1: guest_phys_addr: 0x100000 memory_size: 0x7ff00000 userspace_addr: 0x7f687ff00000 flags_padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x5641ebbea650 2: guest_phys_addr: 0x100000000 memory_size: 0x180000000 userspace_addr: 0x7f68ffe00000 flags_padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x5641ebbea650 3: guest_phys_addr: 0x4800003000 memory_size: 0x1000 userspace_addr: 0x7f6a96aa7000 flags_padding: 0x0
[email protected]:vhost_vdpa_dump_regions dev: 0x5641ebbea650 4: guest_phys_addr: 0x4800004000 memory_size: 0x1000 userspace_addr: 0x7f6a96a39000 flags_padding: 0x0
[email protected]:vhost_vdpa_add_status dev: 0x5641ebbea650 status: 0x4
[email protected]:vhost_vdpa_set_config_call dev: 0x5641ebbea650 fd: 45
[email protected]:vhost_vdpa_set_vring_ready dev: 0x5641ebbea650, idx: 0, r: 0
[email protected]:vhost_vdpa_set_vring_ready dev: 0x5641ebbea650, idx: 1, r: 0
Re: [PATCH v2 6/7] vdpa: move iova_tree allocation to net_vhost_vdpa_init
Quoted 119 lines · Si-Wei Liu
Quoted 107 lines · Eugenio Perez Martin
Quoted 106 lines · Si-Wei Liu
Quoted 34 lines · Eugenio Perez Martin
Quoted 33 lines · Si-Wei Liu
Hi Michael,
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Hi Eugenio,
I thought this new code looks good to me and the original issue I saw with x-svq=on should be gone. However, after rebase my tree on top of this, there's a new failure I found around setting up guest mappings at early boot, please see attached the specific QEMU config and corresponding event traces. Haven't checked into the detail yet, thinking you would need to be aware of ahead.
Quoted 4 lines
Quoted 2 lines
Regards,
-SiweiEugenio were you able to reproduce? Siwei did you have time to look into this?
Didn't get a chance to look into the detail yet in the past week, but thought it may have something to do with the (internals of) iova tree range allocation and the lookup routine. It started to fall apart at the first
vhost_vdpa_dma_unmapcall showing up in the trace events, where it should've gotten IOVA=0x2000001000, but an incorrect IOVA address0x1000was ended up returning from the iova tree lookup routine.HVA GPA IOVA
-------------------------------------------------------------------------------------------------------------------------
Map
[0x7f7903e00000,0x7f7983e00000) [0x0,0x80000000) [0x1000,0x80000000)
[0x7f7983e00000,0x7f9903e00000) [0x100000000,0x2080000000)
[0x80001000,0x2000001000)
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000)
[0x2000001000,0x2000021000)Quoted 6 lines
Quoted 6 lines
Unmap
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000) [0x1000,0x20000) ???shouldn't it be [0x2000001000,
0x2000021000) ???It looks the SVQ iova tree lookup routine
vhost_iova_tree_find_iova(), which is called fromvhost_vdpa_listener_region_del(), can't properly deal with overlapped region. Specifically, q35'smch_realize()has the following:579 memory_region_init_alias(&mch->open_high_smram, OBJECT(mch),
"smram-open-high",
580mch->ram_memory,MCH_HOST_BRIDGE_SMRAM_C_BASE,
581MCH_HOST_BRIDGE_SMRAM_C_SIZE);
582 memory_region_add_subregion_overlap(mch->system_memory,0xfeda0000,
583&mch->open_high_smram, 1);
584memory_region_set_enabled(&mch->open_high_smram, false);#0
0x0000564c30bf6980iniova_tree_find_address_iterator(key=0x564c331cf8e0, value=0x564c331cf8e0, data=0x7fffb6d749b0) at../util/iova-tree.c:96
#10x00007f5f66479654ing_tree_foreach() at/lib64/libglib-2.0.so.0#20x0000564c30bf6b53iniova_tree_find_iova(tree=<optimized out>, map=map@entry=0x7fffb6d74a00) at../util/iova-tree.c:114
#30x0000564c309da0a9invhost_iova_tree_find_iova(tree=<optimized out>, map=map@entry=0x7fffb6d74a00) at../hw/virtio/vhost-iova-tree.c:70#40x0000564c3085e49dinvhost_vdpa_listener_region_del(listener=0x564c331024c8, section=0x7fffb6d74aa0) at../hw/virtio/vhost-vdpa.c:444
#50x0000564c309f4931inaddress_space_update_topology_pass(as=as@entry=0x564c31ab1840 <address_space_memory>, old_view=old_view@entry=0x564c33364cc0, new_view=new_view@entry=0x564c333640f0, adding=adding@entry=false) at../system/memory.c:977
#60x0000564c309f4dcdinaddress_space_set_flatview(as=0x564c31ab1840 <address_space_memory>) at../system/memory.c:1079
#70x0000564c309f86d0inmemory_region_transaction_commit() at../system/memory.c:1132
#80x0000564c309f86d0inmemory_region_transaction_commit() at../system/memory.c:1117
#90x0000564c307cce64inmch_realize(d=<optimized out>, errp=<optimized out>) at../hw/pci-host/q35.c:584However, it looks like
iova_tree_find_address_iterator()only check if the translated address (HVA) falls in to the range when trying to locate the desired IOVA, causing the first DMAMap that happens to overlap in the translated address (HVA) space to be returned prematurely:89 static gboolean iova_tree_find_address_iterator(gpointer key,
gpointer value,
90 gpointer data)91 { : : 99 if (map->translated_addr + map->size < needle->translated_addr ||100
needle->translated_addr+needle->size<map->translated_addr) {
101 return false;
102 }
103
104args->result= map;
105 return true;
106 }In the QEMU trace file, it reveals that the first DMAMap as below gets returned incorrectly instead the second, the latter of which is what the actual IOVA corresponds to:
Quoted 7 lines
Quoted 4 lines
HVA GPA IOVA
[0x7f7903e00000,0x7f7983e00000) [0x0,0x80000000) [0x1000,0x80001000)
[0x7f7903ea0000,0x7f7903ec0000) [0xfeda0000,0xfedc0000) [0x2000001000,0x2000021000)I think the analysis is totally accurate as no code expects to unmap / map overlapping regions. In particular, vdpa kernel does not expect it either.
Quoted 8 lines
Maybe I missed something, but I don't see how vdpa kernel prohibits this overlapping case? The same HVA gets remapped under a different GPA or IOVA range should be a valid use case it seems? For e.g. I don't see mapping failure when x-svq=on was removed from QEMU's vhost-vdpa arguments (where you can see in the attached trace,
mch_realizewith the exactly same overlapping region got remapped successfully, and then got unmapped right after).
I meant to remove part of a map. You can see that vhost_vdpa_pa_unmap / vhost_vdpa_va_unmap removes all the map, not only the portion of it, much like iova_tree does.
Quoted 11 lines
Quoted 3 lines
Since it is issued at
_realize, it should be ok to unmap all the region range and then map the right range again, even if that implies a lot of unpin / pin.You'll find out
mch_realize()already did that - where line 582 is to create a mapping overlapped with entire range, while line 583 is to disable (unmap) this same mapping shortly after.582 memory_region_add_subregion_overlap(mch->system_memory,
0xfeda0000,
583&mch->open_high_smram, 1);
584memory_region_set_enabled(&mch->open_high_smram, false);
Quoted 6 lines
So we don't have to add any special case to deal with these overlapping case (just use the GPA as the hint to help identify which iova range it tries to unmap), as the vdpa's memory listener now moves upfront to the earliest point of time at machine boot, the relevant SVQ code needs to be more flexible and tolerate to the extra churns for the rest of QEMU's subsystems to stabilize the guest memory layout.
Yes I think the same.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Maybe other than check the HVA range, we should also match GPA, or at least the size should exactly match?
The safe actions here would be to unmap all the memory chunk and then map the overlap memory? Or am I missing something?
Another thing I don't get, is this reproducible in previous versions?
Quoted 9 lines
It is not reproducible without this series. I thought that may be because previously the vhost-vdpa's memory listener was registered at a later point of time, after all the overlapped regions are gone and the memory layout is completely stabilized. Now we move registration to the init time, then all the devils come out biting us.
Previous versions of this patch series we didn't get this far yet, when x-svq=on is specified.
Right, good point.
Thanks!
Quoted 37 lines
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 2 lines
As far as I understand, this bug was never found before. I guess this path of q35's
mch_realizeis recent?No, it's been there for quite a while.
Cheers,
-SiweiQuoted 30 lines
Thanks!
Quoted 27 lines
Quoted 8 lines
Yes, I'm still not able to reproduce. In particular, I don't know how how the memory listener adds a region and then release a region with a different size. I'm talking about these log entries:
1706854838.154394:vhost_vdpa_listener_region_add vdpa:
0x556d45c75140iova0x0llend0x80000000vaddr:0x7f7903e00000read-only: 0 452:vhost_vdpa_listener_region_del vdpa:0x556d45c75140iova0x0llend0x7fffffffDidn't see a different size here, though if you referred to the discrepancy in the traces around llend, I thought the two between
_add()and_del()would have to be interpreted differently due to:
3d1e4d34"vhost_vdpa: fix the input intrace_vhost_vdpa_listener_region_del()"Regards,
-SiweiQuoted 10 lines
Is it possible for you to also trace the skipped regions? We should add a debug trace there too...
Thanks!
Quoted 5 lines
PS, I will be taking off from today and for the next two weeks. Will try to help out looking more closely after I get back.
-Siwei
Quoted 1 line
Can't merge patches which are known to break things ...