[PATCH ath-next] wifi: ar5523: cancel the TX watchdog work outside ar->mutex
From: Jiayi Zhang
Date: Sat Dec 05 2026 - 09:11:28 EST
ar5523_stop() takes ar->mutex and calls cancel_work_sync(&ar->tx_wd_work)
with the mutex held. ar5523_tx_wd_work() starts with
mutex_lock(&ar->mutex). If the watchdog work has started and waits for
the mutex when ar5523_stop() reaches cancel_work_sync(), ar5523_stop()
waits for the work and the work waits for the mutex. The interface does
not go down, and since ar5523_stop() runs under the RTNL and the wiphy
mutex, network configuration on the system hangs with it.
tx_wd_timer is re-armed on every submitted frame and every
WDCMSG_SEND_COMPLETE, and queues the watchdog work when
AR5523_TX_WD_TIMEOUT (2 s) passes without a completion. ar5523_stop()
holds the mutex across three synchronous commands that each wait up to
2 s for the dongle, so the timer can expire inside that window when
frames are still outstanding at stop time.
lockdep reports the dependency:
WARNING: possible circular locking dependency detected
...
-> #1 (&ar->mutex){+.+.}-{4:4}:
mutex_lock_nested+0x44/0x100 kernel/locking/rtmutex_api.c:580
ar5523_tx_wd_work+0x39/0x260 drivers/net/wireless/ath/ar5523/ar5523.c:919
process_one_work+0xae3/0x1e30 kernel/workqueue.c:3497
worker_thread+0x6da/0xf30 kernel/workqueue.c:3661
...
-> #0 ((work_completion)(&ar->tx_wd_work)){+.+.}-{0:0}:
...
__flush_work+0x556/0xf00 kernel/workqueue.c:4602
cancel_work_sync+0xcd/0xf0 kernel/workqueue.c:4795
ar5523_stop+0xb4/0x150 drivers/net/wireless/ath/ar5523/ar5523.c:1080
drv_stop+0x193/0x470 net/mac80211/driver-ops.c:45
ieee80211_do_stop+0x1919/0x29e0 net/mac80211/iface.c:777
ieee80211_stop+0x165/0x2f0 net/mac80211/iface.c:871
__dev_close_many+0x29b/0x700 net/core/dev.c:1838
...
Release ar->mutex before the works are cancelled, as ar5523_stop()
already does for stat_work, whose callback takes the mutex as well.
Nothing after timer_delete_sync() needs the mutex:
ar5523_rx_refill_work() and the RX URB completion handler do not take
it, and ar5523_free_rx_bufs() calls ar5523_cancel_rx_bufs() without it
on disconnect. AR5523_HW_UP is cleared under the mutex before the
unlock, so the RX completion handler does not queue rx_refill_work
again and WDCMSG_SEND_COMPLETE no longer re-arms tx_wd_timer.
A watchdog work that already waits for the mutex now gets it after
WDCMSG_TARGET_STOP. Make ar5523_tx_wd_work() return without resetting
the dongle when AR5523_HW_UP is clear.
Fixes: b7d572e1871d ("ar5523: Add new driver")
Signed-off-by: Jiayi Zhang <zhangjiayi1014@xxxxxxxxx>
---
Duoming Zhou sent a fix for the same deadlock in 2022 that dropped the
mutex for the cancels and took it again; Kalle Valo called that a hack
and asked for testing with a real device:
https://lore.kernel.org/all/20220522133055.96405-1-duoming@xxxxxxxxxx/
This patch ends the critical section before the cancels instead, like
the existing cancel of stat_work, and does not take the mutex again.
Found by a scan for cancel_work_sync() called while holding a lock that
the work callback takes.
I have no AR5523 hardware. Tested in QEMU (2 CPUs, mainline 007722b8211f,
syzbot's upstream config: PREEMPT_RT, lockdep, KASAN) with a test program
that emulates the dongle with raw-gadget on dummy_hcd. It differs from a
real dongle in two ways: it answers every command with
WDCMSG_SEND_COMPLETE, which the driver counts as a completed data frame,
so tx_nr_pending goes below zero, tx_wd_timer is never deleted and the
watchdog work runs every 2 s while the interface is up; and it waits
1.5 s after each LED-off command before it reads the next one, so
ar5523_stop() holds ar->mutex for about 3 s while the watchdog work is
queued or running. On real hardware this needs frames still outstanding
at stop time with the last completion less than 2 s before the cancel.
Without the patch, 4 of 4 instances reported the lockdep splat above (a
fifth gave no result). The cycle does not depend on PREEMPT_RT: the same
test on a non-RT 7.4-rc3 kernel gave the splat too, the interface-down
call stayed blocked for more than 40 s and a hung task report followed.
With the patch, 4 instances ran the test in a loop for 10 minutes each
without a lockdep, KASAN or hung task report (a fifth did not boot). In
runs that keep the console log, each round on each instance also brought
the interface up again after a down that raced the watchdog, saw the
watchdog work run again, and unplugged the dongle while the interface was
up; no report. Without the AR5523_HW_UP check, the watchdog work that had
waited for the mutex reset the dongle right after ar5523_stop() in 5 of 5
instances; with it, no reset was logged during ar5523_stop() in 6 of 6
downs.
Build tested with GCC 8.5.0 and W=1 (drivers/net/wireless/ath/ar5523/
ar5523.o): no warnings.
AI tools assisted with the analysis, the code and the changelog.
drivers/net/wireless/ath/ar5523/ar5523.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/ar5523/ar5523.c b/drivers/net/wireless/ath/ar5523/ar5523.c
index 66ac396..62fd39c 100644
--- a/drivers/net/wireless/ath/ar5523/ar5523.c
+++ b/drivers/net/wireless/ath/ar5523/ar5523.c
@@ -917,12 +917,17 @@ static void ar5523_tx_wd_work(struct work_struct *work)
*/
mutex_lock(&ar->mutex);
+ /* ar5523_stop() may have stopped the dongle while we waited */
+ if (!test_bit(AR5523_HW_UP, &ar->flags))
+ goto out;
+
ar5523_err(ar, "TX queue stuck (tot %d pend %d)\n",
atomic_read(&ar->tx_nr_total),
atomic_read(&ar->tx_nr_pending));
ar5523_err(ar, "Will restart dongle.\n");
ar5523_cmd_write(ar, WDCMSG_TARGET_RESET, NULL, 0, 0);
+out:
mutex_unlock(&ar->mutex);
}
@@ -1077,10 +1082,10 @@ static void ar5523_stop(struct ieee80211_hw *hw, bool suspend)
ar5523_cmd_write(ar, WDCMSG_TARGET_STOP, NULL, 0, 0);
timer_delete_sync(&ar->tx_wd_timer);
+ mutex_unlock(&ar->mutex);
cancel_work_sync(&ar->tx_wd_work);
cancel_work_sync(&ar->rx_refill_work);
ar5523_cancel_rx_bufs(ar);
- mutex_unlock(&ar->mutex);
}
static int ar5523_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx,
--
2.53.0