Linux USB
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: hi@yasunobu.dev, Michal Pecio <michal.pecio@gmail.com>,
	linux-media@vger.kernel.org, Hans de Goede <hansg@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Mathias Nyman <mathias.nyman@intel.com>,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142
Date: Thu, 19 Nov 2026 14:43:31 +0200	[thread overview]
Message-ID: <20261119124331.GR1923307@killaraus.ideasonboard.com> (raw)
In-Reply-To: <CANiDSCsdaokL_2u_74b3ADT+U8TXskK53+k+hVA8D+PtttYEZQ@mail.gmail.com>

On Thu, Nov 19, 2026 at 01:06:50PM +0100, Ricardo Ribalda wrote:
> On Thu, 19 Nov 2026 at 12:47, Yasunobu Sakashita via B4 Relay wrote:
> >
> > From: Yasunobu Sakashita <hi@yasunobu.dev>
> >
> > Stopping a SuperSpeed StreamCam can halt xHCI on the ASUS PRIME Z270-A.
> > The fifth Stop Endpoint command timed out after an invalid type 15 event.
> >
> > For the affected StreamCam and ASM2142, block URB resubmission.
> > Queue all unlinks before waiting so xHCI can coalesce them.
> >
> > The stock driver reproduced the halt on Ubuntu 6.8.0-149-generic.
> > Three FFmpeg 720p MJPEG and audio capture cycles passed with the patch.
> >
> > I used Codex to help analyze traces and draft the patch and changelog.
> >
> > Signed-off-by: Yasunobu Sakashita <hi@yasunobu.dev>
> > ---
> > Built uvc_video.o on media-committers/next with and without CONFIG_PCI.
> > ---
> >  drivers/media/usb/uvc/uvc_video.c | 43 ++++++++++++++++++++++++++++++++++-----
> >  1 file changed, 38 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > index a92a986ab..0ee5a7d17 100644
> > --- a/drivers/media/usb/uvc/uvc_video.c
> > +++ b/drivers/media/usb/uvc/uvc_video.c
> > @@ -11,6 +11,7 @@
> >  #include <linux/kernel.h>
> >  #include <linux/list.h>
> >  #include <linux/module.h>
> > +#include <linux/pci.h>
> >  #include <linux/slab.h>
> >  #include <linux/usb.h>
> >  #include <linux/usb/hcd.h>
> > @@ -1885,6 +1886,26 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
> >         return 0;
> >  }
> >
> > +static bool uvc_streamcam_batch_unlink(const struct uvc_streaming *stream)
> > +{
> > +       const struct usb_device *udev = stream->dev->udev;
> > +       struct device *controller = udev->bus->controller;
> > +       const struct pci_dev *pdev;
> > +
> > +       if (stream->frozen || udev->state != USB_STATE_CONFIGURED ||
> > +           udev->speed != USB_SPEED_SUPER ||
> > +           le16_to_cpu(udev->descriptor.idVendor) != 0x046d ||
> > +           le16_to_cpu(udev->descriptor.idProduct) != 0x0893 ||
> > +           !controller || !dev_is_pci(controller))
> > +               return false;
> > +
> > +       pdev = to_pci_dev(controller);
> > +       return pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
> > +              pdev->device == 0x2142 &&
> > +              pdev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK &&
> > +              pdev->subsystem_device == 0x8732 && pdev->revision == 0;
> > +}
> > +
> >  /*
> >   * Uninitialize isochronous/bulk URBs and free transfer buffers.
> >   */
> > @@ -1896,12 +1917,24 @@ static void uvc_video_stop_transfer(struct uvc_streaming *stream,
> >         uvc_video_stats_stop(stream);
> >
> >         /*
> > -        * We must poison the URBs rather than kill them to ensure that even
> > -        * after the completion handler returns, any asynchronous workqueues
> > -        * will be prevented from resubmitting the URBs.
> > +        * URBs must stay blocked until the workqueue has been flushed.
> > +        * A completion handler can leave work that tries to resubmit an URB.
> >          */
> > -       for_each_uvc_urb(uvc_urb, stream)
> > -               usb_poison_urb(uvc_urb->urb);
> > +       if (uvc_streamcam_batch_unlink(stream)) {
> > +               /*
> > +                * usb_block_urb() keeps URBs blocked after usb_kill_urb().
> > +                * Queue unlinks together so xHCI can coalesce them.
> > +                */
> > +               for_each_uvc_urb(uvc_urb, stream)
> > +                       usb_block_urb(uvc_urb->urb);
> > +               for_each_uvc_urb(uvc_urb, stream)
> > +                       usb_unlink_urb(uvc_urb->urb);
> > +               for_each_uvc_urb(uvc_urb, stream)
> > +                       usb_kill_urb(uvc_urb->urb);
> > +       } else {
> > +               for_each_uvc_urb(uvc_urb, stream)
> > +                       usb_poison_urb(uvc_urb->urb);
> > +       }
> >
> 
> Michal proposed something very similar not so long ago:
> 
> https://lore.kernel.org/linux-media/20261115110132.2b0bda47.michal.pecio@gmail.com/
> 
> He also mentioned that those crashes were solved in 7.3. Could you check if your
> device works fine on 7.3, or if it still crashes?
> (Note that even if a workaround is still needed, we probably wouldn't
> want to match
> host-controller PCI IDs inside uvcvideo.)
> 
> Michal, would you recommend applying something like what you proposed in your
> email, or would you rather fix this at the USB level?

This looks like something that should be fixed at the USB level, unless
proven impossible.

> >         flush_workqueue(stream->async_wq);
> >
> >
> > ---
> > base-commit: aa0f4c41d4870a18e65772a1817af16427200371
> > change-id: 20261119-streamcam-batched-unlink-fb4a6e39626e

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2026-11-19 12:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 11:44 [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 Yasunobu Sakashita via B4 Relay
2026-11-19 11:54 ` sashiko-bot
2026-11-19 12:06 ` Ricardo Ribalda
2026-11-19 12:43   ` Laurent Pinchart [this message]
2026-11-19 13:08     ` hi

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=20261119124331.GR1923307@killaraus.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hansg@kernel.org \
    --cc=hi@yasunobu.dev \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=mchehab@kernel.org \
    --cc=michal.pecio@gmail.com \
    --cc=ribalda@chromium.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