From: sashiko-bot@kernel.org
To: "Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 07/12] iommu: qcom_iommu: restore context bank state after power collapse
Date: Sun, 09 Aug 2026 20:28:30 +0000 [thread overview]
Message-ID: <20260809202831.450B21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260809-msm8974-iommu-upstream-v1-7-87f5cd492560@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free and hardware page table corruption due to dangling `ctx->domain` on initialization error path.
--
--- Patch [7]: [PATCH 07/12] iommu: qcom_iommu: restore context bank state after power collapse ---
commit 4c924588306637fe44ecea534620e5e790b49aa8
Author: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
iommu: qcom_iommu: restore context bank state after power collapse
This commit caches the computed context bank register values at attach
time and replays the global reset, stream mapping and context bank
programming on runtime resume. Instances opt in through the new
ctx_restore configuration flag.
> diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> index 3b07c4cf23fe1..8e9488c47d5c1 100644
> --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
[ ... ]
> @@ -1079,6 +1082,16 @@ static int __maybe_unused qcom_iommu_resume(struct device *dev)
> return ret;
> }
>
> + if (qcom_iommu->cfg && qcom_iommu->cfg->ctx_restore) {
> + /* Restore context banks lost over power collapse */
> + for (i = 0; i <= qcom_iommu->max_asid; i++) {
> + struct qcom_iommu_ctx *ctx = qcom_iommu->ctxs[i];
> +
> + if (ctx && ctx->domain && !ctx->secured_ctx)
> + qcom_iommu_program_ctx(qcom_iommu, ctx);
[Severity: High]
This is a pre-existing issue, but could this new resume logic trigger a
use-after-free and corrupt hardware page tables if initialization previously
failed?
In drivers/iommu/arm/arm-smmu/qcom_iommu.c:qcom_iommu_init_domain(), the error
path frees the allocated page tables but fails to clear the ctx->domain pointer
for context banks that were successfully processed before the error occurred:
out_clear_iommu:
free_io_pgtable_ops(pgtbl_ops);
qcom_domain->iommu = NULL;
If a device with multiple context banks fails initialization midway (for example,
during a firmware SCM call for a subsequent bank), the error path leaves
ctx->domain dangling and the page tables freed.
Upon the next PM runtime resume, this new loop in qcom_iommu_resume() sees the
truthy ctx->domain and programs the hardware with the stale ctx->ttbr0, causing
the IOMMU to use freed memory for DMA translation page tables.
> + }
> + }
> +
> return ret;
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260809-msm8974-iommu-upstream-v1-0-87f5cd492560@oss.qualcomm.com?part=7
next prev parent reply other threads:[~2026-08-09 20:28 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 20:15 [PATCH 00/12] iommu: qcom_iommu: implement support for instances on MSM8974 Dmitry Baryshkov
2026-08-09 20:15 ` [PATCH 01/12] dt-bindings: iommu: qcom,iommu: document the MSM8974 IOMMUs Dmitry Baryshkov
2026-08-09 20:28 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 02/12] iommu: arm-smmu: add global register definitions used by the QSMMU Dmitry Baryshkov
2026-08-09 20:15 ` [PATCH 03/12] iommu: qcom_iommu: extract context bank programming into a helper Dmitry Baryshkov
2026-08-09 20:27 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 04/12] iommu: qcom_iommu: support the short-descriptor pagetable format Dmitry Baryshkov
2026-08-09 20:30 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 05/12] iommu: qcom_iommu: handle the SMMU global register space Dmitry Baryshkov
2026-08-09 20:29 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 06/12] iommu: qcom_iommu: support non-TZ-managed instances Dmitry Baryshkov
2026-08-09 20:39 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 07/12] iommu: qcom_iommu: restore context bank state after power collapse Dmitry Baryshkov
2026-08-09 20:28 ` sashiko-bot [this message]
2026-08-09 20:15 ` [PATCH 08/12] iommu: qcom_iommu: halt the micro-MMU while programming context banks Dmitry Baryshkov
2026-08-09 20:33 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 09/12] iommu: qcom_iommu: allow faulting transactions to terminate Dmitry Baryshkov
2026-08-09 20:28 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 10/12] iommu: qcom_iommu: program BFP (prefetch) settings Dmitry Baryshkov
2026-08-09 20:28 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 11/12] iommu: qcom_iommu: add the MSM8974 instances Dmitry Baryshkov
2026-08-09 20:28 ` sashiko-bot
2026-08-09 20:15 ` [PATCH 12/12] ARM: dts: qcom: msm8974: add the IOMMUs Dmitry Baryshkov
2026-08-10 10:16 ` [PATCH 00/12] iommu: qcom_iommu: implement support for instances on MSM8974 Luca Weiss
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=20260809202831.450B21F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=robh@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox