All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
Subject: Re: [Devel] [PATCH vz10] selftests/iommu: skip when /dev/iommu is not available
Date: Mon, 24 Aug 2026 11:40:41 +0200	[thread overview]
Message-ID: <526eec33-bdaa-4373-8653-dddc9b957d6c@virtuozzo.com> (raw)
In-Reply-To: <20260821150557.792945-1-eva.kurchatova@virtuozzo.com>

1. We have /dev/iommu device, just need to load a module iommufd.ko

(root at sbHCI)/vz/finist/vzkernel.vz10:grep IOMMUFD .config
CONFIG_IOMMUFD=m
# CONFIG_IOMMUFD_TEST is not set

2. The check for open is too wide - it will skip the test on ANY error, but should - only in case the file is absent, all other errors from open() should be called next ASSERT_NE(-1, self->fd);

3. Tests won't work anyway in out current config because in our current release config we have 
# CONFIG_IOMMUFD_TEST is not set

But we have it enabled in debug kernel config though.

4. There is a similar test iommufd_fail_nth.c nearby which should suffer from the same problems, so to fix it likewise.

5. Even in case you modprobe iommufd module, in production config we have
# CONFIG_IOMMUFD_TEST is not set
so all the tests will fail later on test ioctls.

=> better to check /sys/bus/iommufd_mock instead, it appears only in case
iommufd is loaded and CONFIG_IOMMUFD_TEST is set.

6. You can perform a single check, not repeating 8 times the same check.

  At the momnent TEST_HARNESS_MAIN is just:

  #define TEST_HARNESS_MAIN \
        int main(int argc, char **argv) { \
                return test_harness_run(argc, argv); \
        }

  test_harness_run() - static func (kselftest_harness.h:1267), so you can call it from main().
  So you can do the following single check:

  static bool iommufd_mock_available(void)
  {
        return access("/sys/bus/iommufd_mock", F_OK) == 0;
  }

  int main(int argc, char **argv)
  {
        if (!iommufd_mock_available())
                ksft_exit_skip("iommufd mock device is not available, need CONFIG_IOMMUFD_TEST=y and the iommufd module load

        return test_harness_run(argc, argv);
  }

  instead of TEST_HARNESS_MAIN ? iommufd.c:3542 and in iommufd_fail_nth.c:748.

=>
summary:
1. pre-load iommufd module in hci-* wrapper if it's not loaded and unload the module after the test if it was not loaded before the test.
2. make a single check for /sys/bus/iommufd_mock
3. fix both iommufd.c and iommufd_fail_nth.c


--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 8/21/26 17:05, Eva Kurchatova wrote:
> Without iommufd all 237 subtests fail in FIXTURE_SETUP on the open().
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-142443
> Feature: fix selftests
> Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
> ---
>  tools/testing/selftests/iommu/iommufd.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
> index de348d641279..0625e1596bbf 100644
> --- a/tools/testing/selftests/iommu/iommufd.c
> +++ b/tools/testing/selftests/iommu/iommufd.c
> @@ -66,6 +66,8 @@ FIXTURE(iommufd)
>  FIXTURE_SETUP(iommufd)
>  {
>  	self->fd = open("/dev/iommu", O_RDWR);
> +	if (self->fd < 0)
> +		SKIP(return, "/dev/iommu is not available");
>  	ASSERT_NE(-1, self->fd);
>  }
>  
> @@ -254,6 +256,8 @@ FIXTURE_VARIANT(change_process)
>  FIXTURE_SETUP(change_process)
>  {
>  	self->fd = open("/dev/iommu", O_RDWR);
> +	if (self->fd < 0)
> +		SKIP(return, "/dev/iommu is not available");
>  	ASSERT_NE(-1, self->fd);
>  
>  	drop_cap_ipc_lock(_metadata);
> @@ -360,6 +364,8 @@ FIXTURE_SETUP(iommufd_ioas)
>  
>  
>  	self->fd = open("/dev/iommu", O_RDWR);
> +	if (self->fd < 0)
> +		SKIP(return, "/dev/iommu is not available");
>  	ASSERT_NE(-1, self->fd);
>  	test_ioctl_ioas_alloc(&self->ioas_id);
>  
> @@ -1641,6 +1647,8 @@ FIXTURE_SETUP(iommufd_mock_domain)
>  	unsigned int i;
>  
>  	self->fd = open("/dev/iommu", O_RDWR);
> +	if (self->fd < 0)
> +		SKIP(return, "/dev/iommu is not available");
>  	ASSERT_NE(-1, self->fd);
>  	test_ioctl_ioas_alloc(&self->ioas_id);
>  
> @@ -2114,6 +2122,8 @@ FIXTURE_SETUP(iommufd_dirty_tracking)
>  	}
>  
>  	self->fd = open("/dev/iommu", O_RDWR);
> +	if (self->fd < 0)
> +		SKIP(return, "/dev/iommu is not available");
>  	ASSERT_NE(-1, self->fd);
>  
>  	mmap_flags = MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED;
> @@ -2484,6 +2494,8 @@ FIXTURE_SETUP(vfio_compat_mock_domain)
>  	};
>  
>  	self->fd = open("/dev/iommu", O_RDWR);
> +	if (self->fd < 0)
> +		SKIP(return, "/dev/iommu is not available");
>  	ASSERT_NE(-1, self->fd);
>  
>  	/* Create what VFIO would consider a group */
> @@ -2773,6 +2785,8 @@ FIXTURE_VARIANT(iommufd_viommu)
>  FIXTURE_SETUP(iommufd_viommu)
>  {
>  	self->fd = open("/dev/iommu", O_RDWR);
> +	if (self->fd < 0)
> +		SKIP(return, "/dev/iommu is not available");
>  	ASSERT_NE(-1, self->fd);
>  	test_ioctl_ioas_alloc(&self->ioas_id);
>  	test_ioctl_set_default_memory_limit();
> @@ -3236,6 +3250,8 @@ FIXTURE_VARIANT(iommufd_device_pasid)
>  FIXTURE_SETUP(iommufd_device_pasid)
>  {
>  	self->fd = open("/dev/iommu", O_RDWR);
> +	if (self->fd < 0)
> +		SKIP(return, "/dev/iommu is not available");
>  	ASSERT_NE(-1, self->fd);
>  	test_ioctl_ioas_alloc(&self->ioas_id);
>  


      reply	other threads:[~2026-08-24  9:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 15:05 Eva Kurchatova
2026-08-24  9:40 ` Konstantin Khorenko [this message]

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=526eec33-bdaa-4373-8653-dddc9b957d6c@virtuozzo.com \
    --to=khorenko@virtuozzo.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.