Skip to content

Commit 56e1a4c

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Add unit tests for arm_smmu_write_entry
Add tests for some of the more common STE update operations that we expect to see, as well as some artificial STE updates to test the edges of arm_smmu_write_entry. These also serve as a record of which common operation is expected to be hitless, and how many syncs they require. arm_smmu_write_entry implements a generic algorithm that updates an STE/CD to any other abritrary STE/CD configuration. The update requires a sequence of write+sync operations with some invariants that must be held true after each sync. arm_smmu_write_entry lends itself well to unit-testing since the function's interaction with the STE/CD is already abstracted by input callbacks that we can hook to introspect into the sequence of operations. We can use these hooks to guarantee that invariants are held throughout the entire update operation. Link: https://lore.kernel.org/r/20240106083617.1173871-3-mshavit@google.com Tested-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Michael Shavit <mshavit@google.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/9-v9-5040dc602008+177d7-smmuv3_newapi_p2_jgg@nvidia.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 04905c1 commit 56e1a4c

File tree

6 files changed

+533
-27
lines changed

6 files changed

+533
-27
lines changed

drivers/iommu/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ config ARM_SMMU_V3
401401
Say Y here if your system includes an IOMMU device implementing
402402
the ARM SMMUv3 architecture.
403403

404+
if ARM_SMMU_V3
404405
config ARM_SMMU_V3_SVA
405406
bool "Shared Virtual Addressing support for the ARM SMMUv3"
406-
depends on ARM_SMMU_V3
407407
select IOMMU_SVA
408408
select IOMMU_IOPF
409409
select MMU_NOTIFIER
@@ -414,6 +414,17 @@ config ARM_SMMU_V3_SVA
414414
Say Y here if your system supports SVA extensions such as PCIe PASID
415415
and PRI.
416416

417+
config ARM_SMMU_V3_KUNIT_TEST
418+
bool "KUnit tests for arm-smmu-v3 driver" if !KUNIT_ALL_TESTS
419+
depends on KUNIT
420+
depends on ARM_SMMU_V3_SVA
421+
default KUNIT_ALL_TESTS
422+
help
423+
Enable this option to unit-test arm-smmu-v3 driver functions.
424+
425+
If unsure, say N.
426+
endif
427+
417428
config S390_IOMMU
418429
def_bool y if S390 && PCI
419430
depends on S390 && PCI

drivers/iommu/arm/arm-smmu-v3/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
obj-$(CONFIG_ARM_SMMU_V3) += arm_smmu_v3.o
33
arm_smmu_v3-objs-y += arm-smmu-v3.o
44
arm_smmu_v3-objs-$(CONFIG_ARM_SMMU_V3_SVA) += arm-smmu-v3-sva.o
5+
arm_smmu_v3-objs-$(CONFIG_ARM_SMMU_V3_KUNIT_TEST) += arm-smmu-v3-test.o
56
arm_smmu_v3-objs := $(arm_smmu_v3-objs-y)

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/mmu_notifier.h>
99
#include <linux/sched/mm.h>
1010
#include <linux/slab.h>
11+
#include <kunit/visibility.h>
1112

1213
#include "arm-smmu-v3.h"
1314
#include "../../io-pgtable-arm.h"
@@ -120,9 +121,10 @@ static u64 page_size_to_cd(void)
120121
return ARM_LPAE_TCR_TG0_4K;
121122
}
122123

123-
static void arm_smmu_make_sva_cd(struct arm_smmu_cd *target,
124-
struct arm_smmu_master *master,
125-
struct mm_struct *mm, u16 asid)
124+
VISIBLE_IF_KUNIT
125+
void arm_smmu_make_sva_cd(struct arm_smmu_cd *target,
126+
struct arm_smmu_master *master, struct mm_struct *mm,
127+
u16 asid)
126128
{
127129
u64 par;
128130

0 commit comments

Comments
 (0)