remoteproc: qcom: pas: Guard dtb metadata release with dtb_pas_id check
PATCH v3 2/5 remoteproc: qcom: pas: Guard dtb metadata release with dtb_pas_id check
All other call sites of qcom_scm_pas_metadata_release() for the DTB context are guarded by a check on pas->dtb_pas_id, but the call inside qcom_pas_load() was not. Fix this by moving the call to the guarded block.
---
Changes in v3: lore.kernel.org/lkml/[email protected]/
- Added R-b tag and split the changes into 2.
Changes in v2: https://lore.kernel.org/lkml/sxklpgc2rtr75maiu7lg4iukmaetvjyho7ytyyykmtdu2tov3k@gctoozxj7frl/
- No change.
drivers/remoteproc/qcom_q6v5_pas.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/remoteproc/qcom_q6v5_pas.c +3 -2
@@ -243,14 +243,15 @@ static int qcom_pas_load(struct rproc *rproc, const struct firmware *fw) ret =qcom_mdt_pas_load (pas->dtb_pas_ctx, pas->dtb_firmware, pas->dtb_firmware_name, (__force void *)pas->dtb_mem_region, &pas->dtb_mem_reloc); -if (ret) +if (ret) { +qcom_scm_pas_metadata_release (pas->dtb_pas_ctx); goto release_dtb_metadata; + } }return 0 ; release_dtb_metadata: -qcom_scm_pas_metadata_release (pas->dtb_pas_ctx);release_firmware (pas->dtb_firmware);return ret;
Signature · 1 line
2.53.0
PATCH v3 3/5 remoteproc: qcom: pas: Fix the dtb PAS context creation
DTB PAS context creation should be done only for subsystems that support a DTB firmware binary; otherwise, memory is wasted. Move the context creation to the appropriate location.
---
Changes in v3: lore.kernel.org/lkml/[email protected]/
- Split the changes compared to v2.
Changes in v2: https://lore.kernel.org/lkml/sxklpgc2rtr75maiu7lg4iukmaetvjyho7ytyyykmtdu2tov3k@gctoozxj7frl/
- No change.
drivers/remoteproc/qcom_q6v5_pas.c | 32 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-)
drivers/remoteproc/qcom_q6v5_pas.c +15 -17
@@ -624,6 +624,7 @@ static void qcom_pas_pds_detach(struct qcom_pas *pas, struct device **pds, size_static int qcom_pas_alloc_memory_region (struct qcom_pas *pas) { +struct rproc *rproc = pas->rproc;struct resource res;int ret;
@@ -641,6 +642,12 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas *pas)return PTR_ERR (pas->mem_region); } + pas->pas_ctx =devm_qcom_scm_pas_context_alloc (pas->dev, pas->pas_id, + pas->mem_phys, pas->mem_size); +if (IS_ERR (pas->pas_ctx)) +return PTR_ERR (pas->pas_ctx); + + pas->pas_ctx->use_tzmem = rproc->has_iommu;if (!pas->dtb_pas_id)return 0 ;
@@ -658,6 +665,14 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas *pas)return PTR_ERR (pas->dtb_mem_region); } + pas->dtb_pas_ctx =devm_qcom_scm_pas_context_alloc (pas->dev, pas->dtb_pas_id, + pas->dtb_mem_phys, + pas->dtb_mem_size); +if (IS_ERR (pas->dtb_pas_ctx)) +return PTR_ERR (pas->dtb_pas_ctx); + + pas->dtb_pas_ctx->use_tzmem = rproc->has_iommu; +return 0 ; }
@@ -839,23 +854,6 @@ static int qcom_pas_probe(struct platform_device *pdev)qcom_add_ssr_subdev (rproc, &pas->ssr_subdev, desc->ssr_name); - pas->pas_ctx =devm_qcom_scm_pas_context_alloc (pas->dev, pas->pas_id, - pas->mem_phys, pas->mem_size); -if (IS_ERR (pas->pas_ctx)) { - ret =PTR_ERR (pas->pas_ctx); - goto remove_ssr_sysmon; - } - - pas->dtb_pas_ctx =devm_qcom_scm_pas_context_alloc (pas->dev, pas->dtb_pas_id, - pas->dtb_mem_phys, - pas->dtb_mem_size); -if (IS_ERR (pas->dtb_pas_ctx)) { - ret =PTR_ERR (pas->dtb_pas_ctx); - goto remove_ssr_sysmon; - } - - pas->pas_ctx->use_tzmem = rproc->has_iommu; - pas->dtb_pas_ctx->use_tzmem = rproc->has_iommu; ret =rproc_add (rproc);if (ret) goto remove_ssr_sysmon;
Signature · 1 line
2.53.0
PATCH v3 4/5 remoteproc: qcom: pas: Map/unmap subsystem region before auth_and_reset
In reply to Mukesh OjhaQualcomm remoteproc drivers such as qcom_q6v5_mss, which do not use the Peripheral Authentication Service (PAS), always map the MBA region before use and unmap it once the usage is complete. This behavior was introduced to avoid issues seen in the past where speculative accesses from the application processor to the MBA region after it was assigned to the remote Q6 led to an XPU violation. The issue was mitigated by unmapping the region before handing control to the remote Q6.
Currently, most Qualcomm SoCs using the PAS driver run either with a standalone QHEE or the Gunyah hypervisor. In these environments, the hypervisor unmaps the Q6 memory from HLOS Stage-2 and remaps it into the Q6 Stage-2 page table. As a result, speculative accesses from HLOS cannot reach the region even if it remains mapped in HLOS Stage-1; therefore, XPU violations cannot occur.
However, when the same SoC runs Linux at EL2, Linux itself must perform the unmapping to avoid such issues. It is still correct to apply this mapping/ unmapping sequence even for SoCs that run under Gunyah, so this behavior should not be conditional.
---
Changes in v3: https://lore.kernel.org/lkml/[email protected]/
- Took care of sparse warning.
Changes in v2: https://lore.kernel.org/lkml/[email protected]/
- Moved map/unmap to pas_load function and further to coredump/minidump function.
drivers/remoteproc/qcom_q6v5_pas.c | 41 ++++++++++++++++++++--------- drivers/soc/qcom/mdt_loader.c | 18 ++++++++++--- include/linux/soc/qcom/mdt_loader.h | 4 +-- 3 files changed, 44 insertions(+), 19 deletions(-)
drivers/remoteproc/qcom_q6v5_pas.c +28 -13
@@ -148,7 +148,16 @@ static void qcom_pas_minidump(struct rproc *rproc)if (rproc->dump_conf ==RPROC_COREDUMP_DISABLED )return ; + pas->mem_region =ioremap_wc (pas->mem_phys, pas->mem_size); +if (!pas->mem_region) { +dev_err (pas->dev,"unable to map memory region: %pa+%zx\n" , + &pas->mem_phys, pas->mem_size); +return ; + } +qcom_minidump (rproc, pas->minidump_id, qcom_pas_segment_dump); +iounmap (pas->mem_region); + pas->mem_region =NULL ; } static int qcom_pas_pds_enable(struct qcom_pas *pas, struct device **pds,
@@ -241,8 +250,7 @@ static int qcom_pas_load(struct rproc *rproc, const struct firmware *fw) } ret =qcom_mdt_pas_load (pas->dtb_pas_ctx, pas->dtb_firmware, - pas->dtb_firmware_name, (__force void *)pas->dtb_mem_region, - &pas->dtb_mem_reloc); + pas->dtb_firmware_name, &pas->dtb_mem_reloc);if (ret) {qcom_scm_pas_metadata_release (pas->dtb_pas_ctx); goto release_dtb_metadata;
@@ -320,7 +328,7 @@ static int qcom_pas_start(struct rproc *rproc) } ret =qcom_mdt_pas_load (pas->pas_ctx, pas->firmware, rproc->firmware, - (__force void *)pas->mem_region, &pas->mem_reloc); + &pas->mem_reloc);if (ret) goto release_pas_metadata;
@@ -511,6 +519,22 @@ static unsigned long qcom_pas_panic(struct rproc *rproc)return qcom_q6v5_panic (&pas->q6v5); } +static void qcom_pas_coredump (struct rproc *rproc) +{ +struct qcom_pas *pas = rproc->priv; + + pas->mem_region =ioremap_wc (pas->mem_phys, pas->mem_size); +if (!pas->mem_region) { +dev_err (pas->dev,"unable to map memory region: %pa+%zx\n" , + &pas->mem_phys, pas->mem_size); +return ; + } + +rproc_coredump (rproc); +iounmap (pas->mem_region); + pas->mem_region =NULL ; +} +static const struct rproc_ops qcom_pas_ops = { .unprepare = qcom_pas_unprepare, .start = qcom_pas_start,
@@ -519,6 +543,7 @@ static const struct rproc_ops qcom_pas_ops = { .parse_fw = qcom_pas_parse_firmware, .load = qcom_pas_load, .panic = qcom_pas_panic, + .coredump = qcom_pas_coredump, };static const struct rproc_ops qcom_pas_minidump_ops = {
@@ -636,11 +661,6 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas *pas) pas->mem_phys = pas->mem_reloc = res.start; pas->mem_size =resource_size (&res); - pas->mem_region =devm_ioremap_resource_wc (pas->dev, &res); -if (IS_ERR (pas->mem_region)) { -dev_err (pas->dev,"unable to map memory region: %pR\n" , &res); -return PTR_ERR (pas->mem_region); - } pas->pas_ctx =devm_qcom_scm_pas_context_alloc (pas->dev, pas->pas_id, pas->mem_phys, pas->mem_size);
@@ -659,11 +679,6 @@ static int qcom_pas_alloc_memory_region(struct qcom_pas *pas) pas->dtb_mem_phys = pas->dtb_mem_reloc = res.start; pas->dtb_mem_size =resource_size (&res); - pas->dtb_mem_region =devm_ioremap_resource_wc (pas->dev, &res); -if (IS_ERR (pas->dtb_mem_region)) { -dev_err (pas->dev,"unable to map dtb memory region: %pR\n" , &res); -return PTR_ERR (pas->dtb_mem_region); - } pas->dtb_pas_ctx = devm_qcom_scm_pas_context_alloc(pas->dev, pas->dtb_pas_id, pas->dtb_mem_phys,
drivers/soc/qcom/mdt_loader.c +14 -4
@@ -11,6 +11,7 @@#include <linux/device.h> #include <linux/elf.h> #include <linux/firmware.h> +#include <linux/io.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/firmware/qcom/qcom_scm.h>
@@ -478,22 +479,31 @@ EXPORT_SYMBOL_GPL(qcom_mdt_load);* @ctx: Pointer to the PAS (Peripheral Authentication Service) context * @fw: Firmware object representing the .mdt file * @firmware: Name of the firmware used to construct segment file names -* @mem_region: Memory region allocated for loading the firmware * @reloc_base: Physical address adjusted after relocation * * Return: 0 on success or a negative error code on failure. */ int qcom_mdt_pas_load (struct qcom_scm_pas_context *ctx,const struct firmware *fw, -const char *firmware,void *mem_region,phys_addr_t *reloc_base) +const char *firmware,phys_addr_t *reloc_base) { +void __iomem *mem_region;int ret; ret =__qcom_mdt_pas_init (ctx->dev, fw, firmware, ctx->pas_id, ctx->mem_phys, ctx);if (ret)return ret; -return qcom_mdt_load_no_init (ctx->dev, fw, firmware, mem_region, ctx->mem_phys, - ctx->mem_size, reloc_base); + mem_region =ioremap_wc (ctx->mem_phys, ctx->mem_size); +if (!mem_region) { +dev_err (ctx->dev,"unable to map memory region: %pa+%zx\n" , &ctx->mem_phys, + ctx->mem_size); +return -EINVAL ; + } + + ret =qcom_mdt_load_no_init (ctx->dev, fw, firmware, (__force void *)mem_region, + ctx->mem_phys, ctx->mem_size, reloc_base); +iounmap (mem_region); +return ret; }EXPORT_SYMBOL_GPL (qcom_mdt_pas_load);
include/linux/soc/qcom/mdt_loader.h +2 -2
@@ -21,7 +21,7 @@ int qcom_mdt_load(struct device *dev, const struct firmware *fw, phys_addr_t *reloc_base);int qcom_mdt_pas_load (struct qcom_scm_pas_context *ctx,const struct firmware *fw, -const char *firmware,void *mem_region,phys_addr_t *reloc_base); +const char *firmware,phys_addr_t *reloc_base); int qcom_mdt_load_no_init(struct device *dev, const struct firmware *fw, const char *fw_name, void *mem_region,
@@ -47,7 +47,7 @@ static inline int qcom_mdt_load(struct device *dev, const struct firmware *fw,static inline int qcom_mdt_pas_load (struct qcom_scm_pas_context *ctx,const struct firmware *fw,const char *firmware, -void *mem_region,phys_addr_t *reloc_base) +phys_addr_t *reloc_base) {return -ENODEV ; }
Signature · 1 line
2.53.0
PATCH v3 5/5 remoteproc: qcom: pas: Drop unused dtb_mem_region field
In reply to Mukesh Ojhadtb_mem_region is no longer referenced after the ioremap was moved to respective places where mapping is required. Remove it from struct qcom_pas.
---
changes in v3: https://lore.kernel.org/lkml/[email protected]/
- No change.
changes in v2:
- New change.
drivers/remoteproc/qcom_q6v5_pas.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/remoteproc/qcom_q6v5_pas.c +2 -1
@@ -100,8 +100,9 @@ struct qcom_pas {phys_addr_t mem_reloc;phys_addr_t dtb_mem_reloc;phys_addr_t region_assign_phys[MAX_ASSIGN_COUNT ]; +void __iomem *mem_region; -void __iomem *dtb_mem_region; +size_t mem_size;size_t dtb_mem_size;size_t region_assign_size[MAX_ASSIGN_COUNT ];
Signature · 1 line
2.53.0