Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaud Pouliquen" <arnaud.pouliquen@foss.st.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v23 3/6] remoteproc: Introduce optional release_fw operation
Date: Wed, 02 Dec 2026 15:00:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-246030@kernel.org> (raw)
In-Reply-To: <20261202-rproc_tee_v23-b4-v23-3-bac8e36eb405@foss.st.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] remoteproc: out-of-order rproc_release_fw() teardown in boot
  and shutdown
- [High] remoteproc: missing and asymmetric rproc_release_fw() in
  rproc_boot_recovery()
- [Medium] remoteproc: unpaired rproc_release_fw() when rproc_parse_fw()
  never ran
--

commit 3fd59c00f1c96ac05a0265ff37076176eaff24d9
Author: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>

remoteproc: Introduce optional release_fw operation

This commit introduces an optional release_fw callback in struct rproc_ops
to release firmware resources on boot failure, recovery failure, and
shutdown.

> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index e31c6b2094242..a9b3d0f4a0d6b 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1849,6 +1849,8 @@ static int rproc_boot_recovery(struct rproc *rproc)
>  
>  	/* boot the remote processor up again */
>  	ret = rproc_start(rproc, firmware_p);
> +	if (ret)
> +		rproc_release_fw(rproc);
>  
>  	release_firmware(firmware_p);
>  

[Severity: High]
Does rproc_boot_recovery() miss releasing the previous firmware before
reloading, and leak resources when recovery fails?

When request_firmware() succeeds, rproc_start() calls rproc_load_segments()
without a prior rproc_release_fw() after rproc_stop() and coredump(), so
ops->load() runs while the crashed boot's firmware resources are still
allocated.

Conversely, if request_firmware() fails after rproc_stop() has set
rproc->state to RPROC_OFFLINE, rproc_release_fw() is skipped, and later
calls to __rproc_shutdown() reject RPROC_OFFLINE with -EINVAL, permanently
leaking those firmware resources.  And if rproc_start() fails here,
rproc_release_fw() runs while rproc->carveouts, rproc->cached_table, the
prepared device, and the IOMMU remain active in RPROC_OFFLINE where
__rproc_shutdown() will no longer clean them up.

> @@ -2000,6 +2002,8 @@ int rproc_boot(struct rproc *rproc)
>  		}
>  
>  		ret = rproc_fw_boot(rproc, firmware_p);
> +		if (ret)
> +			rproc_release_fw(rproc);
>  
>  		release_firmware(firmware_p);
>  	}

[Severity: Medium]
Can this invoke rproc_release_fw() when rproc_parse_fw() and
rproc_load_segments() never ran?

rproc_fw_boot() can fail in rproc_fw_sanity_check(), rproc_enable_iommu(),
or rproc_prepare_device() before reaching rproc_parse_fw(), or inside
rproc_parse_fw() after the callback has already cleaned up its own partial
state.  A similar unpaired call happens in __rproc_shutdown() when stopping
a remote processor that was attached via rproc_attach() rather than booted
via rproc_fw_boot().

> @@ -2052,6 +2056,8 @@ static int __rproc_shutdown(struct rproc *rproc, bool force)
>  
>  	rproc_disable_iommu(rproc);
>  
> +	rproc_release_fw(rproc);
> +
>  	/* Free the copy of the resource table */
>  	kfree(rproc->cached_table);
>  	rproc->cached_table = NULL;

[Severity: High]
Isn't rproc_release_fw() called too late in the teardown sequence both here
and on the rproc_boot() error path?

During boot, rproc_fw_boot() enables the IOMMU, prepares the device, calls
rproc_parse_fw(), allocates carveouts, and loads segments.  Here in
__rproc_shutdown(), rproc_release_fw() runs only after
rproc_resource_cleanup(), rproc_unprepare_device(), and
rproc_disable_iommu() have already freed rproc->carveouts, unprepared
hardware clocks or power, and detached the IOMMU.  On the rproc_boot()
error path, rproc_fw_boot() has additionally freed and cleared
rproc->cached_table and rproc->table_ptr before rproc_release_fw() is
called:

drivers/remoteproc/remoteproc_core.c:rproc_fw_boot() {
    ...
clean_up_resources:
	rproc_resource_cleanup(rproc);
	kfree(rproc->cached_table);
	rproc->cached_table = NULL;
	rproc->table_ptr = NULL;
unprepare_rproc:
	/* release HW resources if needed */
	rproc_unprepare_device(rproc);
disable_iommu:
	rproc_disable_iommu(rproc);
	return ret;
}

Any release_fw() implementation that accesses carveouts, hardware
resources, IOMMU mappings, or rproc->cached_table will see them already
torn down or in an inconsistent state between boot failure and shutdown.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-rproc_tee_v23-b4-v23-0-bac8e36eb405@foss.st.com?part=3

  reply	other threads:[~2026-12-02 15:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 14:48 [PATCH v23 0/6] Introduction of a remoteproc tee to load signed firmware Arnaud Pouliquen
2026-12-02 14:48 ` [PATCH v23 1/6] dt-bindings: remoteproc: st,stm32-rproc: Add st,rproc-tee Arnaud Pouliquen
2026-12-02 14:48 ` [PATCH v23 2/6] remoteproc: core: Introduce rproc_pa_to_va helper Arnaud Pouliquen
2026-12-02 14:48 ` [PATCH v23 3/6] remoteproc: Introduce optional release_fw operation Arnaud Pouliquen
2026-12-02 15:00   ` sashiko-bot [this message]
2026-12-02 14:48 ` [PATCH v23 4/6] remoteproc: Add TEE support Arnaud Pouliquen
2026-12-02 15:10   ` sashiko-bot
2026-12-02 14:48 ` [PATCH v23 5/6] remoteproc: stm32: Create sub-functions to request shutdown and release Arnaud Pouliquen
2026-12-02 14:48 ` [PATCH v23 6/6] remoteproc: stm32: add OP-TEE backend support Arnaud Pouliquen

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-246030@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arnaud.pouliquen@foss.st.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --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