Skip to contentSkip to conversation

wifi: rtw88: fixes around the firmware recovery

PATCH Superseded Mehmet Fide 3 participants 17 messages Nov 17 – Nov 20 Realtek wireless driver (rtw88)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 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. Patches 3 and 5 are new.

Tested on rtw-next on an i.MX8MP board with PROVE_LOCKING, DEBUG_ATOMIC_SLEEP, DEBUG_LIST and kmemleak, with hostapd. The firmware crashes were triggered from debugfs on the RTL8822CE:

- patch 1: three crashes with an associated station interface lost five reserved pages before and none after; six crashes with an AP interface lost three before and none after. With a test build that holds the hardware restart for 4 s after the recovery, two hostapd update_beacon calls in that window warned "Should not have an empty reserved page" with v2 and did not with v3, and a beacon update work queued during the reconfiguration downloaded the pages with v3 where v2 skipped it (two runs each)
- patch 2: an unbind after the crashes warned "Have pending ack frames!" before and did not after. With a test build that drops every TX report of the firmware, the unbind of the RTL8822CE warned before; after, neither it nor the RTL8822BU did
- patch 3: a test build that leaves the station out of the collection during the recovery, as on a failed allocation, skipped its reset with v2; v3 has no allocation left to fail. Three crashes with a station pulling traffic: the station stayed, no list report
- patch 4: each of three crashes with an associated station gave the "sleeping function called from invalid context" report before and none did after; the link was back after every crash
- patch 5: with the AP stopped and its interface down in the same 4 s window, the flag stayed set and writing fw_crash returned -EINPROGRESS with v2; with v3 it was clear and a second crash recovered (two runs)

With the five patches, AP, association, power save, firmware crash and scan tests on the RTL8822CE, RTL8822BU and RTL8821CU on both bands gave no kernel report, and three crashes with an idle and an associated station interface gave no kmemleak report.

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

v2: https://lore.kernel.org/linux-wireless/[email protected]/
v1: https://lore.kernel.org/linux-wireless/[email protected]/

Mehmet Fide (5):
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
wifi: rtw88: clear the restart flag when the device is stopped

 drivers/net/wireless/realtek/rtw88/fw.c       |  6 +++++
 drivers/net/wireless/realtek/rtw88/mac80211.c |  1 +
 drivers/net/wireless/realtek/rtw88/main.c     |  8 +++----
 drivers/net/wireless/realtek/rtw88/main.h     |  1 +
 drivers/net/wireless/realtek/rtw88/tx.c       | 20 ++++++++++++----
 drivers/net/wireless/realtek/rtw88/tx.h       |  1 +
 drivers/net/wireless/realtek/rtw88/util.c     | 24 +++++--------------
 7 files changed, 34 insertions(+), 27 deletions(-)

base-commit: fb51e39dfaea5b5990e783e53c657534a37987d6

Signature · 1 line
2.56.0
#1 lore raw

PATCH v3 1/5 wifi: rtw88: free the reserved pages of an interface on firmware recovery

From: Mehmet Fide <[email protected]>

The recovery after a firmware crash resets the driver state of every interface, and mac80211 then adds the interfaces again without removing them first. rtw_ops_add_interface() starts with an empty reserved page list, so the pages the interface had before the crash are lost: the next page build takes them off the build list and nothing frees them.

kmemleak after a firmware crash with an AP interface:

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]
    rtw_ops_change_interface+0x6c/0x80 [rtw88_core]
    drv_change_interface+0x100/0x258 [mac80211]

Free the pages where the recovery resets the interface.

With the pages freed, a reserved page download before mac80211 adds the interfaces again finds no page and warns "Should not have an empty reserved page". The beacon update work queued by rtw_ops_set_tim() and a beacon change through rtw_ops_bss_info_changed() can both get there:
the recovery drops the driver mutex in rtw_core_stop(), and mac80211 restarts the hardware only after the recovery. The recovery also clears the port of every interface, and rtw_ops_add_interface() sets it again, so download nothing and send no page locations while no port is in use.

Fixes 5c831644e1f4 ("rtw88: handle and recover when firmware crash")

---

Notes:
v3: 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, which also covers a beacon change in the restart window and a TIM update during the reconfiguration (Luka Gejak)
v2: the beacon update work does nothing while RTW_FLAG_RESTARTING is set
(Luka Gejak): rtw_ops_set_tim() can queue it between the reset and the reconfiguration, where it found no page and warned

 drivers/net/wireless/realtek/rtw88/fw.c   | 6 ++++++
 drivers/net/wireless/realtek/rtw88/main.c | 1 +
 2 files changed, 7 insertions(+)
