linux/drivers/net/wireless/ath/ath11k
Wen Gong f45cb6b29c wifi: ath11k: avoid deadlock during regulatory update in ath11k_regd_update()
(cherry picked from commit d99884ad9e in ath-next
as users are seeing this bug more now, also cc stable)

Running this test in a loop it is easy to reproduce an rtnl deadlock:

iw reg set FI
ifconfig wlan0 down

What happens is that thread A (workqueue) tries to update the regulatory:

    try to acquire the rtnl_lock of ar->regd_update_work

    rtnl_lock+0x17/0x20
    ath11k_regd_update+0x15a/0x260 [ath11k]
    ath11k_regd_update_work+0x15/0x20 [ath11k]
    process_one_work+0x228/0x670
    worker_thread+0x4d/0x440
    kthread+0x16d/0x1b0
    ret_from_fork+0x22/0x30

And thread B (ifconfig) tries to stop the interface:

    try to cancel_work_sync(&ar->regd_update_work) in ath11k_mac_op_stop().
    ifconfig  3109 [003]  2414.232506: probe:

    ath11k_mac_op_stop: (ffffffffc14187a0)
    drv_stop+0x30 ([mac80211])
    ieee80211_do_stop+0x5d2 ([mac80211])
    ieee80211_stop+0x3e ([mac80211])
    __dev_close_many+0x9e ([kernel.kallsyms])
    __dev_change_flags+0xbe ([kernel.kallsyms])
    dev_change_flags+0x23 ([kernel.kallsyms])
    devinet_ioctl+0x5e3 ([kernel.kallsyms])
    inet_ioctl+0x197 ([kernel.kallsyms])
    sock_do_ioctl+0x4d ([kernel.kallsyms])
    sock_ioctl+0x264 ([kernel.kallsyms])
    __x64_sys_ioctl+0x92 ([kernel.kallsyms])
    do_syscall_64+0x3a ([kernel.kallsyms])
    entry_SYSCALL_64_after_hwframe+0x63 ([kernel.kallsyms])
    __GI___ioctl+0x7 (/lib/x86_64-linux-gnu/libc-2.23.so)

The sequence of deadlock is:

1. Thread B calls rtnl_lock().

2. Thread A starts to run and calls rtnl_lock() from within
   ath11k_regd_update_work(), then enters wait state because the lock is owned by
   thread B.

3. Thread B continues to run and tries to call
   cancel_work_sync(&ar->regd_update_work), but thread A is in
   ath11k_regd_update_work() waiting for rtnl_lock(). So cancel_work_sync()
   forever waits for ath11k_regd_update_work() to finish and we have a deadlock.

Fix this by switching from using regulatory_set_wiphy_regd_sync() to
regulatory_set_wiphy_regd(). Now cfg80211 will schedule another workqueue which
handles the locking on it's own. So the ath11k workqueue can simply exit without
taking any locks, avoiding the deadlock.

Tested-on: WCN6855 hw2.0 PCI WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3

Cc: <stable@vger.kernel.org>
Signed-off-by: Wen Gong <quic_wgong@quicinc.com>
[kvalo: improve commit log]
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
2022-11-02 19:16:45 +02:00
..
Kconfig
Makefile
ahb.c wireless-next patches for v6.1 2022-09-30 10:07:31 -07:00
ahb.h wifi: ath11k: Add WoW support for WCN6750 2022-09-19 16:03:34 +03:00
ce.c wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
ce.h
core.c wifi: ath11k: Add spectral scan support for 160 MHz 2022-09-26 12:40:12 +03:00
core.h wifi: ath11k: Add support to get power save duration for each client 2022-09-26 12:34:38 +03:00
dbring.c
dbring.h
debug.c
debug.h ath11k: Fix incorrect debug_mask mappings 2022-06-06 17:08:44 +03:00
debugfs.c wifi: ath11k: Add support to get power save duration for each client 2022-09-26 12:34:38 +03:00
debugfs.h wifi: ath11k: move firmware stats out of debugfs 2022-09-22 10:28:20 +03:00
debugfs_htt_stats.c ath11k: update missing MU-MIMO and OFDMA stats 2022-05-18 10:12:25 +03:00
debugfs_htt_stats.h wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
debugfs_sta.c wifi: ath11k: Add support to get power save duration for each client 2022-09-26 12:34:38 +03:00
debugfs_sta.h
dp.c wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
dp.h wifi: ath11k: Fix kernel-doc issues 2022-09-16 12:20:35 +03:00
dp_rx.c wifi: ath11k: fix failed to find the peer with peer_id 0 when disconnected 2022-09-22 10:17:09 +03:00
dp_rx.h
dp_tx.c wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
dp_tx.h
hal.c wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
hal.h wifi: ath11k: Fix kernel-doc issues 2022-09-16 12:20:35 +03:00
hal_desc.h wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
hal_rx.c ath11k: Fix warnings reported by checkpatch 2022-06-06 17:11:18 +03:00
hal_rx.h
hal_tx.c wifi: ath11k: Add multi TX ring support for WCN6750 2022-09-10 09:27:54 +03:00
hal_tx.h wifi: ath11k: Add multi TX ring support for WCN6750 2022-09-10 09:27:54 +03:00
hif.h wifi: ath11k: implement SRAM dump debugfs interface 2022-09-10 09:26:18 +03:00
htc.c ath11k: fix missing skb drop on htc_tx_completion error 2022-06-06 17:07:05 +03:00
htc.h
hw.c wifi: ath11k: Add multi TX ring support for WCN6750 2022-09-10 09:27:54 +03:00
hw.h wifi: ath11k: Add spectral scan support for 160 MHz 2022-09-26 12:40:12 +03:00
mac.c wifi: ath11k: mac: fix reading 16 bytes from a region of size 0 warning 2022-10-11 11:46:31 +03:00
mac.h Revert "ath11k: add support for hardware rfkill for QCA6390" 2022-07-27 13:19:22 +03:00
mhi.c wifi: ath11k: mhi: fix potential memory leak in ath11k_mhi_register() 2022-09-10 09:27:09 +03:00
mhi.h
pci.c wifi: ath11k: implement SRAM dump debugfs interface 2022-09-10 09:26:18 +03:00
pci.h
pcic.c wireless-next patches for v6.1 2022-09-30 10:07:31 -07:00
pcic.h wifi: ath11k: Add WoW support for WCN6750 2022-09-19 16:03:34 +03:00
peer.c wifi: ath11k: fix peer addition/deletion error on sta band migration 2022-09-24 16:42:29 +03:00
peer.h
qmi.c wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
qmi.h wifi: ath11k: Fix QCN9074 firmware boot on x86 2022-11-02 19:14:06 +02:00
reg.c wifi: ath11k: avoid deadlock during regulatory update in ath11k_regd_update() 2022-11-02 19:16:45 +02:00
reg.h
rx_desc.h wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
spectral.c wifi: ath11k: Add spectral scan support for 160 MHz 2022-09-26 12:40:12 +03:00
spectral.h wifi: ath11k: Add spectral scan support for 160 MHz 2022-09-26 12:40:12 +03:00
testmode.c
testmode.h
testmode_i.h
thermal.c wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
thermal.h wifi: ath11k: Fix miscellaneous spelling errors 2022-09-16 12:19:14 +03:00
trace.c
trace.h wifi: ath11k: Add support to get power save duration for each client 2022-09-26 12:34:38 +03:00
wmi.c wifi: ath11k: Add support to get power save duration for each client 2022-09-26 12:34:38 +03:00
wmi.h wifi: ath11k: Add support to get power save duration for each client 2022-09-26 12:34:38 +03:00
wow.c wifi: ath11k: Fix deadlock during WoWLAN suspend 2022-09-26 12:41:04 +03:00
wow.h