Repository navigation
usb: xhci: implement non-blocking interrupt IN transfers to fix GRUB stalls - #81
Merged
Merged
Conversation
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]>
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
Author
|
Tested exact head
|
RyanTheTide
approved these changes
Dec 1, 2026
RyanTheTide
left a comment
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) with05ac:024fApple Aluminium Keyboard (zero keystrokes during boot, Stage 11.0.0b17-ga2ad0085, Stage 21.0.0b17-g749dd6de, Linux7.3.0-j313-272+): PASS —systemctl reboot-> kernelt=0dropped from125.1 s/125.3 s(stock84382f65f672) to25.3 s(100.0 ssaved, 5.0x faster),0failed systemd units, keyboard enumerated cleanly in Linux. Cross-builtapple_m1_defconfigandapple_j873_defconfigwithCONFIG_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:024fApple 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:
EFI_BLOCK_IO_PROTOCOL.ReadBlocks()chunk callsefi_timer_check()(lib/efi_loader/efi_disk.c), which fires the 5 us periodicconsole_timer_event->efi_cin_check()->tstc()->usb_kbd_testc()(~every 20 ms) ->usb_int_msg(..., nonblock = true)._xhci_submit_int_msg()(drivers/usb/host/xhci.c) ignoredbool nonblockand delegated directly toxhci_bulk_tx(), which busy-waitedXHCI_TIMEOUT(5000 ms) and calledabort_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 setkey_available = true, short-circuitingtstc()), masking the stall.lib/efi_loader/efi_boottime.c,efi_timer_check()advanced periodic timers by a singleevt->trigger_next += evt->trigger_timestep, leaving overdue 5 us periodic timers permanently behindnowafter any multi-millisecond I/O.Change
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):int_buf,int_dma,int_len,int_buf_size,int_act_len,int_status,int_pending,int_ready) tostruct xhci_virt_ep.xhci_int_tx(),xhci_int_arm(),xhci_drain_int_events(), andxhci_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-EAGAINimmediately when no HID report is ready.abort_td()events so concurrent transfers never tripBUG_ONor lose keypresses.int_bufinxhci_free_virt_devices()(invoked afterxhci_lowlevel_stop()resets the controller).efi_loader: advance overdue periodic timers past current time(lib/efi_loader/efi_boottime.c):EFI_TIMER_PERIODICdeadlines tonow + evt->trigger_timeinstead of falling behind by one 5 us tick per call.