All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <stf_xl@wp.pl>
To: "Bin Luo (University of Electronic Science and Technology of
	China)" <luob87709@gmail.com>
Cc: johannes@sipsolutions.net, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] wifi: rt2x00: prevent txstatus_timer rearm during USB uninitialize
Date: Wed, 2 Dec 2026 09:05:39 +0100	[thread overview]
Message-ID: <aw_RU6W4wGaAr7VA@wp.pl> (raw)
In-Reply-To: <20261202060652.976-1-luob87709@gmail.com>

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

      reply	other threads:[~2026-12-02  8:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  6:51 [PATCH] wifi: rt2x00: prevent txstatus_timer rearm during USB uninitialize Bin Luo (University of Electronic Science and Technology of China)
2026-12-01 16:39 ` Stanislaw Gruszka
2026-12-02  6:06 ` Bin Luo (University of Electronic Science and Technology of China)
2026-12-02  8:05   ` Stanislaw Gruszka [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw_RU6W4wGaAr7VA@wp.pl \
    --to=stf_xl@wp.pl \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luob87709@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.