Skip to contentSkip to conversation

firmware: qcom: pas: Make MDT buffer retention explicit

PATCH Applied Mukesh Ojha 4 participants 4 messages Sep 25 – Nov 8

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v8 1/1 firmware: qcom: pas: Make MDT buffer retention explicit

The PAS image initialization path retains metadata whenever a valid qcom_pas_context is supplied, although callers may not need the metadata after initialization. This leaves ownership implicit and causes unused metadata buffers to remain allocated.

Add keep_mdt_buf to struct qcom_pas_context and have the generic PAS wrapper release metadata unless the caller requests retention. This applies uniformly to SCM and OP-TEE backends, while qcom_q6v5_pas keeps metadata for subsequent PAS operations.

---
Changes in v8:
- Commit rephrased a bit.
- Make the commit aware of all present backends(scm and tee).
- Link to v7: https://lore.kernel.org/lkml/[email protected]/

Changes in v7:
- Since qcom_scm_pas_context is removed, v6 needs to be rebased removing
the changes related to it.
- Link to v6: https://lore.kernel.org/lkml/[email protected]/

Changes in v6:
- Other patches from the series is merged.
- Removed dependency on below series by adding keep_mdt_buf
into qcom_scm_pas_context structure as well.
https://lore.kernel.org/lkml/[email protected]/
- Addressed minor comment on the documentationi.
- Link to v5: 6/6 of https://lore.kernel.org/lkml/[email protected]/

 drivers/firmware/qcom/qcom_pas.c       | 12 +++++++++---
 drivers/firmware/qcom/qcom_scm.c       |  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c     |  3 +++
 include/linux/firmware/qcom/qcom_pas.h |  1 +
 4 files changed, 14 insertions(+), 4 deletions(-)
drivers/firmware/qcom/qcom_pas.c +9 -3
index 24485dd0fa10..93d78a5c1201 100644
@@ -60,17 +60,23 @@ EXPORT_SYMBOL_GPL(devm_qcom_pas_context_alloc);
  *
  * Return: 0 on success.
  *
- * Upon successful return, the PAS metadata context (@ctx) will be used to
- * track the metadata allocation, this needs to be released by invoking
+ * If @ctx requests metadata retention, the PAS metadata context will track
+ * the allocation, which needs to be released by invoking
  * qcom_pas_metadata_release() by the caller.
  */
 int qcom_pas_init_image(u32 pas_id, const void *metadata, size_t size,
 			struct qcom_pas_context *ctx)
 {
+	int ret;
+
 	if (!ops_ptr)
 		return -ENODEV;
 
-	return ops_ptr->init_image(ops_ptr->dev, pas_id, metadata, size, ctx);
+	ret = ops_ptr->init_image(ops_ptr->dev, pas_id, metadata, size, ctx);
+	if (!ret && ctx && !ctx->keep_mdt_buf)
+		qcom_pas_metadata_release(ctx);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(qcom_pas_init_image);
 
drivers/firmware/qcom/qcom_scm.c +1 -1
index df20773dd754..dc57c87870cf 100644
@@ -666,7 +666,7 @@ static int qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
 	ret = __qcom_scm_pas_init_image(dev, pas_id, mdata_phys, &res);
 	if (ret < 0 || !ctx) {
 		dma_free_coherent(dev, size, mdata_buf, mdata_phys);
-	} else if (ctx) {
+	} else {
 		ctx->ptr = mdata_buf;
 		ctx->phys = mdata_phys;
 		ctx->size = size;
drivers/remoteproc/qcom_q6v5_pas.c +3 -0
index 879c465c4a7a..ae93f693358c 100644
@@ -733,6 +733,7 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas *pas)
 	if (IS_ERR(pas->pas_ctx))
 		return PTR_ERR(pas->pas_ctx);
 
+	pas->pas_ctx->keep_mdt_buf = true;
 	if (!pas->dtb_pas_id)
 		return 0;
 
@@ -751,6 +752,8 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas *pas)
 	if (IS_ERR(pas->dtb_pas_ctx))
 		return PTR_ERR(pas->dtb_pas_ctx);
 
+	pas->dtb_pas_ctx->keep_mdt_buf = true;
+
 	return 0;
 }
 
include/linux/firmware/qcom/qcom_pas.h +1 -0
index fb2ec3be6a16..1d132e89536e 100644
@@ -22,6 +22,7 @@ struct qcom_pas_context {
 	dma_addr_t phys;
 	ssize_t size;
 	bool use_tzmem;
+	bool keep_mdt_buf;
 };
 
 static inline void __iomem *qcom_pas_ctx_map(struct qcom_pas_context *ctx)
Signature · 1 line
2.55.0
Acked-by on v8 1/1
#1 lore raw
Quoted 5 lines · Mukesh Ojha

The PAS image initialization path retains metadata whenever a valid qcom_pas_context is supplied, although callers may not need the metadata after initialization. This leaves ownership implicit and causes unused metadata buffers to remain allocated.

Quoted 7 lines

Add keep_mdt_buf to struct qcom_pas_context and have the generic PAS wrapper release metadata unless the caller requests retention. This applies uniformly to SCM and OP-TEE backends, while qcom_q6v5_pas keeps metadata for subsequent PAS operations.

---

Konrad

maintainer Reviewed-by on v8 1/1
#2 lore raw
In reply to Mukesh Ojha
Quoted 11 lines · Mukesh Ojha

The PAS image initialization path retains metadata whenever a valid qcom_pas_context is supplied, although callers may not need the metadata after initialization. This leaves ownership implicit and causes unused metadata buffers to remain allocated.

Add keep_mdt_buf to struct qcom_pas_context and have the generic PAS wrapper release metadata unless the caller requests retention. This applies uniformly to SCM and OP-TEE backends, while qcom_q6v5_pas keeps metadata for subsequent PAS operations.

Quoted 7 lines

---
Changes in v8:
- Commit rephrased a bit.
- Make the commit aware of all present backends(scm and tee).
- Link to v7: https://lore.kernel.org/lkml/[email protected]/

-Sumit

Quoted 101 lines

Changes in v7:
- Since qcom_scm_pas_context is removed, v6 needs to be rebased removing
the changes related to it.
- Link to v6: https://lore.kernel.org/lkml/[email protected]/

Changes in v6:
- Other patches from the series is merged.
- Removed dependency on below series by adding keep_mdt_buf
into qcom_scm_pas_context structure as well.
https://lore.kernel.org/lkml/[email protected]/
- Addressed minor comment on the documentationi.
- Link to v5: 6/6 of https://lore.kernel.org/lkml/[email protected]/

 drivers/firmware/qcom/qcom_pas.c       | 12 +++++++++---
 drivers/firmware/qcom/qcom_scm.c       |  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c     |  3 +++
 include/linux/firmware/qcom/qcom_pas.h |  1 +
 4 files changed, 14 insertions(+), 4 deletions(-)
drivers/firmware/qcom/qcom_pas.c +9 -3
index 24485dd0fa10..93d78a5c1201 100644
@@ -60,17 +60,23 @@ EXPORT_SYMBOL_GPL(devm_qcom_pas_context_alloc);
  *
  * Return: 0 on success.
  *
- * Upon successful return, the PAS metadata context (@ctx) will be used to
- * track the metadata allocation, this needs to be released by invoking
+ * If @ctx requests metadata retention, the PAS metadata context will track
+ * the allocation, which needs to be released by invoking
  * qcom_pas_metadata_release() by the caller.
  */
 int qcom_pas_init_image(u32 pas_id, const void *metadata, size_t size,
                        struct qcom_pas_context *ctx)
 {
+       int ret;
+
        if (!ops_ptr)
                return -ENODEV;
 
-       return ops_ptr->init_image(ops_ptr->dev, pas_id, metadata, size, ctx);
+       ret = ops_ptr->init_image(ops_ptr->dev, pas_id, metadata, size, ctx);
+       if (!ret && ctx && !ctx->keep_mdt_buf)
+               qcom_pas_metadata_release(ctx);
+
+       return ret;
 }
 EXPORT_SYMBOL_GPL(qcom_pas_init_image);
 
drivers/firmware/qcom/qcom_scm.c +1 -1
index df20773dd754..dc57c87870cf 100644
@@ -666,7 +666,7 @@ static int qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
        ret = __qcom_scm_pas_init_image(dev, pas_id, mdata_phys, &res);
        if (ret < 0 || !ctx) {
                dma_free_coherent(dev, size, mdata_buf, mdata_phys);
-       } else if (ctx) {
+       } else {
                ctx->ptr = mdata_buf;
                ctx->phys = mdata_phys;
                ctx->size = size;
drivers/remoteproc/qcom_q6v5_pas.c +3 -0
index 879c465c4a7a..ae93f693358c 100644
@@ -733,6 +733,7 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas *pas)
        if (IS_ERR(pas->pas_ctx))
                return PTR_ERR(pas->pas_ctx);
 
+       pas->pas_ctx->keep_mdt_buf = true;
        if (!pas->dtb_pas_id)
                return 0;
 
@@ -751,6 +752,8 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas *pas)
        if (IS_ERR(pas->dtb_pas_ctx))
                return PTR_ERR(pas->dtb_pas_ctx);
 
+       pas->dtb_pas_ctx->keep_mdt_buf = true;
+
        return 0;
 }
 
include/linux/firmware/qcom/qcom_pas.h +1 -1
index fb2ec3be6a16..1d132e89536e 100644
@@ -22,6 +22,7 @@ struct qcom_pas_context {
        dma_addr_t phys;
        ssize_t size;
        bool use_tzmem;
+       bool keep_mdt_buf;
 };
 
 static inline void __iomem *qcom_pas_ctx_map(struct qcom_pas_context *ctx)
--

2.55.0

maintainer Applied
#3 lore raw
In reply to Mukesh Ojha
Quoted 11 lines · Mukesh Ojha

The PAS image initialization path retains metadata whenever a valid qcom_pas_context is supplied, although callers may not need the metadata after initialization. This leaves ownership implicit and causes unused metadata buffers to remain allocated.

Add keep_mdt_buf to struct qcom_pas_context and have the generic PAS wrapper release metadata unless the caller requests retention. This applies uniformly to SCM and OP-TEE backends, while qcom_q6v5_pas keeps metadata for subsequent PAS operations.

[...]

Applied, thanks!

[1/1] firmware: qcom: pas: Make MDT buffer retention explicit

      commit: 2aa8fafc08e777e9da356307c1a0117e7f4277cf

Best regards,

Signature · 1 line
Bjorn Andersson <[email protected]>