iommufd: Register iommufd mock devices with fwspec
authorGuixin Liu <kanie@linux.alibaba.com>
Thu, 25 Sep 2025 05:47:30 +0000 (13:47 +0800)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 30 Sep 2025 12:54:12 +0000 (09:54 -0300)
commit2a918911ed3d0841923525ed0fe707762ee78844
treef18c9b442694c59a10f306498a0fcd432f43050f
parent1d235d8494259b588bc3b7d29bc73ce34bf885bc
iommufd: Register iommufd mock devices with fwspec

Since the bus ops were retired the iommu subsystem changed to using fwspec
to match the iommu driver to the iommu device. If a device has a NULL
fwspec then it is matched to the first iommu driver with a NULL fwspec,
effectively disabling support for systems with more than one non-fwspec
iommu driver.

Thus, if the iommufd selfest are run in an x86 system that registers a
non-fwspec iommu driver they fail to bind their mock devices to the mock
iommu driver.

Fix this by allocating a software fwnode for mock iommu driver's
iommu_device, and set it to the device which mock iommu driver created.

This is done by adding a new helper iommu_mock_device_add() which abuses
the internals of the fwspec system to establish a fwspec before the device
is added and is careful not to leak it. A matching dummy fwspec is
automatically added to the mock iommu driver.

Test by "make -C toosl/testing/selftests TARGETS=iommu run_tests":
PASSED: 229 / 229 tests passed.

In addition, this issue is also can be found on amd platform, and
also tested on a amd machine.

Link: https://patch.msgid.link/r/20250925054730.3877-1-kanie@linux.alibaba.com
Fixes: 17de3f5fdd35 ("iommu: Retire bus ops")
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Tested-by: Qinyun Tan <qinyuntan@linux.alibaba.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommu-priv.h
drivers/iommu/iommu.c
drivers/iommu/iommufd/selftest.c