Skip to content

usb: xhci: implement non-blocking interrupt IN transfers to fix GRUB stalls - #81

Merged
DjDeveloperr merged 2 commits into
aurora-wipfrom
fix/xhci-nonblock-int
Dec 1, 2026
Merged

DjDeveloperr merged 2 commits into
aurora-wipfrom
fix/xhci-nonblock-int

Conversation

@sithglan

@sithglan sithglan commented Nov 30, 2026 •

Copy link
Copy Markdown

What: Implement non-blocking xHCI Interrupt IN transfers (_xhci_submit_int_msg(..., nonblock = true)) and clamp overdue periodic EFI timers (lib/efi_loader/efi_boottime.c) so an attached idle USB keyboard no longer stalls GRUB kernel/initrd reads for ~2 minutes on Apple Silicon.
Tested: Mac mini (M1, J274) at exact head e7aecd4a (2026.07-ge7aecd4ae83a) with 05ac:024f Apple Aluminium Keyboard (zero keystrokes during boot, Stage 1 1.0.0b17-ga2ad0085, Stage 2 1.0.0b17-g749dd6de, Linux 7.3.0-j313-272+): PASS — systemctl reboot -> kernel t=0 dropped from 125.1 s / 125.3 s (stock 84382f65f672) to 25.3 s (100.0 s saved, 5.0x faster), 0 failed systemd units, keyboard enumerated cleanly in Linux. Cross-built apple_m1_defconfig and apple_j873_defconfig with CONFIG_WERROR=y (0 warnings).
Risk: two-way · all Macs with USB keyboards attached to xHCI in U-Boot (scoped to non-blocking Interrupt IN polling and overdue periodic EFI timer advancement; blocking interrupt, bulk, and control transfers retain their existing path).
Not yet: Non-M1 Apple Silicon models with USB keyboards attached.

Details

Problem

On Apple Silicon systems with an attached USB keyboard (for example a Mac mini with 05ac:024f Apple Aluminium Keyboard), loading the Linux kernel and initrd in GRUB over U-Boot EFI takes ~2 minutes unless keys are continuously pressed on the keyboard.

Root cause:

  1. Each GRUB EFI_BLOCK_IO_PROTOCOL.ReadBlocks() chunk calls efi_timer_check() (lib/efi_loader/efi_disk.c), which fires the 5 us periodic console_timer_event -> efi_cin_check() -> tstc() -> usb_kbd_testc() (~every 20 ms) -> usb_int_msg(..., nonblock = true).
  2. _xhci_submit_int_msg() (drivers/usb/host/xhci.c) ignored bool nonblock and delegated directly to xhci_bulk_tx(), which busy-waited XHCI_TIMEOUT (5000 ms) and called abort_td() whenever an idle USB keyboard NAKed the Interrupt IN transfer. Pressing keys caused the keyboard to return an 8-byte HID report immediately (and set key_available = true, short-circuiting tstc()), masking the stall.
  3. In lib/efi_loader/efi_boottime.c, efi_timer_check() advanced periodic timers by a single evt->trigger_next += evt->trigger_time step, leaving overdue 5 us periodic timers permanently behind now after any multi-millisecond I/O.

Change

  1. usb: xhci: implement non-blocking interrupt IN transfers (include/usb/xhci.h, drivers/usb/host/xhci.c, drivers/usb/host/xhci-ring.c, drivers/usb/host/xhci-mem.c):
    • Add per-endpoint non-blocking Interrupt IN state (int_buf, int_dma, int_len, int_buf_size, int_act_len, int_status, int_pending, int_ready) to struct xhci_virt_ep.
    • Implement xhci_int_tx(), xhci_int_arm(), xhci_drain_int_events(), and xhci_stash_int_event(): keep a single Interrupt IN TRB armed on the endpoint ring with a DMA-coherent bounce buffer, drain completed events without blocking, and return -EAGAIN immediately when no HID report is ready.
    • Stash interleaved interrupt transfer completions observed while waiting on control, bulk, command, or abort_td() events so concurrent transfers never trip BUG_ON or lose keypresses.
    • Abort any pending non-blocking TRB if a caller later issues a blocking transfer on the same endpoint, and unmap/free int_buf in xhci_free_virt_devices() (invoked after xhci_lowlevel_stop() resets the controller).
  2. efi_loader: advance overdue periodic timers past current time (lib/efi_loader/efi_boottime.c):
    • Clamp overdue EFI_TIMER_PERIODIC deadlines to now + evt->trigger_time instead of falling behind by one 5 us tick per call.

