Skip to content

Commit 4004497

Browse files
brettcreeleyAlex Williamson
authored andcommitted
vfio/pds: Fix calculations in pds_vfio_dirty_sync
The incorrect check is being done for comparing the iova/length being requested to sync. This can cause the dirty sync operation to fail. Fix this by making sure the iova offset added to the requested sync length doesn't exceed the region_size. Also, the region_start is assumed to always be at 0. This can cause dirty tracking to fail because the device/driver bitmap offset always starts at 0, however, the region_start/iova may not. Fix this by determining the iova offset from region_start to determine the bitmap offset. Fixes: f232836 ("vfio/pds: Add support for dirty page tracking") Signed-off-by: Brett Creeley <brett.creeley@amd.com> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com> Link: https://lore.kernel.org/r/20231117001207.2793-2-brett.creeley@amd.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 33cc938 commit 4004497

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/vfio/pci/pds/dirty.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ static int pds_vfio_dirty_sync(struct pds_vfio_pci_device *pds_vfio,
478478
pds_vfio->vf_id, iova, length, pds_vfio->dirty.region_page_size,
479479
pages, bitmap_size);
480480

481-
if (!length || ((dirty->region_start + iova + length) >
482-
(dirty->region_start + dirty->region_size))) {
481+
if (!length || ((iova - dirty->region_start + length) > dirty->region_size)) {
483482
dev_err(dev, "Invalid iova 0x%lx and/or length 0x%lx to sync\n",
484483
iova, length);
485484
return -EINVAL;
@@ -496,7 +495,8 @@ static int pds_vfio_dirty_sync(struct pds_vfio_pci_device *pds_vfio,
496495
return -EINVAL;
497496
}
498497

499-
bmp_offset = DIV_ROUND_UP(iova / dirty->region_page_size, sizeof(u64));
498+
bmp_offset = DIV_ROUND_UP((iova - dirty->region_start) /
499+
dirty->region_page_size, sizeof(u64));
500500

501501
dev_dbg(dev,
502502
"Syncing dirty bitmap, iova 0x%lx length 0x%lx, bmp_offset %llu bmp_bytes %llu\n",

0 commit comments

Comments
 (0)