drivers/net/wireless/realtek/rtw88/fw.c +6 -0
index 945fedcd375b..c66dc9086378 100644
@@ -1059,6 +1059,9 @@ void rtw_send_rsvd_page_h2c(struct rtw_dev *rtwdev)
 	u8 h2c_pkt[H2C_PKT_SIZE] = {0};
 	u8 location = 0;
 
+	if (bitmap_empty(rtwdev->hw_port, RTW_PORT_NUM))
+		return;
+
 	SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_RSVD_PAGE);
 
 	location = rtw_get_rsvd_page_location(rtwdev, RSVD_PROBE_RESP);
@@ -1765,6 +1768,9 @@ int rtw_fw_download_rsvd_page(struct rtw_dev *rtwdev)
 	u32 size;
 	int ret;
 
+	if (bitmap_empty(rtwdev->hw_port, RTW_PORT_NUM))
+		return 0;
+
 	buf = rtw_build_rsvd_page(rtwdev, &size);
 	if (!buf) {
 		rtw_err(rtwdev, "failed to build rsvd page pkt\n");
drivers/net/wireless/realtek/rtw88/main.c +1 -0
index f7708ad17b6f..adc54b063382 100644
@@ -627,6 +627,7 @@ static void rtw_reset_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
 	rtw_bf_disassoc(rtwdev, vif, NULL);
 	rtw_vif_assoc_changed(rtwvif, NULL);
 	rtw_txq_cleanup(rtwdev, vif->txq);
+	rtw_remove_rsvd_page(rtwdev, rtwvif);
 
 	rtw_release_macid(rtwdev, rtwvif->mac_id);
 }
Signature · 1 line
2.56.0
#2 lore raw

Re: [PATCH rtw-next v3 1/5] wifi: rtw88: free the reserved pages of an interface on firmware recovery

Hi Mehmet,

Thanks for the update. Two comments below.

drivers/net/wireless/realtek/rtw88/fw.c int rtw_fw_download_rsvd_page(struct rtw_dev *rtwdev) · line 1774

Quoted 8 lines · Mehmet Fide
drivers/net/wireless/realtek/rtw88/fw.c +3 -0
@@ -1765,6 +1768,9 @@ int rtw_fw_download_rsvd_page(struct rtw_dev *rtwdev)
 	u32 size;
 	int ret;
 
+	if (bitmap_empty(rtwdev->hw_port, RTW_PORT_NUM))
+		return 0;
+
 	buf = rtw_build_rsvd_page(rtwdev, &size);

Could this skip a download that WoWLAN needs? If suspend flushes the recovery work while it holds RTNL, ieee80211_restart_work() cannot add the interfaces back before rtw_wow_suspend() runs. With net detect configured, the station interface can still be picked for WoWLAN. rtw_wow_leave_no_link_ps() can power the device back up without setting the port bitmap again.

So rtw_wow_config_wow_fw_rsvd_page() adds the scan pages, but the check above returns success before downloading them. rtw_wow_fw_start() then tries to enable net detect with a zero page location for the NLO and channel tables. Could we keep the skip in the beacon update paths, or have suspend fall back to the normal suspend path when a restart is pending?

[ ... ]

drivers/net/wireless/realtek/rtw88/main.c static void rtw_reset_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) · line 636

Quoted 5 lines
drivers/net/wireless/realtek/rtw88/main.c +1 -0
@@ -633,6 +633,7 @@ static void rtw_reset_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
 	rtw_bf_disassoc(rtwdev, vif, NULL);
 	rtw_vif_assoc_changed(rtwvif, NULL);
 	rtw_txq_cleanup(rtwdev, vif->txq);
+	rtw_remove_rsvd_page(rtwdev, rtwvif);

I think the empty list warning can still happen with AP and station interfaces on the RTL8822C. If a station interface comes up after the reset clears the bitmap, rtw_ops_add_interface() sets a port before ieee80211_do_open() marks the interface running. The AP still has an empty list, and the page iterator skips the station interface until it is running.

Can a TIM update from the AP run in that gap? For example, the station cleanup timer can expire a buffered frame after rtw_core_stop() cancels the beacon work. The worker can then see a port in use and still hit "Should not have an empty reserved page". Would it make sense to free the old pages before reinitializing the list when adding an interface that was already initialized, as Zong-Zhe suggested?

https://lore.kernel.org/linux-wireless/[email protected]/

Best regards,
Luka Gejak

#3 lore raw

