max3421: a control transfer submitted right after a control timeout overwrites the pending abort

Aperta
#4,475 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug 🐞 follow-up Prio 📌

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

  1. usbh.c:2433-2434: control_xfer_timeout_expired() calls hcd_edpt_abort_xfer(), then
    control_xfer_complete(TIMEOUT) straight away. That sets the slot IDLE and calls the callback (:1200-1203). A
    resubmit reaches hcd_setup_send() at :1102, or at :1172 through the dispatch at :913-915.
  2. hcd_max3421.c:765-768: the abort only sets EP_STATE_ABORTING, which takes effect on the next NAK
    (:901-903).
  3. hcd_max3421.c:781-799: hcd_setup_send() overwrites the shared EP0 entry with EP_STATE_ATTEMPT_1. The NAK loop
    still holds busy_lock, so no SETUP is launched.
  4. hcd_max3421.c:905-908: the next NAK re-writes the cached _hcd_data.hxfr of 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 corrupted wLength and 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.
Lingua principale
C
Stelle
7.3k
Fork
1.6k
Merge medio
1g 19h
PR unite (30g)
67

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hathach/tinyusb

Tutte le issue di hathach/tinyusb

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.