linux/drivers/iommu
Nicolin Chen 767e22001d iommu/tegra241-cmdqv: Fix warnings due to dmam_free_coherent()
Two WARNINGs are observed when SMMU driver rolls back upon failure:
 arm-smmu-v3.9.auto: Failed to register iommu
 arm-smmu-v3.9.auto: probe with driver arm-smmu-v3 failed with error -22
 ------------[ cut here ]------------
 WARNING: CPU: 5 PID: 1 at kernel/dma/mapping.c:74 dmam_free_coherent+0xc0/0xd8
 Call trace:
  dmam_free_coherent+0xc0/0xd8 (P)
  tegra241_vintf_free_lvcmdq+0x74/0x188
  tegra241_cmdqv_remove_vintf+0x60/0x148
  tegra241_cmdqv_remove+0x48/0xc8
  arm_smmu_impl_remove+0x28/0x60
  devm_action_release+0x1c/0x40
 ------------[ cut here ]------------
 128 pages are still in use!
 WARNING: CPU: 16 PID: 1 at mm/page_alloc.c:6902 free_contig_range+0x18c/0x1c8
 Call trace:
  free_contig_range+0x18c/0x1c8 (P)
  cma_release+0x154/0x2f0
  dma_free_contiguous+0x38/0xa0
  dma_direct_free+0x10c/0x248
  dma_free_attrs+0x100/0x290
  dmam_free_coherent+0x78/0xd8
  tegra241_vintf_free_lvcmdq+0x74/0x160
  tegra241_cmdqv_remove+0x98/0x198
  arm_smmu_impl_remove+0x28/0x60
  devm_action_release+0x1c/0x40

This is because the LVCMDQ queue memory are managed by devres, while that
dmam_free_coherent() is called in the context of devm_action_release().

Jason pointed out that "arm_smmu_impl_probe() has mis-ordered the devres
callbacks if ops->device_remove() is going to be manually freeing things
that probe allocated":
https://lore.kernel.org/linux-iommu/20250407174408.GB1722458@nvidia.com/

In fact, tegra241_cmdqv_init_structures() only allocates memory resources
which means any failure that it generates would be similar to -ENOMEM, so
there is no point in having that "falling back to standard SMMU" routine,
as the standard SMMU would likely fail to allocate memory too.

Remove the unwind part in tegra241_cmdqv_init_structures(), and return a
proper error code to ask SMMU driver to call tegra241_cmdqv_remove() via
impl_ops->device_remove(). Then, drop tegra241_vintf_free_lvcmdq() since
devres will take care of that.

Fixes: 483e0bd888 ("iommu/tegra241-cmdqv: Do not allocate vcmdq until dma_set_mask_and_coherent")
Cc: stable@vger.kernel.org
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20250407201908.172225-1-nicolinc@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2025-04-11 12:44:27 +02:00
..
amd Merge branches 'apple/dart', 'arm/smmu/updates', 'arm/smmu/bindings', 'rockchip', 's390', 'core', 'intel/vt-d' and 'amd/amd-vi' into next 2025-03-20 09:11:09 +01:00
arm iommu/tegra241-cmdqv: Fix warnings due to dmam_free_coherent() 2025-04-11 12:44:27 +02:00
intel iommu/vt-d: Remove an unnecessary call set_dma_ops() 2025-04-11 09:06:06 +02:00
iommufd iommufd: Test attach before detaching pasid 2025-03-28 11:40:41 -03:00
riscv iommu/riscv: Fixup compile warning 2025-01-17 08:58:06 +01:00
Kconfig iommu/mediatek-v1: Support COMPILE_TEST 2025-03-13 12:17:30 +01:00
Makefile iommu/riscv: Add RISC-V IOMMU platform device driver 2024-10-29 09:46:23 +01:00
apple-dart.c iommu: apple-dart: fix potential null pointer deref 2025-03-20 08:59:15 +01:00
dma-iommu.c iommu: remove unneeded semicolon 2025-04-11 12:43:06 +02:00
dma-iommu.h iommu: Drop sw_msi from iommu_domain 2025-03-25 10:18:19 -03:00
exynos-iommu.c iommu/exynos: Fix suspend/resume with IDENTITY domain 2025-04-11 12:40:41 +02:00
fsl_pamu.c
fsl_pamu.h
fsl_pamu_domain.c iommu: Use of_property_present() 2024-09-04 11:31:01 +02:00
fsl_pamu_domain.h
hyperv-iommu.c hyperv: Log hypercall status codes as strings 2025-03-20 21:23:03 +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: Add way to debug pgtable walk 2025-01-07 15:44:20 +00:00
io-pgtable-arm.h
io-pgtable-dart.c iommu/io-pgtable-dart: Only set subpage protection disable for DART 1 2025-02-21 12:06:54 +01:00
io-pgtable.c
iommu-debugfs.c
iommu-pages.h
iommu-priv.h iommufd 6.15 merge window pull 2025-04-01 18:03:46 -07:00
iommu-sva.c iommu: Sort out domain user data 2025-03-25 10:18:18 -03:00
iommu-sysfs.c iommu/sysfs: constify the class struct 2024-10-29 09:50:24 +01:00
iommu-traces.c
iommu.c iommu: Clear iommu-dma ops on cleanup 2025-04-11 09:15:59 +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/ipmmu-vmsa: Register in a sensible order 2025-04-11 09:24:10 +02:00
irq_remapping.c IOMMU Updates for Linux v6.10 2024-05-18 10:55:13 -07:00
irq_remapping.h
msm_iommu.c iommu/msm: Use helper function devm_clk_get_prepared() 2025-01-06 12:41:00 +01:00
msm_iommu.h
msm_iommu_hw-8xxx.h
mtk_iommu.c iommu/mediatek: Fix NULL pointer deference in mtk_iommu_device_group 2025-04-11 12:40:55 +02:00
mtk_iommu_v1.c iommu/mediatek-v1: Support COMPILE_TEST 2025-03-13 12:17:30 +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
omap-iommu.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
omap-iommu.h
omap-iopgtable.h
rockchip-iommu.c iommu/rockchip: Retire global dma_dev workaround 2025-03-20 08:58:24 +01:00
s390-iommu.c iommu/s390: implement iommu passthrough via identity domain 2025-02-21 12:02:00 +01:00
sprd-iommu.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
sun50i-iommu.c iommu: sun50i: Add H616 compatible string 2024-06-25 14:02:47 +02:00
tegra-smmu.c iommu: Unexport iommu_fwspec_free() 2025-03-11 14:05:39 +01:00
virtio-iommu.c virtio: rename virtio_find_vqs_info() to virtio_find_vqs() 2024-07-17 05:20:58 -04:00