linux/drivers/iommu
Joe Damato ba17de9854 iommu/amd: Block identity domain when SNP enabled
Previously, commit 8388f7df93 ("iommu/amd: Do not support
IOMMU_DOMAIN_IDENTITY after SNP is enabled") prevented users from
changing the IOMMU domain to identity if SNP was enabled.

This resulted in an error when writing to sysfs:

  # echo "identity" > /sys/kernel/iommu_groups/50/type
  -bash: echo: write error: Cannot allocate memory

However, commit 4402f2627d ("iommu/amd: Implement global identity
domain") changed the flow of the code, skipping the SNP guard and
allowing users to change the IOMMU domain to identity after a machine
has booted.

Once the user does that, they will probably try to bind and the
device/driver will start to do DMA which will trigger errors:

  iommu ivhd3: AMD-Vi: Event logged [ILLEGAL_DEV_TABLE_ENTRY device=0000:43:00.0 pasid=0x00000 address=0x3737b01000 flags=0x0020]
  iommu ivhd3: AMD-Vi: Control Reg : 0xc22000142148d
  AMD-Vi: DTE[0]: 6000000000000003
  AMD-Vi: DTE[1]: 0000000000000001
  AMD-Vi: DTE[2]: 2000003088b3e013
  AMD-Vi: DTE[3]: 0000000000000000
  bnxt_en 0000:43:00.0 (unnamed net_device) (uninitialized): Error (timeout: 500015) msg {0x0 0x0} len:0
  iommu ivhd3: AMD-Vi: Event logged [ILLEGAL_DEV_TABLE_ENTRY device=0000:43:00.0 pasid=0x00000 address=0x3737b01000 flags=0x0020]
  iommu ivhd3: AMD-Vi: Control Reg : 0xc22000142148d
  AMD-Vi: DTE[0]: 6000000000000003
  AMD-Vi: DTE[1]: 0000000000000001
  AMD-Vi: DTE[2]: 2000003088b3e013
  AMD-Vi: DTE[3]: 0000000000000000
  bnxt_en 0000:43:00.0: probe with driver bnxt_en failed with error -16

To prevent this from happening, create an attach wrapper for
identity_domain_ops which returns EINVAL if amd_iommu_snp_en is true.

With this commit applied:

  # echo "identity" > /sys/kernel/iommu_groups/62/type
  -bash: echo: write error: Invalid argument

Fixes: 4402f2627d ("iommu/amd: Implement global identity domain")
Signed-off-by: Joe Damato <joe@dama.to>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
2026-03-17 14:02:02 +01:00
..
amd iommu/amd: Block identity domain when SNP enabled 2026-03-17 14:02:02 +01:00
arm Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
generic_pt Merge branches 'fixes', 'arm/smmu/updates', 'intel/vt-d', 'amd/amd-vi' and 'core' into next 2026-02-06 11:10:40 +01:00
intel iommu/vt-d: Only handle IOPF for SVA when PRI is supported 2026-03-17 13:20:06 +01:00
iommufd Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
riscv Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
apple-dart.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
dma-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
dma-iommu.h iommu: Tidy domain for iommu_setup_dma_ops() 2026-01-10 10:26:43 +01:00
exynos-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
fsl_pamu_domain.c iommu: Pass in old domain to attach_dev callback functions 2025-10-27 13:55:35 +01:00
fsl_pamu_domain.h
fsl_pamu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
fsl_pamu.h
hyperv-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
io-pgfault.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
io-pgtable-arm-selftests.c iommu/io-pgtable-arm-selftests: Use KUnit 2025-11-13 16:25:32 +01:00
io-pgtable-arm-v7s.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
io-pgtable-arm.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
io-pgtable-arm.h
io-pgtable-dart.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
io-pgtable.c iommu/amd: Remove AMD io_pgtable support 2025-11-05 09:08:57 +01:00
iommu-debug-pagealloc.c iommu: debug-pagealloc: Use page_ext_get_from_phys() 2026-01-21 12:51:49 +01:00
iommu-debugfs.c
iommu-pages.c iommu/pages: Add support for incoherent IOMMU page table walkers 2025-11-05 09:47:43 +01:00
iommu-pages.h iommu/pages: Add support for incoherent IOMMU page table walkers 2025-11-05 09:47:43 +01:00
iommu-priv.h iommu: Add calls for IOMMU_DEBUG_PAGEALLOC 2026-01-10 10:52:26 +01:00
iommu-sva.c iommu/sva: Fix crash in iommu_sva_unbind_device() 2026-03-17 14:00:36 +01:00
iommu-sysfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
iommu-traces.c
iommu.c iommu: Fix mapping check for 0x0 to avoid re-mapping it 2026-03-17 13:33:33 +01:00
iova.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
ipmmu-vmsa.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
irq_remapping.c
irq_remapping.h
Kconfig iommu: Add page_ext for IOMMU_DEBUG_PAGEALLOC 2026-01-10 10:52:25 +01:00
Makefile iommu: Add page_ext for IOMMU_DEBUG_PAGEALLOC 2026-01-10 10:52:25 +01:00
msm_iommu_hw-8xxx.h
msm_iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
msm_iommu.h
mtk_iommu_v1.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
mtk_iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08: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 Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
omap-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
omap-iommu.h iommu/omap: fix device leaks on probe_device() 2025-11-17 09:49:44 +01:00
omap-iopgtable.h
rockchip-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
s390-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sprd-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sun50i-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
tegra-smmu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
virtio-iommu.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00