From nobody Mon Feb 9 19:26:45 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 30569331A40 for ; Thu, 15 Jan 2026 08:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768465816; cv=none; b=e83vRb4COnlv9H8905WLpt35Y2YFMFDUgSOx/r86dpLXW59hOlmL7VDK2UkTnO6kdlkF+dlWA6fO2yhabNRsxvokvvWrqhpKY/RUn39la5o374XlV0UlRCFldvQvP01MxsJz1XWYlCS+vBVkwJPKTxUfPePSJB4crBsCZvSTpLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768465816; c=relaxed/simple; bh=Bt0PcQMneI4KUYJQ68wmmXPifSyAdfuywiTPH2bnP5A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R/IeUkBRiTjzUbhWuZcmKI0U6x6rVsNG3mBkJluaKerof55Q5dh5r8fictyeIabK+7jL+Kb3F11+0LpeBsJhCHzJ9ENhkLhzezbYaxhRnDEXiDDNoGKb4xKE8ycOjD053se4BAJoK+EGLZIOeaJtRyWBMPCNRiHEktnLviDi6hg= 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=hVI2nRWj; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=C9zy3G2/; arc=none smtp.client-ip=205.220.180.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="hVI2nRWj"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="C9zy3G2/" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60F6fuRl606569 for ; Thu, 15 Jan 2026 08:30:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=yRAomd5/Wnd mqPt4/KPViCWMZ2kB08fk6+zB+UfeCDE=; b=hVI2nRWjdZSESpYczFwIsLzy9Qx 9zLckqHcW7nRODwuOh/IXba5OqmhGd8vK/Il79OqwH5h4SBnIIsqIfXkQhMFsklf 2r7jlfcfE28LtJ6/BqmMNgewkFN/X5vfpnNgFv9ieIUTLhZXD7Z24uBsbGFqUw6+ sPEqt3PYLxMrIX7c+PMvsD0nuvvbgk4dDKlhZUH9eLRIzi3ElqOobEwANmFLO0CV m1aMNf4UZ313uVOSOxvCxK+WFCTAjSXJBPpg1SyjD+gEYAMLpMQ0SIUIQQAT8vDH HkwoZ59SuYO7u2Wm42SUTNZ74rm+DSi3gQTUZ2D0+CMYYnFdWzw8ZJpe1MA== Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4bptna0ctp-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 15 Jan 2026 08:30:09 +0000 (GMT) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-7f66686710fso1103394b3a.3 for ; Thu, 15 Jan 2026 00:30:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1768465809; x=1769070609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yRAomd5/WndmqPt4/KPViCWMZ2kB08fk6+zB+UfeCDE=; b=C9zy3G2/fhozrSw1d8j4gsmVqjIG18Ur4GnbAWIhyJtaWO///onLNlFKq6c+E/HdQD AcRSqouRt5LZAY/7YL5APZES4LV5gQxscDKbEzn5iz5SGOjWhNhzZSoZOjeqwQMCH9lH J/vr1txG2CChW8x5rir0+2v7x14LinK0p6xt9Q4rbIWMjFiqGbIlAZEWpknB22jRUO8b wJYx1E+84JVzTBQv302kGw2HydTvB92IGgJhZc4mUo3em/iJhVyKSSzP/RAZjPvEnOUv YxXVp56W9Pg+mbNtpuFbazgM8S8W0f4ukZuMOl6ZUk5qkpIos9uEHPqANXlsUNf1lgE1 bf+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768465809; x=1769070609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yRAomd5/WndmqPt4/KPViCWMZ2kB08fk6+zB+UfeCDE=; b=RO3yM3gtQoI3W0o03iyhTd1YsvPQheqyepm4sgmr8XgN6/kK3Sh5ARna/5g20dsZ50 c4fBTlifaShjadQFiIuhczKjLnWW1KNyQvRd5s6vToqN39Ppk6KNOrYxWq2YxVK8jhxk vMvx3Iys2cH/Q+Z9OkWWTgtR5s3cYk9wX1LtaUjz2aDJPbA6gbkg18nBm+1gBqkbXBoC W4gRYNM0cYSZaRJbJ+mKOPvG1nCC/Xn+mWXmw3c76i+TqxB7yGs5wIGLcGxFLG1+AtRh HKrqK3QQQXxN2qxIpE5FZJs2z2hjkGFy2vp1FireFz+pBaJNUHb4t0tIPn2udfnXcdXS iMbg== X-Forwarded-Encrypted: i=1; AJvYcCXnnsljCyVxA6Ugis4fAg5nK/XwNXR22H+y3N9jDvkb5hG/YPb6MdD15zSCQv0EzDwZzuyxU5F/xsTXHbs=@vger.kernel.org X-Gm-Message-State: AOJu0YzFPKoSu1YxlR+adPNIUJE5LjrZnVBmJbIChvPWBo66LMyfi+ww 1fG95S851s5mSg2hRhgCBifDtcKpnGLPpcJbpIzEyYFoDdnGIdFWtnooAx6wr3i4C1sYHLISdgn hZ8+mtM9surIQo3dq5HSsG//bB9OYaMuDvTw4ZnKkvcWm78lEvpCuM1oDEgmNInja5Pc= X-Gm-Gg: AY/fxX4FzBNi+0XPvVdWxlEXiqLPSOvSf4/5AF3QlQ/qhFQss8sqzJgTWPGO7G7hJGR +sWcujD5lILvQdwjYb4GotK/c13GMlNntNwi5nt+8QU3Y0U6AcQrEu+rOHmnLOxC3dzdLeLyCtc PRRPrcHAix0alv8C491gYYDb7vwTaiA1r4uwxkwgINFaEw2B/SNAuzdomrDIr01/L/ZP1n3NNq6 9rZFuSrbVWExkGQ/GgI0WpBw2JoJfnss1/am/PMWMG0GkFaHmS5CtXe2SicdyyxsDV49burcjqn tHNodzxLk7XJn2j9j7QzqlgVp546niaYxdq4KPluTaqLyV0us65OuSHAGM26BsMBtv6XAjNUPDd +WObixrjo8rjbh/1SAsebTylua+So721RtPcMrV1m X-Received: by 2002:a05:6a00:b90a:b0:81f:2b84:6efb with SMTP id d2e1a72fcca58-81f82011df7mr6059472b3a.69.1768465808547; Thu, 15 Jan 2026 00:30:08 -0800 (PST) X-Received: by 2002:a05:6a00:b90a:b0:81f:2b84:6efb with SMTP id d2e1a72fcca58-81f82011df7mr6059441b3a.69.1768465808070; Thu, 15 Jan 2026 00:30:08 -0800 (PST) Received: from QCOM-SocCW5bzXR.qualcomm.com ([202.46.23.19]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-81f8e69d1e7sm1773296b3a.58.2026.01.15.00.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 00:30:07 -0800 (PST) From: Jianping Li To: srini@kernel.org, amahesh@qti.qualcomm.com, arnd@arndb.de, gregkh@linuxfoundation.org, linux-arm-msm@vger.kernel.org Cc: Jianping Li , thierry.escande@linaro.org, abelvesa@kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com, ekansh.gupta@oss.qualcomm.com Subject: [PATCH v2 4/4] misc: fastrpc: Allocate entire reserved memory for Audio PD in probe Date: Thu, 15 Jan 2026 16:28:51 +0800 Message-Id: <20260115082851.570-5-jianping.li@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115082851.570-1-jianping.li@oss.qualcomm.com> References: <20260115082851.570-1-jianping.li@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: FHP36NglIQddjIzNxG8CNnaj3cmDeJ_S X-Proofpoint-ORIG-GUID: FHP36NglIQddjIzNxG8CNnaj3cmDeJ_S X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTE1MDA1NyBTYWx0ZWRfXyHMF4jF8mIeU wpRqSSHvshKdvJS3oCawryYTqwuLI9cL5ekEKr9nsYTW+RGUBvUIZOQ0ZS5Ws5F+Emmn07h+GKN cuhKBifpkTDR2uXNGtWijbGgMc2vJ5mUudcjuGMiNcOfilEljrSsEqBuFf3g4J8dMKg8eK7tz9H DeydPliPDDULo5ZXCuUJgfDJIfrIPEd+NifNtEFi7uRWHbPfwisbDCqcGJ147EbhIxrZ/tV2EOC yZph8nVB9BxxWP7ZOeZuC7B7G932ymlpT/xUVmOlHfvTnh3BibuNoquEgj/yp5qb+0KYr4W2Fps YlUG6vHpc+QMSO4cvJpSTfVwQfawGS4DWT0bhq1P45ndD0HS4tqouQkb5N3OSf/7NbPAS401s7S 5G+OLcTFm9Crmr95wTzUGhSWRZhg07OYXZm2K/IKOH/fwBhQPgor0nWXa/2McPnKMOyfXuHjO+o ZSW0Zfa+bmwyl62Ph/w== X-Authority-Analysis: v=2.4 cv=fsHRpV4f c=1 sm=1 tr=0 ts=6968a591 cx=c_pps a=rEQLjTOiSrHUhVqRoksmgQ==:117 a=j4ogTh8yFefVWWEFDRgCtg==:17 a=vUbySO9Y5rIA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=6yTI7Z6G2gYhkubfSC0A:9 a=2VI0MkxyNR6bbpdq8BZq:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-15_02,2026-01-14_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 bulkscore=0 adultscore=0 spamscore=0 clxscore=1011 impostorscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2601150057 Content-Type: text/plain; charset="utf-8" The entire reserved-memory region is now assigned to DSP VMIDs during channel setup and stored in cctx->remote_heap. Memory is reclaimed in rpmsg_remove by revoking DSP permissions and freeing the buffer, tying heap lifecycle to the rpmsg channel. Signed-off-by: Jianping Li --- drivers/misc/fastrpc.c | 95 ++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 833c265add5e..f9edca7a8de1 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -278,6 +278,8 @@ struct fastrpc_channel_ctx { struct kref refcount; /* Flag if dsp attributes are cached */ bool valid_attributes; + /* Flag if audio PD init mem was allocated */ + bool audio_init_mem; u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES]; struct fastrpc_device *secure_fdevice; struct fastrpc_device *fdevice; @@ -1304,7 +1306,6 @@ static int fastrpc_init_create_static_process(struct = fastrpc_user *fl, struct fastrpc_phy_page pages[1]; char *name; int err; - bool scm_done =3D false; struct { int client_id; u32 namelen; @@ -1334,31 +1335,6 @@ static int fastrpc_init_create_static_process(struct= fastrpc_user *fl, inbuf.client_id =3D fl->client_id; inbuf.namelen =3D init.namelen; inbuf.pageslen =3D 0; - if (!fl->cctx->remote_heap) { - err =3D fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen, - &fl->cctx->remote_heap); - if (err) - goto err_name; - - /* Map if we have any heap VMIDs associated with this ADSP Static Proces= s. */ - if (fl->cctx->vmcount) { - u64 src_perms =3D BIT(QCOM_SCM_VMID_HLOS); - - err =3D qcom_scm_assign_mem(fl->cctx->remote_heap->dma_addr, - (u64)fl->cctx->remote_heap->size, - &src_perms, - fl->cctx->vmperms, fl->cctx->vmcount); - if (err) { - dev_err(fl->sctx->dev, - "Failed to assign memory with dma_addr %pad size 0x%llx err %d\n", - &fl->cctx->remote_heap->dma_addr, - fl->cctx->remote_heap->size, err); - goto err_map; - } - scm_done =3D true; - inbuf.pageslen =3D 1; - } - } =20 fl->pd =3D USER_PD; =20 @@ -1370,8 +1346,15 @@ static int fastrpc_init_create_static_process(struct= fastrpc_user *fl, args[1].length =3D inbuf.namelen; args[1].fd =3D -1; =20 - pages[0].addr =3D fl->cctx->remote_heap->dma_addr; - pages[0].size =3D fl->cctx->remote_heap->size; + if (!fl->cctx->audio_init_mem) { + pages[0].addr =3D fl->cctx->remote_heap->dma_addr; + pages[0].size =3D fl->cctx->remote_heap->size; + fl->cctx->audio_init_mem =3D true; + inbuf.pageslen =3D 1; + } else { + pages[0].addr =3D 0; + pages[0].size =3D 0; + } =20 args[2].ptr =3D (u64)(uintptr_t) pages; args[2].length =3D sizeof(*pages); @@ -1389,26 +1372,7 @@ static int fastrpc_init_create_static_process(struct= fastrpc_user *fl, =20 return 0; err_invoke: - if (fl->cctx->vmcount && scm_done) { - u64 src_perms =3D 0; - struct qcom_scm_vmperm dst_perms; - u32 i; - - for (i =3D 0; i < fl->cctx->vmcount; i++) - src_perms |=3D BIT(fl->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(fl->cctx->remote_heap->dma_addr, - (u64)fl->cctx->remote_heap->size, - &src_perms, &dst_perms, 1); - if (err) - dev_err(fl->sctx->dev, "Failed to assign memory dma_addr %pad size 0x%l= lx err %d\n", - &fl->cctx->remote_heap->dma_addr, fl->cctx->remote_heap->size, err); - } -err_map: - fastrpc_buf_free(fl->cctx->remote_heap); -err_name: + fl->cctx->audio_init_mem =3D false; kfree(name); err: kfree(args); @@ -2396,7 +2360,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *r= pdev) } } =20 - if (domain_id =3D=3D SDSP_DOMAIN_ID) { + if (domain_id =3D=3D SDSP_DOMAIN_ID || domain_id =3D=3D ADSP_DOMAIN_ID) { struct resource res; u64 src_perms; =20 @@ -2408,6 +2372,15 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *= rpdev) data->vmperms, data->vmcount); } =20 + if (domain_id =3D=3D ADSP_DOMAIN_ID) { + data->remote_heap =3D + kzalloc(sizeof(*data->remote_heap), GFP_KERNEL); + if (!data->remote_heap) + return -ENOMEM; + + data->remote_heap->dma_addr =3D res.start; + data->remote_heap->size =3D resource_size(&res); + } } =20 secure_dsp =3D !(of_property_read_bool(rdev->of_node, "qcom,non-secure-do= main")); @@ -2488,10 +2461,13 @@ static void fastrpc_rpmsg_remove(struct rpmsg_devic= e *rpdev) struct fastrpc_buf *buf, *b; struct fastrpc_user *user; unsigned long flags; + bool skip_free =3D false; + int err; =20 /* No invocations past this point */ spin_lock_irqsave(&cctx->lock, flags); cctx->rpdev =3D NULL; + cctx->audio_init_mem =3D false; list_for_each_entry(user, &cctx->users, user) fastrpc_notify_users(user); spin_unlock_irqrestore(&cctx->lock, flags); @@ -2505,7 +2481,26 @@ 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); =20 - fastrpc_buf_free(cctx->remote_heap); + if (cctx->remote_heap) { + if (cctx->vmcount) { + u64 src_perms =3D 0; + struct qcom_scm_vmperm dst_perms; + + for (u32 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->dma_addr, + cctx->remote_heap->size, + &src_perms, &dst_perms, 1); + if (err) + skip_free =3D true; + } + if (!skip_free) + fastrpc_buf_free(cctx->remote_heap); + } =20 of_platform_depopulate(&rpdev->dev); =20 --=20 2.43.0