Print the number of dirty pages after calling cpu_physical_memory_set_lebitmap() on the vfio_get_dirty_bitmap tracepoint. Additionally, print the number of dirty pages to capture the unmap case under a new tracepoint called vfio_set_dirty_pages. Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx> --- hw/vfio/container.c | 12 +++++++++--- hw/vfio/iommufd.c | 10 ++++++---- hw/vfio/trace-events | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index fff8319c0036..b17d3499d9a1 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -146,6 +146,7 @@ static int vfio_dma_unmap_bitmap(VFIOLegacyContainer *container, struct vfio_iommu_type1_dma_unmap *unmap; struct vfio_bitmap *bitmap; uint64_t pages = REAL_HOST_PAGE_ALIGN(size) / qemu_real_host_page_size; + uint64_t dirty; int ret; unmap = g_malloc0(sizeof(*unmap) + sizeof(*bitmap)); @@ -181,8 +182,11 @@ static int vfio_dma_unmap_bitmap(VFIOLegacyContainer *container, ret = ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, unmap); if (!ret) { + dirty = total_dirty_pages; cpu_physical_memory_set_dirty_lebitmap((unsigned long *)bitmap->data, iotlb->translated_addr, pages); + trace_vfio_set_dirty_pages(container->fd, iova, size, + total_dirty_pages - dirty); } else { error_report("VFIO_UNMAP_DMA with DIRTY_BITMAP : %m"); } @@ -312,7 +316,7 @@ static int vfio_get_dirty_bitmap(VFIOContainer *bcontainer, uint64_t iova, VFIOLegacyContainer, obj); struct vfio_iommu_type1_dirty_bitmap *dbitmap; struct vfio_iommu_type1_dirty_bitmap_get *range; - uint64_t pages; + uint64_t pages, dirty; int ret; if (!memory_global_dirty_devices()) { @@ -351,11 +355,13 @@ static int vfio_get_dirty_bitmap(VFIOContainer *bcontainer, uint64_t iova, goto err_out; } + + dirty = total_dirty_pages; cpu_physical_memory_set_dirty_lebitmap((unsigned long *)range->bitmap.data, ram_addr, pages); - trace_vfio_get_dirty_bitmap(container->fd, range->iova, range->size, - range->bitmap.size, ram_addr); + range->bitmap.size, ram_addr, + total_dirty_pages - dirty); err_out: g_free(range->bitmap.data); g_free(dbitmap); diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 4686cc713aac..461030bb7135 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -77,7 +77,7 @@ static int iommufd_copy(VFIOContainer *src, VFIOContainer *dst, static int iommufd_unmap_bitmap(int iommufd, int ioas_id, hwaddr iova, ram_addr_t size, ram_addr_t translated) { - unsigned long *data, pgsize, bitmap_size, pages; + unsigned long *data, pgsize, bitmap_size, pages, dirty; int ret; pgsize = qemu_real_host_page_size; @@ -95,9 +95,10 @@ static int iommufd_unmap_bitmap(int iommufd, int ioas_id, hwaddr iova, goto err_out; } + dirty = total_dirty_pages; cpu_physical_memory_set_dirty_lebitmap(data, translated, pages); - trace_vfio_get_dirty_bitmap(iommufd, iova, size, bitmap_size, translated); + trace_vfio_set_dirty_pages(iommufd, iova, size, total_dirty_pages - dirty); err_out: g_free(data); @@ -148,7 +149,7 @@ static int iommufd_get_dirty_bitmap(VFIOContainer *bcontainer, uint64_t iova, VFIOIOMMUFDContainer, obj); int ret; VFIOIOASHwpt *hwpt; - unsigned long *data, page_size, bitmap_size, pages; + unsigned long *data, page_size, bitmap_size, pages, dirty; if (!memory_global_dirty_devices()) { return 0; @@ -176,10 +177,11 @@ static int iommufd_get_dirty_bitmap(VFIOContainer *bcontainer, uint64_t iova, } } + dirty = total_dirty_pages; cpu_physical_memory_set_dirty_lebitmap(data, ram_addr, pages); trace_vfio_get_dirty_bitmap(container->iommufd, iova, size, bitmap_size, - ram_addr); + ram_addr, total_dirty_pages - dirty); err_out: g_free(data); diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 51f04b0b80b8..c8d6348469aa 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -163,7 +163,8 @@ vfio_load_device_config_state(const char *name) " (%s)" vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 vfio_load_state_device_data(const char *name, uint64_t data_offset, uint64_t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 vfio_load_cleanup(const char *name) " (%s)" -vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64 +vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty=%"PRIu64 +vfio_set_dirty_pages(int fd, uint64_t iova, uint64_t size, uint64_t nr_pages) "container fd=%d, iova=0x%"PRIx64" size=0x%"PRIx64" nr_pages=%"PRIu64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64 #iommufd.c -- 2.17.2