wifi: rtw88: fixes around the firmware recovery
v4 cover wifi: rtw88: fixes around the firmware recovery
From: Mehmet Fide <[email protected]>
Fixes for what a firmware crash test showed on an RTL8822CE, and for what Luka found in v2 and v3. Patch 5 of v3 is dropped, commit 3f2238709f5d ("wifi: rtw88: clear RTW_FLAG_RESTARTING on stop and start failure") does the same.
Tested on rtw-next 0bdc579dbfc2 on an i.MX8MP board with lockdep and kmemleak, with firmware crashes triggered from debugfs on the RTL8822CE:
- patch 1: no reserved page leaked after crashes with an AP or a station interface, where rtw-next leaked pages on each crash. The beacon update work and a WoWLAN suspend between the crash and the reconfiguration found the pages
- patch 2: with the firmware TX reports dropped in a test build, hostapd got a purged client probe as not acknowledged, with no ACK signal or link ID
- patch 3: with the collection held back in a test build, a client moved back to AUTH and deleted in that window was skipped
- patch 4: no "sleeping function called from invalid context" on a crash with an associated station interface
The regression tests on an RTL8822CE, an RTL8822BU, an RTL8822CU and two RTL8821CU on both bands passed, except the 2.4 GHz beacon test of the RTL8822CE. A neighbour AP's beacons pass our TBTT on that channel every 157 s, and the beacon loss over 330 to 400 s is in the same range with and without the series.
v4:
- patch 1: the pages are kept through the recovery and freed when the interface is added again; no port checks (Zong-Zhe Yang, Luka Gejak)
- patch 2: the TX status is cleared when a frame is queued (Luka Gejak); Reviewed-by dropped
- patch 3: stations without si->vif are skipped (Luka Gejak)
- patch 4: no change
- patch 5 of v3 dropped for commit 3f2238709f5d
v3:
- patch 1: no RTW_FLAG_RESTARTING test in the beacon update work; the page download and the page location H2C do nothing while no port is in use (Luka Gejak)
- patch 3: new, rtw_iterate_stas() cannot skip a station (Luka Gejak)
- patch 5: new, RTW_FLAG_RESTARTING is cleared when the device stops (Luka Gejak)
- patches 2 and 4: no change
- rebased on rtw-next
v2:
- patch 1: the beacon update work does nothing while RTW_FLAG_RESTARTING is set (Luka Gejak)
- patches 2 and 3: Reviewed-by Luka Gejak, no change
- rebased on rtw-next
v3: https://lore.kernel.org/linux-wireless/[email protected]/
v2: https://lore.kernel.org/linux-wireless/[email protected]/
v1: https://lore.kernel.org/linux-wireless/[email protected]/
Mehmet Fide (4):
wifi: rtw88: free the reserved pages of an interface on firmware
recovery
wifi: rtw88: report the frames purged from the TX report queue
wifi: rtw88: do not drop stations when collecting them for an
iteration
wifi: rtw88: reset the stations outside of RCU on firmware recovery
drivers/net/wireless/realtek/rtw88/mac80211.c | 8 +++++- drivers/net/wireless/realtek/rtw88/main.c | 7 ++---- drivers/net/wireless/realtek/rtw88/main.h | 2 ++ drivers/net/wireless/realtek/rtw88/tx.c | 25 +++++++++++++++---- drivers/net/wireless/realtek/rtw88/tx.h | 1 + drivers/net/wireless/realtek/rtw88/util.c | 23 ++++++----------- 6 files changed, 39 insertions(+), 27 deletions(-)
base-commit: 0bdc579dbfc251a6b6838ee9459b6771b948c617
Signature · 1 line
2.56.0
PATCH v4 1/4 wifi: rtw88: free the reserved pages of an interface on firmware recovery
From: Mehmet Fide <[email protected]>
After a firmware crash, mac80211 adds the interfaces again without removing them first. rtw_ops_add_interface() then reinitializes the reserved page list, and the pages allocated before the crash leak:
unreferenced object 0xffff0000cbe22c60 (size 96):
comm "hostapd", pid 25545, jiffies 4296463067
backtrace (crc cbdc21c4):
kmemleak_alloc+0xcc/0xe4
__kmalloc_cache_noprof+0x234/0x3bc
rtw_add_rsvd_page+0x38/0xa8 [rtw88_core]
rtw_add_rsvd_page_bcn+0x30/0x58 [rtw88_core]
rtw_ops_add_interface+0x144/0x2cc [rtw88_core]mac80211 zeroes the driver data of a new and of a removed interface, so track in struct rtw_vif whether the list was initialized, and free the old pages when the interface is added again. Until then the pages stay on the list, so a download before the reconfiguration, from the beacon update work or a WoWLAN suspend, still finds them.
---
Notes:
v4: keep the pages through the recovery and free them in
rtw_ops_add_interface() (Zong-Zhe Yang); no port checks
v3: no RTW_FLAG_RESTARTING test; the page download and the page
location H2C do nothing while no port is in use (Luka Gejak)
v2: the beacon update work does nothing while RTW_FLAG_RESTARTING is
set (Luka Gejak)
drivers/net/wireless/realtek/rtw88/mac80211.c | 8 +++++++- drivers/net/wireless/realtek/rtw88/main.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/mac80211.c +7 -1
@@ -166,10 +166,16 @@ static int rtw_ops_add_interface(struct ieee80211_hw *hw, rtwvif->scan_req =NULL ;memset (&rtwvif->bfee,0 ,sizeof (struct rtw_bfee ));rtw_txq_init (rtwdev, vif->txq); -INIT_LIST_HEAD (&rtwvif->rsvd_page_list);mutex_lock (&rtwdev->mutex); +if (rtwvif->rsvd_page_inited) { +rtw_remove_rsvd_page (rtwdev, rtwvif); + }else { +INIT_LIST_HEAD (&rtwvif->rsvd_page_list); + rtwvif->rsvd_page_inited = true; + } + rtwvif->mac_id =rtw_acquire_macid (rtwdev);if (rtwvif->mac_id >=RTW_MAX_MAC_ID_NUM ) {mutex_unlock (&rtwdev->mutex);
drivers/net/wireless/realtek/rtw88/main.h +1 -0
@@ -830,6 +830,7 @@ struct rtw_vif {u8 bssid[ETH_ALEN ];u8 port;u8 bcn_ctrl; +bool rsvd_page_inited;struct list_head rsvd_page_list;struct ieee80211_tx_queue_params tx_params[IEEE80211_NUM_ACS ];const struct rtw_vif_port *conf;
Signature · 1 line
2.56.0
Re: [PATCH rtw-next v4 1/4] wifi: rtw88: free the reserved pages of an interface on firmware recovery
Quoted 21 lines · Mehmet Fide
From: Mehmet Fide <[email protected]>
After a firmware crash, mac80211 adds the interfaces again without removing them first.
rtw_ops_add_interface()then reinitializes the reserved page list, and the pages allocated before the crash leak:unreferenced object
0xffff0000cbe22c60(size 96):
comm "hostapd", pid 25545, jiffies 4296463067
backtrace (crccbdc21c4):kmemleak_alloc+0xcc/0xe4 __kmalloc_cache_noprof+0x234/0x3bc rtw_add_rsvd_page+0x38/0xa8 [rtw88_core] rtw_add_rsvd_page_bcn+0x30/0x58 [rtw88_core] rtw_ops_add_interface+0x144/0x2cc [rtw88_core]mac80211 zeroes the driver data of a new and of a removed interface, so track in struct
rtw_vifwhether the list was initialized, and free the old pages when the interface is added again. Until then the pages stay on the list, so a download before the reconfiguration, from the beacon update work or a WoWLAN suspend, still finds them.
Quoted 5 lines
Fixes 5c831644e1f4 ("rtw88: handle and recover when firmware crash")Suggested-by Zong-Zhe Yang <[email protected]>Signed-off-by Mehmet Fide <[email protected]>---
Looks good to me,
Best regards,
Luka Gejak
PATCH v4 2/4 wifi: rtw88: report the frames purged from the TX report queue
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
Frames waiting for a TX report of the firmware are freed with skb_queue_purge() when the report times out and in rtw_core_deinit(). mac80211 gets no TX status for them, and the frames it keeps for the TX status of user space stay pending until ieee80211_free_hw() warns. On an RTL8822CE, after a firmware crash and an unbind:
rtw88_8822ce 0000:01:00.0: failed to get tx report from firmware [...]
Have pending ack frames!
WARNING: net/mac80211/main.c:1761 at ieee80211_free_ack_frame+0x4c/0x70 [mac80211], CPU#1: sh/24725 Call trace: ieee80211_free_ack_frame+0x4c/0x70 [mac80211] (P) idr_for_each+0x6c/0xf4 ieee80211_free_hw+0x30/0x8c [mac80211] rtw_pci_remove+0xd8/0xf0 [rtw88_pci]
Free them with ieee80211_purge_tx_queue() instead, which reports them as dropped. Clear the TX status of a frame when it is queued, as rtw_tx_report_handle() does, so that a purged frame does not report its leftover TX control data as status flags and link ID.
---
Notes:
v4: clear the TX status when a frame is queued (Luka Gejak);
Reviewed-by dropped for that change
v3: no change
v2: Reviewed-by Luka Gejak, no change
drivers/net/wireless/realtek/rtw88/main.c | 5 +---- drivers/net/wireless/realtek/rtw88/tx.c | 25 ++++++++++++++++++----- drivers/net/wireless/realtek/rtw88/tx.h | 1 + 3 files changed, 22 insertions(+), 9 deletions(-)
drivers/net/wireless/realtek/rtw88/main.c +1 -4
@@ -2232,7 +2232,6 @@ void rtw_core_deinit(struct rtw_dev *rtwdev)struct rtw_fw_state *fw = &rtwdev->fw;struct rtw_fw_state *wow_fw = &rtwdev->wow_fw;struct rtw_rsvd_page *rsvd_pkt, *tmp; -unsigned long flags;rtw_wait_firmware_completion (rtwdev);
@@ -2244,9 +2243,7 @@ void rtw_core_deinit(struct rtw_dev *rtwdev)destroy_workqueue (rtwdev->tx_wq);timer_delete_sync (&rtwdev->tx_report.purge_timer); -spin_lock_irqsave (&rtwdev->tx_report.q_lock, flags); -skb_queue_purge (&rtwdev->tx_report.queue); -spin_unlock_irqrestore (&rtwdev->tx_report.q_lock, flags); +rtw_tx_report_purge (rtwdev);skb_queue_purge (&rtwdev->coex.queue);skb_queue_purge (&rtwdev->c2h_queue);
drivers/net/wireless/realtek/rtw88/tx.c +20 -5
@@ -176,32 +176,47 @@ static void rtw_tx_report_enable(struct rtw_dev *rtwdev, pkt_info->report = true; } +void rtw_tx_report_purge (struct rtw_dev *rtwdev) +{ +struct rtw_tx_report *tx_report = &rtwdev->tx_report; +struct sk_buff_head purge; +unsigned long flags; + +__skb_queue_head_init (&purge); + +spin_lock_irqsave (&tx_report->q_lock, flags); +skb_queue_splice_init (&tx_report->queue, &purge); +spin_unlock_irqrestore (&tx_report->q_lock, flags); + +ieee80211_purge_tx_queue (rtwdev->hw, &purge); +} +void rtw_tx_report_purge_timer (struct timer_list *t) {struct rtw_dev *rtwdev =timer_container_of (rtwdev, t, tx_report.purge_timer);struct rtw_tx_report *tx_report = &rtwdev->tx_report; -unsigned long flags;if (skb_queue_len (&tx_report->queue) ==0 )return ;rtw_warn (rtwdev,"failed to get tx report from firmware\n" ); -spin_lock_irqsave (&tx_report->q_lock, flags); -skb_queue_purge (&tx_report->queue); -spin_unlock_irqrestore (&tx_report->q_lock, flags); +rtw_tx_report_purge (rtwdev); }void rtw_tx_report_enqueue (struct rtw_dev *rtwdev,struct sk_buff *skb,u8 sn) { +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb);struct rtw_tx_report *tx_report = &rtwdev->tx_report;unsigned long timeout;unsigned long flags;u8 *drv_data; +ieee80211_tx_info_clear_status (info); +/* pass sn to tx report handler through driver data */ - drv_data = (u8 *)IEEE80211_SKB_CB (skb)->status.status_driver_data; + drv_data = (u8 *)info->status.status_driver_data; *drv_data = sn;spin_lock_irqsave (&tx_report->q_lock, flags);
drivers/net/wireless/realtek/rtw88/tx.h +1 -0
@@ -98,6 +98,7 @@ void rtw_tx_pkt_info_update(struct rtw_dev *rtwdev, struct sk_buff *skb);void rtw_tx_fill_tx_desc (struct rtw_dev *rtwdev,struct rtw_tx_pkt_info *pkt_info,struct sk_buff *skb); +void rtw_tx_report_purge (struct rtw_dev *rtwdev);void rtw_tx_report_enqueue (struct rtw_dev *rtwdev,struct sk_buff *skb,u8 sn);void rtw_tx_report_handle (struct rtw_dev *rtwdev,struct sk_buff *skb,int src); void rtw_tx_rsvd_page_pkt_info_update(struct rtw_dev *rtwdev,
Signature · 1 line
2.56.0
Re: [PATCH rtw-next v4 2/4] wifi: rtw88: report the frames purged from the TX report queue
Quoted 18 lines · Mehmet Fide
From: Mehmet Fide <[email protected]>
Frames waiting for a TX report of the firmware are freed with
skb_queue_purge()when the report times out and inrtw_core_deinit(). mac80211 gets no TX status for them, and the frames it keeps for the TX status of user space stay pending untilieee80211_free_hw()warns. On an RTL8822CE, after a firmware crash and an unbind:
rtw88_8822ce0000:01:00.0: failed to get tx report from firmware [...]
Have pending ack frames!WARNING: net/mac80211/main.c:1761 at ieee80211_free_ack_frame+0x4c/0x70 [mac80211], CPU#1: sh/24725 Call trace: ieee80211_free_ack_frame+0x4c/0x70 [mac80211] (P) idr_for_each+0x6c/0xf4 ieee80211_free_hw+0x30/0x8c [mac80211] rtw_pci_remove+0xd8/0xf0 [rtw88_pci]
Quoted 9 lines
Free them with
ieee80211_purge_tx_queue()instead, which reports them as dropped. Clear the TX status of a frame when it is queued, asrtw_tx_report_handle()does, so that a purged frame does not report its leftover TX control data as status flags and link ID.Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")Signed-off-by Mehmet Fide <[email protected]>---
Looks good to me,
Best regards,
Luka Gejak
PATCH v4 3/4 wifi: rtw88: do not drop stations when collecting them for an iteration
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
rtw_iterate_stas() allocates an entry with GFP_ATOMIC for each station it collects, and skips the station when that fails. Once the firmware recovery resets the stations through it (next patch), a skipped station keeps its TX queues on rtwdev->txqs, and rtw_txq_init() later reinitializes a list node that is still linked.
Link the stations through a list node in struct rtw_sta_info instead. All callers hold rtwdev->mutex and no iterator collects again, so one node per station is enough.
Skip stations without si->vif. A station moved back from ASSOC to AUTH has gone through rtw_sta_remove() but is still found by the atomic iterator, and mac80211 can free it without calling the driver before the iterator runs.
---
Notes:
v4: skip stations without si->vif (Luka Gejak)
v3: new (Luka Gejak)
drivers/net/wireless/realtek/rtw88/main.h | 1 + drivers/net/wireless/realtek/rtw88/util.c | 23 +++++++---------------- 2 files changed, 8 insertions(+), 16 deletions(-)
drivers/net/wireless/realtek/rtw88/main.h +1 -0
@@ -792,6 +792,7 @@ struct rtw_sta_info {struct cfg80211_bitrate_mask *mask;struct work_struct rc_work; +struct list_head iter_list; };enum rtw_bfee_role {
drivers/net/wireless/realtek/rtw88/util.c +7 -16
@@ -107,11 +107,6 @@ void rtw_desc_to_mcsrate(u16 rate, u8 *mcs, u8 *nss) } } -struct rtw_stas_entry { -struct list_head list; -struct ieee80211_sta *sta; -}; -struct rtw_iter_stas_data {struct rtw_dev *rtwdev;struct list_head list;
@@ -119,15 +114,13 @@ struct rtw_iter_stas_data {static void rtw_collect_sta_iter (void *data,struct ieee80211_sta *sta) { +struct rtw_sta_info *si = (struct rtw_sta_info *)sta->drv_priv;struct rtw_iter_stas_data *iter_stas = data; -struct rtw_stas_entry *stas_entry; - stas_entry =kmalloc_obj (*stas_entry,GFP_ATOMIC ); -if (!stas_entry) +if (!si->vif)return ; - stas_entry->sta = sta; -list_add_tail (&stas_entry->list, &iter_stas->list); +list_add_tail (&si->iter_list, &iter_stas->list); } void rtw_iterate_stas(struct rtw_dev *rtwdev,
@@ -136,7 +129,7 @@ void rtw_iterate_stas(struct rtw_dev *rtwdev, void *data) {struct rtw_iter_stas_data iter_data; -struct rtw_stas_entry *sta_entry, *tmp; +struct rtw_sta_info *si, *tmp;/* &rtwdev->mutex makes sure no stations can be removed between * collecting the stations and iterating over them.
@@ -149,11 +142,9 @@ void rtw_iterate_stas(struct rtw_dev *rtwdev,ieee80211_iterate_stations_atomic (rtwdev->hw, rtw_collect_sta_iter, &iter_data); -list_for_each_entry_safe (sta_entry, tmp, &iter_data.list, - list) { -list_del_init (&sta_entry->list); -iterator (data, sta_entry->sta); -kfree (sta_entry); +list_for_each_entry_safe (si, tmp, &iter_data.list, iter_list) { +list_del_init (&si->iter_list); +iterator (data, si->sta); } }
Signature · 1 line
2.56.0
Re: [PATCH rtw-next v4 3/4] wifi: rtw88: do not drop stations when collecting them for an iteration
Quoted 17 lines · Mehmet Fide
From: Mehmet Fide <[email protected]>
rtw_iterate_stas()allocates an entry withGFP_ATOMICfor each station it collects, and skips the station when that fails. Once the firmware recovery resets the stations through it (next patch), a skipped station keeps its TX queues onrtwdev->txqs, andrtw_txq_init()later reinitializes a list node that is still linked.Link the stations through a list node in struct
rtw_sta_infoinstead. All callers holdrtwdev->mutexand no iterator collects again, so one node per station is enough.Skip stations without
si->vif. A station moved back from ASSOC to AUTH has gone throughrtw_sta_remove()but is still found by the atomic iterator, and mac80211 can free it without calling the driver before the iterator runs.
Quoted 6 lines
Reported-by Luka Gejak <[email protected]>Fixes 78d5bf925f30 ("wifi: rtw88: iterate over vif/sta list non-atomically")Signed-off-by Mehmet Fide <[email protected]>---
Looks good to me,
Best regards,
Luka Gejak
PATCH v4 4/4 wifi: rtw88: reset the stations outside of RCU on firmware recovery
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
The recovery after a firmware crash removes the driver state of every station with rtw_sta_remove(), called from an atomic station iterator. rtw_sta_remove() cancels the rate work of the station with cancel_work_sync(), which can sleep. With a station associated:
BUG: sleeping function called from invalid context at kernel/workqueue.c:4722 in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 14, name: kworker/u16:1 RCU nest depth: 1, expected: 0 Workqueue: phy35 rtw_fw_recovery_work [rtw88_core] Call trace: __might_resched+0x13c/0x1f0 __might_sleep+0x48/0x7c __cancel_work_sync+0xa8/0xb4 cancel_work_sync+0x14/0x20 rtw_sta_remove+0x34/0x10c [rtw88_core] rtw_reset_sta_iter+0x20/0x48 [rtw88_core] ieee80211_iterate_stations_atomic+0x80/0x144 [mac80211] rtw_fw_recovery_work+0x1dc/0x2b8 [rtw88_core]
Use rtw_iterate_stas(), which collects the stations under RCU and calls the iterator after it. The recovery holds the driver mutex it asks for.
---
Notes:
v4: no change
v3: no change
v2: Reviewed-by Luka Gejak, no change
drivers/net/wireless/realtek/rtw88/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/main.c +1 -1
@@ -669,7 +669,7 @@ static void __fw_recovery_work(struct rtw_dev *rtwdev)WARN (1 ,"firmware crash, start reset and recover\n" );rtw_iterate_keys_atomic (rtwdev,NULL , rtw_reset_key_iter, rtwdev); -rtw_iterate_stas_atomic (rtwdev, rtw_reset_sta_iter, rtwdev); +rtw_iterate_stas (rtwdev, rtw_reset_sta_iter, rtwdev);rtw_iterate_vifs_atomic (rtwdev, rtw_reset_vif_iter, rtwdev);bitmap_zero (rtwdev->hw_port,RTW_PORT_NUM );rtw_enter_ips (rtwdev);
Signature · 1 line
2.56.0