Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH wireless v3 0/2] wifi: rt2x00: fix TX queue flush and TX_STA_FIFO teardown
@ 2026-12-04  6:06 Bin Luo via B4 Relay
  2026-12-04  6:06 ` [PATCH wireless v3 1/2] wifi: rt2x00: set DEVICE_STATE_FLUSHING in rt2x00queue_flush_queues() Bin Luo via B4 Relay
  2026-12-04  6:06 ` [PATCH wireless v3 2/2] wifi: rt2x00: prevent TX_STA_FIFO URB resubmission on error and teardown Bin Luo via B4 Relay
  0 siblings, 2 replies; 3+ messages in thread
From: Bin Luo via B4 Relay @ 2026-12-04  6:06 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: Johannes Berg, linux-wireless, linux-kernel

This v3 resends the v2 series cleanly via b4 web relay (v2 was
line-wrapped by Gmail and failed to apply on Patchwork); there are no
code changes from v2.

Per Stanislaw Gruszka's review on v1:
1. Patch 1/2 sets DEVICE_STATE_FLUSHING in rt2x00queue_flush_queues()
   so pending TX entries time out within 50 ms and drain cleanly during
   disable_radio() before work/timer cancellation.
2. Patch 2/2 guards TX_STA_FIFO URB resubmission on non-zero status and
   teardown in rt2800usb and kills anchored URBs after stopping work and
   timers in rt2x00usb_uninitialize().

The QEMU dummy_hcd + raw_gadget RT2872 test harness is available at:
  https://gist.github.com/1121984919/2193f0ccb5af3539e96d55e5d43728fb

Bin Luo (University of Electronic Science and Technology of China) (2):
  wifi: rt2x00: set DEVICE_STATE_FLUSHING in rt2x00queue_flush_queues()
  wifi: rt2x00: prevent TX_STA_FIFO URB resubmission on error and teardown

 drivers/net/wireless/ralink/rt2x00/rt2800usb.c   | 24 ++++++++++++++----------
 drivers/net/wireless/ralink/rt2x00/rt2x00queue.c |  4 ++++
 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c   |  2 +-
 3 files changed, 19 insertions(+), 11 deletions(-)
-- 
2.43.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH wireless v3 1/2] wifi: rt2x00: set DEVICE_STATE_FLUSHING in rt2x00queue_flush_queues()
  2026-12-04  6:06 [PATCH wireless v3 0/2] wifi: rt2x00: fix TX queue flush and TX_STA_FIFO teardown Bin Luo via B4 Relay
@ 2026-12-04  6:06 ` Bin Luo via B4 Relay
  2026-12-04  6:06 ` [PATCH wireless v3 2/2] wifi: rt2x00: prevent TX_STA_FIFO URB resubmission on error and teardown Bin Luo via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Bin Luo via B4 Relay @ 2026-12-04  6:06 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: Johannes Berg, linux-wireless, linux-kernel

From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>

rt2x00lib_disable_radio() flushes all queues via rt2x00queue_flush_queues()
before teardown and uninitialization, but unlike rt2x00mac_flush() it does
not set DEVICE_STATE_FLUSHING.

Without DEVICE_STATE_FLUSHING, rt2800_entry_txstatus_timeout() uses the
2000 ms timeout while rt2x00usb_flush_queue() only waits 10 * 50 ms
(500 ms).  As a result, any TX entry whose bulk-OUT URB completed without
a TX_STA_FIFO report (or was cancelled by rt2x00usb_flush_entry(), since
rt2800_txstatus_timeout() gates entry into rt2800_txdone_nostatus()) is
not drained during disable_radio(), printing "Queue 0 failed to flush"
and leaving rt2800_txstatus_pending() true when rt2x00usb_uninitialize()
runs.

Set DEVICE_STATE_FLUSHING around the TX queue flush loop in
rt2x00queue_flush_queues() so pending TX entries time out after 50 ms and
are drained before work and timers are cancelled.

Fixes: adf26a356f13 ("rt2x00: use different txstatus timeouts when flushing")
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
Changes in v3:
- Resend cleanly via b4 web relay (v2 was line-wrapped by Gmail);
  no code changes from v2.

