linux/drivers/iommu
Guixin Liu 1daf67217b iommufd: Register iommufd mock devices with fwspec
[ Upstream commit 2a918911ed ]

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: 17de3f5fdd ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2025-10-15 12:04:13 +02:00
..
amd iommu/amd/pgtbl: Fix possible race while increase page table level 2025-09-19 09:39:40 +02:00
arm iommu/arm-smmu-v3: Fix smmu_domain->nr_ats_masters decrement 2025-08-22 08:41:20 +02:00
intel iommu/vt-d: Disallow dirty tracking if incoherent page walk 2025-10-15 12:04:09 +02:00
iommufd iommufd: Register iommufd mock devices with fwspec 2025-10-15 12:04:13 +02:00
riscv iommu/riscv: prevent NULL deref in iova_to_phys 2025-08-22 08:51:49 +02:00
apple-dart.c iommu: Remove ops.pgsize_bitmap from drivers that don't use it 2025-06-27 08:55:56 +02:00
dma-iommu.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
dma-iommu.h iommu: Drop sw_msi from iommu_domain 2025-03-25 10:18:19 -03:00
exynos-iommu.c Merge branch 'samsung/exynos' into next 2025-07-24 11:17:34 +01:00
fsl_pamu.c iommu/fsl: fix all kernel-doc warnings in fsl_pamu.c 2023-03-22 14:50:15 +01:00
fsl_pamu.h iommu/fsl_pamu: hardcode the window address and size in pamu_config_ppaace 2021-04-07 10:56:52 +02:00
fsl_pamu_domain.c iommu/fsl_pamu: remove trailing space after \n 2025-05-16 08:39:04 +02:00
fsl_pamu_domain.h iommu/fsl_pamu: remove the snoop_id field 2021-04-07 10:56:52 +02:00
hyperv-iommu.c x86/hyperv: Clean up hv_map/unmap_interrupt() return values 2025-07-09 23:49:25 +00:00
io-pgfault.c iommu: Fix potential memory leak in iopf_queue_remove_device() 2025-02-10 14:49:30 +01:00
io-pgtable-arm-v7s.c iommu/io-pgtable-arm-v7s: Remove split on unmap behavior 2024-11-06 15:42:36 +00:00
io-pgtable-arm.c iommu/io-pgtable-arm: Remove unused macro iopte_prot 2025-07-14 12:12:22 +01:00
io-pgtable-arm.h iommu/io-pgtable-arm: Move some definitions to a header 2020-09-28 23:48:06 +01:00
io-pgtable-dart.c iommu: Update various drivers to pass in lg2sz instead of order to iommu pages 2025-04-17 16:22:48 +02:00
io-pgtable.c iommu: Allow passing custom allocators to pgtable drivers 2023-11-27 11:10:12 +01:00
iommu-debugfs.c iommu: Fix IOMMU debugfs fallout 2019-02-26 11:15:58 +01:00
iommu-pages.c iommu: Clear the freelist after iommu_put_pages_list() 2025-05-16 14:29:16 +02:00
iommu-pages.h iommu/vtd: Remove iommu_alloc_pages_node() 2025-04-17 16:22:54 +02:00
iommu-priv.h iommufd: Register iommufd mock devices with fwspec 2025-10-15 12:04:13 +02:00
iommu-sva.c iommu: Do not call domain_alloc() in iommu_sva_domain_alloc() 2025-04-28 13:14:59 +02:00
iommu-sysfs.c iommu/sysfs: constify the class struct 2024-10-29 09:50:24 +01:00
iommu-traces.c iommu: Remove detach_dev callback 2023-01-13 16:39:18 +01:00
iommu.c iommufd: Register iommufd mock devices with fwspec 2025-10-15 12:04:13 +02:00
iova.c - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
ipmmu-vmsa.c iommu: Remove iommu_ops pgsize_bitmap from simple drivers 2025-06-27 08:55:57 +02:00
irq_remapping.c IOMMU Updates for Linux v6.10 2024-05-18 10:55:13 -07:00
irq_remapping.h iommu/vt-d: Allocate DMAR fault interrupts locally 2024-04-26 11:57:36 +02:00
Kconfig Merge branch 'apple/dart' into next 2025-07-24 11:18:16 +01:00
Makefile iommu: make inclusion of riscv directory conditional 2025-05-16 08:46:47 +02:00
msm_iommu.c iommu/msm: Remove ops->pgsize_bitmap 2025-06-27 17:34:10 +02:00
msm_iommu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
msm_iommu_hw-8xxx.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 267 2019-06-05 17:30:29 +02:00
mtk_iommu.c iommu/mtk: Remove iommu_ops pgsize_bitmap 2025-06-27 08:56:00 +02:00
mtk_iommu_v1.c Merge branch 'mediatek' into next 2025-07-24 11:18:05 +01:00
of_iommu.c iommu: Get DT/ACPI parsing into the proper probe path 2025-03-11 14:05:43 +01:00
omap-iommu-debug.c iommu/omap: Fix buffer overflow in debugfs 2022-09-07 10:42:28 +02:00
omap-iommu.c Merge branch 'ti/omap' into next 2025-07-24 11:18:11 +01:00
omap-iommu.h iommu/omap: Convert to generic_single_device_group() 2023-09-25 11:52:08 +02:00
omap-iopgtable.h iommu/omap: Fix -Woverflow warnings when compiling on 64-bit architectures 2020-03-04 16:24:46 +01:00
rockchip-iommu.c IOMMU Updates for Linux v6.17: 2025-07-30 10:42:00 -07:00
s390-iommu.c iommu/s390: Make attach succeed when the device was surprise removed 2025-09-05 15:11:09 +02:00
sprd-iommu.c iommu: Remove iommu_ops pgsize_bitmap from simple drivers 2025-06-27 08:55:57 +02:00
sun50i-iommu.c iommu: Remove iommu_ops pgsize_bitmap from simple drivers 2025-06-27 08:55:57 +02:00
tegra-smmu.c iommu: Remove iommu_ops pgsize_bitmap from simple drivers 2025-06-27 08:55:57 +02:00
virtio-iommu.c iommu/virtio: Make instance lookup robust 2025-08-22 08:43:23 +02:00