[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7e52f1d4-c05c-45ea-878c-cea2e6354c3f@oss.qualcomm.com>
Date: Fri, 30 Jan 2026 17:22:05 +0530
From: Ekansh Gupta <ekansh.gupta@....qualcomm.com>
To: rob.clark@....qualcomm.com
Cc: Dmitry Baryshkov <dmitry.baryshkov@....qualcomm.com>, srini@...nel.org,
linux-arm-msm@...r.kernel.org, gregkh@...uxfoundation.org,
quic_bkumar@...cinc.com, linux-kernel@...r.kernel.org,
quic_chennak@...cinc.com, dri-devel@...ts.freedesktop.org,
arnd@...db.de
Subject: Re: [PATCH v3 3/3] misc: fastrpc: Support mapping userspace-allocated
buffers
On 1/30/2026 3:41 AM, Rob Clark wrote:
> On Thu, Jan 29, 2026 at 2:39 AM Ekansh Gupta
> <ekansh.gupta@....qualcomm.com> wrote:
>>
>>
>> On 1/6/2026 8:21 AM, Dmitry Baryshkov wrote:
>>> On Tue, Dec 30, 2025 at 04:32:25PM +0530, Ekansh Gupta wrote:
>>>> Currently, FastRPC only supports mapping buffers allocated by the
>>>> kernel. This limits flexibility for applications that allocate memory
>>>> in userspace using rpcmem or DMABUF and need to share it with the DSP.
>>> Hmm, for DMABUF we need _import_ support rather than support for mapping
>>> of userspace-allocated buffers.
>>>
>>>> Add support for mapping and unmapping userspace-allocated buffers to
>>>> the DSP through SMMU. This includes handling map requests for rpcmem
>>>> and DMABUF-backed memory and providing corresponding unmap
>>>> functionality.
>>> For me this definitely looks like a step back. For drm/accel we are
>>> going to have GEM-managed buffers only. Why do we need to handle
>>> userspace-allocated buffers here?
>> That's correct, GEM-PRIME will handle it properly. Here, the reason to add this
>> change is to enable routing of DSP logs to HLOS which is done by using a shared
>> buffer between userspace process and DSP PD. The buffer can be allocated from
>> both fastrpc driver's DMA-BUF or DMABUF heap(eg. system heap).
>>
>> So this shared buffer is getting mapped to both process's IOMMU device and DSP PD
>> with this change.
> So, a mmap'd dma-buf is not necessarily pinned. Or even backed with
> pages. So you wouldn't want to try to map a userspace vaddr from a
> dma-buf to the device.
>
> But looking at the patch, this looks more like mapping an imported
> dmabuf? Presumably going thru dma_buf_map_attachment() somewhere in
> the existing fastrpc code?
yes, when the fd is passed to this call, first fastrpc_map_create is called which is
calling dma_buf_map_attachment[1]. After this the buffer is mapped onto DSP.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/misc/fastrpc.c#n781
>
> BR,
> -R
>
>>>> Signed-off-by: Ekansh Gupta <ekansh.gupta@....qualcomm.com>
>>>> ---
>>>> drivers/misc/fastrpc.c | 97 +++++++++++++++++++++++++++++++++++++-----
>>>> 1 file changed, 86 insertions(+), 11 deletions(-)
>>>>
>>>> @@ -1989,25 +2020,69 @@ static int fastrpc_req_buf_alloc(struct fastrpc_user *fl,
>>>> return err;
>>>> }
>>>>
>>>> -static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
>>>> +static int fastrpc_req_map_create(struct fastrpc_user *fl,
>>>> + struct fastrpc_req_mmap req,
>>>> + char __user *argp)
>>>> {
>>>> - struct fastrpc_req_mmap req;
>>>> + struct fastrpc_map *map = NULL;
>>>> + struct device *dev = fl->sctx->dev;
>>>> + u64 raddr = 0;
>>>> int err;
>>>>
>>>> - if (copy_from_user(&req, argp, sizeof(req)))
>>>> - return -EFAULT;
>>>> + err = fastrpc_map_create(fl, req.fd, req.size, 0, &map);
>>>> + if (err) {
>>>> + dev_err(dev, "failed to map buffer, fd = %d\n", req.fd);
>>>> + return err;
>>>> + }
>>>> +
>>>> + err = fastrpc_req_map_dsp(fl, map->phys, map->size, req.flags,
>>>> + req.vaddrin, &raddr);
>>>> + if (err)
>>>> + goto err_invoke;
>>>>
>>>> - if (req.flags != ADSP_MMAP_ADD_PAGES && req.flags != ADSP_MMAP_REMOTE_HEAP_ADDR) {
>>>> - dev_err(fl->sctx->dev, "flag not supported 0x%x\n", req.flags);
>>>> + /* update the buffer to be able to deallocate the memory on the DSP */
>>>> + map->raddr = (u64)raddr;
>>> Which type are you converting? And why?
>> I'll drop this.
>>>> - return -EINVAL;
>>>> + /* let the client know the address to use */
>>>> + req.vaddrout = raddr;
>>>> + dev_dbg(dev, "mmap OK: raddr=%p [len=0x%08llx]\n",
>>>> + (void *)(unsigned long)map->raddr, map->size);
>>>> +
>>>> + if (copy_to_user(argp, &req, sizeof(req))) {
>>>> + err = -EFAULT;
>>>> + goto err_copy;
>>>> }
>>>>
>>>> - err = fastrpc_req_buf_alloc(fl, req, argp);
>>>> + return 0;
>>>> +err_copy:
>>>> + fastrpc_req_munmap_dsp(fl, map->raddr, map->size);
>>>> +err_invoke:
>>>> + fastrpc_map_put(map);
>>>>
>>>> return err;
>>>> }
>>>>
>>>> +static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
>>>> +{
>>>> + struct fastrpc_req_mmap req;
>>>> + int err;
>>>> +
>>>> + if (copy_from_user(&req, argp, sizeof(req)))
>>>> + return -EFAULT;
>>>> +
>>>> + if ((req.flags == ADSP_MMAP_ADD_PAGES ||
>>>> + req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR)) {
>>> Side note: why are these flags not defined in the uABI header?
>> Ack. These should be part of uABI. I'll create a separate patch for this.
>>>> + err = fastrpc_req_buf_alloc(fl, req, argp);
>>>> + if (err)
>>>> + return err;
Powered by blists - more mailing lists