diff mbox series

media: uvcvideo: Fix spurious DMA max segment size warnings

Message ID 20220609082246.13182-1-tiwai@suse.de (mailing list archive)
State New, archived
Headers show
Series media: uvcvideo: Fix spurious DMA max segment size warnings | expand

Commit Message

Takashi Iwai June 9, 2022, 8:22 a.m. UTC
As default, the DMA max segment size is set to 64k, and uvcvideo may
overflow that size easily, resulting in a warning like:

  DMA-API: xhci_hcd 0000:00:14.0: mapping sg segment longer than device claims to support [len=98304] [max=65536]

Explicitly set up the DMA max segment size for avoiding spurious kernel
warnings.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/media/usb/uvc/uvc_video.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Laurent Pinchart June 9, 2022, 9:18 a.m. UTC | #1
Hi Takashi,

(CC'ing Greg and the linux-usb mailing list)

Thank you for the patch.

On Thu, Jun 09, 2022 at 10:22:46AM +0200, Takashi Iwai wrote:
> As default, the DMA max segment size is set to 64k, and uvcvideo may
> overflow that size easily, resulting in a warning like:
> 
>   DMA-API: xhci_hcd 0000:00:14.0: mapping sg segment longer than device claims to support [len=98304] [max=65536]
> 
> Explicitly set up the DMA max segment size for avoiding spurious kernel
> warnings.
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  drivers/media/usb/uvc/uvc_video.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 1b4cc934109e..25aa6e6a6906 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -2160,6 +2160,8 @@ int uvc_video_init(struct uvc_streaming *stream)
>  	for_each_uvc_urb(uvc_urb, stream)
>  		INIT_WORK(&uvc_urb->work, uvc_video_copy_data_work);
>  
> +	dma_set_max_seg_size(uvc_stream_to_dmadev(stream), UINT_MAX);
> +

uvc_stream_to_dmadev() returns the pointer to the HCD's struct device,
which is shared between all drivers on the bus. Is it really fine for a
USB device driver to change the maximum segment size of the HCD device
directly ?

>  	return 0;
>  }
>
Greg Kroah-Hartman June 10, 2022, 8:57 a.m. UTC | #2
On Thu, Jun 09, 2022 at 12:18:30PM +0300, Laurent Pinchart wrote:
> Hi Takashi,
> 
> (CC'ing Greg and the linux-usb mailing list)
> 
> Thank you for the patch.
> 
> On Thu, Jun 09, 2022 at 10:22:46AM +0200, Takashi Iwai wrote:
> > As default, the DMA max segment size is set to 64k, and uvcvideo may
> > overflow that size easily, resulting in a warning like:
> > 
> >   DMA-API: xhci_hcd 0000:00:14.0: mapping sg segment longer than device claims to support [len=98304] [max=65536]
> > 
> > Explicitly set up the DMA max segment size for avoiding spurious kernel
> > warnings.
> > 
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >  drivers/media/usb/uvc/uvc_video.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > index 1b4cc934109e..25aa6e6a6906 100644
> > --- a/drivers/media/usb/uvc/uvc_video.c
> > +++ b/drivers/media/usb/uvc/uvc_video.c
> > @@ -2160,6 +2160,8 @@ int uvc_video_init(struct uvc_streaming *stream)
> >  	for_each_uvc_urb(uvc_urb, stream)
> >  		INIT_WORK(&uvc_urb->work, uvc_video_copy_data_work);
> >  
> > +	dma_set_max_seg_size(uvc_stream_to_dmadev(stream), UINT_MAX);
> > +
> 
> uvc_stream_to_dmadev() returns the pointer to the HCD's struct device,
> which is shared between all drivers on the bus. Is it really fine for a
> USB device driver to change the maximum segment size of the HCD device
> directly ?

Ick, no!  That feels wrong, it should only change things for that one
specific device, not all devices on that bus.

thanks,

greg k-h
Takashi Iwai June 10, 2022, 11:13 a.m. UTC | #3
On Fri, 10 Jun 2022 10:57:40 +0200,
Greg Kroah-Hartman wrote:
> 
> On Thu, Jun 09, 2022 at 12:18:30PM +0300, Laurent Pinchart wrote:
> > Hi Takashi,
> > 
> > (CC'ing Greg and the linux-usb mailing list)
> > 
> > Thank you for the patch.
> > 
> > On Thu, Jun 09, 2022 at 10:22:46AM +0200, Takashi Iwai wrote:
> > > As default, the DMA max segment size is set to 64k, and uvcvideo may
> > > overflow that size easily, resulting in a warning like:
> > > 
> > >   DMA-API: xhci_hcd 0000:00:14.0: mapping sg segment longer than device claims to support [len=98304] [max=65536]
> > > 
> > > Explicitly set up the DMA max segment size for avoiding spurious kernel
> > > warnings.
> > > 
> > > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > > ---
> > >  drivers/media/usb/uvc/uvc_video.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > > index 1b4cc934109e..25aa6e6a6906 100644
> > > --- a/drivers/media/usb/uvc/uvc_video.c
> > > +++ b/drivers/media/usb/uvc/uvc_video.c
> > > @@ -2160,6 +2160,8 @@ int uvc_video_init(struct uvc_streaming *stream)
> > >  	for_each_uvc_urb(uvc_urb, stream)
> > >  		INIT_WORK(&uvc_urb->work, uvc_video_copy_data_work);
> > >  
> > > +	dma_set_max_seg_size(uvc_stream_to_dmadev(stream), UINT_MAX);
> > > +
> > 
> > uvc_stream_to_dmadev() returns the pointer to the HCD's struct device,
> > which is shared between all drivers on the bus. Is it really fine for a
> > USB device driver to change the maximum segment size of the HCD device
> > directly ?
> 
> Ick, no!  That feels wrong, it should only change things for that one
> specific device, not all devices on that bus.

Hrm, indeed, that points to the HCD.  This made me wonder, though,
whether the current usage of dma_*sgtable() with that device is OK or
not.  The warning came from that code path, after all...


Takashi
diff mbox series

Patch

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 1b4cc934109e..25aa6e6a6906 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -2160,6 +2160,8 @@  int uvc_video_init(struct uvc_streaming *stream)
 	for_each_uvc_urb(uvc_urb, stream)
 		INIT_WORK(&uvc_urb->work, uvc_video_copy_data_work);
 
+	dma_set_max_seg_size(uvc_stream_to_dmadev(stream), UINT_MAX);
+
 	return 0;
 }