Re: [PATCH] wifi: rt2x00: prevent txstatus_timer rearm during USB uninitialize

From: Stanislaw Gruszka

Date: Wed Dec 02 2026 - 03:05:53 EST


On Wed, Dec 02, 2026 at 02:06:52PM +0800, Bin Luo (University of Electronic Science and Technology of China) wrote:
> (Resending in plain text so it reaches the mailing lists.)
>
> Hi Stanislaw,
>
> On Wed, Dec 2, 2026 at 12:39 AM, Stanislaw Gruszka wrote:
> > On Thu, Nov 26, 2026 at 02:51:32PM +0800, Bin Luo (University of Electronic Science and Technology of China) wrote:
> > > rt2x00usb_uninitialize() cancels rt2x00dev->txstatus_timer before
> > > calling cancel_work_sync(&rt2x00dev->txdone_work). Because
> > > rt2800usb_work_txdone() calls rt2800usb_async_read_tx_status() and
> >
> > This is under condition:
> >
> > if (rt2800_txstatus_pending(rt2x00dev))
> >
> > which should be false at this point, or I missed something?
>
> Thanks for the review!
>
> I tested this on an unmodified v7.4-rc4 kernel in QEMU using dummy_hcd +
> raw_gadget emulating an RT2872 USB device (with kprobe tracing), and

Could you provide link to the qemu driver and tests ?

> rt2800_txstatus_pending(rt2x00dev) does indeed remain true when
> rt2x00usb_uninitialize() runs.
>
> Here is why it stays true on both sysfs unbind and physical USB disconnect:
>
> 1. rt2x00lib_remove_dev() clears DEVICE_STATE_PRESENT and calls
> rt2x00lib_disable_radio() -> rt2x00queue_flush_queues(rt2x00dev, true) ->
> rt2x00usb_flush_queue(queue, true).
> 2. Unlike rt2x00mac_flush(), rt2x00lib_disable_radio() does not set
> DEVICE_STATE_FLUSHING (and rt2x00mac_flush() returns early once
> DEVICE_STATE_PRESENT is cleared).
> 3. Without DEVICE_STATE_FLUSHING, rt2800_entry_txstatus_timeout() uses the
> 2000 ms timeout, whereas rt2x00usb_flush_queue() only loops
> 10 * msleep(50) = 500 ms before returning with "Queue 0 failed to flush".
> 4. Any TX entry whose bulk-OUT URB already completed within ~1.5 s without
> a TX_STA_FIFO report (or even a bulk-OUT URB cancelled by
> rt2x00usb_flush_entry() with ENTRY_DATA_IO_FAILED set, since
> rt2800_txstatus_timeout() does not check ENTRY_DATA_IO_FAILED) is not
> drained during the 500 ms flush, leaving Q_INDEX_DMA_DONE != Q_INDEX_DONE
> (rt2800_txstatus_pending() == true) when rt2x00usb_uninitialize() runs.
>
> Here is the observed trace on unmodified v7.4-rc4 during sysfs unbind right
> after a TX bulk-OUT URB completes without a TX_STA_FIFO entry:
>
> [ 31.778597] ieee80211 phy0: rt2x00queue_flush_queue: Warning - Queue 0 failed to flush
> [ 31.780458] ieee80211 phy0: rt2800usb_tx_sta_fifo_read_completed: Warning - TX status read failed -2
>
> rt2800usb_repro-84 [003] ... 31.778300: rt_flush_out: (rt2x00queue_flush_queue <- rt2x00usb_flush_queue)
> pr/ttyS0-42 [000] ... 31.779332: rt_timer_cb: (rt2800usb_tx_sta_fifo_timeout)
> pr/ttyS0-42 [000] ... 31.779341: rt_read_async: (rt2x00usb_register_read_async)
> rt2800usb_repro-84 [003] ... 31.779845: rt_uninit_in: (rt2x00usb_uninitialize)
> rt2800usb_repro-84 [003] ... 31.779913: rt_kill_urbs: (usb_kill_anchored_urbs)
> rt2800usb_repro-85 [000] ... 31.780198: rt_fifo_cb_in: (rt2800usb_tx_sta_fifo_read_completed) urb_status=-2
> rt2800usb_repro-85 [000] ... 31.780531: rt_pending_ret: (rt2800usb_tx_sta_fifo_read_completed+0x171 <- rt2800_txstatus_pending) ret=0x1
> rt2800usb_repro-85 [000] ... 31.780567: rt_fifo_cb_out: (rt2x00usb_register_read_async_cb <- rt2800usb_tx_sta_fifo_read_completed) ret=0x1
> rt2800usb_repro-84 [003] ... 31.781440: rt_kill_urbs_out: (rt2x00usb_uninitialize <- usb_kill_anchored_urbs)
>
> Runtime testing also highlighted two additional details worth addressing in v2:
> - At stop_reading: in rt2800usb_tx_sta_fifo_read_completed(), when
> usb_kill_anchored_urbs() cancels the URB with -ENOENT, stop_reading: sees
> rt2800_txstatus_pending() == true, re-sets TX_STATUS_READING, and returns
> true to resubmit the killed URB (which fails with -EPERM and leaves
> TX_STATUS_READING stuck set, e.g. across suspend/resume).
> - In rt2x00usb_uninitialize(), usb_kill_anchored_urbs() runs before
> hrtimer_cancel(&rt2x00dev->txstatus_timer), so a timer firing in between
> can submit a fresh async TX_STA_FIFO URB after usb_kill_anchored_urbs()
> has returned.
>
> Would you prefer that I send a v2 that also guards stop_reading: with
> DEVICE_STATE_INITIALIZED and kills anchored URBs after stopping

No, while related, this looks like different issue, I would prefer
a separate patch with own description for it.

> txdone_work/txstatus_timer, or would you also like rt2x00lib_disable_radio() /
>rt2800_txstatus_timeout() adjusted to flush pending TX entries faster?

I think assuring that tx queues are drained at the point we are canceling
work would be better fix for original problem presented.

Regards
Stanislaw