We should populate dirty bitmap for newly added vfio_dma as it can be
accessed arbitrarily if vfio_iommu is not promoted to pinned_scope.
vfio_dma_populate_bitmap can handle this properly.

Fixes: d6a4c185660c ("vfio iommu: Implementation of ioctl for dirty pages 
tracking")
Signed-off-by: Keqian Zhu <zhukeqi...@huawei.com>
---
 drivers/vfio/vfio_iommu_type1.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index b0a26e8e0adf..29c8702c3b6e 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1413,7 +1413,9 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
 
        if (!ret && iommu->dirty_page_tracking) {
                ret = vfio_dma_bitmap_alloc(dma, pgsize);
-               if (ret)
+               if (!ret)
+                       vfio_dma_populate_bitmap(iommu, dma);
+               else
                        vfio_remove_dma(iommu, dma);
        }
 
-- 
2.19.1

Reply via email to