From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381657; b=htAQxTkrcFKj9OyzRDcx5ULcasJu06A2w87lWfyNyAFFMlvbdYwrtq6YGw4od4j3/52E ZlL3WlRqgkCylrkVMjVgmvovEq0C0NZutvpD8/AkROQuXN9Vfow+aBsjkPBdZ0EZz5qGw sezeNabzPL4TixWfOnQUtVtIgePYOV5uicJew202Nu41nT8qWCbNc0FzYNR46QIBhWtcU L/QiR+giLFBCnjVIo33OJ5jI03eRVi7dwZMc04KrBqyqaECDnUNcg0G+7MNSfqdLPakn+ HLHcqPOSrF4uSvNB4OLTRrTATD5h3KiT4yPNbNtAGKjFKuBE5JXkHYosqBGj6oruZfQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381657; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=tao/jy0i27SdaunH+Xtaw1th9mDsya3mMSoEUbzF/yM=; b=dFO2LPKGAiNMlV5dwoZ5GtlyRdiOu4lQViM++45BsOJZ9QjPYuajgxweWR2D2R3wurUN 4f/Gw42BJYJGDxOW4SE0uxgvnjD0SSoHxzD75k4/+3vQVENyJ0rvRmjENCHbPtcDI1ayB EoQ+rEt1UfmvNBuVahZqTtYYqr4ZTsjgWWODqVDt3nvNRP03TW+0f/ftZ68KYRRZaot2H qCpLEmAfdApbgg8kgc2kWP8983G8fJG/vcytkq3cI3+NjZqKPLJbzxtHpfwGrfAAMmZQW iF0zgl3kVbKMNWjaytH+QxnLKCL/s34CEJjWrZ4zBIfSibpW817JxVjgWFbPAWHeb8A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NTciEUxH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53F46606A334 for ; Fri, 4 Dec 2026 10:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NTciEUxH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E2F11F0092C; Fri, 4 Dec 2026 10:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796381657; bh=tao/jy0i27SdaunH+Xtaw1th9mDsya3mMSoEUbzF/yM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=NTciEUxHenTg0A309rjMaYXT9/fS7Gpbg9Jjt9ckH3Rx8J6C/cMlat0J14SmWX0qw Pair6FFEYa1gq/saxJHaWrekYSRvnQX0aFjLOV3v2bxJBisSoqcoC0oRdMtlt+dQre 58YqtaSWkJDtwPvRmuq6GijMpq5Qmy+N47V2WJDIt52EttspWEilib6FJs2lxrL00n otevJWXHvhIHaak9zo1mORXDKJdEWd9dryrpT8Dxon2RlxpE2RxNEOU7jFcEUd1qVn +Qrn7i1aBTNLY3dXC5mR1fhruRtYKM4QnwD+JJroxJuT1PEO0K6kTZZizT5CAu61d2 aqOJRtrRvTSJw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH] usb: gadget: uvc: allow userspace to send status packets Reply-To: sashiko-reviews@lists.linux.dev To: "Keisuke Tsukuda" Cc: =?utf-8?b?bGludXgtdXNiQHZnZXIua2VybmVsLm9yZw==?= In-Reply-To: <20261204102506.98205-1-tkdkei@outlook.jp> References: <20261204102506.98205-1-tkdkei@outlook.jp> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 10:54:16 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] usb: gadget: uvc: stale interrupt_ep->desc on SuperSpeed reconnect - [Medium] usb: gadget: uvc: non-extensible UVCIOC_SEND_STATUS UAPI and no completion - [Medium] usb: gadget: uvc: unbind hangs on status_ready without disabling interrupt_ep - [Medium] usb: uvc: uvc_function_set_alt() skips config_ep_by_speed() on stale desc - [Medium] usb: gadget: uvc: uvc_function_unbind() waits without disabling interrupt_ep -- commit 740d5c5287a2ae908ef90a9a8ab7b974a03848e7 Author: Keisuke Tsukuda usb: gadget: uvc: allow userspace to send status packets This commit adds the UVCIOC_SEND_STATUS ioctl and its 32-bit compat handler so userspace can queue raw status packets on the optional VideoControl interrupt endpoint. It preallocates a single status request, serializes queueing with endpoint enable and disable, propagates usb_ep_enable() errors, and waits for any pending request during unbind. > diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/fun= ction/f_uvc.c > index c7ce2ce1d5db5..6cf76134853fb 100644 > --- a/drivers/usb/gadget/function/f_uvc.c > +++ b/drivers/usb/gadget/function/f_uvc.c [ ... ] > @@ -305,14 +342,20 @@ uvc_function_set_alt(struct usb_function *f, unsign= ed interface, unsigned alt) > =20 > if (uvc->enable_interrupt_ep) { > uvcg_info(f, "reset UVC interrupt endpoint\n"); > + spin_lock_irqsave(&uvc->status_ep_lock, flags); > usb_ep_disable(uvc->interrupt_ep); > + spin_unlock_irqrestore(&uvc->status_ep_lock, flags); > =20 > if (!uvc->interrupt_ep->desc) > if (config_ep_by_speed(cdev->gadget, f, > uvc->interrupt_ep)) > return -EINVAL; > =20 > - usb_ep_enable(uvc->interrupt_ep); > + spin_lock_irqsave(&uvc->status_ep_lock, flags); > + ret =3D usb_ep_enable(uvc->interrupt_ep); > + spin_unlock_irqrestore(&uvc->status_ep_lock, flags); > + if (ret) > + return ret; > } [Severity: High] Can propagating the error from usb_ep_enable() here fail SET_CONFIGURATION when reconnecting at SuperSpeed after a Full-Speed or High-Speed session? On UDCs whose ep->ops->disable() does not clear usb_ep->desc (such as cdnsp and tegra-xudc), uvc->interrupt_ep->desc remains non-NULL after disconnect, so config_ep_by_speed() is skipped and uvc->interrupt_ep->comp_desc stays NULL. During usb_ep_enable(), cdnsp_get_endpoint_max_burst() dereferences NULL comp_desc->bMaxBurst, while __tegra_xudc_ep_enable() returns -EINVAL which now aborts uvc_function_set_alt() and fails enumeration. Calling config_ep_by_speed() unconditionally, as uvc->video.ep already does, avoids both failures. [ ... ] > @@ -391,8 +435,11 @@ uvc_function_disable(struct usb_function *f) > uvc->state =3D UVC_STATE_DISCONNECTED; > =20 > usb_ep_disable(uvc->video.ep); > - if (uvc->enable_interrupt_ep) > + if (uvc->enable_interrupt_ep) { > + spin_lock_irqsave(&uvc->status_ep_lock, flags); > usb_ep_disable(uvc->interrupt_ep); > + spin_unlock_irqrestore(&uvc->status_ep_lock, flags); > + } > } [Severity: Medium] Should uvc_function_disable() also clear uvc->interrupt_ep->desc (and comp_desc) after disabling the endpoint? Because core usb_ep_disable() and UDC drivers such as tegra-xudc and dwc2 leave usb_ep->desc populated, a multi-configuration gadget that shares the same hardware endpoint across configurations can re-enable interrupt_ep with the previous configuration's stale descriptor, or fail at SuperSpeed with a stale NULL comp_desc. This matches the issue fixed for f_ecm and f_rndis in commit e5b5da96da50 ("usb: gadget: fix wrong endpoint desc"). [ ... ] > @@ -1076,6 +1145,15 @@ static void uvc_function_unbind(struct usb_configu= ration *c, > uvc->control_req =3D NULL; > kfree(uvc->control_buf); > uvc->control_buf =3D NULL; > + if (uvc->status_req) { > + /* Endpoint disable returns pending requests before unbind. */ > + wait_for_completion(&uvc->status_ready); > + kfree(uvc->status_req->buf); > + usb_ep_free_request(uvc->interrupt_ep, uvc->status_req); > + uvc->status_req =3D NULL; > + /* The same function object may be bound again. */ > + complete(&uvc->status_ready); > + } [Severity: Medium] Can wait_for_completion(&uvc->status_ready) hang forever here if an in-flight setup request re-enables uvc->interrupt_ep during configfs unbind? Unlike legacy usb_remove_function(), configfs purge_configs_funcs() invokes f->unbind() without calling f->disable(). On UDCs that do not implement udc_async_callbacks or set gadget->irq (such as tegra-xudc and renesas_usb3), an in-flight setup callback can run between usb_gadget_disconnect_locked() and gi->unbind =3D 1: CPU0 (unbind) CPU1 (EP0 setup / userspace) gadget_unbind_driver() usb_gadget_disconnect_locked() uvc_function_disable() configfs_composite_setup() uvc_function_set_alt() usb_ep_enable(interrupt_ep) configfs_composite_unbind() gi->unbind =3D 1 purge_configs_funcs() uvc_function_unbind() uvc_function_send_status() try_wait_for_completion(&status_ready) usb_ep_queue(interrupt_ep, status_req) wait_for_completion(&vdev_release_done) wait_for_completion(&status_ready) <-- hangs forever Because usb_gadget_udc_stop_locked() cannot run until uvc_function_unbind() returns, status_req is never completed and unbind wedges in uninterruptible sleep while holding configfs and gadget device locks. [Severity: Medium] Should uvc_function_unbind() explicitly disable uvc->interrupt_ep under uvc->status_ep_lock before waiting on uvc->status_ready? On UDCs such as musb (where musb_gadget_pullup() defers pullup disable to delayed work without stopping setup IRQs) and chipidea (where isr_setup_packet_handler() drops ci->lock before driver->setup() and ci_udc_pullup(0) does not synchronize IRQs), a concurrent setup request can re-enable uvc->interrupt_ep after usb_gadget_disconnect_locked(), allowing UVCIOC_SEND_STATUS to queue status_req while uvc_function_unbind() waits for the V4L2 device to close. Calling usb_ep_disable(uvc->interrupt_ep) under status_ep_lock after wait_for_completion(&vdev_release_done) cancels any pending request before wait_for_completion(&uvc->status_ready). > diff --git a/include/uapi/linux/usb/g_uvc.h b/include/uapi/linux/usb/g_uv= c.h > index 8d7824dde1b2f..cfe290b3063a6 100644 > --- a/include/uapi/linux/usb/g_uvc.h > +++ b/include/uapi/linux/usb/g_uvc.h > @@ -38,5 +38,8 @@ struct uvc_event { > }; > =20 > #define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data) > +#define UVCIOC_SEND_STATUS _IOW('U', 2, struct uvc_request_data) > + > +#define UVC_STATUS_MAX_PACKET_SIZE 16 > =20 > #endif /* __LINUX_USB_G_UVC_H */ [Severity: Medium] Should UVCIOC_SEND_STATUS use a dedicated extensible struct instead of reusing struct uvc_request_data? struct uvc_request_data uses a signed __s32 length specifically for UVCIOC_SEND_RESPONSE's EP0 stall convention and has no flags or reserved fields for future extensions without adding another ioctl. Exporting UVC_STATUS_MAX_PACKET_SIZE as 16 also locks the driver's current hardcoded wMaxPacketSize into permanent UAPI, even though UVC status packets can exceed 16 bytes if made configurable. In addition, uvc_function_status_complete() currently discards req->status without notifying userspace, so callers that receive -EBUSY while a host (such as an idle Linux 6.16+ uvcvideo host) is not polling the interrupt endpoint have no event-driven signal to resend the latest control value. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204102506.9820= 5-1-tkdkei@outlook.jp?part=3D1