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=1796350040; b=rSkWJEwupebxq0G2E6es+IG+2nhNmGaa2aXLETKvfHZpYWLw6xSPZIy3o4Z07cVI17eQ 6zyqyiaAiZ4/MmjTb7JGlHtUdReqKNg/rVcEaHgkcofNu5RjftD6JbaKNp6KeGWAXbXJT hxZgyYuGPpMQZrGba7ylkpvJr5xHzKWruHik8tGOBpaVUTZEhCJK8rjP30bUgU9fioOF2 RnmkfXJxU7WpqlXtsmHC1G6lmwYHUPW5jGytwPHLqWxxmWdNXvhJ5Iy7A6pTfvLxNzm6H vczTJUU2lwLbPAgfJBj7RnY9F3rZti1PlJ0jldeKqk+JUZc8MCUJn0dpzbjxAboEIwA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796350040; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=J4s9T7X/qAan6eYTtJUXrwOti6F3rgeIkmVjC+WbZPo=; b=X1VUbV0Wn2IzU5ICODpqousIlOnLatI+ZeXdiG/slJPXMqMU1jySS0RU8rm1UwGoZIDO YodD+YrAm+Tw06wCXHqDb6bRXUx6nKiRJdaX9G8K/tx8LU+icv/GhHycZqCgnlp+xMCx0 XXuuicQ6dh0oSxDRps8lq3+6+P1rgUi4XzT8Ir4cgHu1CIph9uUPT7GBlLg3tQcszkTLg PlDmeyJ2kwwNZtBPsnbsz/Y9tD4Tzbdv+ZGDegfzt5WSzXvKdvnnuE42sxDgQfsE0J3Yl Tme9itBxlfikgLM3BHeEKGDV2SeOVq0qHroSjfRS0iDL85+gzUnB8BDjr6d58O9Jz+Q== 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=jKMCQRMS; 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 6E346606A332; Fri, 4 Dec 2026 02:07:20 +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=jKMCQRMS Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC7741F000CE; Fri, 4 Dec 2026 02:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796350040; bh=J4s9T7X/qAan6eYTtJUXrwOti6F3rgeIkmVjC+WbZPo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jKMCQRMSTkvRjYqA+YMnL3jjrMQvZeZoyvhfoLBov3As2JrG43I9qRjyx+mo2NyOO +RL45xwN+Des4wDISnmKQxHrH65JZqEksXqNcmlW0zBXEtRvNDqVxO9ywIm1pYpTJj yu+BTbSAUIQp8DoquPYNePlnKTMMYtmfIhsTPHQn29X4aLukzdF4Vz3lzzKnlb5cFS 4f/EzA9vluW0kJO+HfH96LAgljgSCiv0CVEHt+5B5ywZ1898a4wMUYpaca+nKVr3aq 7OXjZbsEXLfCKRKyI/PJVpNta11EA4DqxeMm9WIUCp47tJK6gojTr/L+6PHuc6HFlY f1jT6kC65MLiw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 6/6] usb: gadget: udc: crg: Add core driver and build integration Reply-To: sashiko-reviews@lists.linux.dev To: "Petar Stepanovic" Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203-axiado-ax3000-usb-device-controller-v8-6-d5ff04febd4d@axiado.com> References: <20261203-axiado-ax3000-usb-device-controller-v8-0-d5ff04febd4d@axiado.com> <20261203-axiado-ax3000-usb-device-controller-v8-6-d5ff04febd4d@axiado.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 02:07:19 +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 8 potential issues to consider: - [High] usb: crg: missing recovery/stop checks after lock drop in event ring - [High] usb: crg: suspend re-arms DMA and resume skips hardware state restore - [Medium] usb: gadget: crg: premature usb_ep.enabled clear in crg_udc_recover_link() - [Medium] usb: gadget: crg: bounce copy and IRQ-off unmap in crg_udc_req_done() - [Medium] usb: gadget: crg: hardcoded 1 ms IMOD in crg_udc_init_event_ring() - [Medium] usb: gadget: crg: crg_gadget_irq_init() pairs IRQF_SHARED with IRQF_ONESHOT - [Low] usb: gadget: crg: crg_udc_reset() busy-waits in sleepable callers - [Low] usb: gadget: crg: data race on max_speed in crg_udc_set_speed() -- commit b35e22194ff20279fce619046adf96ac69e8667a Author: Petar Stepanovic usb: gadget: udc: crg: Add core driver and build integration This commit adds the core probe, remove, shutdown, PM, IRQ, and recovery logic for the Axiado AX3000/AX3005 UDC driver in crg-udc-core.c and wires the crg directory into Kconfig and Makefile. > diff --git a/drivers/usb/gadget/udc/crg/Makefile b/drivers/usb/gadget/udc= /crg/Makefile > new file mode 100644 > index 0000000000000..96b209fb59fc3 > --- /dev/null > +++ b/drivers/usb/gadget/udc/crg/Makefile > @@ -0,0 +1,9 @@ [ ... ] > +crg-udc-y :=3D crg-udc-core.o crg-udc-ring.o crg-udc-ep0.o crg-udc-gad= get.o [Severity: Medium] Does crg-udc-gadget.c need to bounce-copy every non-EP0 transfer and run DMA unmap, RX memcpy(), and page freeing under udc_lock with IRQs disabled? On every usb_ep_queue(), crg_udc_bounce_map_pages() allocates order-0 pages one by one (with __GFP_ZERO on RX), copies every TX payload on the CPU, and rejects pre-mapped requests with -EOPNOTSUPP. On completion, crg_udc_req_done() calls crg_udc_unmap_request() before dropping udc_lock, running dma_unmap_sgtable(), full-buffer RX memcpy(), and per-page __free_page() with local IRQs off. This causes heavy allocator churn, SuperSpeed throughput loss, and long IRQ-off stalls on every transfer. Detaching udc_req->bounce under udc_lock and unmapping/copying/freeing it after unlocking would avoid the IRQ-off stall, and mapping DMA-capable gadget buffers directly would avoid the unconditional bounce copy. > diff --git a/drivers/usb/gadget/udc/crg/crg-udc-core.c b/drivers/usb/gadg= et/udc/crg/crg-udc-core.c > new file mode 100644 > index 0000000000000..ed601ad2a23cf > --- /dev/null > +++ b/drivers/usb/gadget/udc/crg/crg-udc-core.c [ ... ] > + /* Use completed recovery or leave a pending reset to the worker. */ > + ret =3D crg_udc->suspend_recovery_result; > + if (ret =3D=3D -EINPROGRESS || (ret && !crg_udc->external_reset_pending= )) > + ret =3D crg_udc_recover(crg_udc, &flags, notify_disconnect); [ ... ] > + if (!crg_udc->gadget_stopping) { > + if (crg_udc->shutting_down || crg_udc->resetting) > + ret =3D -ESHUTDOWN; > + else if (crg_udc->gadget_driver && crg_udc->pullup_on) > + ret =3D crg_udc_set_pullup(crg_udc, true); > + } [Severity: High] Does crg_udc_resume() fail to restore hardware state after hibernation restore or power-gated suspend? DEFINE_SIMPLE_DEV_PM_OPS() binds crg_udc_resume() to .restore as well as .resume. In crg_udc_suspend(), calling crg_udc_recover() immediately reprograms DCBAP and event rings (setting hw_dma_armed =3D true) and stages CRG_CMD_INIT_EP0 right before sleep, without disabling VBUS detect, the PHY, or the clock. After register context loss, crg_udc_resume() asserts CRG_U3DC_CTRL_RUN via crg_udc_set_pullup() on zeroed registers (losing device-role mode, VBUS detect, max speed, DCBAP, event ring pointers, and the staged INIT_EP0), and crg_udc_finish_staged_ep0() reads cmd_control =3D=3D 0 and reports succ= ess. Quiescing the controller in crg_udc_suspend() and rebuilding its register state in crg_udc_resume() would handle power loss cleanly. [ ... ] > +/* Program the speed limit while the controller is stopped. */ > +int crg_udc_program_speed(struct crg_gadget_dev *crg_udc) > +{ > + u32 cfg, speed; > + > + switch (crg_udc->max_speed) { [Severity: Low] Can crg_udc_program_speed() race with crg_udc_set_speed() on crg_udc->max_speed? CPU0 CPU1 crg_udc_suspend() [no gadget] crg_udc_recover() -> timeout external_reset_pending =3D true crg_udc_kick_reset_work() return err (suspend aborted) dpm_complete() crg_udc_recovery_work() gadget_bind_driver() crg_udc_recover_external() usb_gadget_udc_set_speed() spin_lock(&udc_lock) crg_udc_set_speed() crg_udc_program_speed() crg_udc->max_speed =3D ... read crg_udc->max_speed <-- data race crg_udc_set_speed() in crg-udc-gadget.c writes crg_udc->max_speed holding only device_lock(&gadget->dev), without taking crg_udc->udc_lock. Acquiring crg_udc->udc_lock in crg_udc_set_speed() avoids the data race. [ ... ] > + for (i =3D 0; i < CRG_RING_NUM; i++) { > + ret =3D crg_udc_init_event_ring(crg_udc, i); > + if (ret) > + return ret; > + } [Severity: Medium] Is the hardcoded 1 ms interrupt moderation interval in crg_udc_init_event_ring() intentional? On every probe, reset, and recovery, crg_udc_init_event_ring() in drivers/usb/gadget/udc/crg/crg-udc-ring.c writes 4000 (4000 * 250 ns =3D 1 ms, or 8 High-Speed/SuperSpeed microframes) to &uicr->imod. That caps event interrupts at 1000/s, limiting synchronous bulk IOPS, adding up to 1 = ms RTT latency to USB Ethernet gadgets, and introducing up to 8-microframe jitter on isochronous endpoints. [ ... ] > + ret =3D crg_udc_process_event_ring(crg_udc, i, &flags); > + /* > + * The event handlers drop udc_lock, so a reset may have > + * started (resetting) or already completed and rebuilt > + * the rings (generation) while they ran. Either way > + * tmp_status and the checks below are stale. > + */ > + if (unlikely(crg_udc->resetting || crg_udc->suspended || > + crg_udc->shutting_down || > + generation !=3D crg_udc->udc_event[i].generation)) { > + spin_unlock_irqrestore(&crg_udc->udc_lock, flags); > + return; > + } [Severity: High] Can crg_udc_process_event_ring() and crg_gadget_handle_interrupt() keep handling events after crg_udc_reinit() or teardown has taken ownership? CPU0 (irq_thread) CPU1 (port_retry_work) crg_gadget_handle_interrupt() crg_udc_process_event_ring() [after 32 events] spin_unlock(&udc_lock) cond_resched() crg_udc_handle_port_status() crg_udc_reinit() controller_recovering =3D true device_state =3D RECONNECTING crg_udc_ep_nuke() spin_unlock(&udc_lock) spin_lock(&udc_lock) [resetting =3D=3D false, generation unchanged] crg_udc_handle_event() <-- runs during recovery Unlike the entry guard in crg_gadget_handle_interrupt(), the post-ring check omits controller_recovering and gadget_stopping. Inside crg_udc_process_event_ring() in crg-udc-ring.c, the post-relock checks only test generation and resetting, omitting controller_recovering, gadget_stopping, shutting_down, and suspended (and still writing uicr->erdphi/erdplo after breaking on suspended). Because crg_udc_reinit() sets controller_recovering without setting resetting or bumping udc_event[0].generation, the IRQ thread can re-enter crg_udc_handle_event() mid-reinit, completing stale EP0 transfers in crg_udc_handle_xfer_event() or W1C-clearing PORTSC bits during reinit. [ ... ] > + /* > + * IRQF_ONESHOT keeps this (level-triggered) line masked until > + * crg_udc_irq_thread() has cleared the status bits, which is the > + * correct pairing for IRQF_SHARED with a threaded handler. > + */ > + ret =3D devm_request_threaded_irq(&pdev->dev, irq, crg_udc_common_irq, > + crg_udc_irq_thread, > + IRQF_SHARED | IRQF_ONESHOT, "crg_udc", > + crg_udc); [Severity: Medium] Will pairing IRQF_SHARED with IRQF_ONESHOT break probe on shared interrupt lines and starve sibling devices? __setup_irq() returns -EBUSY when shared handlers disagree on IRQF_ONESHOT, so sharing this line with a standard non-oneshot handler such as xhci-plat fails probe. Even if a sibling accepts oneshot, keeping the irqchip line masked until crg_udc_irq_thread() finishes starves sibling devices across cond_resched() yields in crg_udc_process_event_ring() and multi-millisecond command and reset polls. If shared IRQ support is intended, mask CRG_U3DC_CTRL_IRQ_MASK in crg_udc_common_irq() under irq_lock, unmask it when crg_gadget_handle_interrupt() finishes, and drop IRQF_ONESHOT; otherwise drop IRQF_SHARED. [ ... ] > +static int crg_udc_reset(struct crg_gadget_dev *crg_udc, unsigned long *= flags, > + bool preserve_enabled) > +{ > + int ret; > + > + crg_udc_set_irq_mask(crg_udc, 0); > + crg_udc_reset_session(crg_udc); > + spin_unlock_irqrestore(&crg_udc->udc_lock, *flags); > + ret =3D crg_udc_soft_reset(crg_udc, true); > + spin_lock_irqsave(&crg_udc->udc_lock, *flags); [Severity: Low] Does crg_udc_reset() need to busy-wait in sleepable callers? Hardcoding atomic =3D true makes crg_udc_soft_reset() spin in readl_poll_timeout_atomic() for up to 20 ms total even though it already supports sleeping polls and every caller except the crg_udc_ep_disable() fallback (including crg_udc_probe(), crg_udc_suspend(), workqueues, and crg_udc_irq_thread() on cable disconnects) runs in sleepable context. In the SCHED_FIFO IRQ thread, busy-waiting blocks lower-priority tasks on that CPU for the duration of the reset. [ ... ] > + /* Keep enabled state visible if recovery fails and disconnect is owed.= */ > + ret =3D crg_udc_recover(crg_udc, flags, notify_disconnect || notify_res= et || > + crg_udc->disconnect_pending); [ ... ] > + /* A successful recovery without a new callback owns endpoint cleanup. = */ > + if (!notify_reset && !crg_udc->disconnect_pending) > + for (i =3D 2; i < CRG_NUM_EP_CX; i++) > + crg_udc_ep_clear_enabled(&crg_udc->udc_ep[i]); [Severity: Medium] Can crg_udc_recover_link() clear usb_ep.enabled on all data endpoints while driver->disconnect() is still running? If usb_ep_disable() hits a hardware timeout during driver->disconnect(), crg_udc_ep_disable() calls crg_udc_recover_endpoints() -> crg_udc_recover_link() with disconnect_callback_active set. Because both crg_udc_disconnect_needed() and crg_udc_recover_endpoints() suppress new notifications while disconnect_callback_active is true, notify_disconnect, notify_reset, and disconnect_pending are all false, causing both crg_udc_recover() and the post-recovery loop to clear usb_ep.enabled across all data endpoints. Remaining endpoints or composite functions whose disable() callbacks gate teardown on ep->enabled (such as ncm_disable() or ecm_disable()) then silently skip cleanup, leaving gadget ports attached and leaking request or descriptor state. Preserving usb_ep.enabled while disconnect_callback_active is set and clearing disabled endpoints after driver->disconnect() returns in crg_udc_notify_disconnect() avoids this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-axiado-ax3= 000-usb-device-controller-v8-0-d5ff04febd4d@axiado.com?part=3D6