All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 06/12] iommu: qcom_iommu: support non-TZ-managed instances
Date: Sun, 09 Aug 2026 20:39:53 +0000	[thread overview]
Message-ID: <20260809203954.71F341F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260809-msm8974-iommu-upstream-v1-6-87f5cd492560@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [High] Missing configuration data in `qcom_iommu_of_match` makes the non-secure code path unreachable.
- [High] Context bank registers are not restored during runtime resume for non-secure IOMMU instances.

Pre-existing issues:
- [High] Dangling pointer and potential UAF when `qcom_iommu_init_domain()` fails halfway through context bank initialization.
- [High] The shared interrupt handler `qcom_iommu_fault` can be invoked while the device is suspended or before a domain is attached, leading to unclocked register accesses and a NULL pointer dereference.
- [High] `qcom_iommu_unmap` calls `pm_runtime_get_sync`, which sleeps, but IOMMU unmap operations can be invoked from atomic context.
--

--- Patch [6]: [PATCH 06/12] iommu: qcom_iommu: support non-TZ-managed instances ---
commit e923920b01d0c5363e8c876cd9db3360e29f7e5a
Author: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
iommu: qcom_iommu: support non-TZ-managed instances

This patch adds non-secure programming mode support for MSM8974 GPU IOMMU
instances that are not managed by TZ. It configures the global space at
runtime resume, clears global faults, and sets up stream mapping instead of
relying on secure calls.

> diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> index 428b18697244c..3b07c4cf23fe1 100644
> --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
[ ... ]
> @@ -327,7 +411,7 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain,
>  	for (i = 0; i < fwspec->num_ids; i++) {
>  		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
>  
> -		if (!ctx->secure_init) {
> +		if (!qcom_iommu->non_secure && !ctx->secure_init) {

[Severity: High]
This is a pre-existing issue, but is there a dangling pointer and potential
use-after-free when qcom_iommu_init_domain() fails halfway through context
bank initialization?

If context bank initialization fails (for example, qcom_scm_restore_sec_cfg()
fails on a subsequent iteration), the function returns an error without
clearing ctx->domain for the already processed context banks. The IOMMU core
then frees the domain memory.

If a hardware fault interrupt fires, will qcom_iommu_fault() dereference the
freed ctx->domain?

>  			ret = qcom_scm_restore_sec_cfg(qcom_iommu->sec_id, ctx->asid);
>  			if (ret) {
>  				dev_err(qcom_iommu->dev, "secure init failed: %d\n", ret);
[ ... ]
> @@ -907,8 +991,12 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
>  
>  	if (of_property_read_u32(dev->of_node, "qcom,iommu-secure-id",
>  				 &qcom_iommu->sec_id)) {
> -		dev_err(dev, "missing qcom,iommu-secure-id property\n");
> -		return -ENODEV;
> +		if (!qcom_iommu->cfg) {
> +			dev_err(dev, "missing qcom,iommu-secure-id property\n");
> +			return -ENODEV;
> +		}

[Severity: High]
Does the missing configuration data in qcom_iommu_of_match make this
non-secure code path unreachable?

During device probe, of_device_get_match_data() returns NULL because the newly
introduced compatibles (like qcom,msm8974-gpu-iommu) and their struct
qcom_iommu_cfg data were not added to the qcom_iommu_of_match array in this
patch.

This causes qcom_iommu->cfg to evaluate to NULL, unconditionally failing
with -ENODEV here when probing a non-secure instance.

> +		/* The secure world does not manage this instance at all */
> +		qcom_iommu->non_secure = true;
>  	}
>  
>  	if (qcom_iommu_has_secure_context(qcom_iommu)) {
[ ... ]
> @@ -981,8 +1069,15 @@ static int __maybe_unused qcom_iommu_resume(struct device *dev)
>  	if (ret < 0)
>  		return ret;
>  
> -	if (dev->pm_domain)
> -		return qcom_scm_restore_sec_cfg(qcom_iommu->sec_id, 0);
> +	if (qcom_iommu->non_secure) {
> +		ret = qcom_iommu_reset_ns(qcom_iommu);
> +		if (ret)
> +			return ret;

[Severity: High]
Are context bank registers restored during runtime resume for non-secure
IOMMU instances?

When the non-secure IOMMU is runtime resumed (e.g., after GDSC power
collapse), qcom_iommu_resume() restores the global registers via
qcom_iommu_reset_ns(), but it seems to completely omit iterating over and
reprogramming the attached context banks.

Since the context bank child devices lack PM operations, do they remain
disabled (SCTLR = 0) after resume, causing translation faults for all
non-secure instances?

> +	} else if (dev->pm_domain) {
> +		ret = qcom_scm_restore_sec_cfg(qcom_iommu->sec_id, 0);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	return ret;
>  }

[Severity: High]
This is a pre-existing issue, but can the shared interrupt handler
qcom_iommu_fault() be invoked while the device is suspended or before a
domain is attached, leading to unclocked register accesses and a NULL
pointer dereference?

In qcom_iommu_ctx_probe(), a shared IRQ is requested before a domain is
attached:

drivers/iommu/arm/arm-smmu/qcom_iommu.c:qcom_iommu_ctx_probe() {
    ...
	ret = devm_request_irq(dev, irq,
			       qcom_iommu_fault,
			       IRQF_SHARED,
    ...
}

If another device sharing the IRQ fires, qcom_iommu_fault() executes and
accesses ARM_SMMU_CB_FSR. If the device is unclocked, this crashes the bus.

If clocked and a bootloader fault is pending, it dereferences a NULL
ctx->domain. The target patch seems to explicitly bypass clearing pending
bootloader faults for non-secure instances when qcom_iommu->cfg is present:

drivers/iommu/arm/arm-smmu/qcom_iommu.c:qcom_iommu_ctx_probe() {
    ...
	if (!ctx->secured_ctx && !qcom_iommu->cfg) {
		ret = pm_runtime_resume_and_get(dev->parent);
    ...
}

Will this ensure the crash triggers immediately upon shared IRQ firing?

[Severity: High]
This is a pre-existing issue, but does qcom_iommu_unmap() call
pm_runtime_get_sync() which sleeps, even though IOMMU unmap operations can
be invoked from atomic context?

The DMA API invokes the IOMMU unmap operation from an atomic context
(e.g., interrupt handlers):

drivers/iommu/arm/arm-smmu/qcom_iommu.c:qcom_iommu_unmap() {
    ...
	pm_runtime_get_sync(qcom_domain->iommu->dev);
	spin_lock_irqsave(&qcom_domain->pgtbl_lock, flags);
    ...
}

Because the device is not marked with pm_runtime_irq_safe(),
pm_runtime_get_sync() acquires a mutex and sleeps. Can this lead to a "BUG:
sleeping function called from invalid context" panic?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260809-msm8974-iommu-upstream-v1-0-87f5cd492560@oss.qualcomm.com?part=6

  reply	other threads:[~2026-08-09 20:39 UTC|newest]

Thread overview: 25+ 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 [this message]
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
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
2026-08-11 12:43   ` 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=20260809203954.71F341F000E9@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 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.