From: David Matlack <dmatlack@google.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Cc: Alex Williamson <alex@shazbot.org>,
David Matlack <dmatlack@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Shuah Khan <shuah@kernel.org>
Subject: [PATCH v3 0/5] vfio: selftests: Automatically detect the IOMMU mode
Date: Mon, 9 Nov 2026 21:08:28 +0000 [thread overview]
Message-ID: <20261109210833.1250548-1-dmatlack@google.com> (raw)
This series makes the VFIO selftests library automatically detect which
IOMMU mode to use, rather than hardcoding iommufd as the default, and
makes tests skip, rather than fail, when the IOMMU mode they need is not
available. This was suggested by Sean while reviewing the KVM selftest
irq_test [1].
iommufd is an optional feature, and VFIO's iommufd support additionally
requires CONFIG_VFIO_DEVICE_CDEV. On otherwise functional kernels that
only support the legacy VFIO container, the VFIO selftests currently
fail with an unhelpful assert:
tools/testing/selftests/vfio/lib/iommu.c:448: Assertion Failure
Expression: iommu->iommufd > 0
Observed: 0xffffffffffffffff > 0
[errno: 2 - No such file or directory]
irq_test avoids this by probing for the IOMMU mode itself, but its probe
picks iommufd whenever /dev/iommu exists, even if VFIO device cdevs are
not available.
Patch 1 makes iommu_init(NULL) pick the most preferred IOMMU mode that
is available on the current system, and drops the global
default_iommu_mode.
Patch 2 adds iommu_mode_is_available(), iommu_mode_unavailable_msg(),
and SKIP_IF_IOMMU_MODE_UNAVAILABLE(), and uses them to skip tests when
the IOMMU mode they need is not available.
Patch 3 makes the VFIO selftests library print the names of all known
IOMMU modes when passed an unrecognized mode, and the names of the
available modes when a test skips because the mode it requested is not
available. It also adds iommu_mode_names_all() and
iommu_mode_names_available() so that tests can print both lists.
Patch 4 converts irq_test to use the VFIO selftests library to pick the
IOMMU mode, and drops its probe_iommu_type().
Patch 5 lists the known and available IOMMU modes in irq_test's help
output.
This series is based on vfio/next (vfio-v7.4-rc1).
Testing
-------
Tested in a QEMU VM with an emulated igb device behind an emulated Intel
IOMMU, bound to vfio-pci, on a kernel with CONFIG_IOMMUFD=y,
CONFIG_VFIO_DEVICE_CDEV=y, and CONFIG_VFIO_CONTAINER=y. To simulate
kernels with fewer IOMMU modes available, /dev/iommu and /dev/vfio/vfio
were deleted in the VM:
- All IOMMU modes available: All VFIO selftests pass. irq_test -d
passes using iommufd. irq_test -h lists all five IOMMU modes as
available, and irq_test -d -t bogus fails and lists the known modes.
- Only the legacy VFIO container available (/dev/iommu deleted): All
VFIO selftests pass. The iommufd and iommufd_compat variants and
vfio_iommufd_setup_test skip instead of failing. irq_test -d passes
using vfio_type1v2_iommu. irq_test -d -t iommufd skips and lists the
available modes, as does irq_test -h.
- No IOMMU mode available (/dev/iommu and /dev/vfio/vfio deleted): All
VFIO selftests and irq_test -d skip with a message explaining why,
and with well-formed TAP output. irq_test -h lists no available
modes.
Also tested with CONFIG_VFIO_GROUP=n (cdev-only VFIO):
- All VFIO selftests pass, with the iommufd variants running and the
vfio_type1* and iommufd_compat variants skipped. Without the VFIO
group check added in v3, the iommufd_compat variants fail instead.
irq_test -d passes using iommufd, and irq_test -h lists only iommufd
as available.
Changelog
---------
v3:
- Require VFIO group support (CONFIG_VFIO_GROUP) for container modes,
including the iommufd_compat modes (patch 1) [Sashiko [2]]
- List the available IOMMU modes in irq_test's help output, alongside
all known modes, and when the requested mode is not available
(patches 3 and 5) [Sean]
- Simplify the -t help text in irq_test (patch 5) [Sean]
- Make the unrecognized IOMMU mode error easier to read (patch 3)
[Sean]
- Rename iommu_type to iommu_mode in irq_test (patches 4 and 5) [Sean]
- Skip vfio_iommufd_setup_test when iommufd is not available (patch 2)
v2: https://lore.kernel.org/kvm/20261103002205.3348519-1-dmatlack@google.com/
v1: https://lore.kernel.org/kvm/20261029221710.1871112-1-dmatlack@google.com/
[1] https://lore.kernel.org/kvm/aiIG2L_KdPwuxYA1@google.com/
[2] https://lore.kernel.org/kvm/sashiko-outbox-194380@kernel.org/
David Matlack (5):
vfio: selftests: Automatically detect the IOMMU mode in iommu_init()
vfio: selftests: Skip tests when the IOMMU mode is not available
vfio: selftests: Print the IOMMU modes when a requested mode can't be
used
KVM: selftests: Use VFIO selftests library to pick IOMMU mode in
irq_test
KVM: selftests: List the IOMMU modes in irq_test's help output
tools/testing/selftests/kvm/irq_test.c | 32 ++--
.../vfio/lib/include/libvfio/iommu.h | 43 +++++-
tools/testing/selftests/vfio/lib/iommu.c | 139 ++++++++++++++++--
.../vfio/vfio_dma_mapping_mmio_test.c | 2 +
.../selftests/vfio/vfio_dma_mapping_test.c | 4 +
.../selftests/vfio/vfio_iommufd_setup_test.c | 2 +
.../vfio/vfio_pci_device_init_perf_test.c | 2 +
.../selftests/vfio/vfio_pci_device_test.c | 8 +-
.../selftests/vfio/vfio_pci_driver_test.c | 9 +-
.../selftests/vfio/vfio_pci_sriov_uapi_test.c | 4 +
10 files changed, 205 insertions(+), 40 deletions(-)
base-commit: 076d7e989cb69f6ded7d60f2a080eb909930061b
--
2.56.0.506.g506a7eabc5-goog
next reply other threads:[~2026-11-09 21:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 21:08 David Matlack [this message]
2026-11-09 21:08 ` [PATCH v3 1/5] vfio: selftests: Automatically detect the IOMMU mode in iommu_init() David Matlack
2026-11-09 21:08 ` [PATCH v3 2/5] vfio: selftests: Skip tests when the IOMMU mode is not available David Matlack
2026-11-09 21:08 ` [PATCH v3 3/5] vfio: selftests: Print the IOMMU modes when a requested mode can't be used David Matlack
2026-11-09 21:08 ` [PATCH v3 4/5] KVM: selftests: Use VFIO selftests library to pick IOMMU mode in irq_test David Matlack
2026-11-09 21:08 ` [PATCH v3 5/5] KVM: selftests: List the IOMMU modes in irq_test's help output David Matlack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261109210833.1250548-1-dmatlack@google.com \
--to=dmatlack@google.com \
--cc=alex@shazbot.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®