[PATCH ath-next v1 07/10] wifi: ath11k: look the peer of a received MSDU up once

From: Julius Bairaktaris

Date: Mon Nov 23 2026 - 08:43:00 EST


ath11k_dp_rx_h_mpdu() looks up the peer of each MSDU by its peer id in the
rhashtable, under base_lock, for the cipher, and
ath11k_dp_rx_deliver_msdu() looks it up again for the station it hands to
mac80211, under a second hold of the lock. In a profile of bridged uplink
at 900 Mbit/s (IPQ8074, one run) the lookup and its hash take 1.7 % of
all samples (ath11k_peer_find_by_id() 1.12 %, rhashtable_jhash2()
0.62 %).

Keep the station ath11k_dp_rx_h_mpdu() found in the frame's control
block, and have ath11k_dp_rx_deliver_msdu() take it from there. mac80211
then gets the station of the peer whose cipher the frame was handled
with, where two lookups could find different peers if the peer table
changed between them. The station is used after the lock and in the same
NAPI poll, as ath11k_dp_rx_deliver_msdu() used the station of its own
lookup after the lock. A frame that does not pass ath11k_dp_rx_h_mpdu(),
from the monitor and error paths, still looks its peer up; the mark is
cleared where those frames are reaped and when it is read. The debug
message prints the station's address.

Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@xxxxxxxxxxxxxx>
---
drivers/net/wireless/ath/ath11k/core.h | 3 +++
drivers/net/wireless/ath/ath11k/dp_rx.c | 33 ++++++++++++++++++++-----
2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h
index a0d725923ef2..4eb40e674c14 100644
--- a/drivers/net/wireless/ath/ath11k/core.h
+++ b/drivers/net/wireless/ath/ath11k/core.h
@@ -131,6 +131,8 @@ struct ath11k_skb_rxcb {
bool is_continuation;
bool is_mcbc;
bool is_eapol;
+ /* sta holds the station of the peer ath11k_dp_rx_h_mpdu() found */
+ bool sta_valid;
struct hal_rx_desc *rx_desc;
u8 err_rel_src;
u8 err_code;
@@ -140,6 +142,7 @@ struct ath11k_skb_rxcb {
u8 tid;
u16 peer_id;
u16 seq_no;
+ struct ieee80211_sta *sta;
};

enum ath11k_hw_rev {
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index e8226b2b832c..ff09463d829f 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -2512,6 +2512,14 @@ static int ath11k_dp_rx_h_mpdu(struct ath11k *ar,

spin_lock_bh(&ar->ab->base_lock);
peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu);
+ /*
+ * For ath11k_dp_rx_deliver_msdu(): the station of the peer whose
+ * cipher the frame is handled with, from the same hold of the lock.
+ */
+ BUILD_BUG_ON(sizeof(struct ath11k_skb_rxcb) >
+ sizeof_field(struct sk_buff, cb));
+ rxcb->sta = peer ? peer->sta : NULL;
+ rxcb->sta_valid = true;
if (peer) {
if (rxcb->is_mcbc)
enctype = peer->sec_type_grp;
@@ -2721,17 +2729,27 @@ static void ath11k_dp_rx_deliver_msdu(struct ath11k *ar, struct napi_struct *nap
if (!(status->flag & RX_FLAG_ONLY_MONITOR))
decap = ath11k_dp_rx_h_msdu_start_decap_type(ar->ab, rxcb->rx_desc);

- spin_lock_bh(&ar->ab->base_lock);
- peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu);
- if (peer && peer->sta)
- pubsta = peer->sta;
- spin_unlock_bh(&ar->ab->base_lock);
+ /*
+ * The station ath11k_dp_rx_h_mpdu() found for the frame, if it ran,
+ * so that mac80211 gets the station whose cipher the frame was
+ * handled with.
+ */
+ if (rxcb->sta_valid) {
+ rxcb->sta_valid = false;
+ pubsta = rxcb->sta;
+ } else {
+ spin_lock_bh(&ar->ab->base_lock);
+ peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu);
+ if (peer && peer->sta)
+ pubsta = peer->sta;
+ spin_unlock_bh(&ar->ab->base_lock);
+ }

ath11k_dbg(ar->ab, ATH11K_DBG_DATA,
"rx skb %p len %u peer %pM %d %s sn %u %s%s%s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i mic-err %i amsdu-more %i\n",
msdu,
msdu->len,
- peer ? peer->addr : NULL,
+ pubsta ? pubsta->addr : NULL,
rxcb->tid,
is_mcbc ? "mcast" : "ucast",
rxcb->seq_no,
@@ -3081,6 +3099,7 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
continue;
}

+ rxcb->sta_valid = false;
rxcb->is_first_msdu = !!(desc->rx_msdu_info.info0 &
RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU);
rxcb->is_last_msdu = !!(desc->rx_msdu_info.info0 &
@@ -4562,6 +4581,7 @@ int ath11k_dp_rx_process_wbm_err(struct ath11k_base *ab,
continue;
}

+ rxcb->sta_valid = false;
rxcb->err_rel_src = err_info.err_rel_src;
rxcb->err_code = err_info.err_code;
rxcb->rx_desc = (struct hal_rx_desc *)msdu->data;
@@ -5471,6 +5491,7 @@ static int ath11k_dp_rx_mon_deliver(struct ath11k *ar, u32 mac_id,
rxs->flag |= RX_FLAG_ONLY_MONITOR;
ath11k_update_radiotap(ar, ppduinfo, mon_skb, rxs);

+ ATH11K_SKB_RXCB(mon_skb)->sta_valid = false;
ath11k_dp_rx_deliver_msdu(ar, napi, mon_skb, rxs);
mon_skb = skb_next;
} while (mon_skb);
--
2.53.0