From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 274EA3BCD27 for ; Thu, 18 Jun 2026 09:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781776292; cv=none; b=QBozrIupdVR1EbOq4ogauTTyqfRFd920aSa0bOXc6C0MsO3c9ywXxrOnzplM0Ew5+vo9TGYxr2PbsOMm8D5NBm3Tanp4Ys5DZbMNiY0tB1OurtPYO+NIWWJh456/Tin0TD2jxKGssZTIeCJ/VoYBBPI5Qi6WiC8e+35mzTTSqsY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781776292; c=relaxed/simple; bh=Lhk+wqCmn/ipibFL6VoRoGlLTszsCZZNLlvTSevmw3s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=RqQRIo/5VSOmNAnMcjt2cH8KI9AB7fRVk51JRMSj/DPMXdZmpCBvJMBOm1WOCTSZLsRBkCluWdaGR82zT+ppYq6NrOexYC2Yg759MBzQHXiI88A1taYZeHxUzR3DXkZIzZuNs16sFgOhLZ9RQuOHd4tSUltrXe3I6xlsd6anxCo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=QuDHZAuY; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=UksimSpb; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="QuDHZAuY"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="UksimSpb" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65I8xCaX723320 for ; Thu, 18 Jun 2026 09:51:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=b8NCvzGF3XF3GM7U4sZSXs LifZwFKnI0trHh5fGvjOA=; b=QuDHZAuYZfY34qaFOCpR6diZwQpkdNZI34S/bc SDswjGC8iM4fp/1ZeIoFEapwfjsij/v7jAIPKq9mtDLP2Vzw5UYmOps5OUHxhzuu jCJk+D86GCMRWiLgUWKP+EvJ6QDFbR3qUG9h/Wc4v5x+p0ZGnUXQbynng9SHOEye PvZUsWkUEbg/h6SH34PqNsmSBJIlnaTBdUsFL7wCdCDyMZR6pO7dQlWWjgm5a2ij WRH7y/YuFB8cJ3vv4NDavTC6qMXRKhVh6IjgmGyVK/35BiXirHQjbpJzv7PnXMYT XKcXeXLM29XWCqKeifLzj2Q1hQ3/yqvFP0jbEz/cjCj84Nxw== Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4evdn4065u-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 18 Jun 2026 09:51:30 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2c6bbd0afffso18090285ad.0 for ; Thu, 18 Jun 2026 02:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1781776290; x=1782381090; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=b8NCvzGF3XF3GM7U4sZSXsLifZwFKnI0trHh5fGvjOA=; b=UksimSpbsHgtCdh2yfMZF6/8GMFZTx45bo2YVJDEx8UtuLetCzxK9NOmSQyuwO9obB hJUL179N8L5lYv/Fmp6QnBRpL/YlfDmBlmaJ+A2SWRpnX6FJfovUf2NyShN8GvxgVj+L KP2yCsPVlshyvCuSK5deZHm1tjR6Cw1hzTW+ekmcmDHkkIqdDUx6ZU3UJ8dtMOoaznIT f7nAk0TBuIwcPNnKHeTT4zl+DT1lc4Y4WiGIRHBBnwLTVy6/q1lxfVzHFTuCxYqYnsg9 DQ2W4mYHPJyRxtismTrVNvzMEx48sW38bG7SDV5UXNsLjkAlBnutZZRyHXsEO+u33JRp HS7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781776290; x=1782381090; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=b8NCvzGF3XF3GM7U4sZSXsLifZwFKnI0trHh5fGvjOA=; b=D/+RrHb/P+aPXtorV1dYInXa6YlhPdXHbqtPjvtK4Rt/TdlFHgvl6zhmBIlhvvHjF0 X/GMud01T7qOKmND7uhzl36xkz3d+6NK3AeItIx2sI1cNw0VtBb7IP5PcpGXsx3P4D9a jzrK05wRG0brE4Etn5X/UrBlE8qvDaKPI6vOeGO8E7AXpkjClNd6RALN7drz0u35MU6+ bEKH59ZKswm18DT7tB2Ybl+9tEnjqt2yMYMLFKrdwvwoS4TVs5oHLkRiaQqQcqgJSOoI V58GBeRWEFv645gbkv990Njxj9xYgD/dkbiY0UQ0FOnUt0Vf6gRL7cmqBfmu/N3mxwU0 D3Xw== X-Forwarded-Encrypted: i=1; AFNElJ/0reh2QkMFnZMHiYNuifEYerTux4Zw1aCkMmfTf+/cOh3VcpsYFlrhI13480BiNFCo7A/IPixEo4ZAfZI=@vger.kernel.org X-Gm-Message-State: AOJu0YzERmJoWoJPGdY+X/rO0I58SOy05e6NDdoVgSPE4/fK5Nd/UMN6 38rKPm68KqrpqQ4/21VrBGj5218NlwWlpk/YoXOZP6ULVzCx3HY/JI7gGPEZ+1k46yk1IH9N2H5 EZa5A4HjvQVgsj5Qqqx0Tm10NqXltP8QRPqBFqjaRSRHWaNhUyDRRJd9HcmRwubkHW/c= X-Gm-Gg: AfdE7clFILOkeJ4PXQ2+mbKKrc0IWmv81kKk1goyIqnz1gA90ouz866aDhG/pI/erRd LyIHH7WzyU3KTb2m/Ot4LTmhmE269O+N6V/CTcd1k7PlXGlkBUXghv+yzYBRbM1asb+IpKWaQWf sx3c6qh/H36oeTIsA9R9dP71GqDRZ0kpFlB1B08m6LWuPxqPZV4C7c+rzOozC7degv8L2Wn//ja Ust85ntJxDoxek/MzHo75LXgKt1ldpbekF23f1n8iATjegXSl19w7JXxPbRVJUD6Wz7HeYIQCXw RDpeWNVT79Mma4LpQ5ggLZDIpkb1FD1y7eBSFBgp4ZI09dgX9URQ7Et+aWL8hL1vbocfAxmHm1N XH8GlGR8ByNlXTjbaHijN X-Received: by 2002:a17:902:d4c6:b0:2c6:a97e:1c24 with SMTP id d9443c01a7336-2c6bbf8dc65mr77371455ad.7.1781776289665; Thu, 18 Jun 2026 02:51:29 -0700 (PDT) X-Received: by 2002:a17:902:d4c6:b0:2c6:a97e:1c24 with SMTP id d9443c01a7336-2c6bbf8dc65mr77371145ad.7.1781776289219; Thu, 18 Jun 2026 02:51:29 -0700 (PDT) Received: from [10.213.99.236] ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c433078264sm190231805ad.65.2026.06.18.02.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2026 02:51:28 -0700 (PDT) From: Anandu Krishnan E Date: Thu, 18 Jun 2026 15:21:21 +0530 Subject: [PATCH] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260618-audio_fix_clean_v3-v1-1-ec1ee66fe455@oss.qualcomm.com> X-B4-Tracking: v=1; b=H4sIAJi/M2oC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIzMDM0ML3cTSlMz8+LTMivjknNTEvPgyY13LlDQzA3NTEzMDS1MloMaColS gPNjQ6FgIv7g0KSs1uQRkklJtLQByNSbwdgAAAA== X-Change-ID: 20260618-audio_fix_clean_v3-9df607546095 To: Srinivas Kandagatla , Amol Maheshwari , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, ekansh.gupta@oss.qualcomm.com, quic_bkumar@quicinc.com, quic_chennak@quicinc.com, Anandu Krishnan E X-Mailer: b4 0.15.2 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE4MDA5MSBTYWx0ZWRfX0XnUISEB2Ayj rCfFyZ0KIafu5C1iI7I1pRbXNyMu8TI1b1kMBHuG02TrT9XlVyoi5qGm4XBVDGn3Ml/D+wquWOx E0JLV9e52CwbOc8yhPUmAfrii8P6blj98dNG9F+++dqvygdEDUPUwtxgPaplLX4iC6TFuVKjraK pQXZxiWNVtq+UuEgjTehDBEydsNHV7/l6EoTZKNFKNtGhnwy4ObpgaLLDnGr0j534lvVkO7JqI7 QG67GJ0eHe2jIhZkgtwLj/xYv29hWBqbx33HecuKrTALxdz4pR11z/MLrYWg+v1t4xddI4jLlJH Y/SoqsY4Beg2Z5QeD8WL3epdqqA2WHiSAjIbEwV5SR4MBG7096yx7S/5v585VVnCs7muzYouemj BfZr4KZPYoqGs9yP2j4mx+h28hzWmVDUpZr2nVhwSWbtvnWIJLyWzev47lsOnh/5Nhb9fYtcyc5 UUzi3KErw1uxw3qEtGw== X-Proofpoint-ORIG-GUID: 24k42PKHLQH5VSITzVQ6COU4PCEnibpw X-Authority-Analysis: v=2.4 cv=FN4rAeos c=1 sm=1 tr=0 ts=6a33bfa2 cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=LsPkHLYD-RLW9ZWWSBUA:9 a=QEXdDO2ut3YA:10 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-GUID: 24k42PKHLQH5VSITzVQ6COU4PCEnibpw X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE4MDA5MSBTYWx0ZWRfX2by/8pKOCal/ 6gTqrEva3xdEuepz5RmzpwDlKvdCnLimVAMSR+GOKaOzDq1Z3FiTDCMjZMecevx/OCaiy9Gi0M8 XBfBPdKl2h7ajVp92m3AWklFb2FxL9M= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-18_01,2026-06-17_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 suspectscore=0 clxscore=1015 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606180091 On KVM-based targets 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 KVM-based targets no such hypervisor exists, so 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 has_iommu 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. This change relies on the remote heap handling introduced in: https://lore.kernel.org/r/20260609025938.457-1-jianping.li@oss.qualcomm.com Link: https://lore.kernel.org/r/20260609025938.457-1-jianping.li@oss.qualcomm.com Signed-off-by: Anandu Krishnan E --- This patch depends on: [PATCH v8 0/4] misc: fastrpc: Add missing bug fixes https://lore.kernel.org/r/20260609025938.457-1-jianping.li@oss.qualcomm.com Please apply after that series. --- drivers/misc/fastrpc.c | 141 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 114 insertions(+), 27 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index a5af901c1cb8..9ce7af2091f1 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -285,6 +286,8 @@ struct fastrpc_channel_ctx { struct list_head invoke_interrupted_mmaps; bool secure; bool unsigned_support; + /* set when remoteproc has an IOMMU; use iommu_map instead of hyp_assign */ + bool has_iommu; u64 dma_mask; const struct fastrpc_soc_data *soc_data; }; @@ -2343,10 +2346,65 @@ static const struct fastrpc_soc_data default_soc_data = { .dma_addr_bits_default = 32, }; +static int fastrpc_remote_heap_map(struct device *rdev, + struct device_node *rproc_node, + struct fastrpc_buf *heap) +{ + 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, heap->dma_addr, heap->dma_addr, heap->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", + heap->dma_addr, heap->size, ret); + + put_device(&rproc_pdev->dev); + return ret; +} + +static void fastrpc_remote_heap_unmap(struct rpmsg_device *rpdev, + struct fastrpc_buf *heap) +{ + struct device_node *rproc_node; + struct platform_device *rproc_pdev; + struct iommu_domain *domain; + + rproc_node = of_get_parent(of_get_parent(rpdev->dev.of_node)); + if (!rproc_node) + return; + + rproc_pdev = of_find_device_by_node(rproc_node); + of_node_put(rproc_node); + if (!rproc_pdev) + return; + + domain = iommu_get_domain_for_dev(&rproc_pdev->dev); + if (domain) + iommu_unmap(domain, heap->dma_addr, heap->size); + + put_device(&rproc_pdev->dev); +} + static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) { struct device *rdev = &rpdev->dev; struct fastrpc_channel_ctx *data; + struct device_node *rproc_node; int i, err, domain_id = -1, vmcount; const char *domain; bool secure_dsp; @@ -2390,9 +2448,12 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) } } + rproc_node = of_get_parent(of_get_parent(rdev->of_node)); + if (rproc_node) + data->has_iommu = of_property_present(rproc_node, "iommus"); + if (domain_id == SDSP_DOMAIN_ID || domain_id == ADSP_DOMAIN_ID) { struct resource res; - u64 src_perms; err = of_reserved_mem_region_to_resource(rdev->of_node, 0, &res); if (!err) { @@ -2401,21 +2462,41 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) kzalloc_obj(*data->remote_heap, GFP_KERNEL); if (!data->remote_heap) { err = -ENOMEM; - goto err_free_data; + goto err_put_node; } data->remote_heap->dma_addr = res.start; data->remote_heap->size = resource_size(&res); + + if (data->has_iommu) { + err = fastrpc_remote_heap_map(rdev, + rproc_node, + data->remote_heap); + if (err) { + kfree(data->remote_heap); + data->remote_heap = NULL; + goto err_put_node; + } + } } - src_perms = BIT(QCOM_SCM_VMID_HLOS); - err = qcom_scm_assign_mem(res.start, resource_size(&res), &src_perms, - data->vmperms, data->vmcount); - if (err) - goto err_free_data; + if (!data->has_iommu) { + u64 src_perms = BIT(QCOM_SCM_VMID_HLOS); + + err = qcom_scm_assign_mem(res.start, + resource_size(&res), + &src_perms, + data->vmperms, + data->vmcount); + if (err) + goto err_put_node; + } } } + of_node_put(rproc_node); + rproc_node = NULL; + secure_dsp = !(of_property_read_bool(rdev->of_node, "qcom,non-secure-domain")); data->secure = secure_dsp; data->soc_data = soc_data; @@ -2471,6 +2552,9 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) if (data->secure_fdevice) misc_deregister(&data->secure_fdevice->miscdev); +err_put_node: + of_node_put(rproc_node); + err_free_data: kfree(data->remote_heap); kfree(data); @@ -2513,28 +2597,31 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) list_for_each_entry_safe(buf, b, &cctx->invoke_interrupted_mmaps, node) list_del(&buf->node); - if (cctx->remote_heap && cctx->vmcount) { - u64 src_perms = 0; - struct qcom_scm_vmperm dst_perms; - - for (u32 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->dma_addr, - cctx->remote_heap->size, &src_perms, - &dst_perms, 1); - if (err) - dev_err(&rpdev->dev, - "Failed to assign memory back to HLOS: dma_addr %pad size %#llx err %d\n", - &cctx->remote_heap->dma_addr, cctx->remote_heap->size, err); + if (cctx->remote_heap) { + if (cctx->has_iommu) { + fastrpc_remote_heap_unmap(rpdev, cctx->remote_heap); + kfree(cctx->remote_heap); + cctx->remote_heap = NULL; + } else if (cctx->vmcount) { + u64 src_perms = 0; + struct qcom_scm_vmperm dst_perms; + + for (u32 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->dma_addr, + cctx->remote_heap->size, + &src_perms, &dst_perms, 1); + if (!err) { + kfree(cctx->remote_heap); + cctx->remote_heap = NULL; + } + } } - kfree(cctx->remote_heap); - cctx->remote_heap = NULL; - of_platform_depopulate(&rpdev->dev); fastrpc_channel_ctx_put(cctx); --- base-commit: f1256704b88067430e255e5c85d6b727e1bbb2ea change-id: 20260618-audio_fix_clean_v3-9df607546095 Best regards, -- Anandu Krishnan E