Re: [PATCH rtw-next v3 1/5] wifi: rtw88: free the reserved pages of an interface on firmware recovery

Hi Luka,

Quoted 3 lines

Could this skip a download that WoWLAN needs? If suspend flushes the recovery work while it holds RTNL, ieee80211_restart_work() cannot add the interfaces back before rtw_wow_suspend() runs.

Yes. On an RTL8822CE with net detect configured, a firmware crash forced right before suspend made rtw_wow_suspend() run with no port in use. The download was skipped and the driver logged "failed to get probe_req rsvd loc".

Quoted 2 lines

I think the empty list warning can still happen with AP and station interfaces on the RTL8822C.

It can. With the window widened by a test build, a station interface brought up during the recovery got port 0, and a queued beacon update then hit "Should not have an empty reserved page".

v4 follows Zong-Zhe's suggestion: the reset no longer frees the pages, rtw_ops_add_interface() frees the old pages of an interface that was already initialized, and both port checks go away. The lists then stay filled through the recovery, and the TIM update you raised on v2 is not skipped. I will run both tests above again on v4.

Mehmet

#4 lore raw

PATCH v3 2/5 wifi: rtw88: report the frames purged from the TX report queue

In reply to Mehmet Fide

From: Mehmet Fide <[email protected]>

A frame whose sender asked for its TX status waits in the TX report queue for the report of the firmware. When no report comes, the purge timer frees the frames with skb_queue_purge(), and rtw_core_deinit() does the same. mac80211 is not told: the sender gets no status, and the copy mac80211 keeps for the status of a frame from user space stays in its list until ieee80211_free_hw() warns about it. On an RTL8822CE with hostapd, after a firmware crash and an unbind of the driver:

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]
 pci_device_remove+0x44/0xd4

Take the frames off the queue under its lock and hand them to ieee80211_purge_tx_queue(), which reports each one as not sent.

Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")

---

Notes:
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   | 20 ++++++++++++++++----
 drivers/net/wireless/realtek/rtw88/tx.h   |  1 +
 3 files changed, 18 insertions(+), 8 deletions(-)
drivers/net/wireless/realtek/rtw88/main.c +1 -4
index adc54b063382..ce65a1a80840 100644
@@ -2225,7 +2225,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);
 
@@ -2237,9 +2236,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 +16 -4
index 701ed7c4f3f7..87d993282b1c 100644
@@ -176,21 +176,33 @@ 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)
drivers/net/wireless/realtek/rtw88/tx.h +1 -0
index 168f48e87853..363f63525965 100644
@@ -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
#5 lore raw

Re: [PATCH rtw-next v3 2/5] wifi: rtw88: report the frames purged from the TX report queue

Hi Mehmet,

Thanks for the patch. One comment below.

drivers/net/wireless/realtek/rtw88/tx.c static void rtw_tx_report_enable(struct rtw_dev *rtwdev, · line 191

Quoted 5 lines · Mehmet Fide
drivers/net/wireless/realtek/rtw88/tx.c +5 -0
+	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);

As far as I can see, an AP peer probe that times out can report an ACK signal and a link ID from the old TX control fields. On x86_64, status.flags and status.link_valid overlap control.vif. The firmware report path clears the status before handing the skb back, but the purge path passes it straight to mac80211. The timer can do this while the AP is still up.

ieee80211_report_ack_skb() reads those fields for a null frame even when it was dropped. cfg80211_probe_status() can then include both attributes in the event without an ACK. Could we clear the TX status in rtw_tx_report_enqueue() before saving the sequence number?

Best regards,
Luka Gejak

#6 lore raw

Re: [PATCH rtw-next v3 2/5] wifi: rtw88: report the frames purged from the TX report queue

Hi Luka,

Quoted 2 lines

Could we clear the TX status in rtw_tx_report_enqueue() before saving the sequence number?

Yes. With a test build that drops the firmware reports, a purged QoS null frame reached mac80211 with status.flags 0xff and link ID 15 on arm64, and userspace got a probe client event without ACK. v4 clears the status there. Since the patch changes, I will drop your Reviewed-by from it.

Mehmet

#7 lore raw

PATCH v3 3/5 wifi: rtw88: do not drop stations when collecting them for an iteration

In reply to Mehmet Fide

From: Mehmet Fide <[email protected]>

rtw_iterate_stas() collects the stations with an atomic iterator and calls the iterator for them afterwards. It allocates an entry for each station with GFP_ATOMIC and silently skips the station when that fails.

