[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250917140216.2199055-1-smostafa@google.com>
Date: Wed, 17 Sep 2025 14:02:01 +0000
From: Mostafa Saleh <smostafa@...gle.com>
To: iommu@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org
Cc: robin.murphy@....com, will@...nel.org, joro@...tes.org, jgg@...pe.ca,
praan@...gle.com, Mostafa Saleh <smostafa@...gle.com>
Subject: [PATCH 0/2] Move io-pgtable-arm selftest to KUnit
This is a small series to clean up the io-pgtable-arm library.
The first patch was originally part of SMMUv3 KVM driver support[1],
which was needed to factor out the kernel code from the io-pgtable-arm
library, and based on Jason’s suggestion this can taken out as a cleanup
and to converge to kunit.
The first patch just moves the code to a new file with no other changes,
so it can be easier to review it with “--color-moved”
The second patch registers the test using kunit, and converges some of
the APIs, some notes about that:
Dealing with __init:
--------------------
At the moment, all the test code and data are part of the init section.
To avoid changing all the functions and data and removing them from the
init section, we can rely on the kunit “kunit_test_init_section_suite”
to keep the test in the init section.
That will make the results only available on debugfs (there is no
possibility to run them after boot) unlike the SMMUv3 tests for example
which can run on-demand.
As the of results are saved in the kunit structs, they can’t be tagged
as __init_data, instead they are be tagged to __refdata to avoid the
modpost warning, as it’s guaranteed that kunit will only access the results,
not the test after init.
Instead, we can remove the __init constraint, and be able to run the tests
on-demand, and possibly compile it as a module.
Granularity of tests:
---------------------
To make the series easier to review, the series changes the test to run in
kunit without making intrusive changes to the test itself.
It’s possible to refactor the tests to have smaller granularity (although
I think that would make it less efficient as we might create the same io-pgtable
config multiple times) and integrate them in kunit as multiple tests, that
change would be more intrusive, if you think that is the right approach,
I can add a couple of more patches re-writing the tests.
Other changes:
--------------
- Also, to make the test changes minimal, and fail messages similar, “KUNIT_FAIL”
is used to fail all tests instead of using KUNIT specific assertions.
- Instead of using faux device, we rely on kunit_device_register()
- The WARN is removed when a test fails, as that doesn’t seem to be a pattern
used with kunit.
A failure at the test with the new implementation look as
[ 2.115982] # io_pgtable_arm_test_run: EXPECTATION FAILED at drivers/iommu/io-pgtable-arm-selftests.c:94
[ 2.118381] # io_pgtable_arm_test_run: selftest: test failed for fmt idx 0
[ 2.118501] # io_pgtable_arm_test_run: cfg: pgsize_bitmap 0x40201000, ias 32-bit
[ 2.118863] # io_pgtable_arm_test_run: data: 3 levels, 0x20 pgd_size, 12 pg_shift, 9 bits_per_level, pgd @ 00000000a15afb2d
[1] https://lore.kernel.org/all/20250819215156.2494305-5-smostafa@google.com/
Mostafa Saleh (2):
iommu/io-pgtable-arm: Move selftests to a separate file
iommu/io-pgtable-arm-selftest: Use KUnit
drivers/iommu/Kconfig | 2 +-
drivers/iommu/Makefile | 1 +
drivers/iommu/io-pgtable-arm-selftests.c | 223 +++++++++++++++++++++
drivers/iommu/io-pgtable-arm.c | 243 -----------------------
drivers/iommu/io-pgtable-arm.h | 41 ++++
5 files changed, 266 insertions(+), 244 deletions(-)
create mode 100644 drivers/iommu/io-pgtable-arm-selftests.c
--
2.51.0.384.g4c02a37b29-goog
Powered by blists - more mailing lists