From mboxrd@z Thu Jan 1 00:00:00 1970 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 EE6B3374E5B for ; Mon, 27 Jul 2026 06:19:38 +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=1785133180; cv=none; b=gi+oDETPnwTNPHlEI1TU0LPz/R9M2NnW1gK43ByThgTEqji/mRe2VvJFk/O4QoDdX2R+D/jF7Wu2cQkB8XF21qnmwMuMmQFsAQ9L6CwMDiefRAEsFjUokbaCpnaXo+TsSIqwor0y8p6cSIO9/Jdy7+4P6ZH0JQH0CibjMdUIg+M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785133180; c=relaxed/simple; bh=sFOfAcqsUltuCzYJ2B96Bv7JL+bG+6JAXPkrrRM8cvs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ABT72JCa6K2T+LFzghSyOLkTx+1abXUZT5v25X9Mc4rjRzWdtcsjJ/Q6uFhGK1Rflo4PCE04ODRf6kE8ENvYmqHLzP+k6RwGacreoMy/lYgb3HeOHjghekec7VDJDO/N5as4ikq0DOHH+fobtufbXA5JsnZom20+eXj/VnKJNqY= 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=hrEKHBlc; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=NzJU+ZDf; 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="hrEKHBlc"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="NzJU+ZDf" 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 66R1fjUR2240045 for ; Mon, 27 Jul 2026 06:19:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ehdzVGWUZzE+UoMe7M6UqvX2cjN1lz3E+HTXhdWdQYE=; b=hrEKHBlcEA0992qm VJdKo3i/134xh7j6L5Evc7kZI+CZA3VQFQl8sE68ER1a8fYOm447hcmyzwW3MMFI q5DEq6XmFAMRuJJCYpv+i18nHpn6WSVYMSZYoe413ZG6d61qnkU5fQ6uiH3yR2CN uk0S3N0gcr2T6Yu7UDwYsrZZayAAS9/nO6HsARVdev9V5Omni3kbYjG6f/Snqurp uqHzUlT3SrG95DsrFKozGHcsgnXQ4FqnyZEML6Pphj5HDfTivRSO5xTJMNEEd0iY RDjB8q5X3HZVAE+0PSKoXMQ+6f+Fs7sq9ZXMkE2JhcTwygpY7TKhbYVS0s78bo9O oqFcfQ== Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fnsxs12n0-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 27 Jul 2026 06:19:37 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2cee894b3d8so22712155ad.2 for ; Sun, 26 Jul 2026 23:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1785133176; x=1785737976; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ehdzVGWUZzE+UoMe7M6UqvX2cjN1lz3E+HTXhdWdQYE=; b=NzJU+ZDfuTfD8DxcqvBpPGgHwttmazcEJoAL8Eu2mfs/niD7GL2HHIIVquxRErCvcN a9JyqggfJvVpgETYJ7Lz2CFSir3jsDKDO1Lspp/Kau9khGx/p5lCXVZed+NZs+v8nW3Q tkziXUvoYiB/y4E5Q30qsSwbE/rPZKSjFczVJLLS57NoeSx+ezkEKVRH1ueeUWEE+937 pmk0wWStoyGL3HOTsD6BxUx2gP3IeL9435qmIHx+SPSkvRSDSEEiVGYP/DbBMpvXANS6 utSMxP3xwnRbgBV7FWqvMBiQoETfvFrjQTsWhh/y/M0IluRPC6QOclvloVLyKapTSf6p 5HMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785133176; x=1785737976; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ehdzVGWUZzE+UoMe7M6UqvX2cjN1lz3E+HTXhdWdQYE=; b=lQjhsGu570hlQzPSr8PYkc1Nc6NRycQ804dmkiHuGoZdB0a1OiHobR4ah26Spca0it 3WqretTpB1T/L8PZsPmzN1CQO7nC4q7+VC+RtjcdomR8yFnmg/TAtYoDXRTpsIMujcnn 5omPkdJNTNkGfCql+WeoSv2toD94qMOtyBuia1O4V0VYvGLssF6Vo0P7apIY21qcKbzF QSWIZ2f1mcdWb5DD3q3wXzpe9ewUzHs3ddNRzHlUchk/CVfjRss4sxmXDgn7Mf0un38f i1wdr3uOLHXUSL87xH18VA1ENYMJhgM7FQzKiLVGGLJvfKYTue4d+hvY4CesnPYfoP6L d90Q== X-Forwarded-Encrypted: i=1; AHgh+RqSBLS8m9nTD/g/ZV7lslOYWP/gPuHzUiTCfhLQ23sMQla+M5tzis/RrgD0/L46iVa7qUfsvwNeoWgFdtg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+RamFCHdTQGF5X3QV4zfYC4U0D8KhDus0A5f3ekIpci0WDHkw KeGt+7fYLC8935SzNIW8AaJio+P23t/rpiFY7jeASw47aKUbWPfDSnDqAOxp6c8TYTtU0kakHd8 hnKAIl0kFRYjkqJETxd38qDNtwvdEKmVGG6XMo4GIMkVZEVK/GhjBR5MI0MAaVjzN5ms= X-Gm-Gg: AR+sD10Feic77eZcphi+ghJyI3JeATbIAmdyUoabANuclywkKH2SWVBb6ZxNsSoLCLo nabkePmYigOgVrgV1Q4uBPHnOTT+0RHODSMUdtX1qSHLzT/TjEVvqViyUsA0ZjiMdrBTGhX6VBj z3oLM7Z8P8fFRDnZ4ghkwMad1fYP0AQgC2puoNIPITHG4Ex96t7FOl1/2GouTp0HhTJdBcZjajS BFekZ2rXvJW2gSJcoDEpKxDIqlTOuut1vddaUiM1lbHSeGnh2gvWuKB9sOuj7kZnOngBEi/4X+G iw74RH3/N1rzXlZarSAaLvyndrWduSVHTEnKBXUrtrqQNDbV/FssqKVAbbU4jmNBqeS+jUhwAfR TBULCaXlDyVGuAleg9ZEeMgVHqzgaxA== X-Received: by 2002:a17:903:2284:b0:2c9:ff83:41fa with SMTP id d9443c01a7336-2cfde85fb71mr70196135ad.24.1785133176453; Sun, 26 Jul 2026 23:19:36 -0700 (PDT) X-Received: by 2002:a17:903:2284:b0:2c9:ff83:41fa with SMTP id d9443c01a7336-2cfde85fb71mr70196005ad.24.1785133176002; Sun, 26 Jul 2026 23:19:36 -0700 (PDT) Received: from [10.204.78.209] ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cfde7d9464sm29059665ad.58.2026.07.26.23.19.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jul 2026 23:19:35 -0700 (PDT) Message-ID: <1bfd9503-ebcb-4613-943a-f6b31676f8e5@oss.qualcomm.com> Date: Mon, 27 Jul 2026 11:49:30 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10] misc: fastrpc: Allocate entire reserved memory for Audio PD in probe To: Jianping Li , Srinivas Kandagatla Cc: Arnd Bergmann , Greg Kroah-Hartman , Abel Vesa , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com, stable@kernel.org References: <20260716095847.479-1-jianping.li@oss.qualcomm.com> Content-Language: en-US From: Ekansh Gupta In-Reply-To: <20260716095847.479-1-jianping.li@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI3MDA2MCBTYWx0ZWRfX1fhU5a5ddrFE /LkmUNCZCxgC6CjGgFd+j0E9ergDMqMVaKc5YrcuZpsHZtG8FDSqKLHobvRTzV9Q6UPXz7zHy3G Jwn1GEJyDmXIpB5CxuE12A9jismnGsyikTJpjX+zdJuYE066M0wX7w8jxl0Tm8DaI8v3dd8tGPZ UoRkoZqcDZEirRGZ0bfWxlnX+P3qANPQA/y9AFFAeeMeqGGJij36f+oWnaMUqhga8xIj6vpDPhv W10d6HcI0iI7JvvtS3YC5fZmhEyWIz4hFEitkMb/B71aplePaSkONnqzBBlPuF/vZLX+CVlznw3 uenuku3DOtpQhfHCiFtZsbZIzK8LhpQBwg+gX7Z0pBlfuPnwjAWVlordH8/oFIEjlhiAGDoZbp9 GQkkzNbhwDeanDFCOtQ4mbwgkC3BdQHX/ZXTPgWD34t+KSlF7jGUpYN8awV2pVCv1u/EIzkYJ+R R8oa+PMSWwdmcXpm4wg== X-Authority-Analysis: v=2.4 cv=EYr4hvmC c=1 sm=1 tr=0 ts=6a66f879 cx=c_pps a=JL+w9abYAAE89/QcEU+0QA==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=DYcdDKNzWsWSpgcxVykA:9 a=QEXdDO2ut3YA:10 a=324X-CrmTo6CU4MGRt3R:22 X-Proofpoint-ORIG-GUID: cyymwiUzKegkkT1jqZ88fDf2XMGgkfyz X-Proofpoint-GUID: cyymwiUzKegkkT1jqZ88fDf2XMGgkfyz X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI3MDA2MCBTYWx0ZWRfX+NqS+78swj9X 9PPNnHW987P+2W5ww1R8R9Wf9a0IsQe322Khvhn3vLM55u+mB2dF2W/A1N0/eSqchV4xX4ZLYf4 JS7mdGfaqdy67HNQ3Exu17154wD1LhI= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-27_01,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607270060 On 16-07-2026 15:28, Jianping Li wrote: > Allocating and freeing Audio PD memory from userspace is unsafe because > the kernel cannot reliably determine when the DSP has finished using the > memory. Userspace may free buffers while they are still in use by the DSP, > and remote free requests cannot be safely trusted. > > Additionally, the current implementation allows userspace to repeatedly > grow the Audio PD heap, but does not support shrinking it. This can lead > to unbounded memory usage over time, effectively causing a memory leak. > > Fix this by allocating the entire Audio PD reserved-memory region during > rpmsg probe and tying its lifetime to the rpmsg channel. This removes > userspace-controlled alloc/free and ensures that memory is reclaimed only > when the DSP process is torn down. > > Add explicit validation for remote_heap presence and size before sending > the memory to DSP, and fail early if the reserved-memory region is > missing or incomplete. Can you also drop ADSP_MMAP_REMOTE_HEAP_ADDR support from fastrpc_req_mmap as we don't intend user process to grow/shrink audio PD's remote heap.> > Fixes: 0871561055e66 ("misc: fastrpc: Add support for audiopd") > Cc: stable@kernel.org > Signed-off-by: Jianping Li > > Patch [v9]: https://lore.kernel.org/all/20260707061733.495-1-jianping.li@oss.qualcomm.com/ > > Changes in v10: > - Move Audio PD remote heap validation into > fastrpc_rpmsg_probe(). > > - Treat Audio PD remote heap as a mandatory > resource and fail probe if the reserved > memory region is missing. > > Changes in v9: > - Make sure fastrpc_init_create_static_process() > only sets audio_init_mem to false when the sent > address is actually invalid. > --- > drivers/misc/fastrpc.c | 121 +++++++++++++++++++++++------------------ > 1 file changed, 69 insertions(+), 52 deletions(-) > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > index d86e79134c68..03f633028c00 100644 > --- a/drivers/misc/fastrpc.c > +++ b/drivers/misc/fastrpc.c > @@ -276,6 +276,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; > @@ -1344,15 +1346,17 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > struct fastrpc_init_create_static init; > struct fastrpc_invoke_args *args; > struct fastrpc_phy_page pages[1]; > + struct fastrpc_channel_ctx *cctx = fl->cctx; > char *name; > int err; > - bool scm_done = false; > struct { > int client_id; > u32 namelen; > u32 pageslen; > } inbuf; > u32 sc; > + unsigned long flags; > + bool sent_heap = false; > > args = kzalloc_objs(*args, FASTRPC_CREATE_STATIC_PROCESS_NARGS); > if (!args) > @@ -1376,31 +1380,6 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > inbuf.client_id = fl->client_id; > inbuf.namelen = init.namelen; > inbuf.pageslen = 0; > - if (!fl->cctx->remote_heap) { > - err = 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 Process. */ > - if (fl->cctx->vmcount) { > - u64 src_perms = BIT(QCOM_SCM_VMID_HLOS); > - > - err = 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 = true; > - inbuf.pageslen = 1; > - } > - } > > fl->pd = USER_PD; > > @@ -1412,8 +1391,25 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > args[1].length = inbuf.namelen; > args[1].fd = -1; > > - pages[0].addr = fl->cctx->remote_heap->dma_addr; > - pages[0].size = fl->cctx->remote_heap->size; > + /* > + * Audio PD is a static PD and retains the remote heap > + * information across daemon restarts. Therefore only > + * the first attach should provide heap information to > + * DSP. Subsequent attaches reuse the previously > + * initialized memory pool. > + */ > + spin_lock_irqsave(&cctx->lock, flags); > + if (!cctx->audio_init_mem) { > + pages[0].addr = cctx->remote_heap->dma_addr; > + pages[0].size = cctx->remote_heap->size; > + cctx->audio_init_mem = true; > + inbuf.pageslen = 1; > + sent_heap = true; > + } else { > + pages[0].addr = 0; > + pages[0].size = 0; > + } > + spin_unlock_irqrestore(&cctx->lock, flags); > > args[2].ptr = (u64)(uintptr_t) pages; > args[2].length = sizeof(*pages); > @@ -1431,27 +1427,11 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > > return 0; > err_invoke: > - if (fl->cctx->vmcount && scm_done) { > - u64 src_perms = 0; > - struct qcom_scm_vmperm dst_perms; > - u32 i; > - > - for (i = 0; i < fl->cctx->vmcount; i++) > - src_perms |= BIT(fl->cctx->vmperms[i].vmid); > - > - dst_perms.vmid = QCOM_SCM_VMID_HLOS; > - dst_perms.perm = QCOM_SCM_PERM_RWX; > - err = 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%llx err %d\n", > - &fl->cctx->remote_heap->dma_addr, fl->cctx->remote_heap->size, err); > + if (sent_heap) { > + spin_lock_irqsave(&cctx->lock, flags); > + cctx->audio_init_mem = false; > + spin_unlock_irqrestore(&cctx->lock, flags); > } > -err_map: > - fastrpc_buf_free(fl->cctx->remote_heap); > - fl->cctx->remote_heap = NULL; > -err_name: > kfree(name); > err: > kfree(args); > @@ -2418,12 +2398,29 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) > } > } > > - if (domain_id == SDSP_DOMAIN_ID) { > + 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 && domain_id == ADSP_DOMAIN_ID) { > + dev_err(rdev, "missing mandatory remote heap memory-region\n"); > + goto err_free_data; > + } > + > if (!err) { > + if (domain_id == ADSP_DOMAIN_ID) { > + data->remote_heap = > + kzalloc_obj(*data->remote_heap); > + if (!data->remote_heap) { > + err = -ENOMEM; > + goto err_free_data; > + } > + > + data->remote_heap->dma_addr = res.start; > + data->remote_heap->size = resource_size(&res); other struct fastrpc_buf members are not initialized here. Either initialize all or better just add remote_heap_addr and remote_heap_size to fastrpc_channel_ctx structure.> + } > src_perms = BIT(QCOM_SCM_VMID_HLOS); > > err = qcom_scm_assign_mem(res.start, resource_size(&res), &src_perms, > @@ -2431,7 +2428,6 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) > if (err) > goto err_free_data; > } > - > } > > secure_dsp = !(of_property_read_bool(rdev->of_node, "qcom,non-secure-domain")); > @@ -2490,6 +2486,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) > misc_deregister(&data->secure_fdevice->miscdev); > > err_free_data: > + kfree(data->remote_heap); > kfree(data); > return err; > } > @@ -2512,6 +2509,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) > struct fastrpc_buf *buf, *b; > struct fastrpc_user *user; > unsigned long flags; > + int err, i; > > /* No invocations past this point */ > spin_lock_irqsave(&cctx->lock, flags); > @@ -2529,8 +2527,27 @@ 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) > - fastrpc_buf_free(cctx->remote_heap); > + if (cctx->remote_heap && cctx->vmcount) { > + u64 src_perms = 0; > + 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->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); > + } > + > + kfree(cctx->remote_heap); > + cctx->remote_heap = NULL; > > of_platform_depopulate(&rpdev->dev); >