* [PATCH v4] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain
@ 2026-12-01 14:10 Anandu Krishnan E
2026-12-01 14:27 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Anandu Krishnan E @ 2026-12-01 14:10 UTC (permalink / raw)
To: Srinivas Kandagatla, Ekansh Gupta, Arnd Bergmann,
Greg Kroah-Hartman
Cc: linux-arm-msm, dri-devel, linux-kernel, quic_bkumar, quic_chennak,
amahesh, Tyler Baker, Anandu Krishnan E
On Qualcomm platforms without Gunyah/QHEE, the kernel runs at EL2
without a separate hypervisor to manage inter-VM memory access
control. In this configuration the remoteproc is assigned its own
IOMMU domain, and any memory carveout the DSP must access requires
an explicit mapping into that domain before the DSP can reach it.
The existing code calls qcom_scm_assign_mem() to transfer ownership
of the ADSP remote heap carveout from HLOS to the DSP VM. This SCM
call is only meaningful when a separate hypervisor (e.g. Gunyah) is
present to enforce inter-VM memory access control. On platforms
without such a hypervisor, the carveout must instead be mapped into
the remoteproc's IOMMU domain via an identity mapping (IOVA == PA)
using iommu_map(). Without this mapping the DSP triggers an SMMU
translation fault when accessing the remote heap during audio PD
static process creation.
Detect whether the remoteproc has an IOMMU by checking for the
"iommus" property on the remoteproc DT node and store the result in
a new use_iommu_map flag in fastrpc_channel_ctx. When the flag is
set, map the carveout into the remoteproc's IOMMU domain instead of
calling qcom_scm_assign_mem(). Introduce fastrpc_remote_heap_map()
and fastrpc_remote_heap_unmap() helpers to encapsulate the IOMMU
domain lookup and map/unmap operations, and a shared
fastrpc_remote_heap_release() helper that tears the mapping (or SCM
assignment) back down, used both from fastrpc_rpmsg_remove() and
from fastrpc_rpmsg_probe()'s error path.
Tested-by: Tyler Baker <tyler.baker@oss.qualcomm.com> # Eliza EVK, EL2
Signed-off-by: Anandu Krishnan E <anandu.e@oss.qualcomm.com>
---
Changes in v4:
- Rebased.
- Link to v3: https://lore.kernel.org/r/20261027-fastrpc-kvm-iommu-v3-v3-1-f3cd5c030c78@oss.qualcomm.com
- Link to v2: https://lore.kernel.org/r/20261001-fastrpc-kvm-iommu-v2-v2-1-6c32ad6f662f@oss.qualcomm.com
- Link to v1: https://lore.kernel.org/r/20260618-audio_fix_clean_v3-v1-1-ec1ee66fe455@oss.qualcomm.com
---
drivers/misc/fastrpc.c | 149 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 130 insertions(+), 19 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 56284a7e42ca..2a5f21d0a3a6 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -8,6 +8,7 @@
#include <linux/dma-mapping.h>
#include <linux/dma-resv.h>
#include <linux/idr.h>
+#include <linux/iommu.h>
#include <linux/list.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
@@ -324,6 +325,8 @@ struct fastrpc_channel_ctx {
/* Audio PD reserved remote heap region */
phys_addr_t remote_heap_addr;
u64 remote_heap_size;
+ /* set when remoteproc has an IOMMU; use iommu_map instead of hyp_assign */
+ bool use_iommu_map;
u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES];
struct fastrpc_device *secure_fdevice;
struct fastrpc_device *fdevice;
@@ -2629,9 +2632,120 @@ static const struct of_device_id fastrpc_poll_supported_machines[] __maybe_unuse
{},
};
+static struct device_node *fastrpc_get_rproc_node(struct device_node *node)
+{
+ struct device_node *parent, *rproc_node;
+
+ parent = of_get_parent(node);
+ if (!parent)
+ return NULL;
+
+ rproc_node = of_get_parent(parent);
+ of_node_put(parent);
+
+ return rproc_node;
+}
+
+static int fastrpc_remote_heap_map(struct device *rdev,
+ struct device_node *rproc_node,
+ phys_addr_t addr, u64 size)
+{
+ struct platform_device *rproc_pdev;
+ struct iommu_domain *domain;
+ int ret;
+
+ rproc_pdev = of_find_device_by_node(rproc_node);
+ if (!rproc_pdev) {
+ dev_err(rdev, "failed to find remoteproc platform device\n");
+ return -ENODEV;
+ }
+
+ domain = iommu_get_domain_for_dev(&rproc_pdev->dev);
+ if (!domain) {
+ put_device(&rproc_pdev->dev);
+ dev_err(rdev, "no IOMMU domain for remoteproc\n");
+ return -ENODEV;
+ }
+
+ ret = iommu_map(domain, addr, addr, size, IOMMU_READ | IOMMU_WRITE, GFP_KERNEL);
+ if (ret)
+ dev_err(rdev, "failed to map remote heap phys=0x%llx size=0x%llx err=%d\n",
+ (u64)addr, size, ret);
+
+ put_device(&rproc_pdev->dev);
+ return ret;
+}
+
+static void fastrpc_remote_heap_unmap(struct rpmsg_device *rpdev,
+ phys_addr_t addr, u64 size)
+{
+ struct device_node *rproc_node;
+ struct platform_device *rproc_pdev;
+ struct iommu_domain *domain;
+ size_t unmapped;
+
+ rproc_node = fastrpc_get_rproc_node(rpdev->dev.of_node);
+ if (!rproc_node) {
+ dev_warn(&rpdev->dev, "failed to find remoteproc node for heap unmap\n");
+ return;
+ }
+
+ rproc_pdev = of_find_device_by_node(rproc_node);
+ of_node_put(rproc_node);
+ if (!rproc_pdev) {
+ dev_warn(&rpdev->dev, "failed to find remoteproc platform device for heap unmap\n");
+ return;
+ }
+
+ domain = iommu_get_domain_for_dev(&rproc_pdev->dev);
+ if (!domain) {
+ dev_warn(&rpdev->dev, "no IOMMU domain for remoteproc during heap unmap\n");
+ put_device(&rproc_pdev->dev);
+ return;
+ }
+
+ unmapped = iommu_unmap(domain, addr, size);
+ if (unmapped != size)
+ dev_warn(&rpdev->dev, "partial/failed heap unmap: requested=0x%llx unmapped=0x%zx\n",
+ size, unmapped);
+
+ put_device(&rproc_pdev->dev);
+}
+
+static void fastrpc_remote_heap_release(struct fastrpc_channel_ctx *cctx,
+ struct rpmsg_device *rpdev)
+{
+ if (!cctx->remote_heap_size)
+ return;
+
+ if (cctx->use_iommu_map) {
+ fastrpc_remote_heap_unmap(rpdev, cctx->remote_heap_addr,
+ cctx->remote_heap_size);
+ } else if (cctx->vmcount) {
+ u64 src_perms = 0;
+ int err, i;
+ struct qcom_scm_vmperm dst_perms;
+
+ for (i = 0; i < cctx->vmcount; i++)
+ src_perms |= BIT(cctx->vmperms[i].vmid);
+
+ dst_perms.vmid = QCOM_SCM_VMID_HLOS;
+ dst_perms.perm = QCOM_SCM_PERM_RWX;
+
+ err = qcom_scm_assign_mem(cctx->remote_heap_addr,
+ cctx->remote_heap_size, &src_perms,
+ &dst_perms, 1);
+ if (err)
+ dev_err(&rpdev->dev,
+ "Failed to assign memory back to HLOS: addr %pa size %#llx err %d\n",
+ &cctx->remote_heap_addr, cctx->remote_heap_size, err);
+ }
+}
+
static int fastrpc_init_reserved_mem(struct fastrpc_channel_ctx *cctx,
struct device *rdev, u32 domain_id)
{
+ struct device_node *rproc_node;
struct resource res;
u64 src_perms;
int err;
@@ -2658,6 +2772,19 @@ static int fastrpc_init_reserved_mem(struct fastrpc_channel_ctx *cctx,
if (domain_id == ADSP_DOMAIN_ID) {
cctx->remote_heap_addr = res.start;
cctx->remote_heap_size = resource_size(&res);
+
+ rproc_node = fastrpc_get_rproc_node(rdev->of_node);
+ if (rproc_node)
+ cctx->use_iommu_map = of_property_present(rproc_node, "iommus");
+
+ if (cctx->use_iommu_map) {
+ err = fastrpc_remote_heap_map(rdev, rproc_node, res.start,
+ resource_size(&res));
+ of_node_put(rproc_node);
+ return err;
+ }
+
+ of_node_put(rproc_node);
}
if (!cctx->vmcount)
@@ -2813,10 +2940,12 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
spin_unlock_irqrestore(&data->lock, flags);
of_platform_depopulate(rdev);
+ fastrpc_remote_heap_release(data, rpdev);
fastrpc_channel_ctx_put(data);
return err;
err_free_data:
+ fastrpc_remote_heap_release(data, rpdev);
kfree(data);
return err;
}
@@ -2840,25 +2969,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
fastrpc_notify_users(user);
spin_unlock_irqrestore(&cctx->lock, flags);
- if (cctx->remote_heap_size && cctx->vmcount) {
- u64 src_perms = 0;
- int err, i;
- struct qcom_scm_vmperm dst_perms;
-
- for (i = 0; i < cctx->vmcount; i++)
- src_perms |= BIT(cctx->vmperms[i].vmid);
-
- dst_perms.vmid = QCOM_SCM_VMID_HLOS;
- dst_perms.perm = QCOM_SCM_PERM_RWX;
-
- err = qcom_scm_assign_mem(cctx->remote_heap_addr,
- cctx->remote_heap_size, &src_perms,
- &dst_perms, 1);
- if (err)
- dev_err(&rpdev->dev,
- "Failed to assign memory back to HLOS: addr %pa size %#llx err %d\n",
- &cctx->remote_heap_addr, cctx->remote_heap_size, err);
- }
+ fastrpc_remote_heap_release(cctx, rpdev);
of_platform_depopulate(&rpdev->dev);
---
base-commit: 89f33682b2c34b12b3a7a549ba94a808f0c7c98d
change-id: 20261201-fastrpc-kvm-iommu-v4-b4-33a2da96c714
Best regards,
--
Anandu Krishnan E <anandu.e@oss.qualcomm.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v4] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain
2026-12-01 14:10 [PATCH v4] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain Anandu Krishnan E
@ 2026-12-01 14:27 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01 14:27 UTC (permalink / raw)
To: Anandu Krishnan E; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] misc: fastrpc: fastrpc_remote_heap_map() maps unallocated
CMA pages to ADSP
- [Medium] misc: fastrpc: fastrpc_rpmsg_probe() unmaps or reassigns heap
on map failure
--
commit 03c79f8a7679a47c02d5cf3108f39937f2846e46
Author: Anandu Krishnan E <anandu.e@oss.qualcomm.com>
misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain
This commit maps the ADSP remote heap carveout into the remoteproc's
iommu domain when the remoteproc device tree node has an "iommus"
property, instead of transferring memory ownership via
qcom_scm_assign_mem().
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 56284a7e42ca5..2a5f21d0a3a69 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
[ ... ]
> @@ -2629,9 +2632,120 @@ static const struct of_device_id fastrpc_poll_supported_machines[] __maybe_unuse
> {},
> };
>
[ ... ]
> +static void fastrpc_remote_heap_release(struct fastrpc_channel_ctx *cctx,
> + struct rpmsg_device *rpdev)
> +{
> + if (!cctx->remote_heap_size)
> + return;
> +
> + if (cctx->use_iommu_map) {
> + fastrpc_remote_heap_unmap(rpdev, cctx->remote_heap_addr,
> + cctx->remote_heap_size);
> + } else if (cctx->vmcount) {
> + u64 src_perms = 0;
> + int err, i;
> + struct qcom_scm_vmperm dst_perms;
> +
> + for (i = 0; i < cctx->vmcount; i++)
> + src_perms |= BIT(cctx->vmperms[i].vmid);
> +
> + dst_perms.vmid = QCOM_SCM_VMID_HLOS;
> + dst_perms.perm = QCOM_SCM_PERM_RWX;
> +
> + err = qcom_scm_assign_mem(cctx->remote_heap_addr,
> + cctx->remote_heap_size, &src_perms,
> + &dst_perms, 1);
> + if (err)
> + dev_err(&rpdev->dev,
> + "Failed to assign memory back to HLOS: addr %pa size %#llx err %d\n",
> + &cctx->remote_heap_addr, cctx->remote_heap_size, err);
> + }
> +}
> +
> static int fastrpc_init_reserved_mem(struct fastrpc_channel_ctx *cctx,
> struct device *rdev, u32 domain_id)
> {
> + struct device_node *rproc_node;
> struct resource res;
> u64 src_perms;
> int err;
> @@ -2658,6 +2772,19 @@ static int fastrpc_init_reserved_mem(struct fastrpc_channel_ctx *cctx,
> if (domain_id == ADSP_DOMAIN_ID) {
> cctx->remote_heap_addr = res.start;
> cctx->remote_heap_size = resource_size(&res);
> +
> + rproc_node = fastrpc_get_rproc_node(rdev->of_node);
> + if (rproc_node)
> + cctx->use_iommu_map = of_property_present(rproc_node, "iommus");
> +
> + if (cctx->use_iommu_map) {
> + err = fastrpc_remote_heap_map(rdev, rproc_node, res.start,
> + resource_size(&res));
> + of_node_put(rproc_node);
> + return err;
> + }
> +
> + of_node_put(rproc_node);
> }
[Severity: Critical]
Does fastrpc_remote_heap_map() map unallocated CMA pages into the
remoteproc's iommu domain when the reserved-memory region is a reusable
shared-dma-pool?
On platforms such as arch/arm64/boot/dts/qcom/glymur.dtsi where
adsp_rpc_remote_heap_mem has compatible = "shared-dma-pool" and the
"reusable" property, rmem_cma_setup() registers the region as a CMA pool
whose pages remain in the kernel buddy allocator for movable allocations
until allocated via CMA or DMA APIs. devm_of_reserved_mem_device_init()
in fastrpc_rpmsg_probe() only attaches rdev->cma_area, and
of_reserved_mem_region_to_resource() reads the raw physical range without
allocating the pages from CMA.
Mapping [res.start, res.end] with IOMMU_READ | IOMMU_WRITE and passing
that physical range to the DSP in fastrpc_init_create_static_process()
allows the DSP to read and write physical pages that are still in the
buddy allocator and concurrently used by host processes, the page cache,
or fastrpc_remote_heap_alloc() buffers.
> @@ -2813,10 +2940,12 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
> spin_unlock_irqrestore(&data->lock, flags);
>
> of_platform_depopulate(rdev);
> + fastrpc_remote_heap_release(data, rpdev);
> fastrpc_channel_ctx_put(data);
> return err;
>
> err_free_data:
> + fastrpc_remote_heap_release(data, rpdev);
> kfree(data);
> return err;
> }
[Severity: Medium]
If fastrpc_init_reserved_mem() fails for ADSP_DOMAIN_ID, does jumping to
err_free_data cause fastrpc_remote_heap_release() to unmap or reassign a
heap whose mapping or assignment just failed?
fastrpc_init_reserved_mem() sets cctx->remote_heap_addr,
cctx->remote_heap_size, and cctx->use_iommu_map before calling
fastrpc_remote_heap_map() or qcom_scm_assign_mem(). When either call
fails, fastrpc_rpmsg_probe() jumps to err_free_data with
data->remote_heap_size already non-zero, so fastrpc_remote_heap_release()
runs iommu_unmap() on the range (which can tear down a pre-existing
mapping if iommu_map() failed on a conflict) or calls
qcom_scm_assign_mem() to transfer memory back from DSP VMIDs that never
received ownership.
Setting cctx->remote_heap_addr and cctx->remote_heap_size only after the
map or SCM assignment succeeds would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-fastrpc-kvm-iommu-v4-b4-v4-1-b83c79d2c541@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 14:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 14:10 [PATCH v4] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain Anandu Krishnan E
2026-12-01 14:27 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.