git: 1ec403297e4e - stable/14 - LinuxKPI: 802.11: better dealing with errors in RX path

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Fri, 18 Apr 2025 14:37:27 UTC
The branch stable/14 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=1ec403297e4e7585a6fbc753de8cec0244c58d6d

commit 1ec403297e4e7585a6fbc753de8cec0244c58d6d
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-04-13 20:53:36 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-04-18 14:36:03 +0000

    LinuxKPI: 802.11: better dealing with errors in RX path
    
    In case we fail to allocate the mbuf or mtag in the RX path or fail
    for other reasons report it as ic_ierrors for better diagnostics
    and more correct statistics.
    Also do what the comment had indicated and mandate that mtag allocation
    succeeds or otherwise drop the packet.  There may be room for future
    improvements in a follow-up commit here.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit c013f810ecb615289c2bd69a10f4317a3a867d50)
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 29 +++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 19ad12d73d12..11c0077fe571 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -6446,8 +6446,12 @@ linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
 	uint8_t rssi;
 	bool is_beacon;
 
+	lhw = HW_TO_LHW(hw);
+	ic = lhw->ic;
+
 	if (skb->len < 2) {
 		/* Need 80211 stats here. */
+		counter_u64_add(ic->ic_ierrors, 1);
 		IMPROVE();
 		goto err;
 	}
@@ -6457,8 +6461,10 @@ linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
 	 * have an mbuf backing the skb data then?
 	 */
 	m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR);
-	if (m == NULL)
+	if (m == NULL) {
+		counter_u64_add(ic->ic_ierrors, 1);
 		goto err;
+	}
 	m_copyback(m, 0, skb->tail - skb->data, skb->data);
 
 	shinfo = skb_shinfo(skb);
@@ -6523,9 +6529,6 @@ no_trace_beacons:
 	rssi = 0;
 	lkpi_convert_rx_status(hw, rx_status, &rx_stats, &rssi);
 
-	lhw = HW_TO_LHW(hw);
-	ic = lhw->ic;
-
 	ok = ieee80211_add_rx_params(m, &rx_stats);
 	if (ok == 0) {
 		m_freem(m);
@@ -6628,28 +6631,28 @@ skip_device_ts:
 	}
 #endif
 
-	/*
-	 * Attach meta-information to the mbuf for the deferred RX path.
-	 * Currently this is best-effort.  Should we need to be hard,
-	 * drop the frame and goto err;
-	 */
+	/* Attach meta-information to the mbuf for the deferred RX path. */
 	if (ni != NULL) {
 		struct m_tag *mtag;
 		struct lkpi_80211_tag_rxni *rxni;
 
 		mtag = m_tag_alloc(MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI,
 		    sizeof(*rxni), IEEE80211_M_NOWAIT);
-		if (mtag != NULL) {
-			rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1);
-			rxni->ni = ni;		/* We hold a reference. */
-			m_tag_prepend(m, mtag);
+		if (mtag == NULL) {
+			m_freem(m);
+			counter_u64_add(ic->ic_ierrors, 1);
+			goto err;
 		}
+		rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1);
+		rxni->ni = ni;		/* We hold a reference. */
+		m_tag_prepend(m, mtag);
 	}
 
 	LKPI_80211_LHW_RXQ_LOCK(lhw);
 	if (lhw->rxq_stopped) {
 		LKPI_80211_LHW_RXQ_UNLOCK(lhw);
 		m_freem(m);
+		counter_u64_add(ic->ic_ierrors, 1);
 		goto err;
 	}