From: JP Hein <jp@jphein.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Hans de Goede <hansg@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-media@vger.kernel.org, linux-usb@vger.kernel.org,
stable@vger.kernel.org, JP Hein <jp@jphein.com>
Subject: [PATCH v3 2/3] media: uvcvideo: add UVC_QUIRK_CTRL_THROTTLE for fragile firmware
Date: Sun, 22 Mar 2026 15:09:39 -0700 [thread overview]
Message-ID: <20260322220940.1462189-3-jp@jphein.com> (raw)
In-Reply-To: <20260322220940.1462189-1-jp@jphein.com>
Some USB webcams have firmware that crashes when it receives rapid
consecutive UVC control transfers (SET_CUR). The Razer Kiyo Pro
(1532:0e05) is one such device -- after several hundred rapid control
changes over a few seconds, the device stops responding entirely,
triggering an xHCI stop-endpoint command timeout that causes the host
controller to be declared dead, disconnecting every USB device on the
bus.
The failure is amplified by the standard UVC error-code query: when a
SET_CUR fails with EPIPE, the driver sends a second transfer (GET_CUR
on UVC_VC_REQUEST_ERROR_CODE_CONTROL) to read the UVC error code. On a
device that is already stalling, this second transfer pushes the
firmware into a full lockup.
Introduce UVC_QUIRK_CTRL_THROTTLE (0x00080000) to address both issues:
- Enforce a minimum 50ms interval between SET_CUR control transfers,
preventing the rapid-fire pattern that overwhelms the firmware.
50ms allows up to 20 control changes per second, which is sufficient
for interactive slider adjustments while keeping the device stable.
- Skip the UVC_VC_REQUEST_ERROR_CODE_CONTROL query after EPIPE errors
on devices with this quirk. EPIPE is returned directly without the
follow-up query that would amplify the failure.
The UVC control path is serialized by ctrl_mutex, so last_ctrl_set_jiffies
does not require additional locking.
Cc: stable@vger.kernel.org
Signed-off-by: JP Hein <jp@jphein.com>
---
drivers/media/usb/uvc/uvc_video.c | 33 +++++++++++++++++++++++++++++++++
drivers/media/usb/uvc/uvcvideo.h | 3 +++
2 files changed, 36 insertions(+)
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index XXXXXXX..XXXXXXX 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -90,5 +90,6 @@
#define UVC_QUIRK_MJPEG_NO_EOF 0x00020000
#define UVC_QUIRK_MSXU_META 0x00040000
+#define UVC_QUIRK_CTRL_THROTTLE 0x00080000
/* Format flags */
#define UVC_FMT_FLAG_COMPRESSED 0x00000001
@@ -737,5 +738,7 @@ struct uvc_device {
unsigned long warnings;
u32 quirks;
+ /* Control transfer throttling (UVC_QUIRK_CTRL_THROTTLE) */
+ unsigned long last_ctrl_set_jiffies;
int intfnum;
char name[32];
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index XXXXXXX..XXXXXXX 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -71,11 +71,34 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
u8 intfnum, u8 cs, void *data, u16 size)
{
int ret;
u8 error;
u8 tmp;
+ /*
+ * Rate-limit SET_CUR operations for devices with fragile firmware.
+ * The Razer Kiyo Pro locks up under sustained rapid SET_CUR
+ * transfers (hundreds without delay), crashing the xHCI controller.
+ */
+ if (query == UVC_SET_CUR &&
+ (dev->quirks & UVC_QUIRK_CTRL_THROTTLE)) {
+ unsigned long min_interval = msecs_to_jiffies(50);
+
+ if (dev->last_ctrl_set_jiffies &&
+ time_before(jiffies,
+ dev->last_ctrl_set_jiffies + min_interval)) {
+ unsigned long elapsed = dev->last_ctrl_set_jiffies +
+ min_interval - jiffies;
+ msleep(jiffies_to_msecs(elapsed));
+ }
+ }
+
ret = __uvc_query_ctrl(dev, query, unit, intfnum, cs, data, size,
UVC_CTRL_CONTROL_TIMEOUT);
+
+ if (query == UVC_SET_CUR &&
+ (dev->quirks & UVC_QUIRK_CTRL_THROTTLE))
+ dev->last_ctrl_set_jiffies = jiffies;
+
if (likely(ret == size))
return 0;
@@ -107,8 +130,18 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
return ret < 0 ? ret : -EPIPE;
}
+ /*
+ * Skip the error code query for devices that crash under load.
+ * The standard error-code query (GET_CUR on
+ * UVC_VC_REQUEST_ERROR_CODE_CONTROL) sends a second USB transfer to
+ * a device that is already stalling, which can amplify the failure
+ * into a full firmware lockup and xHCI controller death.
+ */
+ if (dev->quirks & UVC_QUIRK_CTRL_THROTTLE)
+ return -EPIPE;
+
/* Reuse data[0] to request the error code. */
tmp = *(u8 *)data;
ret = __uvc_query_ctrl(dev, UVC_GET_CUR, 0, intfnum,
UVC_VC_REQUEST_ERROR_CODE_CONTROL, data, 1,
--
2.43.0
next prev parent reply other threads:[~2026-03-22 22:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-22 22:09 [PATCH v3 0/3] USB/UVC: Add quirks to prevent Razer Kiyo Pro xHCI cascade failure JP Hein
2026-03-22 22:09 ` [PATCH v3 1/3] USB: core: add NO_LPM quirk for Razer Kiyo Pro webcam JP Hein
2026-03-22 22:09 ` JP Hein [this message]
2026-03-22 22:09 ` [PATCH v3 3/3] media: uvcvideo: add quirks " JP Hein
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=20260322220940.1462189-3-jp@jphein.com \
--to=jp@jphein.com \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.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