remoteproc: qcom_q6v5_adsp: Fix iommu_unmap() usage
Subsystems (2)
PATCH 1/1 remoteproc: qcom_q6v5_adsp: Fix iommu_unmap() usage
During adsp_map_carveout, the IOVA is computed by combining the physical address and the SID:
iova = adsp->mem_phys | (sid << 32);
However, adsp_unmap_carveout() uses the physical address and not the IOVA in iommu_unmap(), causing the unmap to fail or leak mappings because the address doesn't match the original IOVA.
Cache the constructed IOVA within the qcom_adsp device struct during mapping and use it during unmapping.
---
I found this using gemini while auditing the iommu API usage based on unrelated bug report.
https://lore.kernel.org/all/[email protected]/
--- drivers/remoteproc/qcom_q6v5_adsp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/remoteproc/qcom_q6v5_adsp.c +4 -4
@@ -104,6 +104,7 @@ struct qcom_adsp {struct completion stop_done;phys_addr_t mem_phys; +unsigned long iova;phys_addr_t mem_reloc;void __iomem *mem_region;size_t mem_size;
@@ -333,7 +334,7 @@ static void adsp_unmap_carveout(struct rproc *rproc)struct qcom_adsp *adsp = rproc->priv;if (adsp->has_iommu) -iommu_unmap (rproc->domain, adsp->mem_phys, adsp->mem_size); +iommu_unmap (rproc->domain, adsp->iova, adsp->mem_size); }static int adsp_map_carveout (struct rproc *rproc)
@@ -341,7 +342,6 @@ static int adsp_map_carveout(struct rproc *rproc)struct qcom_adsp *adsp = rproc->priv;struct of_phandle_args args;long long sid; -unsigned long iova;int ret;if (!adsp->has_iommu)
@@ -358,9 +358,9 @@ static int adsp_map_carveout(struct rproc *rproc)of_node_put (args.np);/* Add SID configuration for ADSP Firmware to SMMU */ - iova = adsp->mem_phys | (sid <<32 ); + adsp->iova = adsp->mem_phys | (sid <<32 ); - ret =iommu_map (rproc->domain, iova, adsp->mem_phys, + ret =iommu_map (rproc->domain, adsp->iova, adsp->mem_phys, adsp->mem_size,IOMMU_READ |IOMMU_WRITE ,GFP_KERNEL );if (ret) {
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Quoted 9 lines · Mostafa Saleh
During
adsp_map_carveout, the IOVA is computed by combining the physical address and the SID:iova = adsp->mem_phys | (sid << 32);However,
adsp_unmap_carveout()uses the physical address and not the IOVA iniommu_unmap(), causing the unmap to fail or leak mappings because the address doesn't match the original IOVA.[...]
Applied, thanks!
[1/1] remoteproc: qcom_q6v5_adsp: Fix iommu_unmap() usage
commit: 0d8e2195bce6f08c1c53c5ef4d7347fe46418101
Best regards,
Signature · 1 line
Bjorn Andersson <[email protected]>