Re: [EXT] Re: [PATCH] media: videobuf2-dma-sg: limit the sg segment size

From: Tomasz Figa
Date: Wed Sep 06 2023 - 05:28:52 EST


On Wed, Sep 6, 2023 at 5:16 PM Hui Fang <hui.fang@xxxxxxx> wrote:
>
> On Wed, Sep 5, 2023 at 12:44 AM Tomasz Figa <tfiga@xxxxxxxxxxxx> wrote:
> >
> > I see. I guess the mapping is done by the USB gadget controller driver? Could
> > you point us to the exact driver that's used?
> >
> > Just to clarify, swiotlb should only be needed in the very extreme fallback case,
> > because of the performance impact of the memory copy back and forth. The
> > right approach would depend on the DMA capabilities of your device, though.
>
>
> [ 138.493943][ T2104] Call trace:
> [ 138.497090][ T2104] vb2_dma_sg_alloc+0x2ec/0x2fc
> [ 138.501808][ T2104] __vb2_queue_alloc+0x224/0x724
> [ 138.506608][ T2104] vb2_core_reqbufs+0x374/0x528
> [ 138.511320][ T2104] vb2_reqbufs+0xe0/0xf4
> [ 138.515428][ T2104] uvcg_alloc_buffers+0x18/0x34
> [ 138.520159][ T2104] uvc_v4l2_reqbufs+0x38/0x54
> [ 138.524703][ T2104] v4l_reqbufs+0x68/0x80
> [ 138.528820][ T2104] __video_do_ioctl+0x370/0x4dc
> [ 138.533535][ T2104] video_usercopy+0x43c/0xb38
> [ 138.538076][ T2104] video_ioctl2+0x18/0x28
> [ 138.542272][ T2104] v4l2_ioctl+0x6c/0x84
> [ 138.546291][ T2104] __arm64_sys_ioctl+0xa8/0xe4
> [ 138.550928][ T2104] invoke_syscall+0x58/0x114
> [ 138.555389][ T2104] el0_svc_common+0x88/0xfc
> [ 138.559755][ T2104] do_el0_svc+0x2c/0xb8
> [ 138.563776][ T2104] el0_svc+0x2c/0xa4
> [ 138.567544][ T2104] el0t_64_sync_handler+0x68/0xb4
> [ 138.572434][ T2104] el0t_64_sync+0x1a4/0x1a8
> [ 138.576803][ T2104] Code: 17ffffcb 928002b3 d4210000 17ffffc8 (d4210000)
> [ 138.583598][ T2104] ---[ end trace 0000000000000000 ]---
>
> Also, below should explain why vb2_dma_sg_alloc is used.
> We tested on 8mp with use dwc3 controller.
>
> In drivers/usb/dwc3/gadget.c:
> dwc->gadget->sg_supported = true;
>
> In drivers/usb/gadget/function/uvc_queue.c
> if (cdev->gadget->sg_supported) {
> queue->queue.mem_ops = &vb2_dma_sg_memops;
> queue->use_sg = 1;
> } else {
> queue->queue.mem_ops = &vb2_vmalloc_memops;
> }
>

That all makes sense, but it still doesn't answer the real question on
why swiotlb ends up being used. I think you may want to trace what
happens in the DMA mapping ops implementation on your system causing
it to use swiotlb.

Best regards,
Tomasz