[PATCH v3 0/3] vfio: selftests: Add MMIO DMA mapping test

Alex Mastro posted 3 patches 3 weeks, 2 days ago
tools/testing/selftests/vfio/Makefile              |   1 +
tools/testing/selftests/vfio/lib/include/libvfio.h |   9 ++
.../selftests/vfio/lib/include/libvfio/iommu.h     |   6 +
tools/testing/selftests/vfio/lib/iommu.c           |  12 +-
tools/testing/selftests/vfio/lib/libvfio.c         |  25 ++++
tools/testing/selftests/vfio/lib/vfio_pci_device.c |  24 +++-
.../selftests/vfio/vfio_dma_mapping_mmio_test.c    | 143 +++++++++++++++++++++
.../testing/selftests/vfio/vfio_dma_mapping_test.c |   2 +-
8 files changed, 214 insertions(+), 8 deletions(-)
[PATCH v3 0/3] vfio: selftests: Add MMIO DMA mapping test
Posted by Alex Mastro 3 weeks, 2 days ago
Test IOMMU mapping the BAR mmaps created during vfio_pci_device_setup().

All IOMMU modes are tested: vfio_type1 variants are expected to succeed,
while non-type1 modes are expected to fail. iommufd compat mode can be
updated to expect success once kernel support lands. Native iommufd will
not support mapping vaddrs backed by MMIO (it will support dma-buf based
MMIO mapping instead).

Changes in v3:
- Rename mmap_aligned() to mmap_reserve()
- Reorder variable declarations for reverse-fir-tree style
- Update patch 2 commit message to mention MADV_HUGEPAGE and MAP_FILE
- Move BAR size check into map_partial_bar test only
- Link to v2: https://lore.kernel.org/r/20260113-map-mmio-test-v2-0-e6d34f09c0bb@fb.com

Changes in v2:
- Split into patch series
- Factor out mmap_reserve() for vaddr alignment
- Align BAR mmaps to improve hugepage IOMMU mapping efficiency
- Centralize MODE_* string definitions
- Add is_power_of_2() assertion for BAR size
- Simplify align calculation to min(size, 1G)
- Add map_bar_misaligned test case
- Link to v1: https://lore.kernel.org/all/20260107-scratch-amastro-vfio-dma-mapping-mmio-test-v1-1-0cec5e9ec89b@fb.com

Signed-off-by: Alex Mastro <amastro@fb.com>

---
Alex Mastro (3):
      vfio: selftests: Centralize IOMMU mode name definitions
      vfio: selftests: Align BAR mmaps for efficient IOMMU mapping
      vfio: selftests: Add vfio_dma_mapping_mmio_test

 tools/testing/selftests/vfio/Makefile              |   1 +
 tools/testing/selftests/vfio/lib/include/libvfio.h |   9 ++
 .../selftests/vfio/lib/include/libvfio/iommu.h     |   6 +
 tools/testing/selftests/vfio/lib/iommu.c           |  12 +-
 tools/testing/selftests/vfio/lib/libvfio.c         |  25 ++++
 tools/testing/selftests/vfio/lib/vfio_pci_device.c |  24 +++-
 .../selftests/vfio/vfio_dma_mapping_mmio_test.c    | 143 +++++++++++++++++++++
 .../testing/selftests/vfio/vfio_dma_mapping_test.c |   2 +-
 8 files changed, 214 insertions(+), 8 deletions(-)
---
base-commit: d721f52e31553a848e0e9947ca15a49c5674aef3
change-id: 20260112-map-mmio-test-b4e4c2d917a9

Best regards,
-- 
Alex Mastro <amastro@fb.com>
Re: [PATCH v3 0/3] vfio: selftests: Add MMIO DMA mapping test
Posted by Alex Williamson 2 weeks, 4 days ago
On Wed, 14 Jan 2026 10:57:15 -0800
Alex Mastro <amastro@fb.com> wrote:

