max3421: a control transfer submitted right after a control timeout overwrites the pending abort
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c
- Domain
- backend-api-design, embedded-iot
Research direction
Start with src/host/usbh.c and hcd_max3421.c, tracing the control timeout, abort, and setup paths cited in the issue. Check how EP0 state and busy_lock behave when a new transfer is submitted before HXFRDN retires the abort. The fix should prevent the replacement SETUP from being lost or a late completion from advancing the replacement; the proposed HIL case on metro_m4_express could confirm this.
Written by the indexing model from the issue text.
Description
Greptile raised this in adafruit/Adafruit_TinyUSB_Arduino#615, the vendored sync of d543126c5. I checked it against
26adc208a (src/host/usbh.c and hcd_max3421.c are unchanged on current master).
Related: #4070 lists max3421 as aborting an active transfer, which this contradicts. #4472 plans HIL abort tests.
Trigger
On a MAX3421 host, a device NAKs a control stage for longer than CFG_TUH_CONTROL_TIMEOUT_MS. A new control transfer
to the same address is then submitted before the next HXFRDN, either from the TIMEOUT complete_cb or by
control_xfer_dispatch_pending() on the next loop pass.
Causal path
usbh.c:2433-2434:control_xfer_timeout_expired()callshcd_edpt_abort_xfer(), then
control_xfer_complete(TIMEOUT)straight away. That sets the slot IDLE and calls the callback (:1200-1203). A
resubmit reacheshcd_setup_send()at:1102, or at:1172through the dispatch at:913-915.hcd_max3421.c:765-768: the abort only setsEP_STATE_ABORTING, which takes effect on the next NAK
(:901-903).hcd_max3421.c:781-799:hcd_setup_send()overwrites the shared EP0 entry withEP_STATE_ATTEMPT_1. The NAK loop
still holdsbusy_lock, so no SETUP is launched.hcd_max3421.c:905-908: the next NAK re-writes the cached_hcd_data.hxfrof the old stage. The MAX3421E
Programming Guide (p10, p56) says every retry is a CPU write of HXFR; the chip has no hardware abort.
Consequence
- The replacement's SETUP never goes on the wire, and while the device keeps NAKing it times out too.
- If the device later ACKs the old IN, RCVDAV (
hcd_max3421.c:1066-1072) writes up to 8 bytes into
_usbh_epbuf.request.usbh_control_xfer_cb()(usbh.c:1216,:1249-1254) treats that completion as the SETUP
and starts the data stage with a corruptedwLengthand direction. - A late zero-length status completion can likewise advance the replacement past a SETUP the device never received.
Fix direction
Keep the slot unavailable until the abort retires, or make hcd_setup_send() defer a new SETUP while EP0 is
EP_STATE_ABORTING and busy_lock is held.
Uncertain
- Not reproduced on hardware.
- The window depends on the gap between the abort and the next HXFRDN. It is wider where the MAX3421 interrupt is
serviced from a task, as in the ESP32 BSP. - The corruption branch needs a device that answers the old IN after the timeout.
- A HIL case with a NAK-forever EP0 fixture on metro_m4_express would confirm it.
- Dominant language
- C
- Stars
- 7.3k
- Forks
- 1.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 67
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from hathach/tinyusb
-
follow-up Port WCH USBFS Prio 📌
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
follow-up Prio 📌
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
hil-contract: a background hil_remote.py launch is killed at the Bash default 10 min timeoutPossibly taken @hathach claimed this 16 days ago. Openfollow-up Prio 📌
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
ch32v30x: debug UART loses queued bytes when its TX ring fillsPossibly taken @hathach claimed this 16 days ago. Openfollow-up Prio 📌
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
followup Prio 📌
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
-
Missing slice offset check in jvp_equal fast path corrupts slice comparison and aborts delpathsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 83/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
area9innovation/flow9#1805 ·
Maintainers usually reply within 3 days
-
AI:Robustness triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
open5gs/open5gs#5246 · 1 comment ·
Maintainers usually reply within 1 day