Skip to contentSkip to conversation

vfio/type1: fix dirty bitmap calculation in vfio_dma_rw

PATCH New Yan Zhao 1 participant 1 message Sep 16, 2020

Subsystems (2)
lore
Share & tools
lore

Yan Zhao

author
#0 lore raw

PATCH v2 1/1 vfio/type1: fix dirty bitmap calculation in vfio_dma_rw

the count of dirtied pages is not only determined by count of copied pages, but also by the start offset.

e.g. if offset = PAGE_SIZE - 1, and *copied=2, the dirty pages count is 2, instead of 1 or 0.

Fixes d6a4c185660c ("vfio iommu: Implementation of ioctl for dirty pages tracking")

---
v2: updated the format of the Fixes: line.

---
 drivers/vfio/vfio_iommu_type1.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vfio/vfio_iommu_type1.c +2 -1
index 5fbf0c1f7433..d0438388feeb 100644
@@ -2933,7 +2933,8 @@ static int vfio_iommu_type1_dma_rw_chunk(struct vfio_iommu *iommu,
 			 * size
 			 */
 			bitmap_set(dma->bitmap, offset >> pgshift,
-				   *copied >> pgshift);
+				   ((offset + *copied - 1) >> pgshift) -
+				   (offset >> pgshift) + 1);
 		}
 	} else
 		*copied = copy_from_user(data, (void __user *)vaddr,
Signature · 1 line
2.17.1