Re: [PATCH v2 -next] usb: xhci: disable irq during initialization

From: Mathias Nyman
Date: Wed Jun 15 2022 - 10:31:19 EST


On 15.6.2022 12.07, Hongyu Xie wrote:
irq is disabled in xhci_quiesce(called by xhci_halt, with bit:2 cleared
in USBCMD register), but xhci_run(called by usb_add_hcd) re-enable it.
It's possible that you will receive thousands of interrupt requests
after initialization for 2.0 roothub. And you will get a lot of
warning like, "xHCI dying, ignoring interrupt. Shouldn't IRQs be
disabled?". This amount of interrupt requests will cause the entire
system to freeze.
This problem was first found on a device with ASM2142 host controller
on it
I see, makes sense to enable interrupts as close as possible to where we
start the host.

For some unknown reason xHCI specification recommends enabling interrupts
(INTE and IE bits) before setting the Run/Stop bit, see xhci 4.2
Host Controller Initialization, "Note" part

So the order here needs to be swapped to comply with spec.
This unfortunately also creates a small window where xHC can interrupt
before xHC is running, but it's better than current situation.

This small window could be solved by protecting this part with a
spin_lock_irqsave().

Thanks
-Mathias