[PATCH] iommu/arm-smmu-v3: Add unit tests for arm_smmu_write_entry

Jason Gunthorpe jgg at nvidia.com
Fri Jan 12 08:36:51 PST 2024


On Sat, Jan 06, 2024 at 04:36:16PM +0800, Michael Shavit wrote:
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c
> new file mode 100644
> index 0000000000000..59ffcafb575fb
> --- /dev/null
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c
> @@ -0,0 +1,329 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <kunit/test.h>

I added

* Copyright 2024 Google LLC.

Here, let me know if it should be something else

> +	arm_smmu_get_ste_used(ops, ste->data, used_bits.data);
> +	pr_debug("STE used bits: ");
> +	print_hex_dump_debug(
> +		"    ", DUMP_PREFIX_NONE, 16, 8, used_bits.data,
> +		ARRAY_SIZE(used_bits.data) * sizeof(*used_bits.data), false);

I fixed up alot of these weird sizeof things all over the three patches

sizeof(struct arm_smmu_ste) is the correct way to get the size of the
HW structure, no need to peek into data. This is because we use the
struct as the pointer to an array so the whole struct must be
correctly sized.

ARRAY_SIZE(x.data)*(sizeof(*x.data)) == sizeof(x)

Sadly there is no ARRAY_SIZE_FIELD()

I also made some hacky patches so smmuv3 would compile on x86 and ran
this kunit on x86 - looks fine to me

I'm going to put it in part 3, just because it is new and doesn't have
any RB/TB tags like the rest of part 1.

Thanks,
Jason



More information about the linux-arm-kernel mailing list