vhost-vdpa: Do not send empty IOTLB update batches
commite6db5df7e2c6e64846f47a6785a9a67f08574790
authorEugenio Pérez <eperezma@redhat.com>
Thu, 12 Aug 2021 14:09:33 +0000 (12 16:09 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Sat, 4 Sep 2021 13:07:45 +0000 (4 09:07 -0400)
tree5db9674e04eb8a82508f934462baf9e779914edb
parent8880cc4362fde4ecdac0b2092318893118206fcf
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.

v3:
  * Use a bool instead of a counter avoiding potential number wrapping
  * Fix bad check on _commit
  * Move VHOST_BACKEND_F_IOTLB_BATCH check to
    vhost_vdpa_iotlb_batch_begin_once

v2 (from RFC):
  * Rename misleading name
  * Abstract start batching function for listener_add/del

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Message-Id: <20210812140933.226288-1-eperezma@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/virtio/vhost-vdpa.c
include/hw/virtio/vhost-vdpa.h