mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
To: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Cc: srinivas.kandagatla@oss.qualcomm.com,
	linux-arm-msm@vger.kernel.org, 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 5/5] misc: fastrpc: Add missing unmapping user-requested remote heap
Date: Wed, 9 Jul 2025 11:13:49 +0530	[thread overview]
Message-ID: <8b877eeb-941a-47c5-a67d-450dfb772d6e@oss.qualcomm.com> (raw)
In-Reply-To: <cq3qfx32dallivdcwjwqgq7kggiwucpcyhwqqlbrf6n4efkmuc@htjwnigojag2>



On 6/12/2025 3:54 PM, Dmitry Baryshkov wrote:
> On Thu, Jun 12, 2025 at 03:02:52PM +0530, Ekansh Gupta wrote:
>>
>> On 6/12/2025 1:35 PM, Dmitry Baryshkov wrote:
>>> On Thu, Jun 12, 2025 at 10:50:10AM +0530, Ekansh Gupta wrote:
>>>> On 5/22/2025 5:43 PM, Dmitry Baryshkov wrote:
>>>>> On Thu, 22 May 2025 at 08:01, Ekansh Gupta
>>>>> <ekansh.gupta@oss.qualcomm.com> wrote:
>>>>>> On 5/19/2025 7:04 PM, Dmitry Baryshkov wrote:
>>>>>>> On Mon, May 19, 2025 at 04:28:34PM +0530, Ekansh Gupta wrote:
>>>>>>>> On 5/19/2025 4:22 PM, Dmitry Baryshkov wrote:
>>>>>>>>> On Tue, May 13, 2025 at 09:58:25AM +0530, Ekansh Gupta wrote:
>>>>>>>>>> User request for remote heap allocation is supported using ioctl
>>>>>>>>>> interface but support for unmap is missing. This could result in
>>>>>>>>>> memory leak issues. Add unmap user request support for remote heap.
>>>>>>>>> Can this memory be in use by the remote proc?
>>>>>>>> Remote heap allocation request is only intended for audioPD. Other PDs
>>>>>>>> running on DSP are not intended to use this request.
>>>>>>> 'Intended'. That's fine. I asked a different question: _can_ it be in
>>>>>>> use? What happens if userspace by mistake tries to unmap memory too
>>>>>>> early? Or if it happens intentionally, at some specific time during
>>>>>>> work.
>>>>>> If the unmap is restricted to audio daemon, then the unmap will only
>>>>>> happen if the remoteproc is no longer using this memory.
>>>>>>
>>>>>> But without this restriction, yes it possible that some userspace process
>>>>>> calls unmap which tries to move the ownership back to HLOS which the
>>>>>> remoteproc is still using the memory. This might lead to memory access
>>>>>> problems.
>>>>> This needs to be fixed in the driver. We need to track which memory is
>>>>> being used by the remoteproc and unmap it once remoteproc stops using
>>>>> it, without additional userspace intervention.
>>>> If it's the audio daemon which is requesting for unmap then it basically means that
>>>> the remoteproc is no longer using the memory. Audio PD can request for both grow
>>>> and shrink operations for it's dedicated heap. The case of grow is already supported
>>>> from fastrpc_req_mmap but the case of shrink(when remoteproc is no longer using the
>>>> memory) is not yet available. This memory is more specific to audio PD rather than
>>>> complete remoteproc.
>>>>
>>>> If we have to control this completely from driver then I see a problem in freeing/unmapping
>>>> the memory when the PD is no longer using the memory.
>>> What happens if userspace requests to free the memory that is still in
>>> use by the PD
>> I understand your point, for this I was thinking to limit the unmap functionality to the process
>> that is already attached to audio PD on DSP, no other process will be able to map/unmap this
>> memory from userspace.
> Ugh... and what if the adsprpcd misbehaves?
>
>>> How does PD signal the memory is no longer in use?
>> PD makes a reverse fastrpc request[1] to unmap the memory when it is no longer used.
> I don't see how this can be made robust. I fear that the only way would
> be to unmap the memory only on audio PD restart / shutdown. Such
> requests should never leave the kernel.
>
> Moreover, the payload should not be trusted, however you don't validate
> the length that you've got from the remote side.
I was thinking of giving the entire reserved memory to audio PD when
init_create_static_process is called. This way, we can avoid any need to
support grow/free request from user process and the audio PD pool on
DSP will have sufficient memory support the use cases.

This way the free can be moved to fastrpc_rpmsg_remove(When DSP
is shutting down) or during Audio PD restart(Static PD restart is not
yet supported, but clean-up can be done when PDR framework is
implemented in the future).

Do you see any drawbacks with this design?

>
>> [1] https://github.com/quic/fastrpc/blob/development/src/apps_mem_imp.c#L231


  reply	other threads:[~2025-07-09  5:43 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
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 [this message]
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=8b877eeb-941a-47c5-a67d-450dfb772d6e@oss.qualcomm.com \
    --to=ekansh.gupta@oss.qualcomm.com \
    --cc=arnd@arndb.de \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --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®