wifi: iwlwifi: release frames before one beyond the reorder window
Subsystems (2)
cover wifi: iwlwifi: release frames before one beyond the reorder window
An AP that gives up on an MPDU of a BA session without sending a BAR and keeps transmitting will eventually send a frame with SN == head_sn + buf_size. Both iwlmvm and iwlmld store that frame in the slot of head_sn and then release it ahead of the frames before it, which all fail the PN check. A single lost MPDU becomes a burst of up to 63 dropped frames, i.e. a TCP loss burst.
I ran into this with an AX210 (iwlmvm) on an rtw88 SDIO AP (RTL8822CS) that drops frames without a BAR while the client is off-channel for background scans; the AP side is a separate problem. A kprobe at the PN check showed every burst starting with the frame at hole + 64.
Patch 1 restores the window check that iwlmvm had before the reorder buffer was simplified. Tested on 7.2.15 (same code): PN-replay drops per client scan went from about 280 to about 12, and in normal use (8 two-minute bidirectional TCP runs each) from 290 to 3 per run.
Patch 2 does the same for iwlmld, which has the same code. I have no iwlmld hardware; it adds a KUnit case that fails without the fix and passes with it.
The patches were generated with the help of an LLM; I have reviewed them (to the best of my ability), and tested patch 1 on actual hardware as described above (patch 2 only with the KUnit case).
David Härdeman (2):
wifi: iwlwifi: mvm: release frames before one beyond the window
wifi: iwlwifi: mld: release frames before one beyond the window
drivers/net/wireless/intel/iwlwifi/mld/agg.c | 14 ++++++++++ .../wireless/intel/iwlwifi/mld/tests/agg.c | 28 +++++++++++++++++++ drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 13 +++++++++ 3 files changed, 55 insertions(+)
base-commit: 3627924ed81fd7783394fb2555ea179c6606a231
Signature · 1 line
2.47.3
PATCH 1/2 wifi: iwlwifi: mvm: release frames before one beyond the window
If a transmitter gives up on an MPDU of a BA session without sending a BAR and keeps sending, it can send a frame with SN == head_sn + buf_size (or beyond). The firmware then moves the window and reports an NSSN past the hole, but iwl_mvm_reorder() first stores the frame at sn % buf_size, which is the slot of head_sn. iwl_mvm_release_frames() starts at head_sn and so passes the new frame to mac80211 ahead of the buf_size - 1 frames before it, and those then all fail iwl_mvm_check_pn(): one lost frame turns into buf_size lost frames.
Seen with an AX210 (iwlmvm, 7.2.15) on an rtw88 AP during client background scans: bursts of up to 63 PN-replay drops per lost frame (two such bursts back to back when two holes were close together), each starting with the frame at hole + 64 (traced at iwl_mvm_release_frames, e.g. SN 447 PN 0x1bb3f0 passed, then SN 384-446 with PN 0x1bb3b1-0x1bb3ef dropped).
The driver used to release frames up to min(sn, nssn) for a frame outside the window; that check went with the RSS-sync logic. Restore just the window check.
With the fix, the PN-replay drops in that setup went from about 280 to about 12 per client scan.
--- drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c +13 -0
@@ -899,6 +899,19 @@ static bool iwl_mvm_reorder(struct iwl_mvm *mvm,return false; } +/* +* A frame beyond the end of the reorder window means that the +* transmitter gave up on older frames without sending a BAR. The +* firmware moves the window (NSSN) for it, but the frame would be +* stored in the slot of an older SN and released ahead of the frames +* before it, which would then all fail the PN check. Release the +* older frames first, as for a BAR. +*/ +if (!ieee80211_sn_less (sn,ieee80211_sn_add (buffer->head_sn, + baid_data->buf_size))) +iwl_mvm_release_frames (mvm, sta, napi, baid_data, buffer, +ieee80211_sn_less (sn, nssn) ? sn : nssn); +/* put in reorder buffer */ index = sn % baid_data->buf_size;__skb_queue_tail (&entries[index].frames, skb);
Signature · 1 line
2.47.3
PATCH 2/2 wifi: iwlwifi: mld: release frames before one beyond the window
In reply to David Härdemaniwl_mld_reorder() has the same problem as iwlmvm had: a frame with SN >= head_sn + buf_size, which a transmitter sends after giving up on an older MPDU without a BAR, is stored in the slot of head_sn, and iwl_mld_reorder_release_frames() then passes it to mac80211 ahead of the frames before it, which all fail the PN check.
Release the older frames first, up to min(sn, nssn), as iwlmvm did before the reorder buffer was simplified, and add a KUnit case for it.
Not tested on hardware (seen and tested with iwlmvm on an AX210); the new KUnit case fails without the fix (SN=164 is released first) and passes with it.
--- drivers/net/wireless/intel/iwlwifi/mld/agg.c | 14 ++++++++++ .../wireless/intel/iwlwifi/mld/tests/agg.c | 28 +++++++++++++++++++ 2 files changed, 42 insertions(+)
drivers/net/wireless/intel/iwlwifi/mld/agg.c +14 -0
@@ -305,6 +305,20 @@ iwl_mld_reorder(struct iwl_mld *mld, struct napi_struct *napi,return IWL_MLD_PASS_SKB ; } +/* A frame beyond the end of the reorder window means that the +* transmitter gave up on older frames without sending a BAR. The +* firmware moves the window (NSSN) for it, but the frame would be +* stored in the slot of an older SN and released ahead of the frames +* before it, which would then all fail the PN check. Release the +* older frames first, as for a BAR. +*/ +if (!ieee80211_sn_less (sn,ieee80211_sn_add (buffer->head_sn, + baid_data->buf_size))) +iwl_mld_reorder_release_frames (mld, link_sta, napi, baid_data, + buffer, +ieee80211_sn_less (sn, nssn) ? + sn : nssn); +/* put in reorder buffer */ index = sn % baid_data->buf_size;__skb_queue_tail (&entries[index].frames, skb);
drivers/net/wireless/intel/iwlwifi/mld/tests/agg.c +28 -0
@@ -426,6 +426,34 @@ static const struct reorder_buffer_case { .head_sn = 100, }, }, + { + .desc = "RX packet beyond the reorder window, release older packets first", + .rx_pkt = { + .fc = FC_QOS_DATA, + .sn = 164, + .nssn = 165, + }, + .reorder_buf_state = { + .valid = true, + .head_sn = 100, + .num_entries = 2, + .entries[0].sn = 101, + .entries[1].sn = 102, + }, + .expected = { +/* 1. Reorder buffer contains SN={101, 102}, hole at 100. +* 2. RX packet SN=164 = head_sn + BA_WINDOW_SIZE: the +* transmitter gave up on SN=100 (no BAR), NSSN moves +* past it. SN=164 maps to the slot of SN=100. +* The stored packets are released before the RX packet. +*/ + .reorder_res = IWL_MLD_BUFFERED_SKB, + .num_stored = 0, + .head_sn = 165, + .skb_release_order = {101, 102, 164}, + .skb_release_order_count = 3, + }, + }, };KUNIT_ARRAY_PARAM_DESC (test_reorder_buffer, reorder_buffer_cases, desc);
Signature · 1 line
2.47.3