From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C18D5606A31A for ; Tue, 1 Dec 2026 14:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=D91K2ZfR Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 376BC10F989; Tue, 1 Dec 2026 14:27:54 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9924E10F989 for ; Tue, 1 Dec 2026 14:27:47 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id D61AA611F2; Tue, 1 Dec 2026 14:27:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CF421F00893; Tue, 1 Dec 2026 14:27:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796135266; bh=+i2ck3gEPIZZP5Eq9IL9LIR0wdkTlvmny+3dw3Cv888=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=D91K2ZfRYV3G7KXMdYfxeI+JAgr6aN3a6UPn6TbDScTWZzWBrjMOGrkMcNO5G7DN2 t5H6RxgKmhiiQmH6YG9FJaJrSn10aL9b1mLfJVeg2cJunFUtnQ6ksMqFDGraeqswtX o+AiJRbeUDLl6PW8Ecgg6kmui+2LAkmesn/8A9ChPmdb8szb3kGbacC2tSX6qpWuDT jf8QBTJ9EjsmSa/lmeZUYgXe9hlcjIaffsMMfbW1EWTWktv13WjMLdQCa+6geSai5/ ValmuI//NlePseiNIT1P4CSxLWuVwjvOg06BYzRQXtK4lxHue+Nov8VIZ+E4h3fohn v2YjNpvgayVXA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain To: "Anandu Krishnan E" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261201-fastrpc-kvm-iommu-v4-b4-v4-1-b83c79d2c541@oss.qualcomm.com> References: <20261201-fastrpc-kvm-iommu-v4-b4-v4-1-b83c79d2c541@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 14:27:45 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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_sup= ported_machines[] __maybe_unuse > {}, > }; > =20 [ ... ] > +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 =3D 0; > + int err, i; > + struct qcom_scm_vmperm dst_perms; > + > + for (i =3D 0; i < cctx->vmcount; i++) > + src_perms |=3D BIT(cctx->vmperms[i].vmid); > + > + dst_perms.vmid =3D QCOM_SCM_VMID_HLOS; > + dst_perms.perm =3D QCOM_SCM_PERM_RWX; > + > + err =3D 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 fastrp= c_channel_ctx *cctx, > if (domain_id =3D=3D ADSP_DOMAIN_ID) { > cctx->remote_heap_addr =3D res.start; > cctx->remote_heap_size =3D resource_size(&res); > + > + rproc_node =3D fastrpc_get_rproc_node(rdev->of_node); > + if (rproc_node) > + cctx->use_iommu_map =3D of_property_present(rproc_node, "iommus"); > + > + if (cctx->use_iommu_map) { > + err =3D 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 =3D "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_devic= e *rpdev) > spin_unlock_irqrestore(&data->lock, flags); > =20 > of_platform_depopulate(rdev); > + fastrpc_remote_heap_release(data, rpdev); > fastrpc_channel_ctx_put(data); > return err; > =20 > 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201-fastrpc-kv= m-iommu-v4-b4-v4-1-b83c79d2c541@oss.qualcomm.com?part=3D1