The firmware recovery resets the stations through it with the next patch. A skipped station keeps its TX queues on rtwdev->txqs, and when mac80211 adds it again, rtw_txq_init() reinitializes the list node of a queue that is still linked there.

Link the stations through a list node in struct rtw_sta_info instead, so the collection cannot fail. All callers hold rtwdev->mutex, which keeps two collections apart, and no station iterator collects again.

Fixes 78d5bf925f30 ("wifi: rtw88: iterate over vif/sta list non-atomically")

---

Notes:
v3: new, recovery resets every station through rtw_iterate_stas() with
the next patch (Luka Gejak)

 drivers/net/wireless/realtek/rtw88/main.h |  1 +
 drivers/net/wireless/realtek/rtw88/util.c | 24 ++++++-----------------
 2 files changed, 7 insertions(+), 18 deletions(-)
drivers/net/wireless/realtek/rtw88/main.h +1 -0
index 6ecbeb4ffe4b..6b26c517c738 100644
@@ -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 +6 -18
index fcd6eb1ab32a..3e8a520177d1 100644
@@ -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;
@@ -120,14 +115,9 @@ struct rtw_iter_stas_data {
 static void rtw_collect_sta_iter(void *data, struct ieee80211_sta *sta)
 {
 	struct rtw_iter_stas_data *iter_stas = data;
-	struct rtw_stas_entry *stas_entry;
+	struct rtw_sta_info *si = (struct rtw_sta_info *)sta->drv_priv;
 
-	stas_entry = kmalloc_obj(*stas_entry, GFP_ATOMIC);
-	if (!stas_entry)
-		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 +126,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 +139,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
#8 lore raw

Re: [PATCH rtw-next v3 3/5] wifi: rtw88: do not drop stations when collecting them for an iteration

Hi Mehmet,

Thanks for taking care of the allocation failure. One comment below.

Quoted 4 lines · Mehmet Fide

static void rtw_collect_sta_iter(void *data, struct ieee80211_sta *sta) {

drivers/net/wireless/realtek/rtw88/util.c +0 -1
 	struct rtw_iter_stas_data *iter_stas = data;
-	struct rtw_stas_entry *stas_entry;

drivers/net/wireless/realtek/rtw88/util.c struct rtw_iter_stas_data { · line 121

Quoted 10 lines
drivers/net/wireless/realtek/rtw88/util.c +2 -6
+	struct rtw_sta_info *si = (struct rtw_sta_info *)sta->drv_priv;
 
-	stas_entry = kmalloc_obj(*stas_entry, GFP_ATOMIC);
-	if (!stas_entry)
-		return;
-
-	stas_entry->sta = sta;
-	list_add_tail(&stas_entry->list, &iter_stas->list);
+	list_add_tail(&si->iter_list, &iter_stas->list);
 }

Does the driver mutex still pin a client that has already gone back from ASSOC to AUTH? In AP mode mac80211 can do that when userspace clears ASSOCIATED. drv_sta_state() calls rtw_ops_sta_remove() then, but leaves sta->uploaded set, so the watchdog can still collect the client.

If userspace deletes that client after the collection drops RCU, mac80211 can free it without calling rtw_ops_sta_remove() again. The temporary list now has a node in the freed station. list_del_init() can write to that node before the callback runs. The old code already kept the station pointer too long, and this adds the list operations on it.

Could we skip stations with no si->vif while collecting them? As far as I can see, rtw_sta_remove() clears it under the same mutex.

Best regards,
Luka Gejak

#9 lore raw

Re: [PATCH rtw-next v3 3/5] wifi: rtw88: do not drop stations when collecting them for an iteration

Hi Luka,

Quoted 2 lines

Does the driver mutex still pin a client that has already gone back from ASSOC to AUTH?

No. I reproduced it with a small netlink tool that clears ASSOCIATED, which hostapd never does: rtw_sta_remove() ran, the watchdog still collected the client, and deleting it while a test build held the collection freed it in mac80211 without a second rtw_sta_remove().

Quoted 2 lines

Could we skip stations with no si->vif while collecting them? As far as I can see, rtw_sta_remove() clears it under the same mutex.

rtw_sta_remove() does not clear it today, si->vif is only set in rtw_sta_add(). The client above was collected with si->vif still set. v4 clears it in rtw_sta_remove() and skips such stations in rtw_collect_sta_iter(). That also stops a firmware recovery from calling rtw_sta_remove() a second time for such a client.

Mehmet

#10 lore raw

Re: [PATCH rtw-next v3 3/5] wifi: rtw88: do not drop stations when collecting them for an iteration

Hi Mehmet,

Thanks for reproducing this. I was looking at 0bdc579dbfc2, which already has b719e9bced93 clearing si->vif in rtw_sta_remove().

Could you rebase v4 on rtw-next and keep the si->vif check in rtw_collect_sta_iter()? That should cover the case you reproduced.

Best regards,
Luka Gejak

#11 lore raw

Re: [PATCH rtw-next v3 3/5] wifi: rtw88: do not drop stations when collecting them for an iteration

Hi Luka,

Quoted 2 lines

Thanks for reproducing this. I was looking at 0bdc579dbfc2, which already has b719e9bced93 clearing si->vif in rtw_sta_remove().

Right, my test tree was older than that commit, so what I wrote about rtw_sta_remove() was wrong.

Quoted 2 lines

Could you rebase v4 on rtw-next and keep the si->vif check in rtw_collect_sta_iter()? That should cover the case you reproduced.

Yes. On rtw-next 0bdc579dbfc2 with v3, the client was collected with si->vif NULL and was gone from mac80211 after the held collection in 2 of 3 runs; in the third the watchdog did not collect it in time. With the check in v4 it was skipped in 3 of 4 runs. In the fourth the collection came before the client went back to AUTH, and the removal waited for it.

Mehmet

#12 lore raw

PATCH v3 4/5 wifi: rtw88: reset the stations outside of RCU on firmware recovery

In reply to Mehmet Fide

From: 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.

Fixes bcafcb959a57 ("wifi: rtw88: use work to update rate to avoid RCU warning")

---

Notes:
v3: no change; the station skip Luka Gejak found is removed by the
previous patch
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
index ce65a1a80840..8e7ae747b900 100644
@@ -664,7 +664,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
#13 lore raw

PATCH v3 5/5 wifi: rtw88: clear the restart flag when the device is stopped

In reply to Mehmet Fide

From: Mehmet Fide <[email protected]>

The firmware recovery sets RTW_FLAG_RESTARTING, and rtw_reconfig_complete() clears it once mac80211 has restarted the hardware. If the last interface goes down before the restart work runs, ieee80211_reconfig() finds no open interface and does not call reconfig_complete(), so the flag is still set when an interface comes up again. rtw_fw_recovery() then ignores every later firmware crash, and writing the fw_crash debugfs file returns -EINPROGRESS.

Clear the flag in rtw_ops_stop(). mac80211 does not stop the device while it restarts it, so a stop leaves no restart to wait for.

Fixes 5c831644e1f4 ("rtw88: handle and recover when firmware crash")

---

Notes:
v3: new (Luka Gejak)

 drivers/net/wireless/realtek/rtw88/mac80211.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/realtek/rtw88/mac80211.c +1 -0
index 5e40cf06a9e3..10f1ae08f383 100644
@@ -68,6 +68,7 @@ static void rtw_ops_stop(struct ieee80211_hw *hw, bool suspend)
 
 	mutex_lock(&rtwdev->mutex);
 	rtw_core_stop(rtwdev);
+	clear_bit(RTW_FLAG_RESTARTING, rtwdev->flags);
 	mutex_unlock(&rtwdev->mutex);
 }
 
Signature · 1 line
2.56.0
#14 lore raw

Re: [PATCH rtw-next v3 5/5] wifi: rtw88: clear the restart flag when the device is stopped

Hi Ping-Ke,

Commit 3f2238709f5d ("wifi: rtw88: clear RTW_FLAG_RESTARTING on stop and start failure") in rtw-next fixes the same case, so please drop this one. Patches 1-4 apply to rtw-next as they are.

Mehmet

maintainer
#15 lore raw

RE: [PATCH rtw-next v3 5/5] wifi: rtw88: clear the restart flag when the device is stopped

Mehmet Fide <[email protected]> wroet:

Quoted 5 lines

Hi Ping-Ke,

Commit 3f2238709f5d ("wifi: rtw88: clear RTW_FLAG_RESTARTING on stop and start failure") in rtw-next fixes the same case, so please drop this one. Patches 1-4 apply to rtw-next as they are.

Dropped from patchwork.

#16 lore raw
In reply to Mehmet Fide
Quoted 5 lines · Mehmet Fide

From: Mehmet Fide <[email protected]>

Fixes for what a firmware crash test showed on an RTL8822CE, and for what Luka found in v2. Patches 3 and 5 are new.

Hi Mehmet,

I won't be available today as I am going outside my country's borders for some trip. I will take a look at both of your patch series and that RFC you have sent in the meantime and sent my comments when I am back(I won't have internet there).

Best regards,
Luka Gejak