When a existing mapping is unmapped, there could already be dirty bits which need to be recorded before unmap.
If query dirty bitmap fails, we still need to do unmapping or else there is stale mapping and it's risky to guest. Co-developed-by: Joao Martins <[email protected]> Signed-off-by: Joao Martins <[email protected]> Signed-off-by: Zhenzhong Duan <[email protected]> Tested-by: Xudong Hao <[email protected]> Tested-by: Giovannio Cabiddu <[email protected]> --- hw/vfio/iommufd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index b5d6e54c45..0057488ce9 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -73,7 +73,13 @@ static int iommufd_cdev_unmap_one(const VFIOContainerBase *bcontainer, if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer) && bcontainer->dirty_pages_supported) { - /* TODO: query dirty bitmap before DMA unmap */ + ret = vfio_container_query_dirty_bitmap(bcontainer, iova, size, + iotlb->translated_addr, + &local_err); + if (ret) { + error_report_err(local_err); + } + /* Unmap stale mapping even if query dirty bitmap fails */ return iommufd_backend_unmap_dma(be, ioas_id, iova, size); } -- 2.47.1
