iommufd/selftest: Make selftest create a more complete mock device
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 1 Mar 2023 19:30:28 +0000 (15:30 -0400)
committerJason Gunthorpe <jgg@nvidia.com>
Mon, 6 Mar 2023 17:06:11 +0000 (13:06 -0400)
commit65c619ae06801e1f21cff1a78c7e64923ad17896
treeb01dfd4b56a67013bc66c9c0605808925c42a6f8
parentf8406f65c1cfe4c8e3646ea66f5bac07b1f10b55
iommufd/selftest: Make selftest create a more complete mock device

iommufd wants to use more infrastructure, like the iommu_group, that the
mock device does not support. Create a more complete mock device that can
go through the whole cycle of ownership, blocking domain, and has an
iommu_group.

This requires creating a real struct device on a real bus to be able to
connect it to a iommu_group. Unfortunately we cannot formally attach the
mock iommu driver as an actual driver as the iommu core does not allow
more than one driver or provide a general way for busses to link to
iommus. This can be solved with a little hack to open code the dev_iommus
struct.

With this infrastructure things work exactly the same as the normal domain
path, including the auto domains mechanism and direct attach of hwpts.  As
the created hwpt is now an autodomain it is no longer required to destroy
it and trying to do so will trigger a failure.

Link: https://lore.kernel.org/r/11-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/device.c
drivers/iommu/iommufd/iommufd_private.h
drivers/iommu/iommufd/selftest.c
tools/testing/selftests/iommu/iommufd.c
tools/testing/selftests/iommu/iommufd_fail_nth.c