With er_events_cnt == er_size - 1, pci_xhci_insert_event() decided
whether the ring is full from the cycle bit of the TRB at the enqueue
slot. That TRB is from the previous lap (or zero on the first one), so
its cycle bit never matches the producer's and the event went into the
last free slot without being counted: the count then said one less than
the ring held, and the next event overwrote a TRB the guest had not
consumed yet. When the Event Ring Full Error was written at the end of
the segment, the producer cycle state was not toggled either.
Follow xHCI 4.9.4: keep one slot for the Event Ring Full Error, post it
there when the ring is otherwise full, and toggle the cycle state on a
wrap as for any other event.
Together with the unlocked hci_intr path (D60432) this showed up as
Windows 10 stopping the tablet's endpoint and resetting the controller
under fast mouse input over VNC/RDP.
Signed-off-by: Wanpeng Qian <wanpengqian@gmail.com>
Sponsored by: keelos.dev