vhost-vdpa: Do not send empty IOTLB update batches
PATCH v2 1/1 vhost-vdpa: Do not send empty IOTLB update batches
With the introduction of the batch hinting, meaningless batches can be created with no IOTLB updates if the memory region was skipped by vhost_vdpa_listener_skipped_section. This is the case of host notifiers memory regions, device un/realize, and others. This causes the vdpa device to receive dma mapping settings with no changes, a possibly expensive operation for nothing.
To avoid that, VHOST_IOTLB_BATCH_BEGIN hint is delayed until we have a meaningful (not skipped section) mapping or unmapping operation, and VHOST_IOTLB_BATCH_END is not written unless at least one of _UPDATE / _INVALIDATE has been issued.
--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 50 ++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-)
include/hw/virtio/vhost-vdpa.h +1 -0
@@ -23,6 +23,7 @@ typedef struct vhost_vdpa {int device_fd;int index;uint32_t msg_type; +size_t n_mr_updated;MemoryListener listener;struct vhost_dev *dev;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];
hw/virtio/vhost-vdpa.c +38 -12
94 lines not on this page · raw message
Signature · 1 line
2.27.0
Quoted 107 lines · Eugenio Pérez
With the introduction of the batch hinting, meaningless batches can be created with no IOTLB updates if the memory region was skipped by
vhost_vdpa_listener_skipped_section. This is the case of host notifiers memory regions, device un/realize, and others. This causes the vdpa device to receive dma mapping settings with no changes, a possibly expensive operation for nothing.To avoid that,
VHOST_IOTLB_BATCH_BEGINhint is delayed until we have a meaningful (not skipped section) mapping or unmapping operation, andVHOST_IOTLB_BATCH_ENDis not written unless at least one of_UPDATE/_INVALIDATEhas been issued.Signed-off-by Eugenio Pérez <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 50 ++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -23,6 +23,7 @@ typedef struct vhost_vdpa {int device_fd;int index;uint32_t msg_type; +size_t n_mr_updated;MemoryListener listener;struct vhost_dev *dev;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];hw/virtio/vhost-vdpa.c +30
-11@@ -89,19 +89,13 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova,return ret; } -static void vhost_vdpa_listener_begin (MemoryListener *listener) +static void vhost_vdpa_listener_begin_batch (struct vhost_vdpa *v) { - struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); -struct vhost_dev *dev = v->dev; -struct vhost_msg_v2 msg = {};int fd = v->device_fd; - -if (!(dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) { -return ; - } - - msg.type = v->msg_type; - msg.iotlb.type =VHOST_IOTLB_BATCH_BEGIN ; +struct vhost_msg_v2 msg = { + .type = v->msg_type, + .iotlb.type =VHOST_IOTLB_BATCH_BEGIN , + };if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) { error_report("failed to write, fd=%d, errno=%d (%s)",@@ -109,6 +103,25 @@ static void vhost_vdpa_listener_begin(MemoryListener *listener) } } +static bool vhost_vdpa_iotlb_batch_is_started (const struct vhost_vdpa *v) +{ +return v->n_mr_updated !=0 ; +} + +static void vhost_vdpa_iotlb_batch_begin_once (struct vhost_vdpa *v) +{ +if (!vhost_vdpa_iotlb_batch_is_started (v)) { +vhost_vdpa_listener_begin_batch (v); + } + + v->n_mr_updated++; +} + +static void vhost_vdpa_iotlb_batch_reset (struct vhost_vdpa *v) +{ + v->n_mr_updated =0 ; +} +static void vhost_vdpa_listener_commit (MemoryListener *listener) { struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener);@@ -120,6 +133,10 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)return ; } +if (vhost_vdpa_iotlb_batch_is_started (v)) { +return ; + } + msg.type = v->msg_type; msg.iotlb.type =VHOST_IOTLB_BATCH_END ;@@ -127,6 +144,8 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno)); } + +vhost_vdpa_iotlb_batch_reset (v); } static void vhost_vdpa_listener_region_add(MemoryListener *listener,
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 192
Quoted 4 lines
hw/virtio/vhost-vdpa.c +1
-0@@ -170,6 +189,10 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, llsize =int128_sub (llend,int128_make64 (iova)); +if (v->dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) {
Let's move this in to vhost_vdpa_iotlb_batch_begin_once()?
Quoted 7 lines
hw/virtio/vhost-vdpa.c +3
-0+vhost_vdpa_iotlb_batch_begin_once (v); + } + ret =vhost_vdpa_dma_map (v, iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_del(MemoryListener *listener, · line 250
Quoted 7 lines
hw/virtio/vhost-vdpa.c +4
-0@@ -221,6 +244,10 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, llsize =int128_sub (llend,int128_make64 (iova)); +if (v->dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) { +vhost_vdpa_iotlb_batch_begin_once (v); + } +
Do we need to check vhost_vdpa_iotlb_batch_is_started() in the .commit?
Others look good.
Thanks
Quoted 14 lines
hw/virtio/vhost-vdpa.c +0
-2ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize));if (ret) {error_report ("vhost_vdpa dma unmap error!" );@@ -234,7 +261,6 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,* depends on the addnop(). */ static const MemoryListener vhost_vdpa_memory_listener = { - .begin = vhost_vdpa_listener_begin, .commit = vhost_vdpa_listener_commit, .region_add = vhost_vdpa_listener_region_add, .region_del = vhost_vdpa_listener_region_del, --2.27.0
Quoted 107 lines · Jason Wang
Quoted 105 lines · Eugenio Pérez
With the introduction of the batch hinting, meaningless batches can be created with no IOTLB updates if the memory region was skipped by
vhost_vdpa_listener_skipped_section. This is the case of host notifiers memory regions, device un/realize, and others. This causes the vdpa device to receive dma mapping settings with no changes, a possibly expensive operation for nothing.To avoid that,
VHOST_IOTLB_BATCH_BEGINhint is delayed until we have a meaningful (not skipped section) mapping or unmapping operation, andVHOST_IOTLB_BATCH_ENDis not written unless at least one of_UPDATE/_INVALIDATEhas been issued.Signed-off-by Eugenio Pérez <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 50 ++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -23,6 +23,7 @@ typedef struct vhost_vdpa {int device_fd;int index;uint32_t msg_type; +size_t n_mr_updated;MemoryListener listener;struct vhost_dev *dev;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];hw/virtio/vhost-vdpa.c +30
-11@@ -89,19 +89,13 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova,return ret; } -static void vhost_vdpa_listener_begin (MemoryListener *listener) +static void vhost_vdpa_listener_begin_batch (struct vhost_vdpa *v) { - struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); -struct vhost_dev *dev = v->dev; -struct vhost_msg_v2 msg = {};int fd = v->device_fd; - -if (!(dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) { -return ; - } - - msg.type = v->msg_type; - msg.iotlb.type =VHOST_IOTLB_BATCH_BEGIN ; +struct vhost_msg_v2 msg = { + .type = v->msg_type, + .iotlb.type =VHOST_IOTLB_BATCH_BEGIN , + };if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) { error_report("failed to write, fd=%d, errno=%d (%s)",@@ -109,6 +103,25 @@ static void vhost_vdpa_listener_begin(MemoryListener *listener) } } +static bool vhost_vdpa_iotlb_batch_is_started (const struct vhost_vdpa *v) +{ +return v->n_mr_updated !=0 ; +} + +static void vhost_vdpa_iotlb_batch_begin_once (struct vhost_vdpa *v) +{ +if (!vhost_vdpa_iotlb_batch_is_started (v)) { +vhost_vdpa_listener_begin_batch (v); + } + + v->n_mr_updated++; +} + +static void vhost_vdpa_iotlb_batch_reset (struct vhost_vdpa *v) +{ + v->n_mr_updated =0 ; +} +static void vhost_vdpa_listener_commit (MemoryListener *listener) { struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener);@@ -120,6 +133,10 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)return ; } +if (vhost_vdpa_iotlb_batch_is_started (v)) { +return ; + } + msg.type = v->msg_type; msg.iotlb.type =VHOST_IOTLB_BATCH_END ;@@ -127,6 +144,8 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno)); } + +vhost_vdpa_iotlb_batch_reset (v); }
Quoted 9 lines
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 192
Quoted 6 lines
hw/virtio/vhost-vdpa.c +1
-0static void vhost_vdpa_listener_region_add(MemoryListener *listener,@@ -170,6 +189,10 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, llsize =int128_sub (llend,int128_make64 (iova)); +if (v->dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) {Let's move this in to
vhost_vdpa_iotlb_batch_begin_once()?
Sure
Quoted 8 lines
Quoted 8 lines
hw/virtio/vhost-vdpa.c +3
-0+vhost_vdpa_iotlb_batch_begin_once (v); + } + ret =vhost_vdpa_dma_map (v, iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {@@ -221,6 +244,10 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,
Quoted 9 lines
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 195
Quoted 6 lines
hw/virtio/vhost-vdpa.c +4
-0llsize =int128_sub (llend,int128_make64 (iova)); +if (v->dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) { +vhost_vdpa_iotlb_batch_begin_once (v); + } +Do we need to check
vhost_vdpa_iotlb_batch_is_started()in the .commit?
I don't follow you here. It's that comment in this position of the patch for a reason?
That checking is the one that allows qemu to skip the IOTLB_END write.
Quoted 19 lines
Others look good.
Thanks
Quoted 14 lines
hw/virtio/vhost-vdpa.c +0
-2ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize));if (ret) {error_report ("vhost_vdpa dma unmap error!" );@@ -234,7 +261,6 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,* depends on the addnop(). */ static const MemoryListener vhost_vdpa_memory_listener = { - .begin = vhost_vdpa_listener_begin, .commit = vhost_vdpa_listener_commit, .region_add = vhost_vdpa_listener_region_add, .region_del = vhost_vdpa_listener_region_del, --2.27.0
Quoted 139 lines · Eugenio Perez Martin
Quoted 107 lines · Jason Wang
Quoted 105 lines · Eugenio Pérez
With the introduction of the batch hinting, meaningless batches can be created with no IOTLB updates if the memory region was skipped by
vhost_vdpa_listener_skipped_section. This is the case of host notifiers memory regions, device un/realize, and others. This causes the vdpa device to receive dma mapping settings with no changes, a possibly expensive operation for nothing.To avoid that,
VHOST_IOTLB_BATCH_BEGINhint is delayed until we have a meaningful (not skipped section) mapping or unmapping operation, andVHOST_IOTLB_BATCH_ENDis not written unless at least one of_UPDATE/_INVALIDATEhas been issued.Signed-off-by Eugenio Pérez <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 50 ++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -23,6 +23,7 @@ typedef struct vhost_vdpa {int device_fd;int index;uint32_t msg_type; +size_t n_mr_updated;MemoryListener listener;struct vhost_dev *dev;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];hw/virtio/vhost-vdpa.c +30
-11@@ -89,19 +89,13 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova,return ret; } -static void vhost_vdpa_listener_begin (MemoryListener *listener) +static void vhost_vdpa_listener_begin_batch (struct vhost_vdpa *v) { - struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); -struct vhost_dev *dev = v->dev; -struct vhost_msg_v2 msg = {};int fd = v->device_fd; - -if (!(dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) { -return ; - } - - msg.type = v->msg_type; - msg.iotlb.type =VHOST_IOTLB_BATCH_BEGIN ; +struct vhost_msg_v2 msg = { + .type = v->msg_type, + .iotlb.type =VHOST_IOTLB_BATCH_BEGIN , + };if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) { error_report("failed to write, fd=%d, errno=%d (%s)",@@ -109,6 +103,25 @@ static void vhost_vdpa_listener_begin(MemoryListener *listener) } } +static bool vhost_vdpa_iotlb_batch_is_started (const struct vhost_vdpa *v) +{ +return v->n_mr_updated !=0 ; +} + +static void vhost_vdpa_iotlb_batch_begin_once (struct vhost_vdpa *v) +{ +if (!vhost_vdpa_iotlb_batch_is_started (v)) { +vhost_vdpa_listener_begin_batch (v); + } + + v->n_mr_updated++; +} + +static void vhost_vdpa_iotlb_batch_reset (struct vhost_vdpa *v) +{ + v->n_mr_updated =0 ; +} +static void vhost_vdpa_listener_commit (MemoryListener *listener) { struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener);@@ -120,6 +133,10 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)return ; } +if (vhost_vdpa_iotlb_batch_is_started (v)) { +return ; + } + msg.type = v->msg_type; msg.iotlb.type =VHOST_IOTLB_BATCH_END ;@@ -127,6 +144,8 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno)); } + +vhost_vdpa_iotlb_batch_reset (v); }Quoted 9 lines
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 192
Quoted 6 lines
hw/virtio/vhost-vdpa.c +1
-0static void vhost_vdpa_listener_region_add(MemoryListener *listener,@@ -170,6 +189,10 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, llsize =int128_sub (llend,int128_make64 (iova)); +if (v->dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) {Let's move this in to
vhost_vdpa_iotlb_batch_begin_once()?Sure
Quoted 8 lines
Quoted 8 lines
hw/virtio/vhost-vdpa.c +3
-0+vhost_vdpa_iotlb_batch_begin_once (v); + } + ret =vhost_vdpa_dma_map (v, iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {@@ -221,6 +244,10 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,Quoted 9 lines
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 195
Quoted 6 lines
hw/virtio/vhost-vdpa.c +4
-0llsize =int128_sub (llend,int128_make64 (iova)); +if (v->dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) { +vhost_vdpa_iotlb_batch_begin_once (v); + } +Do we need to check
vhost_vdpa_iotlb_batch_is_started()in the .commit?
Quoted 4 lines
I don't follow you here. It's that comment in this position of the patch for a reason?
That checking is the one that allows qemu to skip the
IOTLB_ENDwrite.
So it looks to me the BATCH_END will be sent unconditionally in this patch?
If yes, will this become a problem?
Thanks
Quoted 21 lines
Quoted 20 lines
Others look good.
Thanks
Quoted 14 lines
hw/virtio/vhost-vdpa.c +0
-2ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize));if (ret) {error_report ("vhost_vdpa dma unmap error!" );@@ -234,7 +261,6 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,* depends on the addnop(). */ static const MemoryListener vhost_vdpa_memory_listener = { - .begin = vhost_vdpa_listener_begin, .commit = vhost_vdpa_listener_commit, .region_add = vhost_vdpa_listener_region_add, .region_del = vhost_vdpa_listener_region_del, --2.27.0
Quoted 142 lines · Jason Wang
Quoted 139 lines · Eugenio Perez Martin
Quoted 107 lines · Jason Wang
Quoted 105 lines · Eugenio Pérez
With the introduction of the batch hinting, meaningless batches can be created with no IOTLB updates if the memory region was skipped by
vhost_vdpa_listener_skipped_section. This is the case of host notifiers memory regions, device un/realize, and others. This causes the vdpa device to receive dma mapping settings with no changes, a possibly expensive operation for nothing.To avoid that,
VHOST_IOTLB_BATCH_BEGINhint is delayed until we have a meaningful (not skipped section) mapping or unmapping operation, andVHOST_IOTLB_BATCH_ENDis not written unless at least one of_UPDATE/_INVALIDATEhas been issued.Signed-off-by Eugenio Pérez <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 50 ++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -23,6 +23,7 @@ typedef struct vhost_vdpa {int device_fd;int index;uint32_t msg_type; +size_t n_mr_updated;MemoryListener listener;struct vhost_dev *dev;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];hw/virtio/vhost-vdpa.c +30
-11@@ -89,19 +89,13 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova,return ret; } -static void vhost_vdpa_listener_begin (MemoryListener *listener) +static void vhost_vdpa_listener_begin_batch (struct vhost_vdpa *v) { - struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); -struct vhost_dev *dev = v->dev; -struct vhost_msg_v2 msg = {};int fd = v->device_fd; - -if (!(dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ))) { -return ; - } - - msg.type = v->msg_type; - msg.iotlb.type =VHOST_IOTLB_BATCH_BEGIN ; +struct vhost_msg_v2 msg = { + .type = v->msg_type, + .iotlb.type =VHOST_IOTLB_BATCH_BEGIN , + };if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) { error_report("failed to write, fd=%d, errno=%d (%s)",@@ -109,6 +103,25 @@ static void vhost_vdpa_listener_begin(MemoryListener *listener) } } +static bool vhost_vdpa_iotlb_batch_is_started (const struct vhost_vdpa *v) +{ +return v->n_mr_updated !=0 ; +} + +static void vhost_vdpa_iotlb_batch_begin_once (struct vhost_vdpa *v) +{ +if (!vhost_vdpa_iotlb_batch_is_started (v)) { +vhost_vdpa_listener_begin_batch (v); + } + + v->n_mr_updated++; +} + +static void vhost_vdpa_iotlb_batch_reset (struct vhost_vdpa *v) +{ + v->n_mr_updated =0 ; +} +static void vhost_vdpa_listener_commit (MemoryListener *listener) { struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener);@@ -120,6 +133,10 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)return ; } +if (vhost_vdpa_iotlb_batch_is_started (v)) { +return ; + } + msg.type = v->msg_type; msg.iotlb.type =VHOST_IOTLB_BATCH_END ;@@ -127,6 +144,8 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)error_report ("failed to write, fd=%d, errno=%d (%s)" , fd, errno,strerror (errno)); } + +vhost_vdpa_iotlb_batch_reset (v); }Quoted 9 lines
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 192
Quoted 6 lines
hw/virtio/vhost-vdpa.c +1
-0static void vhost_vdpa_listener_region_add(MemoryListener *listener,@@ -170,6 +189,10 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, llsize =int128_sub (llend,int128_make64 (iova)); +if (v->dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) {Let's move this in to
vhost_vdpa_iotlb_batch_begin_once()?Sure
Quoted 17 lines
Quoted 7 lines
hw/virtio/vhost-vdpa.c +3
-0+vhost_vdpa_iotlb_batch_begin_once (v); + } + ret =vhost_vdpa_dma_map (v, iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_del(MemoryListener *listener, · line 250
Quoted 7 lines
hw/virtio/vhost-vdpa.c +4
-0@@ -221,6 +244,10 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, llsize =int128_sub (llend,int128_make64 (iova)); +if (v->dev->backend_cap & (0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH )) { +vhost_vdpa_iotlb_batch_begin_once (v); + } +Do we need to check
vhost_vdpa_iotlb_batch_is_started()in the .commit?
Quoted 9 lines
Quoted 4 lines
I don't follow you here. It's that comment in this position of the patch for a reason?
That checking is the one that allows qemu to skip the
IOTLB_ENDwrite.So it looks to me the
BATCH_ENDwill be sent unconditionally in this patch?If yes, will this become a problem?
Ok so actually the check in .commit needs to be the opposite, !vhost_vdpa_iotlb_batch_is_started. In my fast testing, the host notifiers memory regions were the ones actually sending the guest's memory regions.
Once that testing is negated, it shouldn't send any batches that have been skipped:
* listener_begin it's not called unconditionally anymore,
* IOTLB_BATCH_BEGIN is only written once in region add/del *if* section is not skipped and other tests like (iova + len > iova).
* IOTLB_BATCH_END is only written if IOTLB_BATCH_BEGIN has been sent, that should make vhost_vdpa_iotlb_batch_is_started return true.
Sending the next version with the mentioned changes as v3, please let me know if I've missed something else.
Thanks!
Quoted 24 lines
Thanks
Quoted 21 lines
Quoted 20 lines
Others look good.
Thanks
Quoted 14 lines
hw/virtio/vhost-vdpa.c +0
-2ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize));if (ret) {error_report ("vhost_vdpa dma unmap error!" );@@ -234,7 +261,6 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,* depends on the addnop(). */ static const MemoryListener vhost_vdpa_memory_listener = { - .begin = vhost_vdpa_listener_begin, .commit = vhost_vdpa_listener_commit, .region_add = vhost_vdpa_listener_region_add, .region_del = vhost_vdpa_listener_region_del, --2.27.0