> Test IOMMU mapping the BAR mmaps created during vfio_pci_device_setup().
> 
> All IOMMU modes are tested: vfio_type1 variants are expected to succeed,
> while non-type1 modes are expected to fail. iommufd compat mode can be
> updated to expect success once kernel support lands. Native iommufd will
> not support mapping vaddrs backed by MMIO (it will support dma-buf based
> MMIO mapping instead).
> 
> Changes in v3:
> - Rename mmap_aligned() to mmap_reserve()
> - Reorder variable declarations for reverse-fir-tree style
> - Update patch 2 commit message to mention MADV_HUGEPAGE and MAP_FILE
> - Move BAR size check into map_partial_bar test only
> - Link to v2: https://lore.kernel.org/r/20260113-map-mmio-test-v2-0-e6d34f09c0bb@fb.com
> 
> Changes in v2:
> - Split into patch series
> - Factor out mmap_reserve() for vaddr alignment
> - Align BAR mmaps to improve hugepage IOMMU mapping efficiency
> - Centralize MODE_* string definitions
> - Add is_power_of_2() assertion for BAR size
> - Simplify align calculation to min(size, 1G)
> - Add map_bar_misaligned test case
> - Link to v1: https://lore.kernel.org/all/20260107-scratch-amastro-vfio-dma-mapping-mmio-test-v1-1-0cec5e9ec89b@fb.com
> 
> Signed-off-by: Alex Mastro <amastro@fb.com>
> 
> ---
> Alex Mastro (3):
>       vfio: selftests: Centralize IOMMU mode name definitions
>       vfio: selftests: Align BAR mmaps for efficient IOMMU mapping
>       vfio: selftests: Add vfio_dma_mapping_mmio_test
> 
>  tools/testing/selftests/vfio/Makefile              |   1 +
>  tools/testing/selftests/vfio/lib/include/libvfio.h |   9 ++
>  .../selftests/vfio/lib/include/libvfio/iommu.h     |   6 +
>  tools/testing/selftests/vfio/lib/iommu.c           |  12 +-
>  tools/testing/selftests/vfio/lib/libvfio.c         |  25 ++++
>  tools/testing/selftests/vfio/lib/vfio_pci_device.c |  24 +++-
>  .../selftests/vfio/vfio_dma_mapping_mmio_test.c    | 143 +++++++++++++++++++++
>  .../testing/selftests/vfio/vfio_dma_mapping_test.c |   2 +-
>  8 files changed, 214 insertions(+), 8 deletions(-)
> ---
> base-commit: d721f52e31553a848e0e9947ca15a49c5674aef3
> change-id: 20260112-map-mmio-test-b4e4c2d917a9
> 
> Best regards,

Applied to vfio next branch for v6.20/7.0.  Thanks,

Alex
Re: [PATCH v3 0/3] vfio: selftests: Add MMIO DMA mapping test
Posted by David Matlack 3 weeks ago
On 2026-01-14 10:57 AM, Alex Mastro wrote:
> Test IOMMU mapping the BAR mmaps created during vfio_pci_device_setup().
> 
> All IOMMU modes are tested: vfio_type1 variants are expected to succeed,
> while non-type1 modes are expected to fail. iommufd compat mode can be
> updated to expect success once kernel support lands. Native iommufd will
> not support mapping vaddrs backed by MMIO (it will support dma-buf based
> MMIO mapping instead).
> 
> Changes in v3:
> - Rename mmap_aligned() to mmap_reserve()
> - Reorder variable declarations for reverse-fir-tree style
> - Update patch 2 commit message to mention MADV_HUGEPAGE and MAP_FILE
> - Move BAR size check into map_partial_bar test only
> - Link to v2: https://lore.kernel.org/r/20260113-map-mmio-test-v2-0-e6d34f09c0bb@fb.com
> 
> Changes in v2:
> - Split into patch series
> - Factor out mmap_reserve() for vaddr alignment
> - Align BAR mmaps to improve hugepage IOMMU mapping efficiency
> - Centralize MODE_* string definitions
> - Add is_power_of_2() assertion for BAR size
> - Simplify align calculation to min(size, 1G)
> - Add map_bar_misaligned test case
> - Link to v1: https://lore.kernel.org/all/20260107-scratch-amastro-vfio-dma-mapping-mmio-test-v1-1-0cec5e9ec89b@fb.com
> 
> Signed-off-by: Alex Mastro <amastro@fb.com>

Reviewed-by: David Matlack <dmatlack@google.com>
Tested-by: David Matlack <dmatlack@google.com>