[PATCH v2 0/3] add dma noncoherent API

Xu Yang posted 3 patches 3 months, 1 week ago
There is a newer version of this series
drivers/media/usb/stk1160/stk1160-v4l.c   |  4 --
drivers/media/usb/stk1160/stk1160-video.c | 43 ++++--------
drivers/media/usb/stk1160/stk1160.h       |  7 --
drivers/media/usb/uvc/uvc_video.c         | 56 ++++------------
drivers/usb/core/hcd.c                    | 30 +++++++++
drivers/usb/core/usb.c                    | 80 +++++++++++++++++++++++
include/linux/usb.h                       |  9 +++
7 files changed, 144 insertions(+), 85 deletions(-)
[PATCH v2 0/3] add dma noncoherent API
Posted by Xu Yang 3 months, 1 week ago
On architectures where there is no coherent caching such as ARM it's
proved that using dma_alloc_noncontiguous API and handling manually
the cache flushing will significantly improve performance.

Refer to:
commit 20e1dbf2bbe2 ("media: uvcvideo: Use dma_alloc_noncontiguous API")
commit 68d0c3311ec1 ("media: stk1160: use dma_alloc_noncontiguous API")

However, it's obvious that there is significant code duplication between
these two commits. Beside, a potential user USB Monitor may read outdated
data before the driver do dma sync for cpu which will make the data
unreliable.

To reduce code duplication and avoid USB Monitor result unreliable, this
series will introduce dma noncoherent API to usb core. And the USB core
layer will manage synchronization itself.

Then the last 2 patches have used the API.

I have tested uvcvideo driver. But I haven't tested stk1160 driver as I
don't have such boards. @Ezequiel Garcia, @Dafna Hirschfeld do you have
time to test it? Your support on this would be greatly appreciated.

Changes in v2:
 - handle it in USB core

v1:
 - https://lore.kernel.org/linux-usb/20250614132446.251218-1-xu.yang_2@nxp.com/

Xu Yang (3):
  usb: core: add dma-noncoherent buffer alloc and free API
  media: uvcvideo: use usb_alloc_noncoherent/usb_free_noncoherent()
  media: stk1160: use usb_alloc_noncoherent/usb_free_noncoherent()

 drivers/media/usb/stk1160/stk1160-v4l.c   |  4 --
 drivers/media/usb/stk1160/stk1160-video.c | 43 ++++--------
 drivers/media/usb/stk1160/stk1160.h       |  7 --
 drivers/media/usb/uvc/uvc_video.c         | 56 ++++------------
 drivers/usb/core/hcd.c                    | 30 +++++++++
 drivers/usb/core/usb.c                    | 80 +++++++++++++++++++++++
 include/linux/usb.h                       |  9 +++
 7 files changed, 144 insertions(+), 85 deletions(-)

-- 
2.34.1
Re: [PATCH v2 0/3] add dma noncoherent API
Posted by Andy Shevchenko 3 months, 1 week ago
On Fri, Jun 27, 2025 at 06:19:36PM +0800, Xu Yang wrote:
> On architectures where there is no coherent caching such as ARM it's
> proved that using dma_alloc_noncontiguous API and handling manually

dma_alloc_noncontiguous()

> the cache flushing will significantly improve performance.

> Refer to:
> commit 20e1dbf2bbe2 ("media: uvcvideo: Use dma_alloc_noncontiguous API")
> commit 68d0c3311ec1 ("media: stk1160: use dma_alloc_noncontiguous API")
> 
> However, it's obvious that there is significant code duplication between
> these two commits. Beside, a potential user USB Monitor may read outdated
> data before the driver do dma sync for cpu which will make the data

DMA
CPU

> unreliable.
> 
> To reduce code duplication and avoid USB Monitor result unreliable, this
> series will introduce dma noncoherent API to usb core. And the USB core

DMA
USB

> layer will manage synchronization itself.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 0/3] add dma noncoherent API
Posted by Xu Yang 3 months, 1 week ago
On Fri, Jun 27, 2025 at 02:25:41PM +0300, Andy Shevchenko wrote:
> On Fri, Jun 27, 2025 at 06:19:36PM +0800, Xu Yang wrote:
> > On architectures where there is no coherent caching such as ARM it's
> > proved that using dma_alloc_noncontiguous API and handling manually
> 
> dma_alloc_noncontiguous()

Okay.

> 
> > the cache flushing will significantly improve performance.
> 
> > Refer to:
> > commit 20e1dbf2bbe2 ("media: uvcvideo: Use dma_alloc_noncontiguous API")
> > commit 68d0c3311ec1 ("media: stk1160: use dma_alloc_noncontiguous API")
> > 
> > However, it's obvious that there is significant code duplication between
> > these two commits. Beside, a potential user USB Monitor may read outdated
> > data before the driver do dma sync for cpu which will make the data
> 
> DMA
> CPU

Okay.

> 
> > unreliable.
> > 
> > To reduce code duplication and avoid USB Monitor result unreliable, this
> > series will introduce dma noncoherent API to usb core. And the USB core
> 
> DMA
> USB

Okay.

Thanks,
Xu Yang

> 
> > layer will manage synchronization itself.
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>