From: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
To: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>,
linux-arm-msm@vger.kernel.org
Cc: gregkh@linuxfoundation.org, quic_bkumar@quicinc.com,
linux-kernel@vger.kernel.org, quic_chennak@quicinc.com,
dri-devel@lists.freedesktop.org, arnd@arndb.de,
stable@kernel.org
Subject: Re: [PATCH v1 2/5] misc: fastrpc: Move all remote heap allocations to a new list
Date: Thu, 22 May 2025 10:39:36 +0530 [thread overview]
Message-ID: <c970fdd9-4dab-4e02-865f-7f8e6a830088@oss.qualcomm.com> (raw)
In-Reply-To: <3b9dc9d5-be31-420a-ae90-335377ad6d08@oss.qualcomm.com>
On 5/19/2025 5:05 PM, Srinivas Kandagatla wrote:
> On 5/13/25 05:28, Ekansh Gupta wrote:
>> Remote heap allocations are not organized in a maintainable manner,
>> leading to potential issues with memory management. As the remote
>> heap allocations are maintained in fl mmaps list, the allocations
>> will go away if the audio daemon process is killed but there are
>> chances that audio PD might still be using the memory. Move all
>> remote heap allocations to a dedicated list where the entries are
>> cleaned only for user requests and subsystem shutdown.
>>
>> Fixes: 0871561055e66 ("misc: fastrpc: Add support for audiopd")
>> Cc: stable@kernel.org
>> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
>> ---
>> drivers/misc/fastrpc.c | 93 ++++++++++++++++++++++++++++++++----------
>> 1 file changed, 72 insertions(+), 21 deletions(-)
>>
>> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
>> index ca3721365ddc..d4e38b5e5e6c 100644
>> --- a/drivers/misc/fastrpc.c
>> +++ b/drivers/misc/fastrpc.c
>> @@ -273,10 +273,12 @@ 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;
>> - struct fastrpc_buf *remote_heap;
>> + struct list_head rhmaps;
> Other than Audiopd, do you see any other remote heaps getting added to
> this list?
With current implementation it is possible but that is not correct, I
will include a patch to restrict remote heap map and unmap requests to
audio daemon only.
>
>> struct list_head invoke_interrupted_mmaps;
>> bool secure;
>> bool unsigned_support;
>> @@ -1237,12 +1239,47 @@ static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_reques
>> return false;
>> }
>>
>> +static void fastrpc_cleanup_rhmaps(struct fastrpc_channel_ctx *cctx)
>> +{
>> + struct fastrpc_buf *buf, *b;
>> + struct list_head temp_list;
>> + int err;
>> + unsigned long flags;
>> +
>> + INIT_LIST_HEAD(&temp_list);
>> +
>> + spin_lock_irqsave(&cctx->lock, flags);
>> + list_splice_init(&cctx->rhmaps, &temp_list);
>> + spin_unlock_irqrestore(&cctx->lock, flags);
> Can you explain why do we need to do this?
To avoid any locking issue. While clean-up, I'm replacing the rhmaps
list with an empty one under a lock and cleaning up the list without
any more locking.
>
>> +
>> + list_for_each_entry_safe(buf, b, &temp_list, node) {> + if (cctx->vmcount) {
>> + u64 src_perms = 0;
>> + struct qcom_scm_vmperm dst_perms;
>> + u32 i;
>> +
>> + 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(buf->phys, (u64)buf->size,
>> + &src_perms, &dst_perms, 1);
>> + if (err)
>> + continue;
> Memory leak here.
I don't see any better way to handle the failure here as the clean-up
is called when the channel is going down and there won't be any
way to free this memory if qcom_scm call fails?
Do you see any better way to address this? Or should I add a comment
highlighting this limitation?
>
>> + }
>> + fastrpc_buf_free(buf);
>> + }
>> +}
>> +
> --srini
next prev parent reply other threads:[~2025-05-22 5:09 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-13 4:28 [PATCH v1 0/5] misc: fastrpc: Add missing bug fixes Ekansh Gupta
2025-05-13 4:28 ` [PATCH v1 1/5] misc: fastrpc: Add NULL check to fastrpc_buf_free to prevent crash Ekansh Gupta
2025-05-19 9:25 ` Srinivas Kandagatla
2025-05-19 10:09 ` Dmitry Baryshkov
2025-05-19 10:40 ` Srinivas Kandagatla
2025-05-19 10:50 ` Ekansh Gupta
2025-05-13 4:28 ` [PATCH v1 2/5] misc: fastrpc: Move all remote heap allocations to a new list Ekansh Gupta
2025-05-19 10:16 ` Dmitry Baryshkov
2025-05-19 11:06 ` Ekansh Gupta
2025-05-19 13:29 ` Dmitry Baryshkov
2025-05-22 4:54 ` Ekansh Gupta
2025-05-22 12:09 ` Dmitry Baryshkov
2025-06-12 5:13 ` Ekansh Gupta
2025-06-12 11:16 ` Dmitry Baryshkov
2025-05-19 11:35 ` Srinivas Kandagatla
2025-05-22 5:09 ` Ekansh Gupta [this message]
2025-05-13 4:28 ` [PATCH v1 3/5] misc: fastrpc: Fix initial memory allocation for Audio PD memory pool Ekansh Gupta
2025-05-19 10:17 ` Dmitry Baryshkov
2025-05-19 10:53 ` Ekansh Gupta
2025-05-19 13:31 ` Dmitry Baryshkov
2025-05-22 4:58 ` Ekansh Gupta
2025-05-22 12:11 ` Dmitry Baryshkov
2025-05-19 11:41 ` Srinivas Kandagatla
2025-05-22 5:11 ` Ekansh Gupta
2025-05-13 4:28 ` [PATCH v1 4/5] misc: fastrpc: Remove buffer from list prior to unmap operation Ekansh Gupta
2025-05-19 10:20 ` Dmitry Baryshkov
2025-05-19 10:56 ` Ekansh Gupta
2025-05-19 13:32 ` Dmitry Baryshkov
2025-05-13 4:28 ` [PATCH v1 5/5] misc: fastrpc: Add missing unmapping user-requested remote heap Ekansh Gupta
2025-05-19 10:52 ` Dmitry Baryshkov
2025-05-19 10:58 ` Ekansh Gupta
2025-05-19 13:34 ` Dmitry Baryshkov
2025-05-22 5:01 ` Ekansh Gupta
2025-05-22 12:13 ` Dmitry Baryshkov
2025-06-12 5:20 ` Ekansh Gupta
2025-06-12 8:05 ` Dmitry Baryshkov
2025-06-12 9:32 ` Ekansh Gupta
2025-06-12 10:24 ` Dmitry Baryshkov
2025-07-09 5:43 ` Ekansh Gupta
2025-07-19 9:44 ` Dmitry Baryshkov
2025-07-23 9:24 ` Ekansh Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c970fdd9-4dab-4e02-865f-7f8e6a830088@oss.qualcomm.com \
--to=ekansh.gupta@oss.qualcomm.com \
--cc=arnd@arndb.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_bkumar@quicinc.com \
--cc=quic_chennak@quicinc.com \
--cc=srinivas.kandagatla@oss.qualcomm.com \
--cc=stable@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®