The USB keyboard driver polls keyboards with usb_int_msg(..., nonblock = true)
from tstc() / efi_cin_check() every ~20 ms, including inside GRUB's
EFI_BLOCK_IO_PROTOCOL.ReadBlocks() disk reads via efi_timer_check().

Previously _xhci_submit_int_msg() ignored the nonblock flag and delegated to
xhci_bulk_tx(), which busy-waited XHCI_TIMEOUT (5 seconds) and aborted the TD
whenever an idle USB keyboard NAKed the Interrupt IN transfer. On systems with
an attached USB keyboard (such as Apple Mac mini with 05ac:024f Apple Aluminium
Keyboard), every GRUB read stalled for 5 seconds unless keys were pressed to
satisfy the pending Interrupt IN transfer.

Keep a single persistent Interrupt IN TRB armed per endpoint on xhci_int_tx()
with a DMA-coherent bounce buffer, draining completed events without blocking
and returning -EAGAIN immediately when idle. Stash any interleaved interrupt
completions observed during control, bulk, command, or abort_td event waits so
concurrent transfers never trip BUG_ON or drop keypresses, and release the
bounce buffer in xhci_free_virt_devices().

Signed-off-by: Thomas Glanzmann <[email protected]>
efi_timer_check() previously advanced periodic timers with a single
evt->trigger_next += evt->trigger_time step. After any pause longer than
trigger_time (for example a 5 us console poll timer after a multi-millisecond
disk I/O), trigger_next remained behind now and the callback fired on every
single efi_timer_check() invocation until it caught up.

Clamp periodic timers whose next deadline is still <= now to
now + evt->trigger_time.

Signed-off-by: Thomas Glanzmann <[email protected]>
@github-actions github-actions Bot added door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks required sections (bot) labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Merge readiness at e7aecd4a: ready to merge

Check Detail
CI at head ok 2 checks passed
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok in the PR body at e7aecd4a
Conflicts ok none
PR text ok Risk: two-way · all Macs with USB keyboards attached to xHCI in U-Boot (scoped to non-blocking Interrupt IN polling and overdue periodic EFI timer advancement; blocking interrupt, bulk, and control transfers retain their existing path).

Areas: none matched in CODEOWNERS
Merge: gh pr merge 81 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot added blast:all Macs affected, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks required sections (bot) labels Nov 30, 2026
@sithglan

Copy link
Copy Markdown
Author

Tested exact head e7aecd4ae83a on J313 (MacBook Air M1) as a no-regression EFI/U-Boot boot check (with one-shot aura-try replacing only the U-Boot payload in Stage 2):

  • Machine / Boot: J313 (air), Stage 2 aura 1.0.0b17-gf52d8324 / U-Boot 2026.07-ge7aecd4ae83a, EFI v2.11 -> GRUB -> Linux 7.3.0-j313-sgv2+.
  • Result: PASS (no-regression boot check). Clean boot into Debian, /proc/device-tree/chosen/aurora,trial = aurora/stage2-j313-uboot-pr81.bin, internal SPI HID keyboard/trackpad operational, speakerguardd-v2 active, 0 new failed systemd units and 0 new kernel boot errors.
  • Note on scope: J313 uses the built-in SPI keyboard/trackpad (no USB keyboard attached for interactive GRUB xHCI/EFI-input testing), and T8152/M6 (J873g) U-Boot does not enable xHCI/NVMe/EFI OS boot yet; the J274 USB-keyboard + GRUB navigation coverage in the PR description remains the primary functional verification.
  • Stock return: Removed /boot/efi/aura-try and temporary trial stage2, rebooted cleanly back to stock U-Boot 2026.07-g84382f65f672 (chosen/aurora,trial absent, speakerguardd-v2 active).

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nonblocking interrupt-IN path keeps a single transfer armed and routes its completions separately from bulk and control traffic. The J274 row demonstrates the GRUB boot-time improvement, and the M1 and J873 builds passed with WERROR.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@DjDeveloperr
DjDeveloperr merged commit 5c0d5fe into aurora-wip Dec 1, 2026
4 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/xhci-nonblock-int branch December 1, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants