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 3/5] vfio: selftests: Print the IOMMU modes when a requested mode can't be used
Date: Mon, 9 Nov 2026 21:08:31 +0000 [thread overview]
Message-ID: <20261109210833.1250548-4-dmatlack@google.com> (raw)
In-Reply-To: <20261109210833.1250548-1-dmatlack@google.com>
Print the names of all known IOMMU modes when passed an unrecognized
IOMMU mode, and the names of the available IOMMU modes when a test skips
because the IOMMU mode it requested is not available. If no IOMMU mode
is available at all, print the generic "No IOMMU mode is available"
message instead. Expose both lists via iommu_mode_names_all() and
iommu_mode_names_available() so that tests can also print them, e.g. in
their help output.
irq_test lets users choose the IOMMU mode with -t, so a typo or
unavailable mode should tell them which modes are valid.
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 | 9 ++++
tools/testing/selftests/vfio/lib/iommu.c | 44 ++++++++++++++++---
2 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h b/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h
index 8306ade5f069..309b231eb0d8 100644
--- a/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h
+++ b/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h
@@ -52,6 +52,15 @@ 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_all(void);
+
+/*
+ * Returns a comma-separated list of the names of the IOMMU modes that are
+ * available on the current system, or "none" if no IOMMU mode is available.
+ */
+const char *iommu_mode_names_available(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 56696bd5c30d..bde53bd55208 100644
--- a/tools/testing/selftests/vfio/lib/iommu.c
+++ b/tools/testing/selftests/vfio/lib/iommu.c
@@ -105,6 +105,38 @@ static const struct iommu_mode *iommu_mode_detect(void)
return NULL;
}
+static const char *iommu_mode_names(bool include_unavailable)
+{
+ static char all_names[256];
+ static char avl_names[sizeof(all_names)];
+ char *names = include_unavailable ? all_names : avl_names;
+ int i, len = 0;
+
+ if (names[0])
+ return names;
+
+ for (i = 0; i < ARRAY_SIZE(iommu_modes); i++) {
+ if (!include_unavailable && !iommu_mode_probe(&iommu_modes[i]))
+ continue;
+
+ len += snprintf(names + len, sizeof(all_names) - len, "%s%s",
+ names[0] ? ", " : "", iommu_modes[i].name);
+ VFIO_ASSERT_LT(len, (int)sizeof(all_names));
+ }
+
+ return names[0] ? names : "none";
+}
+
+const char *iommu_mode_names_all(void)
+{
+ return iommu_mode_names(true);
+}
+
+const char *iommu_mode_names_available(void)
+{
+ return iommu_mode_names(false);
+}
+
/*
* 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).
@@ -123,7 +155,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_all());
}
bool iommu_mode_is_available(const char *iommu_mode)
@@ -136,13 +169,14 @@ bool iommu_mode_is_available(const char *iommu_mode)
const char *iommu_mode_unavailable_msg(const char *iommu_mode)
{
- static char msg[128];
+ static char msg[512];
- if (!iommu_mode)
+ if (!iommu_mode || !iommu_mode_detect())
return NO_IOMMU_MODE_AVAILABLE_MSG;
- snprintf(msg, sizeof(msg), "IOMMU mode '%s' is not available",
- iommu_mode);
+ snprintf(msg, sizeof(msg),
+ "IOMMU mode '%s' is not available. Available modes: %s.",
+ iommu_mode, iommu_mode_names_available());
return msg;
}
--
2.56.0.506.g506a7eabc5-goog
next prev parent 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 [PATCH v3 0/5] vfio: selftests: Automatically detect the IOMMU mode David Matlack
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 ` David Matlack [this message]
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-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®