From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796223645; b=W1KND8sywRnZyzErVGaBsbFfswob/EFXNl0nytvxeQ1OjdX5aD0rjJkKz0iTQEA3mE2h Kdhdup0vK4Wl3wMBfBFKSsij8+mNmqNKGNLsaA73xnVBgo4yn0p6C0W67pzU2zPDNACgC 5yvpEBnRAyxoJBwJdQ3YJQAZz/CpRQr4NlOQhpXIqxM7blg9bGODfrVU9pcgsY2/xK95V 8uJmu+sBZuKwiKpH7fytHshBaGtUG132lIHa91OsJq3Y/c6+0nHTAdWhRjTlhBw/4QohR JScH3DgmkGM2nhiQXIze7MeJJNDzxRMQCJLK04Re6AzTsxEORK0BM45wNRK5wqn2RVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796223645; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=1AgbIvnXm0LbvhM9VsXFuGgmB5zTWqrjMz4a4NzevGY=; b=THD2o0qCAgqoHGpU2A83YWdj/Wuwt7qz1Ra4atRb5uDmD1K3LXl+nYjgpZBgQoH7U4yr VzNCY8bDIyAqljj29Mikgjfm3y1VKtldPcsQj8waRAshcameqQuc+B49nYeLV7eHXTHD0 u2gizXsSlGfQblAyFaq1bALaqdbfQcLqVWMBJDckhFSK3TDNWM2iGlgmO1oLWkLjkfeoY JmGnOysxNn+L/MI8d2FdUmmlnnx3ZwK36XsdqPnPhiGzDRzLMKDV3nYKYeL5GkrGoeReK +lxM6rBXN+TKiS2gcJGX61mLUsljZG/PAO2SRV+nQt5kvRlp7q80nF7U+1rZ4GW6tSQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QF6gTLFJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 196FB606A325 for ; Wed, 2 Dec 2026 15:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QF6gTLFJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id A41C01F000C1; Wed, 2 Dec 2026 15:00:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796223644; bh=1AgbIvnXm0LbvhM9VsXFuGgmB5zTWqrjMz4a4NzevGY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QF6gTLFJHRrc1N6KhzXp6H2DSqLud/QMWJ73il7pFQ1A/PUAN2Um9/nPpeZTY/bzI 0Z65ubaOKygReSv22Fa9f9MX8/ZiaAlA7KTHmR6oIsA5H/CuEeXu/N6il+jfDGUMuP AOAlX7ZopVa1KdkKPJcdT7N1221bo1AHGQ9+yRAJsf4nXd+XDvIC+J4/Np5cAAHozp Ykr18ym6AqHRN4G9ggkU1yvRgIrRhoUTMZlzU25LEDaDQJ4jiwuUUqOFoYbaPkmx/2 p3cyKSvc6GG967nJSgaVUdK4mGstKj8UYDsFOJ36MMECLqaps/wH4Bi4OSD7lEU5/o XV+u0CTllpr9A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v23 3/6] remoteproc: Introduce optional release_fw operation Reply-To: sashiko-reviews@lists.linux.dev To: "Arnaud Pouliquen" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261202-rproc_tee_v23-b4-v23-3-bac8e36eb405@foss.st.com> References: <20261202-rproc_tee_v23-b4-v23-0-bac8e36eb405@foss.st.com> <20261202-rproc_tee_v23-b4-v23-3-bac8e36eb405@foss.st.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 15:00:44 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/re= moteproc_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) > =20 > /* boot the remote processor up again */ > ret =3D rproc_start(rproc, firmware_p); > + if (ret) > + rproc_release_fw(rproc); > =20 > release_firmware(firmware_p); > =20 [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) > } > =20 > ret =3D rproc_fw_boot(rproc, firmware_p); > + if (ret) > + rproc_release_fw(rproc); > =20 > 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, bo= ol force) > =20 > rproc_disable_iommu(rproc); > =20 > + rproc_release_fw(rproc); > + > /* Free the copy of the resource table */ > kfree(rproc->cached_table); > rproc->cached_table =3D 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 =3D NULL; rproc->table_ptr =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202-rproc_tee_= v23-b4-v23-0-bac8e36eb405@foss.st.com?part=3D3