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 v2 3/5] vfio: selftests: Print the known IOMMU modes on an unrecognized mode
Date: Tue, 3 Nov 2026 00:22:03 +0000 [thread overview]
Message-ID: <20261103002205.3348519-4-dmatlack@google.com> (raw)
In-Reply-To: <20261103002205.3348519-1-dmatlack@google.com>
Print the names of all known IOMMU modes when iommu_init() is passed an
unrecognized IOMMU mode, and expose the list of names via
iommu_mode_names() so that tests can also print it, e.g. in their help
output.
Users can specify the IOMMU mode for some tests on the command line (e.g.
irq_test -t), and so a typo or unsupported mode should tell the user what
the valid options are rather than leaving them to go read the library.
Suggested-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/kvm/auit0kVkAaWcNUvk@google.com/
Signed-off-by: David Matlack <dmatlack@google.com>
---
.../vfio/lib/include/libvfio/iommu.h | 3 +++
tools/testing/selftests/vfio/lib/iommu.c | 20 ++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h b/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h
index f204c71494fe..42d1de742c0c 100644
--- a/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h
+++ b/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h
@@ -51,6 +51,9 @@ bool iommu_mode_is_available(const char *iommu_mode);
*/
const char *iommu_mode_unavailable_msg(const char *iommu_mode);
+/* Returns a comma-separated list of the names of all IOMMU modes. */
+const char *iommu_mode_names(void);
+
int __iommu_map(struct iommu *iommu, struct dma_region *region);
static inline void iommu_map(struct iommu *iommu, struct dma_region *region)
diff --git a/tools/testing/selftests/vfio/lib/iommu.c b/tools/testing/selftests/vfio/lib/iommu.c
index 526bb21f2766..64614325c49b 100644
--- a/tools/testing/selftests/vfio/lib/iommu.c
+++ b/tools/testing/selftests/vfio/lib/iommu.c
@@ -90,6 +90,23 @@ static const struct iommu_mode *iommu_mode_detect(void)
return NULL;
}
+const char *iommu_mode_names(void)
+{
+ static char names[256];
+ int i, len = 0;
+
+ if (names[0])
+ return names;
+
+ for (i = 0; i < ARRAY_SIZE(iommu_modes); i++) {
+ len += snprintf(names + len, sizeof(names) - len, "%s%s",
+ i ? ", " : "", iommu_modes[i].name);
+ VFIO_ASSERT_LT(len, (int)sizeof(names));
+ }
+
+ return names;
+}
+
/*
* Returns the IOMMU mode with the given name, or if iommu_mode is NULL, the
* most preferred IOMMU mode that is available (or NULL if none).
@@ -108,7 +125,8 @@ static const struct iommu_mode *iommu_mode_lookup(const char *iommu_mode)
return &iommu_modes[i];
}
- VFIO_FAIL("Unrecognized IOMMU mode: %s\n", iommu_mode);
+ VFIO_FAIL("Unrecognized IOMMU mode: %s (known modes: %s)\n",
+ iommu_mode, iommu_mode_names());
}
bool iommu_mode_is_available(const char *iommu_mode)
--
2.56.0.385.gac671c819a-goog
next prev parent reply other threads:[~2026-11-03 0:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 0:22 [PATCH v2 0/5] vfio: selftests: Automatically detect the IOMMU mode David Matlack
2026-11-03 0:22 ` [PATCH v2 1/5] vfio: selftests: Automatically detect the IOMMU mode in iommu_init() David Matlack
2026-11-03 0:22 ` [PATCH v2 2/5] vfio: selftests: Skip tests when the IOMMU mode is not available David Matlack
2026-11-03 0:22 ` David Matlack [this message]
2026-11-03 0:22 ` [PATCH v2 4/5] KVM: selftests: Use VFIO selftests library to pick IOMMU mode in irq_test David Matlack
2026-11-03 0:22 ` [PATCH v2 5/5] KVM: selftests: List the known 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=20261103002205.3348519-4-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®