From: sashiko-bot@kernel.org
To: "Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 2/3] iommu/msm: use the IOMMU device for page table allocation
Date: Thu, 30 Jul 2026 16:20:38 +0000 [thread overview]
Message-ID: <20260730162038.C96891F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730-fix-qcom-smmu-v2-2-18e0daf2d836@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Unchecked `list_first_entry` usage on potentially empty `ctx_list` causes out-of-bounds reads and fundamentally breaks support for multiple masters.
- [Critical] Adding an IOMMU device to a domain's list overwrites shared list pointers, corrupting lists if attached to multiple domains.
- [Critical] Hardware registers are accessed during probe before bus clocks are enabled.
- [High] I/O page tables are permanently leaked when an IOMMU domain is freed.
- [High] Attaching multiple devices to a domain unconditionally re-initializes locks and reallocates page tables, leaking memory and breaking domain consistency.
- [High] The `io_pgtable_ops` structure is leaked on error paths during device attachment.
- [High] IOMMU clocks are left persistently enabled if device attachment fails.
--
--- Patch [2]: [PATCH v2 2/3] iommu/msm: use the IOMMU device for page table allocation ---
commit e64cb01e4df1d4190662ca41772b64a8225c289f
Author: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Subject: iommu/msm: use the IOMMU device for page table allocation
This patch updates the MSM IOMMU driver to allocate page tables using the
IOMMU device rather than the client device. This prevents issues on ARM32
where the client device's DMA ops might map tables through the very IOMMU
they describe. It locates the IOMMU instance before configuring the domain
and passes its device to io-pgtable.
> diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
> index d6ef17cf6d108..30e2d061ecd1d 100644
> --- a/drivers/iommu/msm_iommu.c
> +++ b/drivers/iommu/msm_iommu.c
[ ... ]
> @@ -336,7 +335,8 @@ static void msm_iommu_domain_free(struct iommu_domain *domain)
> spin_unlock_irqrestore(&msm_iommu_lock, flags);
> }
[Severity: High]
This is a pre-existing issue, but does msm_iommu_domain_free() permanently
leak the dynamically allocated page tables?
msm_iommu_domain_free() frees the priv container via kfree(priv) but does not
call free_io_pgtable_ops(priv->iop) to release the io-pgtable resources. Will
this lead to a permanent memory leak when the domain is freed?
>
> -static int msm_iommu_domain_config(struct msm_priv *priv)
> +static int msm_iommu_domain_config(struct msm_priv *priv,
> + struct msm_iommu_dev *iommu)
> {
[ ... ]
> @@ -400,8 +400,15 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev,
> struct msm_priv *priv = to_msm_priv(domain);
> struct msm_iommu_ctx_dev *master;
>
> - priv->dev = dev;
> - msm_iommu_domain_config(priv);
> + spin_lock_irqsave(&msm_iommu_lock, flags);
> + iommu = find_iommu_for_dev(dev);
> + spin_unlock_irqrestore(&msm_iommu_lock, flags);
> + if (!iommu)
> + return -ENODEV;
> +
> + ret = msm_iommu_domain_config(priv, iommu);
[Severity: High]
This is a pre-existing issue, but does unconditionally calling
msm_iommu_domain_config() on every device attach corrupt the shared domain
state?
When multiple devices are attached to an active IOMMU domain,
msm_iommu_attach_dev() executes msm_iommu_domain_config() for every attach.
This blindly executes spin_lock_init(&priv->pgtlock) and reassigns priv->iop
without freeing the previous allocation.
Could this permanently leak the first device's page tables and force the
driver to track a new structure that does not match the hardware state?
Additionally, there are a few pre-existing regressions in this file that might
warrant review:
[Severity: Critical]
This is a pre-existing issue, but does the list lookup in
msm_iommu_attach_dev() safely handle an empty ctx_list?
drivers/iommu/msm_iommu.c:msm_iommu_attach_dev() {
...
list_for_each_entry(iommu, &qcom_iommu_devices, dev_node) {
master = list_first_entry(&iommu->ctx_list,
struct msm_iommu_ctx_dev,
list);
if (master->of_node == dev->of_node) {
...
}
If an IOMMU probes with no masters yet, could list_first_entry() generate a
bogus pointer and cause an out-of-bounds read on master->of_node?
Also, if an IOMMU has multiple masters, does this lookup inadvertently limit
matching to only the first appended master?
[Severity: High]
This is a pre-existing issue, but are the io-pgtable allocations permanently
leaked on the error path during device attachment?
drivers/iommu/msm_iommu.c:msm_iommu_attach_dev() {
...
master->num =
msm_iommu_alloc_ctx(iommu->context_map,
0, iommu->ncb);
if (IS_ERR_VALUE(master->num)) {
ret = -ENODEV;
goto fail;
}
...
fail:
spin_unlock_irqrestore(&msm_iommu_lock, flags);
return ret;
}
Since msm_iommu_domain_config() already succeeded in allocating priv->iop,
does jumping to the fail label and returning without unwinding priv->iop
permanently leak these resources?
[Severity: Critical]
This is a pre-existing issue, but does adding the IOMMU device to a domain's
list inadvertently corrupt the list if it is attached to multiple domains?
drivers/iommu/msm_iommu.c:msm_iommu_attach_dev() {
...
__disable_clocks(iommu);
list_add(&iommu->dom_node, &priv->list_attached);
}
}
...
}
Since dom_node is a single list_head in the shared msm_iommu_dev structure,
would attaching a second domain to the master forcefully overwrite its
next and prev pointers, breaking the first domain's list?
[Severity: High]
This is a pre-existing issue, but are the IOMMU clocks left persistently
enabled if device attachment fails?
drivers/iommu/msm_iommu.c:msm_iommu_attach_dev() {
...
if (master->of_node == dev->of_node) {
ret = __enable_clocks(iommu);
if (ret)
goto fail;
...
if (IS_ERR_VALUE(master->num)) {
ret = -ENODEV;
goto fail;
}
...
fail:
spin_unlock_irqrestore(&msm_iommu_lock, flags);
return ret;
}
If an error occurs after __enable_clocks(), does jumping to the fail label
without calling __disable_clocks() leave the clocks unbalanced and drain
power?
[Severity: Critical]
This is a pre-existing issue, but are hardware registers accessed during probe
before the bus clocks are enabled?
drivers/iommu/msm_iommu.c:msm_iommu_probe() {
...
msm_iommu_reset(iommu->base, iommu->ncb);
SET_M(iommu->base, 0, 1);
SET_PAR(iommu->base, 0, 0);
...
}
If the hardware is in a power-managed domain, would accessing unclocked
registers synchronously trigger an external abort and panic the kernel?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-fix-qcom-smmu-v2-0-18e0daf2d836@oss.qualcomm.com?part=2
next prev parent reply other threads:[~2026-07-30 16:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 16:04 [PATCH v2 0/3] Fix GPU and display on ARM32 platforms using the MSM IOMMU Dmitry Baryshkov
2026-07-30 16:04 ` Dmitry Baryshkov
2026-07-30 16:04 ` [PATCH v2 1/3] iommu/msm: track a context master per device and IOMMU Dmitry Baryshkov
2026-07-30 16:04 ` Dmitry Baryshkov
2026-07-30 16:24 ` sashiko-bot
2026-07-30 16:04 ` [PATCH v2 2/3] iommu/msm: use the IOMMU device for page table allocation Dmitry Baryshkov
2026-07-30 16:04 ` Dmitry Baryshkov
2026-07-30 16:20 ` sashiko-bot [this message]
2026-07-30 16:04 ` [PATCH v2 3/3] drm/msm: detach the ARM DMA mapping before attaching our own domain Dmitry Baryshkov
2026-07-30 16:04 ` Dmitry Baryshkov
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=20260730162038.C96891F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--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.