Changes in v2:
- Per Stanislaw Gruszka's review, fix the original issue by setting
  DEVICE_STATE_FLUSHING in rt2x00queue_flush_queues() so TX queues drain
  before teardown cancels work/timers, and move the separate TX_STA_FIFO
  URB error/teardown handling fix into patch 2/2.

Validation:
- scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks
- W=1 KASAN+LOCKDEP build of rt2x00queue.o: 0 warnings, 0 errors
- QEMU KVM (v7.4-rc4, KASAN+LOCKDEP) with dummy_hcd + raw_gadget
  emulating an RT2872 USB device: both sysfs unbind and physical USB
  disconnect drain Queue 0 within ~50 ms (rt2800_txstatus_pending() == 0)
  with 0 "Queue 0 failed to flush" warnings.

 drivers/net/wireless/ralink/rt2x00/rt2x00queue.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
index 4b84249..3900ef3 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
@@ -1058,9 +1058,13 @@ void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop)
 {
 	struct data_queue *queue;
 
+	set_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags);
+
 	tx_queue_for_each(rt2x00dev, queue)
 		rt2x00queue_flush_queue(queue, drop);
 
+	clear_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags);
+
 	rt2x00queue_flush_queue(rt2x00dev->rx, drop);
 }
 EXPORT_SYMBOL_GPL(rt2x00queue_flush_queues);
-- 
2.43.0




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH wireless v3 2/2] wifi: rt2x00: prevent TX_STA_FIFO URB resubmission on error and teardown
  2026-12-04  6:06 [PATCH wireless v3 0/2] wifi: rt2x00: fix TX queue flush and TX_STA_FIFO teardown Bin Luo via B4 Relay
  2026-12-04  6:06 ` [PATCH wireless v3 1/2] wifi: rt2x00: set DEVICE_STATE_FLUSHING in rt2x00queue_flush_queues() Bin Luo via B4 Relay
@ 2026-12-04  6:06 ` Bin Luo via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Bin Luo via B4 Relay @ 2026-12-04  6:06 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: Johannes Berg, linux-wireless, linux-kernel

From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>

Two TX_STA_FIFO polling issues remain on URB failure or if a TX queue
fails to drain before rt2x00usb_uninitialize():

1. In rt2800usb_tx_sta_fifo_read_completed(), a non-zero urb_status (such
   as -ENOENT from usb_kill_anchored_urbs() or a bus error on disconnect)
   jumps to stop_reading: and runs the rt2800_txstatus_pending() race
   recheck meant for normal completion.  When TX status is still pending,
   it sets TX_STATUS_READING again and returns true to resubmit the
   failed URB; if usb_submit_urb() then fails (e.g. -EPERM while killing
   anchored URBs), TX_STATUS_READING stays stuck set.

2. In rt2x00usb_uninitialize(), usb_kill_anchored_urbs() runs before
   hrtimer_cancel(&rt2x00dev->txstatus_timer) and cancel_work_sync() on
   txdone_work, allowing txstatus_timer to fire after anchored URBs were
   killed and submit a fresh async TX_STA_FIFO URB.

Clear TX_STATUS_READING and return false directly when urb_status is
non-zero, guard TX_STA_FIFO timer/URB rearming with
DEVICE_STATE_INITIALIZED, and cancel txstatus_timer before
usb_kill_anchored_urbs() as well as after draining txdone_work.

Fixes: f421111b5e69 ("rt2x00: rt2800usb: rework txstatus code")
Fixes: 6232c17438ed ("rt2x00: avoid introducing a USB dependency in the rt2x00lib module")
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
Changes in v3:
- Resend cleanly via b4 web relay (v2 was line-wrapped by Gmail);
  no code changes from v2.

Changes in v2:
- Split into a separate patch with its own description per Stanislaw
  Gruszka's request.
- Clear TX_STATUS_READING and return false directly when urb_status != 0
  in rt2800usb_tx_sta_fifo_read_completed() instead of jumping into the
  stop_reading: race-window recheck.

Validation:
- scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks
- W=1 KASAN+LOCKDEP build of rt2800usb.o and rt2x00usb.o:
  0 warnings, 0 errors
- QEMU KVM (v7.4-rc4, KASAN+LOCKDEP) tested both standalone (when Queue 0
  fails to flush) and together with patch 1/2 across sysfs unbind and
  physical USB disconnect: 0 killed-URB resubmissions, 0 warnings,
  0 KASAN, 0 Lockdep.

 drivers/net/wireless/ralink/rt2x00/rt2800usb.c | 16 ++++++++++++----
 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c |  8 +++++++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
index 15de3db..0327785 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
@@ -99,8 +99,8 @@ static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
 	if (urb_status) {
 		rt2x00_warn(rt2x00dev, "TX status read failed %d\n",
 			    urb_status);
-
-		goto stop_reading;
+		clear_bit(TX_STATUS_READING, &rt2x00dev->flags);
+		return false;
 	}
 
 	valid = rt2x00_get_field32(tx_status, TX_STA_FIFO_VALID);
@@ -118,7 +118,8 @@ static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
 	if (rt2800_txstatus_timeout(rt2x00dev))
 		queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
 
-	if (rt2800_txstatus_pending(rt2x00dev)) {
+	if (rt2800_txstatus_pending(rt2x00dev) &&
+	    test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags)) {
 		/* Read register after 1 ms */
 		hrtimer_start(&rt2x00dev->txstatus_timer,
 			      TXSTATUS_READ_INTERVAL,
@@ -126,7 +127,6 @@ static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
 		return false;
 	}
 
-stop_reading:
 	clear_bit(TX_STATUS_READING, &rt2x00dev->flags);
 	/*
 	 * There is small race window above, between txstatus pending check and
@@ -134,6 +134,7 @@ stop_reading:
 	 * here again if status reading is needed.
 	 */
 	if (rt2800_txstatus_pending(rt2x00dev) &&
+	    test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags) &&
 	    !test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags))
 		return true;
 	else
@@ -142,6 +143,8 @@ stop_reading:
 
 static void rt2800usb_async_read_tx_status(struct rt2x00_dev *rt2x00dev)
 {
+	if (!test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags))
+		return;
 
 	if (test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags))
 		return;
@@ -164,6 +167,11 @@ static enum hrtimer_restart rt2800usb_tx_sta_fifo_timeout(struct hrtimer *timer)
 	struct rt2x00_dev *rt2x00dev =
 	    container_of(timer, struct rt2x00_dev, txstatus_timer);
 
+	if (!test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags)) {
+		clear_bit(TX_STATUS_READING, &rt2x00dev->flags);
+		return HRTIMER_NORESTART;
+	}
+
 	rt2x00usb_register_read_async(rt2x00dev, TX_STA_FIFO,
 				      rt2800usb_tx_sta_fifo_read_completed);
 
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
index c9fbc37..8d77cd5 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
@@ -745,10 +745,16 @@ void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev)
 {
 	struct data_queue *queue;
 
-	usb_kill_anchored_urbs(rt2x00dev->anchor);
+	/*
+	 * Cancel txstatus_timer before killing anchored TX_STA_FIFO URBs so
+	 * the timer cannot submit new URBs afterwards, then cancel again
+	 * after draining txdone_work in case an earlier callback rearmed it.
+	 */
 	hrtimer_cancel(&rt2x00dev->txstatus_timer);
+	usb_kill_anchored_urbs(rt2x00dev->anchor);
 	cancel_work_sync(&rt2x00dev->rxdone_work);
 	cancel_work_sync(&rt2x00dev->txdone_work);
+	hrtimer_cancel(&rt2x00dev->txstatus_timer);
 
 	queue_for_each(rt2x00dev, queue)
 		rt2x00usb_free_entries(queue);
-- 
2.43.0




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04  6:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  6:06 [PATCH wireless v3 0/2] wifi: rt2x00: fix TX queue flush and TX_STA_FIFO teardown Bin Luo via B4 Relay
2026-12-04  6:06 ` [PATCH wireless v3 1/2] wifi: rt2x00: set DEVICE_STATE_FLUSHING in rt2x00queue_flush_queues() Bin Luo via B4 Relay
2026-12-04  6:06 ` [PATCH wireless v3 2/2] wifi: rt2x00: prevent TX_STA_FIFO URB resubmission on error and teardown Bin Luo via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox