From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konstantin Khorenko Date: Mon, 24 Aug 2026 11:40:41 +0200 Subject: Re: [Devel] [PATCH vz10] selftests/iommu: skip when /dev/iommu is not available In-Reply-To: <20260821150557.792945-1-eva.kurchatova@virtuozzo.com> References: <20260821150557.792945-1-eva.kurchatova@virtuozzo.com> Message-ID: <526eec33-bdaa-4373-8653-dddc9b957d6c@virtuozzo.com> List-Id: 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 > --- > 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); >