linux/drivers/vfio
Alex Mastro ef270ec446 vfio/type1: handle DMA map/unmap up to the addressable limit
Before this commit, it was possible to create end of address space
mappings, but unmapping them via VFIO_IOMMU_UNMAP_DMA, replaying them
for newly added iommu domains, and querying their dirty pages via
VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP was broken due to bugs caused by
comparisons against (iova + size) expressions, which overflow to zero.
Additionally, there appears to be a page pinning leak in the
vfio_iommu_type1_release() path, since vfio_unmap_unpin()'s loop body
where unmap_unpin_*() are called will never be entered due to overflow
of (iova + size) to zero.

This commit handles DMA map/unmap operations up to the addressable
limit by comparing against inclusive end-of-range limits, and changing
iteration to perform relative traversals across range sizes, rather than
absolute traversals across addresses.

vfio_link_dma() inserts a zero-sized vfio_dma into the rb-tree, and is
only used for that purpose, so discard the size from consideration for
the insertion point.

Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Fixes: 73fa0d10d0 ("vfio: Type1 IOMMU implementation")
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Signed-off-by: Alex Mastro <amastro@fb.com>
Link: https://lore.kernel.org/r/20251028-fix-unmap-v6-3-2542b96bcc8e@fb.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
2025-10-28 15:54:41 -06:00
..
cdx vfio/cdx: update driver to build without CONFIG_GENERIC_MSI_IRQ 2025-08-27 12:14:13 -06:00
fsl-mc vfio/fsl-mc: Mark for removal 2025-08-27 09:23:00 -06:00
mdev drivers: core: remove device_link argument from class_compat_[create|remove]_link 2025-01-10 15:42:20 +01:00
pci VFIO updates for v6.18-rc1 2025-10-04 08:24:54 -07:00
platform vfio/platform: Mark reset drivers for removal 2025-09-19 14:36:38 -06:00
Kconfig vfio/migration: Add debugfs to live migration driver 2023-12-04 14:29:08 -07:00
Makefile vfio/migration: Add debugfs to live migration driver 2023-12-04 14:29:08 -07:00
container.c VFIO updates for v6.3-rc1 2023-02-25 11:52:57 -08:00
debugfs.c vfio: Dump migration features under debugfs 2025-10-06 11:22:48 -06:00
device_cdev.c vfio/pci: Do vf_token checks for VFIO_DEVICE_BIND_IOMMUFD 2025-08-05 15:41:14 -06:00
group.c vfio: Fix unbalanced vfio_df_close call in no-iommu mode 2025-07-11 14:43:37 -06:00
iommufd.c vfio: Fix unbalanced vfio_df_close call in no-iommu mode 2025-07-11 14:43:37 -06:00
vfio.h vfio: replace CONFIG_HAVE_KVM with IS_ENABLED(CONFIG_KVM) 2024-02-08 08:45:35 -05:00
vfio_iommu_spapr_tce.c vfio/spapr: Always clear TCEs before unsetting the window 2024-06-28 17:03:39 +10:00
vfio_iommu_type1.c vfio/type1: handle DMA map/unmap up to the addressable limit 2025-10-28 15:54:41 -06:00
vfio_main.c vfio: return -ENOTTY for unsupported device feature 2025-09-19 14:45:43 -06:00
virqfd.c assorted variants of irqfd setup: convert to CLASS(fd) 2024-11-03 01:28:07 -05:00