Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Matlack" <dmatlack@google.com>, kvm@vger.kernel.org
Subject: Re: [PATCH v2 2/5] vfio: selftests: Skip tests when the IOMMU mode is not available
Date: Tue, 03 Nov 2026 00:30:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-194380@kernel.org> (raw)
In-Reply-To: <20261103002205.3348519-3-dmatlack@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] vfio: selftests: iommu_mode_is_available() misses CONFIG_VFIO_GROUP check
--

commit 254a1695e07cd0eb0e8a8f399f3d939f79af60d2
Author: David Matlack <dmatlack@google.com>

vfio: selftests: Skip tests when the IOMMU mode is not available

This commit adds iommu_mode_is_available(), iommu_mode_unavailable_msg(),
and SKIP_IF_IOMMU_MODE_UNAVAILABLE() to skip VFIO selftest variants when
the requested IOMMU mode is unavailable on the system.

> diff --git a/tools/testing/selftests/vfio/lib/iommu.c b/tools/testing/selftests/vfio/lib/iommu.c
> index 0393536370e79..526bb21f27666 100644
> --- a/tools/testing/selftests/vfio/lib/iommu.c
> +++ b/tools/testing/selftests/vfio/lib/iommu.c
> @@ -111,6 +111,26 @@ static const struct iommu_mode *iommu_mode_lookup(const char *iommu_mode)
>  	VFIO_FAIL("Unrecognized IOMMU mode: %s\n", iommu_mode);
>  }
>  
> +bool iommu_mode_is_available(const char *iommu_mode)
> +{
> +	if (!iommu_mode)
> +		return iommu_mode_detect();
> +
> +	return iommu_mode_probe(iommu_mode_lookup(iommu_mode));
> +}

[Severity: Medium]
Can iommu_mode_is_available() return true for iommufd_compat_type1,
iommufd_compat_type1v2, and NULL when CONFIG_VFIO_GROUP is disabled (for
example on a cdev-only VFIO kernel with CONFIG_IOMMUFD=y and
CONFIG_VFIO_DEVICE_CDEV=y) or when the vfio module is not loaded?

In tools/testing/selftests/vfio/lib/iommu.c, iommu_mode_probe() only checks
for /dev/vfio/devices when !mode->container_path:

	/* iommufd mode requires VFIO device cdevs (CONFIG_VFIO_DEVICE_CDEV). */
	if (!mode->container_path && access("/dev/vfio/devices", F_OK))
		return false;

	fd = open(path, O_RDWR);
	if (fd < 0)
		return false;

	available = !mode->container_path ||
		    ioctl(fd, VFIO_CHECK_EXTENSION, mode->iommu_type) > 0;

For iommufd_compat_type1 and iommufd_compat_type1v2, mode->container_path
is "/dev/iommu". Because drivers/iommu/iommufd/vfio_compat.c is compiled
into iommufd unconditionally regardless of CONFIG_VFIO_GROUP, opening
/dev/iommu and calling VFIO_CHECK_EXTENSION succeeds whenever iommufd is
present.

However, vfio_pci_device_init() and device_init() in
vfio_pci_sriov_uapi_test.c route all modes with a non-NULL
mode->container_path through vfio_pci_container_setup() ->
vfio_pci_group_setup(), which opens /dev/vfio/<group_id> and asserts on
failure when CONFIG_VFIO_GROUP is disabled.

Should iommu_mode_probe() also verify that VFIO group support is available
(such as checking access("/sys/class/vfio", F_OK) == 0) when
mode->container_path is non-NULL?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261103002205.3348519-1-dmatlack@google.com?part=2

  reply	other threads:[~2026-11-03  0:30 UTC|newest]

Thread overview: 11+ 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:30   ` sashiko-bot [this message]
2026-11-04 19:41     ` David Matlack
2026-11-03  0:22 ` [PATCH v2 3/5] vfio: selftests: Print the known IOMMU modes on an unrecognized mode David Matlack
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
2026-11-04 14:53   ` Sean Christopherson
2026-11-04 21:09     ` David Matlack
2026-11-04 21:50       ` Sean Christopherson

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=sashiko-outbox-194380@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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