vfio/pds: Fix calculations in pds_vfio_dirty_sync
authorBrett Creeley <brett.creeley@amd.com>
Fri, 17 Nov 2023 00:12:02 +0000 (16:12 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jan 2024 23:35:51 +0000 (15:35 -0800)
commit358b1c992ec04c296b959b59c178a5d426c730a5
treec834c89e373cbb05c6376a1a7a5272cfa4650853
parentc7e8c0e61da537b358946baee8c430d67e7551c1
vfio/pds: Fix calculations in pds_vfio_dirty_sync

[ Upstream commit 4004497cec3093d7b0087bc70709b45969fa07b6 ]

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: f232836a9152 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/vfio/pci/pds/dirty.c