* [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 @ 2026-11-19 11:44 Yasunobu Sakashita via B4 Relay 2026-11-19 11:54 ` sashiko-bot 2026-11-19 12:06 ` Ricardo Ribalda 0 siblings, 2 replies; 6+ messages in thread From: Yasunobu Sakashita via B4 Relay @ 2026-11-19 11:44 UTC (permalink / raw) To: linux-media Cc: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab, Mathias Nyman, linux-usb, Yasunobu Sakashita 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); + } flush_workqueue(stream->async_wq); --- base-commit: aa0f4c41d4870a18e65772a1817af16427200371 change-id: 20261119-streamcam-batched-unlink-fb4a6e39626e Best regards, -- Yasunobu Sakashita <hi@yasunobu.dev> ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 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 1 sibling, 0 replies; 6+ messages in thread From: sashiko-bot @ 2026-11-19 11:54 UTC (permalink / raw) To: Yasunobu Sakashita; +Cc: linux-usb, media-ci Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] media: uvcvideo: uvc_streamcam_batch_unlink() skips suspend and over-scopes IDs -- commit f1a098ca74da80c22f81d063591bc26d9db211f8 Author: Yasunobu Sakashita <hi@yasunobu.dev> media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 This commit batches URB unlinks before waiting in uvc_video_stop_transfer() when stopping a Logitech StreamCam attached to an ASMedia ASM2142 xHCI controller on an ASUS PRIME Z270-A motherboard. > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > index a92a986ab714b..0ee5a7d175032 100644 > --- a/drivers/media/usb/uvc/uvc_video.c > +++ b/drivers/media/usb/uvc/uvc_video.c [ ... ] > @@ -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); > + } [Severity: Medium] Does checking stream->frozen in uvc_streamcam_batch_unlink() leave the suspend path exposed to the same xHCI halt? uvc_video_suspend() sets stream->frozen = 1 immediately before calling uvc_video_stop_transfer(), so suspending while streaming falls back to the unbatched usb_poison_urb() loop. Also, restricting this to a single USB device ID and motherboard PCI subsystem ID leaves the ASM2142 host controller exposed on other boards and cameras. In uvc_video_complete(), stream->frozen is currently checked only for -ENOENT before falling through to -ECONNRESET: drivers/media/usb/uvc/uvc_video.c:uvc_video_complete() { ... case -ENOENT: /* usb_poison_urb() called. */ if (stream->frozen) return; fallthrough; case -ECONNRESET: /* usb_unlink_urb() called. */ ... } If uvc_video_complete() checks stream->frozen for both -ENOENT and -ECONNRESET, uvc_video_stop_transfer() can block, unlink, and poison all URBs unconditionally without PCI or USB ID checks. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261119-streamcam-batched-unlink-v1-1-076bc02866c1@yasunobu.dev?part=1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 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 2026-11-19 13:19 ` Michal Pecio 1 sibling, 2 replies; 6+ messages in thread From: Ricardo Ribalda @ 2026-11-19 12:06 UTC (permalink / raw) To: hi, Michal Pecio Cc: linux-media, Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab, Mathias Nyman, linux-usb Hi Yasunobu Thanks for your patch On Thu, 19 Nov 2026 at 12:47, Yasunobu Sakashita via B4 Relay <devnull+hi.yasunobu.dev@kernel.org> 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? Thanks! > flush_workqueue(stream->async_wq); > > > --- > base-commit: aa0f4c41d4870a18e65772a1817af16427200371 > change-id: 20261119-streamcam-batched-unlink-fb4a6e39626e > > Best regards, > -- > Yasunobu Sakashita <hi@yasunobu.dev> > > > -- Ricardo Ribalda ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 2026-11-19 12:06 ` Ricardo Ribalda @ 2026-11-19 12:43 ` Laurent Pinchart 2026-11-19 13:08 ` hi 2026-11-19 13:19 ` Michal Pecio 1 sibling, 1 reply; 6+ messages in thread From: Laurent Pinchart @ 2026-11-19 12:43 UTC (permalink / raw) To: Ricardo Ribalda Cc: hi, Michal Pecio, linux-media, Hans de Goede, Mauro Carvalho Chehab, Mathias Nyman, linux-usb 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 2026-11-19 12:43 ` Laurent Pinchart @ 2026-11-19 13:08 ` hi 0 siblings, 0 replies; 6+ messages in thread From: hi @ 2026-11-19 13:08 UTC (permalink / raw) To: Laurent Pinchart Cc: Ricardo Ribalda, Michal Pecio, linux-media, Hans de Goede, Mauro Carvalho Chehab, Mathias Nyman, linux-usb On Thu, Nov 19, 2026, Laurent Pinchart wrote: > On Thu, Nov 19, 2026 at 01:06:50PM +0100, Ricardo Ribalda wrote: > > Could you check if your device works fine on 7.3, or if it still crashes? Thanks for the quick replies. I tested 7.3.5 on the same USB-C port, and the xHCI hang did not recur. > This looks like something that should be fixed at the USB level, unless > proven impossible. I agree the fix belongs at the USB level, so I'll drop the patch. I appreciate your help with my first Linux kernel contribution. I hope to contribute again. Yasunobu ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 2026-11-19 12:06 ` Ricardo Ribalda 2026-11-19 12:43 ` Laurent Pinchart @ 2026-11-19 13:19 ` Michal Pecio 1 sibling, 0 replies; 6+ messages in thread From: Michal Pecio @ 2026-11-19 13:19 UTC (permalink / raw) To: Ricardo Ribalda Cc: hi, linux-media, Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab, Mathias Nyman, linux-usb On Thu, 19 Nov 2026 13:06:50 +0100, Ricardo Ribalda wrote: > On Thu, 19 Nov 2026 at 12:47, Yasunobu Sakashita via B4 Relay > <devnull+hi.yasunobu.dev@kernel.org> 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. Hi Yasunobu, I'm curious what's your general experience with SuperSpeed isochronous cameras on ASM2142 (or ASM3142 - same IDs, not sure what difference). Does it work, including in high resolution uncompressed video modes? In my experience with one no-name USB3 camera, ASMedia contrellers worked poorly in general, which is why I haven't bothered upstreaming this compatibility hack. Could you post "lsusb -v" of this camera? Preferably with usbutils v019 or newer. > > > > 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; > > +} > > + This shouldn't be unnecessary, the alternative unlinking logic is unlikely to cause compatibility issues with any hardware. > > /* > > * 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); For the record, the objective of this ugly code was to hopefully preserve the same guarantees to the UVC driver as the original, while avoiding repeatedly stopping and restarting the xHCI endpoint, which occurs because usb_poison_urb() forces unlink of urb N to complete before unlink of urb N+1 can begin. I don't claim that this is the best or the only solution. > > + } 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/ Yes, LLMs got pretty good at stealing test patches from maling lists. > 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.) To be exact, 7.3 solved interrupt endpoint crashes on ASMedia and isochronous endpoint crashes on VIA. I haven't tested isochronous on ASMedia, but now I will, subject to the limitation that my camera barely works with those controllers at all. > Michal, would you recommend applying something like what you proposed > in your email, or would you rather fix this at the USB level? Other than bloat, the UVC change should be harmless and it makes unlinking multiple URBs somewhat wore efficient and faster. But it does make the code longer and weirder. If there is a need, perhaps USB core could provide a new usb_nuke_endpoint() call. I'm also curious to hear whether the 7.3 changes or this patch affect the Intel+Razer case (linked above). Regards, Michal ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-19 13:20 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2026-11-19 13:08 ` hi 2026-11-19 13:19 ` Michal Pecio
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox