Re: [PATCH v9 4/7] remoteproc: core: Add TEE interface support for firmware release

Mathieu Poirier
2024-09-23T14:53:47Z

On Tue, Sep 17, 2024 at 06:56:58PM +0200, Arnaud POULIQUEN wrote:
> Hello Mathieu,
>
> On 9/12/24 17:26, Mathieu Poirier wrote:
> > On Fri, Aug 30, 2024 at 11:51:44AM +0200, Arnaud Pouliquen wrote:
> >> Add support for releasing remote processor firmware through
> >> the Trusted Execution Environment (TEE) interface.
> >>
> >> The tee_rproc_release_fw() function is called in the following cases:
> >>
> >> - An error occurs in rproc_start() between the loading of the segments and
> >> the start of the remote processor.
> >> - When rproc_release_fw is called on error or after stopping the remote
> >> processor.
> >>
> >> Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
> >> ---
> >> drivers/remoteproc/remoteproc_core.c | 10 ++++++++--
> >> 1 file changed, 8 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> >> index 7694817f25d4..32052dedc149 100644
> >> --- a/drivers/remoteproc/remoteproc_core.c
> >> +++ b/drivers/remoteproc/remoteproc_core.c
> >> @@ -29,6 +29,7 @@
> >> #include <linux/debugfs.h>
> >> #include <linux/rculist.h>
> >> #include <linux/remoteproc.h>
> >> +#include <linux/remoteproc_tee.h>
> >> #include <linux/iommu.h>
> >> #include <linux/idr.h>
> >> #include <linux/elf.h>
> >> @@ -1258,6 +1259,9 @@ static int rproc_alloc_registered_carveouts(struct rproc *rproc)
> >>
> >> static void rproc_release_fw(struct rproc *rproc)
> >> {
> >> + if (rproc->state == RPROC_OFFLINE && rproc->tee_interface)
> >> + tee_rproc_release_fw(rproc);
> >
> > Function tee_rproc_release_fw() returns a value that is ignored. I don't know
> > how it passes the Sparse checker but I already see patches coming in my Inbox to
> > deal with that. In this case there is nothing else to do if there is an error
> > releasing the firware. As such I would put a (void) in front and add a comment
> > about the return value being ignore on purpose.
>
> Instead of ignoring the error, I wonder if we should panic in
> tee_rproc_release_fw(). Indeed, we would be in an unexpected state without any
> possible action to return to a normal state.

Nowadays a call to panic() is only used in very dire situations and I don't see
this meeting that requirement. I would just call a dev_err() and let it be.

>
> Regards,
> Arnaud
>
> >
> >> +
> >> /* Free the copy of the resource table */
> >> kfree(rproc->cached_table);
> >> rproc->cached_table = NULL;
> >> @@ -1348,7 +1352,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
> >> if (ret) {
> >> dev_err(dev, "failed to prepare subdevices for %s: %d\n",
> >> rproc->name, ret);
> >> - goto reset_table_ptr;
> >> + goto release_fw;
> >> }
> >>
> >> /* power up the remote processor */
> >> @@ -1376,7 +1380,9 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
> >> rproc->ops->stop(rproc);
> >> unprepare_subdevices:
> >> rproc_unprepare_subdevices(rproc);
> >> -reset_table_ptr:
> >> +release_fw:
> >> + if (rproc->tee_interface)
> >> + tee_rproc_release_fw(rproc);
> >
> > Same here.
> >
> >> rproc->table_ptr = rproc->cached_table;
> >>
> >> return ret;
> >> --
> >> 2.25.1
> >>