On Tue, Jun 30, 2026 at 12:39:12PM +0200, Konrad Dybcio wrote: > On 4/30/26 9:12 PM, Mukesh Ojha wrote: > > The PAS image initialization path always retains the metadata buffer > > when a valid qcom_scm_pas_context is provided, even if the caller does > > not require it. This implicit behavior leads to unclear buffer ownership > > and forces new users of qcom_mdt_pas_load() to manually release > > metadata, which is error‑ prone and incorrect. > > > > Add a keep_mdt_buf flag to struct qcom_scm_pas_context to make metadata > > retention explicit. Metadata buffers are now freed by default and are > > only preserved when this flag is set. qcom_q6v5_pas enables this during > > probe for contexts that require retained metadata for subsequent PAS > > operations, while existing callers continue to work unchanged. > > > > Signed-off-by: Mukesh Ojha <[email protected]> > > --- > > [...] > > > ret = __qcom_scm_pas_init_image(pas_id, mdata_phys, &res); > > - if (ret < 0 || !ctx) { > > + > > + /* > > + * Some clients still pass the PAS context as NULL. Until all clients > > + * switch to qcom_mdt_pas_load() and provide a valid PAS context, check > > + * for NULL before dereferencing it. > > + * > > + * When a valid context is provided, metadata handling differs across > > + * clients. For example, modem clients pass metadata to TrustZone that > > + * must not be freed until the authentication and reset SMCs are > > + * invoked, as the buffers remain locked until then. > > + * > > + * Other clients free their metadata immediately after the PAS_INIT > > + * SMC call. Therefore, keep_mdt_buf should be set to true for modem > > + * clients and false for others. > > You say this... > > [...] > > > --- a/drivers/remoteproc/qcom_q6v5_pas.c > > +++ b/drivers/remoteproc/qcom_q6v5_pas.c > > @@ -669,6 +669,7 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas > > *pas) > > return PTR_ERR(pas->pas_ctx); > > > > pas->pas_ctx->use_tzmem = rproc->has_iommu; > > + pas->pas_ctx->keep_mdt_buf = true; > > if (!pas->dtb_pas_id) > > return 0; > > > > @@ -688,6 +689,7 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas > > *pas) > > return PTR_ERR(pas->dtb_pas_ctx); > > > > pas->dtb_pas_ctx->use_tzmem = rproc->has_iommu; > > + pas->dtb_pas_ctx->keep_mdt_buf = true; > > And you set it globally for all PAS rprocs
You are right, but in the upstream Qualcomm PAS driver as of today, we do not differentiate the freeing of the metadata region among various subsystems — ADSP, CDSP, MPSS — and it is true for all: release metadata only once auth and reset is successful. And I see no side effect even if you delay the metadata release from PAS init to after auth and reset(). But all the non-remoteproc subsystems like IRIS, IPA, etc., have their metadata released right after a successful or failed PAS init call. I could refine the above comment to reflect what is there today in upstream. -- -Mukesh Ojha

