On 2026-07-02 11:28 PM, Narayana Murty N wrote:
> Add support for selecting the IOMMU mode through the environment
> variable VFIO_SELFTESTS_IOMMU_MODE. This allows tests to be run
> with different IOMMU backends without modifying test code.
>
> The environment variable is validated against the list of supported
> modes. On PowerPC, this includes the sPAPR TCE v2 mode which will
> be added in a subsequent patch.
>
> If the environment variable is not set, tests use their default
> mode, preserving existing behavior.
>
> Signed-off-by: Narayana Murty N <[email protected]>
> diff --git a/tools/testing/selftests/vfio/vfio_pci_device_test.c
> b/tools/testing/selftests/vfio/vfio_pci_device_test.c
> index 93c11fd5e081..45b8bf60527a 100644
> --- a/tools/testing/selftests/vfio/vfio_pci_device_test.c
> +++ b/tools/testing/selftests/vfio/vfio_pci_device_test.c
> @@ -29,7 +29,7 @@ FIXTURE(vfio_pci_device_test) {
>
> FIXTURE_SETUP(vfio_pci_device_test)
> {
> - self->iommu = iommu_init(default_iommu_mode);
> + self->iommu = iommu_init(vfio_selftests_get_iommu_mode());
> self->device = vfio_pci_device_init(device_bdf, self->iommu);
> }
>
> @@ -121,7 +121,7 @@ FIXTURE_VARIANT_ADD(vfio_pci_irq_test, msix) {
>
> FIXTURE_SETUP(vfio_pci_irq_test)
> {
> - self->iommu = iommu_init(default_iommu_mode);
> + self->iommu = iommu_init(vfio_selftests_get_iommu_mode());
> self->device = vfio_pci_device_init(device_bdf, self->iommu);
> }
Rather than forcing the user to pass in the mode via environment
variable, can vfio_selftests_get_iommu_mode() pick a reasonable default
based on what the host supports? i.e. Is it possible for
vfio_selftests_get_iommu_mode() to now when to pick
MODE_VFIO_SPAPR_TCE_V2_IOMMU as the default mode?
The new KVM device-posted interrupt test that uses the VFIO selftests
library also wants this to pick between MODE_IOMMUFD and
MODE_VFIO_TYPE1_IOMMU.
https://lore.kernel.org/kvm/[email protected]/
And this would also fix VFIO selftests that get run on kernels where
IOMMUFD is not enabled.