From: sashiko-bot@kernel.org
To: "Mikko Perttunen" <mperttunen@nvidia.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 12/12] iommu/tegra-smmu: Use a DMA API default domain per swgroup
Date: Wed, 18 Nov 2026 01:01:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-219890@kernel.org> (raw)
In-Reply-To: <20261118-b4-arm32-iommu-dma-cookie-v4-12-0c5561288e22@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] iommu/tegra-smmu: NULL dereference in
tegra_smmu_identity_attach() on probe fail
--
commit 771cf7a7b7503c071081ede10ec54512cfe880ec
Author: Mikko Perttunen <mperttunen@nvidia.com>
iommu/tegra-smmu: Use a DMA API default domain per swgroup
This commit enables IOMMU_DOMAIN_DMA default domains on a per-swgroup
basis for TegraDRM and Host1x devices and sets .release_domain to the
identity domain in tegra_smmu_ops.
> diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
> index 0e8414d8a5047..3f938ae4cffc6 100644
> --- a/drivers/iommu/tegra-smmu.c
> +++ b/drivers/iommu/tegra-smmu.c
> @@ -997,16 +997,20 @@ static int tegra_smmu_of_xlate(struct device *dev,
>
> static int tegra_smmu_def_domain_type(struct device *dev)
> {
> - /*
> - * FIXME: For now we want to run all translation in IDENTITY mode, due
> - * to some device quirks. Better would be to just quirk the troubled
> - * devices.
> - */
> - return IOMMU_DOMAIN_IDENTITY;
> + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
> + struct tegra_smmu *smmu = dev_iommu_priv_get(dev);
> + const struct tegra_smmu_swgroup *swgroup;
> +
> + swgroup = tegra_smmu_find_swgroup(smmu, fwspec->ids[0]);
> + if (WARN_ON(!swgroup) || !swgroup->use_dma_api)
> + return IOMMU_DOMAIN_IDENTITY;
> +
> + return IOMMU_DOMAIN_DMA;
> }
>
> static const struct iommu_ops tegra_smmu_ops = {
> .identity_domain = &tegra_smmu_identity_domain,
> + .release_domain = &tegra_smmu_identity_domain,
> .def_domain_type = &tegra_smmu_def_domain_type,
[Severity: High]
Can setting .release_domain = &tegra_smmu_identity_domain cause a NULL
pointer dereference in tegra_smmu_identity_attach() if attaching the
default DMA domain fails during device probe?
When iommu_setup_default_domain() attaches a newly allocated paging
domain via __iommu_group_set_domain_internal() with
IOMMU_SET_DOMAIN_MUST_SUCCEED, group->domain is set even if
tegra_smmu_attach_dev() -> tegra_smmu_as_prepare() fails (for example,
when all 4 hardware ASIDs on Tegra30/Tegra114 are in use and
tegra_smmu_alloc_asid() returns -ENOSPC), leaving as->smmu as NULL and
as->use_count as 0:
drivers/iommu/tegra-smmu.c:tegra_smmu_as_prepare() {
...
err = tegra_smmu_alloc_asid(smmu, &as->id);
if (err < 0)
goto err_unmap;
...
as->smmu = smmu;
as->use_count++;
}
On the error unwind path in __iommu_probe_device(), iommu_deinit_device()
attaches release_domain and passes group->domain as old to
tegra_smmu_identity_attach(), which unconditionally reads smmu = as->smmu
and dereferences it in tegra_smmu_disable() and
tegra_smmu_as_unprepare():
drivers/iommu/tegra-smmu.c:tegra_smmu_identity_attach() {
...
as = to_smmu_as(old);
smmu = as->smmu;
for (index = 0; index < fwspec->num_ids; index++) {
tegra_smmu_disable(smmu, fwspec->ids[index], as->id);
tegra_smmu_as_unprepare(smmu, as);
}
}
Similarly, if a second device joining an already active shared group
fails in __iommu_probe_device() before attaching to group->domain,
iommu_deinit_device() calls tegra_smmu_identity_attach() with the shared
group->domain, disabling the swgroup and decrementing as->use_count for
a device that never attached.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-b4-arm32-iommu-dma-cookie-v4-0-0c5561288e22@nvidia.com?part=12
prev parent reply other threads:[~2026-11-18 1:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 0:35 [PATCH v4 00/12] Make the 32-bit ARM DMA API work with normal IOMMU DMA default domains (+ Tegra PoC) Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 01/12] iommu: Initialize default domain policy at core initcall level Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 02/12] iommu: Add iommu_teardown_dma_ops Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 03/12] iommu: Add cookie type for ARM_DMA_USE_IOMMU Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 04/12] ARM: dma-mapping: Split mapping initialization from allocation Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 05/12] ARM: dma-mapping: Implement and expose DMA setup functions Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 06/12] ARM: dma-mapping: Bypass the legacy path for core-owned DMA API domains Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 07/12] ARM: dma-mapping: Bound IOVA allocation by device DMA limits Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 08/12] iommu: Enable DMA default domains on (most) 32-bit ARM platforms Mikko Perttunen
2026-11-18 1:14 ` sashiko-bot
2026-11-18 0:35 ` [PATCH v4 09/12] drm/tegra: Fix device parameter to dma_get_sgtable Mikko Perttunen
2026-11-18 0:51 ` sashiko-bot
2026-11-18 0:35 ` [PATCH v4 10/12] iommu/tegra-smmu: Defer display client translation to driver handover Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 11/12] iommu/tegra-smmu: Release previous address space on paging domain switch Mikko Perttunen
2026-11-18 0:35 ` [PATCH v4 12/12] iommu/tegra-smmu: Use a DMA API default domain per swgroup Mikko Perttunen
2026-11-18 1:01 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-219890@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=mperttunen@nvidia.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.