Skip to contentSkip to conversation

wifi: mt76: don't pin undrainable PS stations in the tx scheduler

PATCH In review Felix Fietkau 2 participants 33 messages Nov 17 – Nov 18

Subsystems (2)
lore
Share & tools
lore

Felix Fietkau

author maintainer
#0 lore raw

PATCH 1/19 wifi: mt76: don't pin undrainable PS stations in the tx scheduler

A power save station whose buffered frames cannot be delivered consumes no airtime, so its airtime deficit never goes negative, and ieee80211_return_txq() keeps it at the head of the active_txqs list. With all bands on one ieee80211_hw, each scheduling round then ends at that station, and all other stations starve.

Return the txq only when it sent frames or its queue is stopped. __mt76_tx_complete_skb() schedules it again when a buffered frame completes.

Fixes a547b414bf7e ("wifi: mt76: add PS buffering support for HW-managed TIM drivers")
---
 drivers/net/wireless/mediatek/mt76/tx.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/tx.c +5 -2
index ea9993e9a199..0085b7a29fce 100644
@@ -625,10 +625,13 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid)
 			if (!mt76_txq_stopped(q))
 				n_frames = mt76_txq_send_burst(phy, q, mtxq, wcid);
 
-			ieee80211_return_txq(phy->hw, txq, false);
-
 			if (unlikely(n_frames < 0))
 				return n_frames;
+
+			/* an undrainable PS station would starve all others */
+			if (n_frames > 0 || mt76_txq_stopped(q))
+				ieee80211_return_txq(phy->hw, txq, false);
+
 			ret += n_frames;
 			continue;
 		}
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 2/19 wifi: mt76: mt7996: return a negative error for a firmware status

mt7996_mcu_parse_response() returns the status of a UNI event as a positive value. Callers that test for a negative return take a firmware failure as success, and callers that pass the value on hand a positive error to mac80211 and nl80211, which leaves hostapd waiting for a further netlink reply.

Return -EREMOTEIO for a non-zero firmware status.

Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +2 -1
index 34ac25c22b01..94e88455c732 100644
@@ -258,10 +258,11 @@ mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 
 		skb_pull(skb, sizeof(*rxd));
 		event = (struct mt7996_mcu_uni_event *)skb->data;
-		ret = le32_to_cpu(event->status);
 		/* skip invalid event */
 		if (mcu_cmd != le16_to_cpu(event->cid))
 			ret = -EAGAIN;
+		else if (le32_to_cpu(event->status))
+			ret = -EREMOTEIO;
 	} else {
 		skb_pull(skb, sizeof(struct mt7996_mcu_rxd));
 	}
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 3/19 wifi: mt76: mt7996: use the default timeout for STA_REC and BSS_INFO

In reply to Felix Fietkau

mt7996_mcu_set_timeout() gives STA_REC_UPDATE and BSS_INFO_UPDATE a timeout of 2 seconds. Their payload grows with the beacon templates of MBSS and MLD configurations, the firmware can take longer to process them, and an MCU timeout resets the device.

Use the default timeout for both commands.

Fixes beb01caa570c ("wifi: mt76: mt7996: decrease timeout for commonly issued MCU commands")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +0 -2
index 94e88455c732..e56b60346fc4 100644
@@ -282,8 +282,6 @@ mt7996_mcu_set_timeout(struct mt76_dev *mdev, int cmd)
 	case MCU_UNI_CMD_THERMAL:
 	case MCU_UNI_CMD_TWT:
 	case MCU_UNI_CMD_GET_MIB_INFO:
-	case MCU_UNI_CMD_STA_REC_UPDATE:
-	case MCU_UNI_CMD_BSS_INFO_UPDATE:
 		mdev->mcu.timeout = 2 * HZ;
 		return;
 	case MCU_UNI_CMD_EFUSE_CTRL:
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 3/19
#3 lore raw

Re: [PATCH mt76-next 03/19] wifi: mt76: mt7996: use the default timeout for STA_REC and BSS_INFO

Quoted 9 lines

mt7996_mcu_set_timeout() gives STA_REC_UPDATE and BSS_INFO_UPDATE a timeout of 2 seconds. Their payload grows with the beacon templates of MBSS and MLD configurations, the firmware can take longer to process them, and an MCU timeout resets the device.

Use the default timeout for both commands.

Fixes beb01caa570c ("wifi: mt76: mt7996: decrease timeout for commonly issued MCU commands")
Quoted 21 lines
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +0 -2
index 94e88455c732..e56b60346fc4 100644
@@ -282,8 +282,6 @@ mt7996_mcu_set_timeout(struct mt76_dev *mdev, int cmd)
 	case MCU_UNI_CMD_THERMAL:
 	case MCU_UNI_CMD_TWT:
 	case MCU_UNI_CMD_GET_MIB_INFO:
-	case MCU_UNI_CMD_STA_REC_UPDATE:
-	case MCU_UNI_CMD_BSS_INFO_UPDATE:
 		mdev->mcu.timeout = 2 * HZ;
 		return;
 	case MCU_UNI_CMD_EFUSE_CTRL:
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

PATCH 4/19 wifi: mt76: mt7915: use the default timeout for STA_REC and BSS_INFO

In reply to Felix Fietkau

mt7915_mcu_set_timeout() gives STA_REC_UPDATE and BSS_INFO_UPDATE a timeout of 2 seconds. Their payload grows with the beacon templates of MBSS configurations, the firmware can take longer to process them, and an MCU timeout resets the device.

Use the default timeout for both commands, like mt7996.

Fixes 1254c66356d1 ("wifi: mt76: mt7915: decrease timeout for commonly issued MCU commands")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +0 -2
index e66968b819da..9b748b37624d 100644
@@ -214,8 +214,6 @@ mt7915_mcu_set_timeout(struct mt76_dev *mdev, int cmd)
 	case MCU_EXT_CMD_THERMAL_CTRL:
 	case MCU_EXT_CMD_GET_MIB_INFO:
 	case MCU_EXT_CMD_PHY_STAT_INFO:
-	case MCU_EXT_CMD_STA_REC_UPDATE:
-	case MCU_EXT_CMD_BSS_INFO_UPDATE:
 		mdev->mcu.timeout = 2 * HZ;
 		return;
 	case MCU_EXT_CMD_EFUSE_BUFFER_MODE:
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 4/19
#5 lore raw

Re: [PATCH mt76-next 04/19] wifi: mt76: mt7915: use the default timeout for STA_REC and BSS_INFO

Quoted 9 lines

mt7915_mcu_set_timeout() gives STA_REC_UPDATE and BSS_INFO_UPDATE a timeout of 2 seconds. Their payload grows with the beacon templates of MBSS configurations, the firmware can take longer to process them, and an MCU timeout resets the device.

Use the default timeout for both commands, like mt7996.

Fixes 1254c66356d1 ("wifi: mt76: mt7915: decrease timeout for commonly issued MCU commands")
Quoted 21 lines
---
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +0 -2
index e66968b819da..9b748b37624d 100644
@@ -214,8 +214,6 @@ mt7915_mcu_set_timeout(struct mt76_dev *mdev, int cmd)
 	case MCU_EXT_CMD_THERMAL_CTRL:
 	case MCU_EXT_CMD_GET_MIB_INFO:
 	case MCU_EXT_CMD_PHY_STAT_INFO:
-	case MCU_EXT_CMD_STA_REC_UPDATE:
-	case MCU_EXT_CMD_BSS_INFO_UPDATE:
 		mdev->mcu.timeout = 2 * HZ;
 		return;
 	case MCU_EXT_CMD_EFUSE_BUFFER_MODE:
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

PATCH 5/19 wifi: mt76: delete only the RX NAPIs that were added

In reply to Felix Fietkau

mt76_dma_cleanup() calls netif_napi_del() for every RX queue, also for the WED RRO queues of mt7996, which get no NAPI while WED is active. __netif_napi_del() then locks the NULL netdev of that NAPI, and rmmod of mt7996e with WED crashes.

Delete only the RX NAPIs that have a netdev.

Fixes 6b470f36616e ("wifi: mt76: Fix memory leak destroying device")
---
 drivers/net/wireless/mediatek/mt76/dma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/dma.c +2 -1
index a67880a9281c..8c0403820299 100644
@@ -1217,7 +1217,8 @@ void mt76_dma_cleanup(struct mt76_dev *dev)
 	mt76_for_each_q_rx(dev, i) {
 		struct mt76_queue *q = &dev->q_rx[i];
 
-		netif_napi_del(&dev->napi[i]);
+		if (dev->napi[i].dev)
+			netif_napi_del(&dev->napi[i]);
 		mt76_dma_rx_cleanup(dev, q);
 
 		page_pool_destroy(q->page_pool);
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 5/19
#7 lore raw

Re: [PATCH mt76-next 05/19] wifi: mt76: delete only the RX NAPIs that were added

Quoted 9 lines · Felix Fietkau

mt76_dma_cleanup() calls netif_napi_del() for every RX queue, also for the WED RRO queues of mt7996, which get no NAPI while WED is active. __netif_napi_del() then locks the NULL netdev of that NAPI, and rmmod of mt7996e with WED crashes.

Delete only the RX NAPIs that have a netdev.

Fixes 6b470f36616e ("wifi: mt76: Fix memory leak destroying device")
Quoted 22 lines
---
 drivers/net/wireless/mediatek/mt76/dma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/dma.c +2 -1
index a67880a9281c..8c0403820299 100644
@@ -1217,7 +1217,8 @@ void mt76_dma_cleanup(struct mt76_dev *dev)
 	mt76_for_each_q_rx(dev, i) {
 		struct mt76_queue *q = &dev->q_rx[i];
 
-		netif_napi_del(&dev->napi[i]);
+		if (dev->napi[i].dev)
+			netif_napi_del(&dev->napi[i]);
 		mt76_dma_rx_cleanup(dev, q);
 
 		page_pool_destroy(q->page_pool);
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH 6/19 wifi: mt76: mt7996: report radar on the channel context of its band

In reply to Felix Fietkau

mt7996_mcu_rx_radar_detected() reports a radar with a NULL channel context, so mac80211 marks every channel context of the multi-radio wiphy. A radar on the 5 GHz band thus also ends the CAC on the other bands and is reported on their channels.

Report the radar on the channel context of the radio that detected it.

Fixes 69d54ce7491d ("wifi: mt76: mt7996: switch to single multi-radio wiphy")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +7 -1
index e56b60346fc4..b082998a4170 100644
@@ -572,10 +572,16 @@ mt7996_mcu_rx_radar_detected(struct mt7996_dev *dev, struct sk_buff *skb)
 						&dev->rdd2_chandef,
 						GFP_ATOMIC);
 	} else {
+		struct mt76_chanctx *ctx = READ_ONCE(mphy->chanctx);
 		struct mt7996_phy *phy = mphy->priv;
+		struct ieee80211_chanctx_conf *conf;
 
 		phy->rdd_tx_paused = true;
-		ieee80211_radar_detected(mphy->hw, NULL);
+		if (ctx) {
+			conf = container_of((void *)ctx,
+					    struct ieee80211_chanctx_conf, drv_priv);
+			ieee80211_radar_detected(mphy->hw, conf);
+		}
 	}
 	dev->hw_pattern++;
 
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH 7/19 wifi: mt76: mt7996: stop WED before the DMA reset of a full reset

In reply to Felix Fietkau

Unlike the L1 SER path, mt7996_mac_restart() resets the WFSYS while the attached WEDs still access it over PCIe. Their reads during the reset get no completion, and MT7988 reports uncorrectable PCIe completion timeouts on both root ports.

Stop both WEDs at the start of the restart, and disable the WED interrupt agent and wait for it to go idle before the WFSYS reset. The other agents stay enabled, since TX through WED stops after the restart otherwise.

Fixes 83eafc9251d6 ("wifi: mt76: mt7996: add wed tx support")
---
 .../net/wireless/mediatek/mt76/mt7996/dma.c   | 25 ++++++++++++++++++-
 .../net/wireless/mediatek/mt76/mt7996/mac.c   | 19 +++++++++-----
 .../net/wireless/mediatek/mt76/mt7996/regs.h  |  5 ++++
 3 files changed, 42 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/dma.c +24 -1
index 3d9353811a02..4450d35e9439 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2022 MediaTek Inc.
  */
 
+#include <linux/iopoll.h>
 #include "mt7996.h"
 #include "../dma.h"
 #include "mac.h"
@@ -957,6 +958,25 @@ int mt7996_dma_init(struct mt7996_dev *dev)
 	return 0;
 }
 
+static void
+mt7996_wed_int_agent_disable(struct mt7996_dev *dev,
+			     struct mtk_wed_device *wed)
+{
+	u32 val;
+
+	if (!mtk_wed_device_active(wed))
+		return;
+
+	val = mtk_wed_device_reg_read(wed, MT_WED_CTRL);
+	mtk_wed_device_reg_write(wed, MT_WED_CTRL,
+				 val & ~MT_WED_CTRL_WPDMA_INT_AGENT_EN);
+
+	if (read_poll_timeout(mtk_wed_device_reg_read, val,
+			      !(val & MT_WED_CTRL_WPDMA_INT_AGENT_BUSY),
+			      100, 20000, false, wed, MT_WED_CTRL))
+		dev_warn(dev->mt76.dev, "WED interrupt agent still busy\n");
+}
+
 void mt7996_dma_reset(struct mt7996_dev *dev, bool force)
 {
 	struct mt76_phy *phy2 = dev->mt76.phys[MT_BAND1];
@@ -996,8 +1016,11 @@ void mt7996_dma_reset(struct mt7996_dev *dev, bool force)
 		mt7996_rro_msdu_page_map_free(dev);
 
 	/* reset wfsys */
-	if (force)
+	if (force) {
+		mt7996_wed_int_agent_disable(dev, &dev->mt76.mmio.wed_hif2);
+		mt7996_wed_int_agent_disable(dev, &dev->mt76.mmio.wed);
 		mt7996_wfsys_reset(dev);
+	}
 
 	if (dev->hif2 && mtk_wed_device_active(&dev->mt76.mmio.wed_hif2))
 		mtk_wed_device_dma_reset(&dev->mt76.mmio.wed_hif2);
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +13 -6
index 03670293a78f..2e1d98bf823a 100644
@@ -2291,6 +2291,16 @@ void mt7996_tx_token_put(struct mt7996_dev *dev)
 	}
 }
 
+static void
+mt7996_wed_stop(struct mt7996_dev *dev)
+{
+	if (mtk_wed_device_active(&dev->mt76.mmio.wed_hif2))
+		mtk_wed_device_stop(&dev->mt76.mmio.wed_hif2);
+
+	if (mtk_wed_device_active(&dev->mt76.mmio.wed))
+		mtk_wed_device_stop(&dev->mt76.mmio.wed);
+}
+
 static int
 mt7996_mac_restart(struct mt7996_dev *dev)
 {
@@ -2298,6 +2308,8 @@ mt7996_mac_restart(struct mt7996_dev *dev)
 	struct mt7996_phy *phy;
 	int i, ret;
 
+	mt7996_wed_stop(dev);
+
 	if (dev->hif2) {
 		mt76_wr(dev, MT_INT1_MASK_CSR, 0x0);
 		mt76_wr(dev, MT_INT1_SOURCE_CSR, ~0);
@@ -2573,12 +2585,7 @@ void mt7996_mac_reset_work(struct work_struct *work)
 	dev_info(dev->mt76.dev,"\n%s L1 SER recovery start.",
 		 wiphy_name(hw->wiphy));
 
-	if (mtk_wed_device_active(&dev->mt76.mmio.wed_hif2))
-		mtk_wed_device_stop(&dev->mt76.mmio.wed_hif2);
-
-	if (mtk_wed_device_active(&dev->mt76.mmio.wed))
-		mtk_wed_device_stop(&dev->mt76.mmio.wed);
-
+	mt7996_wed_stop(dev);
 	mt7996_npu_hw_stop(dev);
 	ieee80211_stop_queues(mt76_hw(dev));
 
drivers/net/wireless/mediatek/mt76/mt7996/regs.h +5 -0
index 6df6e4c3d45d..e82a281a773a 100644
@@ -782,6 +782,11 @@ enum offs_rev {
 #define MT_WF_SUBSYS_RST_BYPASS_WFDMA2_SLP_PROT	BIT(16)
 #define MT_WF_SUBSYS_RST_WHOLE_PATH_RST_REVERT_CYCLE	GENMASK(15, 8)
 
+/* WED registers, offsets for mtk_wed_device_reg_read() */
+#define MT_WED_CTRL				0x00c
+#define MT_WED_CTRL_WPDMA_INT_AGENT_EN		BIT(0)
+#define MT_WED_CTRL_WPDMA_INT_AGENT_BUSY	BIT(1)
+
 /* PCIE MAC */
 #define MT_PCIE_MAC_BASE			0x74030000
 #define MT_PCIE_MAC(ofs)			(MT_PCIE_MAC_BASE + (ofs))
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 7/19
#10 lore raw

Re: [PATCH mt76-next 07/19] wifi: mt76: mt7996: stop WED before the DMA reset of a full reset

Quoted 5 lines

Unlike the L1 SER path, mt7996_mac_restart() resets the WFSYS while the attached WEDs still access it over PCIe. Their reads during the reset get no completion, and MT7988 reports uncorrectable PCIe completion timeouts on both root ports.

Quoted 7 lines

Stop both WEDs at the start of the restart, and disable the WED interrupt agent and wait for it to go idle before the WFSYS reset. The other agents stay enabled, since TX through WED stops after the restart otherwise.

Fixes 83eafc9251d6 ("wifi: mt76: mt7996: add wed tx support")
Quoted 121 lines
---
 .../net/wireless/mediatek/mt76/mt7996/dma.c   | 25 ++++++++++++++++++-
 .../net/wireless/mediatek/mt76/mt7996/mac.c   | 19 +++++++++-----
 .../net/wireless/mediatek/mt76/mt7996/regs.h  |  5 ++++
 3 files changed, 42 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/dma.c +24 -1
index 3d9353811a02..4450d35e9439 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2022 MediaTek Inc.
  */
 
+#include <linux/iopoll.h>
 #include "mt7996.h"
 #include "../dma.h"
 #include "mac.h"
@@ -957,6 +958,25 @@ int mt7996_dma_init(struct mt7996_dev *dev)
 	return 0;
 }
 
+static void
+mt7996_wed_int_agent_disable(struct mt7996_dev *dev,
+			     struct mtk_wed_device *wed)
+{
+	u32 val;
+
+	if (!mtk_wed_device_active(wed))
+		return;
+
+	val = mtk_wed_device_reg_read(wed, MT_WED_CTRL);
+	mtk_wed_device_reg_write(wed, MT_WED_CTRL,
+				 val & ~MT_WED_CTRL_WPDMA_INT_AGENT_EN);
+
+	if (read_poll_timeout(mtk_wed_device_reg_read, val,
+			      !(val & MT_WED_CTRL_WPDMA_INT_AGENT_BUSY),
+			      100, 20000, false, wed, MT_WED_CTRL))
+		dev_warn(dev->mt76.dev, "WED interrupt agent still busy\n");
+}
+
 void mt7996_dma_reset(struct mt7996_dev *dev, bool force)
 {
 	struct mt76_phy *phy2 = dev->mt76.phys[MT_BAND1];
@@ -996,8 +1016,11 @@ void mt7996_dma_reset(struct mt7996_dev *dev, bool force)
 		mt7996_rro_msdu_page_map_free(dev);
 
 	/* reset wfsys */
-	if (force)
+	if (force) {
+		mt7996_wed_int_agent_disable(dev, &dev->mt76.mmio.wed_hif2);
+		mt7996_wed_int_agent_disable(dev, &dev->mt76.mmio.wed);
 		mt7996_wfsys_reset(dev);
+	}
 
 	if (dev->hif2 && mtk_wed_device_active(&dev->mt76.mmio.wed_hif2))
 		mtk_wed_device_dma_reset(&dev->mt76.mmio.wed_hif2);
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +13 -6
index 03670293a78f..2e1d98bf823a 100644
@@ -2291,6 +2291,16 @@ void mt7996_tx_token_put(struct mt7996_dev *dev)
 	}
 }
 
+static void
+mt7996_wed_stop(struct mt7996_dev *dev)
+{
+	if (mtk_wed_device_active(&dev->mt76.mmio.wed_hif2))
+		mtk_wed_device_stop(&dev->mt76.mmio.wed_hif2);
+
+	if (mtk_wed_device_active(&dev->mt76.mmio.wed))
+		mtk_wed_device_stop(&dev->mt76.mmio.wed);
+}
+
 static int
 mt7996_mac_restart(struct mt7996_dev *dev)
 {
@@ -2298,6 +2308,8 @@ mt7996_mac_restart(struct mt7996_dev *dev)
 	struct mt7996_phy *phy;
 	int i, ret;
 
+	mt7996_wed_stop(dev);
+
 	if (dev->hif2) {
 		mt76_wr(dev, MT_INT1_MASK_CSR, 0x0);
 		mt76_wr(dev, MT_INT1_SOURCE_CSR, ~0);
@@ -2573,12 +2585,7 @@ void mt7996_mac_reset_work(struct work_struct *work)
 	dev_info(dev->mt76.dev,"\n%s L1 SER recovery start.",
 		 wiphy_name(hw->wiphy));
 
-	if (mtk_wed_device_active(&dev->mt76.mmio.wed_hif2))
-		mtk_wed_device_stop(&dev->mt76.mmio.wed_hif2);
-
-	if (mtk_wed_device_active(&dev->mt76.mmio.wed))
-		mtk_wed_device_stop(&dev->mt76.mmio.wed);
-
+	mt7996_wed_stop(dev);
 	mt7996_npu_hw_stop(dev);
 	ieee80211_stop_queues(mt76_hw(dev));
 
drivers/net/wireless/mediatek/mt76/mt7996/regs.h +5 -0
index 6df6e4c3d45d..e82a281a773a 100644
@@ -782,6 +782,11 @@ enum offs_rev {
 #define MT_WF_SUBSYS_RST_BYPASS_WFDMA2_SLP_PROT	BIT(16)
 #define MT_WF_SUBSYS_RST_WHOLE_PATH_RST_REVERT_CYCLE	GENMASK(15, 8)
 
+/* WED registers, offsets for mtk_wed_device_reg_read() */
+#define MT_WED_CTRL				0x00c
+#define MT_WED_CTRL_WPDMA_INT_AGENT_EN		BIT(0)
+#define MT_WED_CTRL_WPDMA_INT_AGENT_BUSY	BIT(1)
+
 /* PCIE MAC */
 #define MT_PCIE_MAC_BASE			0x74030000
 #define MT_PCIE_MAC(ofs)			(MT_PCIE_MAC_BASE + (ofs))
Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH 8/19 wifi: mt76: skip the radiotap TLVs in mt76_skb_get_hdr()

In reply to Felix Fietkau

mt76_skb_get_hdr() skips only the HE radiotap fields, so for a frame with EHT radiotap TLVs in front of the 802.11 header it returns the first TLV. mt76_check_ccmp_pn() then checks QoS Data of EHT PPDUs against the counter of robust Management frames, and mt76_rx_aggr_check_ctl() does not see a BlockAckReq.

Return the mac header for a frame with RX_FLAG_RADIOTAP_TLV_AT_END, which mac80211 requires to point to the 802.11 header.

Fixes 97d7ab9f51ec ("wifi: mt76: mt7925: add EHT radiotap support in monitor mode")
Fixes e016239fcb98 ("wifi: mt76: mt7996: Add eht radiotap tlv")
---
 drivers/net/wireless/mediatek/mt76/mt76.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt76.h +3 -0
index da135e76aabb..8f8388d44aa9 100644
@@ -1485,6 +1485,9 @@ static inline void *mt76_skb_get_hdr(struct sk_buff *skb)
 
 	mstat = *((struct mt76_rx_status *)skb->cb);
 
+	if (mstat.flag & RX_FLAG_RADIOTAP_TLV_AT_END)
+		return skb_mac_header(skb);
+
 	if (mstat.flag & RX_FLAG_RADIOTAP_HE)
 		data += sizeof(struct ieee80211_radiotap_he);
 	if (mstat.flag & RX_FLAG_RADIOTAP_HE_MU)
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH 9/19 wifi: mt76: find the first A-MSDU subframe behind the radiotap data

In reply to Felix Fietkau

mt76_rx_release_amsdu() reads the first subframe relative to skb->data, which points to the radiotap data where the driver pushed HE fields or EHT TLVs. It then misses an RFC1042 header in place of the destination address, so an A-MSDU of an HE or EHT PPDU in 802.11 format passes the mitigation of CVE-2020-24588.

Locate the subframe behind the header that mt76_skb_get_hdr() returns.

Fixes 2c2bdd2372af ("mt76: validate rx A-MSDU subframes")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +7 -4
index bd822193e769..271fbd4711f7 100644
@@ -965,18 +965,21 @@ static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q)
 	 * address.
 	 */
 	if (skb_shinfo(skb)->frag_list) {
-		int offset = 0;
+		u8 *subframe = skb->data;
 
 		if (!(status->flag & RX_FLAG_8023)) {
-			offset = ieee80211_get_hdrlen_from_skb(skb);
+			struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
+
+			subframe = (u8 *)hdr +
+				   ieee80211_hdrlen(hdr->frame_control);
 
 			if ((status->flag &
 			     (RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED)) ==
 			    RX_FLAG_DECRYPTED)
-				offset += 8;
+				subframe += 8;
 		}
 
-		if (ether_addr_equal(skb->data + offset, rfc1042_header)) {
+		if (ether_addr_equal(subframe, rfc1042_header)) {
 			dev_kfree_skb(skb);
 			return;
 		}
Signature · 1 line
2.47.3
maintainer
#13 lore raw

Re: [PATCH mt76-next 09/19] wifi: mt76: find the first A-MSDU subframe behind the radiotap data

Quoted 31 lines

mt76_rx_release_amsdu() reads the first subframe relative to skb->data, which points to the radiotap data where the driver pushed HE fields or EHT TLVs. It then misses an RFC1042 header in place of the destination address, so an A-MSDU of an HE or EHT PPDU in 802.11 format passes the mitigation of CVE-2020-24588.

Locate the subframe behind the header that mt76_skb_get_hdr() returns.

Fixes 2c2bdd2372af ("mt76: validate rx A-MSDU subframes")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +5 -2
index bd822193e769..271fbd4711f7 100644
@@ -965,18 +965,21 @@ static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q)
 	 * address.
 	 */
 	if (skb_shinfo(skb)->frag_list) {
-		int offset = 0;
+		u8 *subframe = skb->data;
 
 		if (!(status->flag & RX_FLAG_8023)) {
-			offset = ieee80211_get_hdrlen_from_skb(skb);
+			struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
+
+			subframe = (u8 *)hdr +
+				   ieee80211_hdrlen(hdr->frame_control);

drivers/net/wireless/mediatek/mt76/mac80211.c static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q) · line 982

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/mac80211.c +2 -2
 
 			if ((status->flag &
 			     (RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED)) ==
 			    RX_FLAG_DECRYPTED)
-				offset += 8;
+				subframe += 8;
 		}
 
-		if (ether_addr_equal(skb->data + offset, rfc1042_header)) {
+		if (ether_addr_equal(subframe, rfc1042_header)) {

maybe I am too paranoic, but should we check this is part of the skb head running pskb_may_pull()? Otherwise I am fine with the patch.

Regards,
Lorenzo

Quoted 7 lines
drivers/net/wireless/mediatek/mt76/mac80211.c +0 -0
 			dev_kfree_skb(skb);
 			return;
 		}
Signature · 1 line
2.47.3
author maintainer
#14 lore raw

Re: [PATCH mt76-next 09/19] wifi: mt76: find the first A-MSDU subframe behind the radiotap data

Quoted 39 lines · Lorenzo Bianconi
Quoted 39 lines

mt76_rx_release_amsdu() reads the first subframe relative to skb->data, which points to the radiotap data where the driver pushed HE fields or EHT TLVs. It then misses an RFC1042 header in place of the destination address, so an A-MSDU of an HE or EHT PPDU in 802.11 format passes the mitigation of CVE-2020-24588.

Locate the subframe behind the header that mt76_skb_get_hdr() returns.

Fixes 2c2bdd2372af ("mt76: validate rx A-MSDU subframes")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +6 -3
index bd822193e769..271fbd4711f7 100644
@@ -965,18 +965,21 @@ static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q)
 	 * address.
 	 */
 	if (skb_shinfo(skb)->frag_list) {
-		int offset = 0;
+		u8 *subframe = skb->data;
 
 		if (!(status->flag & RX_FLAG_8023)) {
-			offset = ieee80211_get_hdrlen_from_skb(skb);
+			struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
+
+			subframe = (u8 *)hdr +
+				   ieee80211_hdrlen(hdr->frame_control);
 
 			if ((status->flag &
 			     (RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED)) ==
 			    RX_FLAG_DECRYPTED)
-				offset += 8;
+				subframe += 8;
 		}
 
Quoted 5 lines

drivers/net/wireless/mediatek/mt76/mac80211.c static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q) · line 982

Quoted 2 lines
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -1
-		if (ether_addr_equal(skb->data + offset, rfc1042_header)) {
+		if (ether_addr_equal(subframe, rfc1042_header)) {

maybe I am too paranoic, but should we check this is part of the skb head running pskb_may_pull()? Otherwise I am fine with the patch.

This is only called for hw-deaggregated A-MSDU subframes, and each subframe has its own buffer. Even if the hardware were to misbehave and pass a truncated subframe here, the pointer would still be much closer to the start of the buffer than the end, and never overflow.

- Felix

maintainer Reviewed-by
#15 lore raw

Re: [PATCH mt76-next 09/19] wifi: mt76: find the first A-MSDU subframe behind the radiotap data

Quoted 42 lines · Felix Fietkau
Quoted 33 lines · Lorenzo Bianconi
Quoted 33 lines

mt76_rx_release_amsdu() reads the first subframe relative to skb->data, which points to the radiotap data where the driver pushed HE fields or EHT TLVs. It then misses an RFC1042 header in place of the destination address, so an A-MSDU of an HE or EHT PPDU in 802.11 format passes the mitigation of CVE-2020-24588.

Locate the subframe behind the header that mt76_skb_get_hdr() returns.

Fixes 2c2bdd2372af ("mt76: validate rx A-MSDU subframes")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +5 -2
index bd822193e769..271fbd4711f7 100644
@@ -965,18 +965,21 @@ static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q)
 	 * address.
 	 */
 	if (skb_shinfo(skb)->frag_list) {
-		int offset = 0;
+		u8 *subframe = skb->data;
 		if (!(status->flag & RX_FLAG_8023)) {
-			offset = ieee80211_get_hdrlen_from_skb(skb);
+			struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
+
+			subframe = (u8 *)hdr +
+				   ieee80211_hdrlen(hdr->frame_control);
 			if ((status->flag &
 			     (RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED)) ==
 			    RX_FLAG_DECRYPTED)
Quoted 8 lines

drivers/net/wireless/mediatek/mt76/mac80211.c static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q) · line 982

Quoted 5 lines
drivers/net/wireless/mediatek/mt76/mac80211.c +2 -2
-				offset += 8;
+				subframe += 8;
 		}
-		if (ether_addr_equal(skb->data + offset, rfc1042_header)) {
+		if (ether_addr_equal(subframe, rfc1042_header)) {

maybe I am too paranoic, but should we check this is part of the skb head running pskb_may_pull()? Otherwise I am fine with the patch.

Quoted 4 lines

This is only called for hw-deaggregated A-MSDU subframes, and each subframe has its own buffer. Even if the hardware were to misbehave and pass a truncated subframe here, the pointer would still be much closer to the start of the buffer than the end, and never overflow.

ack, in this case:

Quoted 2 lines

- Felix

author maintainer
#16 lore raw

PATCH 10/19 wifi: mt76: mark all but the last subframe of an A-MSDU chain

In reply to Felix Fietkau

mt76_rx_complete() passes the subframes of a hardware-split A-MSDU to mac80211 without RX_FLAG_AMSDU_MORE. They share the sequence control of the MPDU, so in 802.11 format ieee80211_rx_h_check_dup() drops the later subframes of a retransmitted A-MSDU as duplicates.

Set RX_FLAG_AMSDU_MORE on every subframe but the last.

Fixes cc4b3c139ad3 ("mt76: mt7915: enable hw rx-amsdu de-aggregation")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +4 -0
index 271fbd4711f7..d72ade2d46cb 100644
@@ -1625,6 +1625,8 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
 		mt76_check_ccmp_pn(skb);
 		skb_shinfo(skb)->frag_list = NULL;
 		mt76_rx_convert(dev, skb, &hw, &link_sta);
+		if (nskb)
+			IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_AMSDU_MORE;
 		ieee80211_rx_list(hw, link_sta, skb, &list);
 
 		/* subsequent amsdu frames */
@@ -1634,6 +1636,8 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
 			skb->next = NULL;
 
 			mt76_rx_convert(dev, skb, &hw, &link_sta);
+			if (nskb)
+				IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_AMSDU_MORE;
 			ieee80211_rx_list(hw, link_sta, skb, &list);
 		}
 	}
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 10/19
#17 lore raw

Re: [PATCH mt76-next 10/19] wifi: mt76: mark all but the last subframe of an A-MSDU chain

Quoted 9 lines

mt76_rx_complete() passes the subframes of a hardware-split A-MSDU to mac80211 without RX_FLAG_AMSDU_MORE. They share the sequence control of the MPDU, so in 802.11 format ieee80211_rx_h_check_dup() drops the later subframes of a retransmitted A-MSDU as duplicates.

Set RX_FLAG_AMSDU_MORE on every subframe but the last.

Fixes cc4b3c139ad3 ("mt76: mt7915: enable hw rx-amsdu de-aggregation")
Quoted 30 lines
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +4 -0
index 271fbd4711f7..d72ade2d46cb 100644
@@ -1625,6 +1625,8 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
 		mt76_check_ccmp_pn(skb);
 		skb_shinfo(skb)->frag_list = NULL;
 		mt76_rx_convert(dev, skb, &hw, &link_sta);
+		if (nskb)
+			IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_AMSDU_MORE;
 		ieee80211_rx_list(hw, link_sta, skb, &list);
 
 		/* subsequent amsdu frames */
@@ -1634,6 +1636,8 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
 			skb->next = NULL;
 
 			mt76_rx_convert(dev, skb, &hw, &link_sta);
+			if (nskb)
+				IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_AMSDU_MORE;
 			ieee80211_rx_list(hw, link_sta, skb, &list);
 		}
 	}
Signature · 1 line
2.47.3
author maintainer
#18 lore raw

PATCH 11/19 wifi: mt76: mt7996: set qos_ctl of a frame that hardware reordered

In reply to Felix Fietkau

mt7996_mac_fill_rx() returns before it sets status->qos_ctl for a frame that the hardware reordered. mt76_check_ccmp_pn() then checks every such frame against the counter of TID 0, so frames of different TIDs read as replays.

Set qos_ctl for these frames as well.

Fixes 950d0abb5cd9 ("wifi: mt76: mt7996: add wed rx support")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +5 -2
index 2e1d98bf823a..c70e429ab419 100644
@@ -707,12 +707,15 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q,
 		}
 	}
 
-	if (!status->wcid || !ieee80211_is_data_qos(fc) || hw_aggr)
+	if (!status->wcid || !ieee80211_is_data_qos(fc))
+		return 0;
+
+	status->qos_ctl = qos_ctl;
+	if (hw_aggr)
 		return 0;
 
 	status->aggr = unicast &&
 		       !ieee80211_is_qos_nullfunc(fc);
-	status->qos_ctl = qos_ctl;
 	status->seqno = IEEE80211_SEQ_TO_SN(seq_ctrl);
 
 	return 0;
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 11/19
#19 lore raw

Re: [PATCH mt76-next 11/19] wifi: mt76: mt7996: set qos_ctl of a frame that hardware reordered

Quoted 9 lines · Felix Fietkau

mt7996_mac_fill_rx() returns before it sets status->qos_ctl for a frame that the hardware reordered. mt76_check_ccmp_pn() then checks every such frame against the counter of TID 0, so frames of different TIDs read as replays.

Set qos_ctl for these frames as well.

Fixes 950d0abb5cd9 ("wifi: mt76: mt7996: add wed rx support")
Quoted 30 lines
---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +5 -2
index 2e1d98bf823a..c70e429ab419 100644
@@ -707,12 +707,15 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q,
 		}
 	}
 
-	if (!status->wcid || !ieee80211_is_data_qos(fc) || hw_aggr)
+	if (!status->wcid || !ieee80211_is_data_qos(fc))
+		return 0;
+
+	status->qos_ctl = qos_ctl;
+	if (hw_aggr)
 		return 0;
 
 	status->aggr = unicast &&
 		       !ieee80211_is_qos_nullfunc(fc);
-	status->qos_ctl = qos_ctl;
 	status->seqno = IEEE80211_SEQ_TO_SN(seq_ctrl);
 
 	return 0;
Signature · 1 line
2.47.3
author maintainer
#20 lore raw

PATCH 12/19 wifi: mt76: check the PN of a BA session frame at its release

In reply to Felix Fietkau

mt76_rx_complete() checks the PN after a frame left the reorder buffer, outside tid->lock. The links of an MLD peer share one PN state, so a frame released on one RX ring can be checked before an earlier frame of the same TID on another ring, which then reads as a replay. The reorder work has the same gap on a single link.

Check the PN of a BA session frame where it leaves the reorder buffer, under tid->lock. mt76_rx_complete() still checks all other frames.

Fixes 30ce7f4456ae ("mt76: validate rx CCMP PN")
Fixes 62694ed0b76f ("wifi: mt76: check the RX PN of an MLD peer once per peer")
---
 drivers/net/wireless/mediatek/mt76/agg-rx.c   | 11 +++++++++++
 drivers/net/wireless/mediatek/mt76/mac80211.c |  6 ++++--
 drivers/net/wireless/mediatek/mt76/mt76.h     |  3 ++-
 3 files changed, 17 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/agg-rx.c +11 -0
index bf1babac3895..49721b4faab1 100644
@@ -12,6 +12,15 @@ static unsigned long mt76_aggr_tid_to_timeo(u8 tidno)
 	return HZ / (tidno >= 4 ? 25 : 10);
 }
 
+static void
+mt76_rx_aggr_pn_check(struct sk_buff *skb)
+{
+	struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
+
+	mt76_check_ccmp_pn(skb);
+	status->skip_pn_check = true;
+}
+
 static void
 mt76_aggr_release(struct mt76_rx_tid *tid, struct sk_buff_head *frames, int idx)
 {
@@ -25,6 +34,7 @@ mt76_aggr_release(struct mt76_rx_tid *tid, struct sk_buff_head *frames, int idx)
 
 	tid->reorder_buf[idx] = NULL;
 	tid->nframes--;
+	mt76_rx_aggr_pn_check(skb);
 	__skb_queue_tail(frames, skb);
 }
 
@@ -204,6 +214,7 @@ void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames)
 	}
 
 	if (seqno == head) {
+		mt76_rx_aggr_pn_check(skb);
 		tid->head = ieee80211_sn_inc(head);
 		if (tid->nframes)
 			mt76_rx_aggr_release_head(tid, frames);
drivers/net/wireless/mediatek/mt76/mac80211.c +4 -2
index d72ade2d46cb..b1789be134d6 100644
@@ -1387,8 +1387,7 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
 	*hw = mt76_phy_hw(dev, mstat.phy_idx);
 }
 
-static void
-mt76_check_ccmp_pn(struct sk_buff *skb)
+void mt76_check_ccmp_pn(struct sk_buff *skb)
 {
 	struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
 	struct mt76_wcid *wcid = status->wcid;
@@ -1403,6 +1402,9 @@ mt76_check_ccmp_pn(struct sk_buff *skb)
 	if (status->flag & RX_FLAG_ONLY_MONITOR)
 		return;
 
+	if (status->skip_pn_check)
+		return;
+
 	if (!wcid || !wcid->rx_check_pn)
 		return;
 
drivers/net/wireless/mediatek/mt76/mt76.h +2 -1
index 8f8388d44aa9..0b16567920fa 100644
@@ -774,7 +774,7 @@ struct mt76_rx_status {
 		} eht;
 	};
 
-	u8 amsdu:1, first_amsdu:1, last_amsdu:1;
+	u8 amsdu:1, first_amsdu:1, last_amsdu:1, skip_pn_check:1;
 	u8 rate_idx;
 	u8 nss:5, band:3;
 	u8 chains;
@@ -1842,6 +1842,7 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
 void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q,
 			   struct napi_struct *napi);
 void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames);
+void mt76_check_ccmp_pn(struct sk_buff *skb);
 void mt76_testmode_tx_pending(struct mt76_phy *phy);
 void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q,
 			    struct mt76_queue_entry *e);
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 12/19
#21 lore raw

Re: [PATCH mt76-next 12/19] wifi: mt76: check the PN of a BA session frame at its release

Quoted 6 lines · Felix Fietkau

mt76_rx_complete() checks the PN after a frame left the reorder buffer, outside tid->lock. The links of an MLD peer share one PN state, so a frame released on one RX ring can be checked before an earlier frame of the same TID on another ring, which then reads as a replay. The reorder work has the same gap on a single link.

Quoted 6 lines

Check the PN of a BA session frame where it leaves the reorder buffer, under tid->lock. mt76_rx_complete() still checks all other frames.

Fixes 30ce7f4456ae ("mt76: validate rx CCMP PN")
Fixes 62694ed0b76f ("wifi: mt76: check the RX PN of an MLD peer once per peer")
Quoted 91 lines
---
 drivers/net/wireless/mediatek/mt76/agg-rx.c   | 11 +++++++++++
 drivers/net/wireless/mediatek/mt76/mac80211.c |  6 ++++--
 drivers/net/wireless/mediatek/mt76/mt76.h     |  3 ++-
 3 files changed, 17 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/agg-rx.c +11 -0
index bf1babac3895..49721b4faab1 100644
@@ -12,6 +12,15 @@ static unsigned long mt76_aggr_tid_to_timeo(u8 tidno)
 	return HZ / (tidno >= 4 ? 25 : 10);
 }
 
+static void
+mt76_rx_aggr_pn_check(struct sk_buff *skb)
+{
+	struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
+
+	mt76_check_ccmp_pn(skb);
+	status->skip_pn_check = true;
+}
+
 static void
 mt76_aggr_release(struct mt76_rx_tid *tid, struct sk_buff_head *frames, int idx)
 {
@@ -25,6 +34,7 @@ mt76_aggr_release(struct mt76_rx_tid *tid, struct sk_buff_head *frames, int idx)
 
 	tid->reorder_buf[idx] = NULL;
 	tid->nframes--;
+	mt76_rx_aggr_pn_check(skb);
 	__skb_queue_tail(frames, skb);
 }
 
@@ -204,6 +214,7 @@ void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames)
 	}
 
 	if (seqno == head) {
+		mt76_rx_aggr_pn_check(skb);
 		tid->head = ieee80211_sn_inc(head);
 		if (tid->nframes)
 			mt76_rx_aggr_release_head(tid, frames);
drivers/net/wireless/mediatek/mt76/mac80211.c +4 -2
index d72ade2d46cb..b1789be134d6 100644
@@ -1387,8 +1387,7 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
 	*hw = mt76_phy_hw(dev, mstat.phy_idx);
 }
 
-static void
-mt76_check_ccmp_pn(struct sk_buff *skb)
+void mt76_check_ccmp_pn(struct sk_buff *skb)
 {
 	struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
 	struct mt76_wcid *wcid = status->wcid;
@@ -1403,6 +1402,9 @@ mt76_check_ccmp_pn(struct sk_buff *skb)
 	if (status->flag & RX_FLAG_ONLY_MONITOR)
 		return;
 
+	if (status->skip_pn_check)
+		return;
+
 	if (!wcid || !wcid->rx_check_pn)
 		return;
 
drivers/net/wireless/mediatek/mt76/mt76.h +2 -1
index 8f8388d44aa9..0b16567920fa 100644
@@ -774,7 +774,7 @@ struct mt76_rx_status {
 		} eht;
 	};
 
-	u8 amsdu:1, first_amsdu:1, last_amsdu:1;
+	u8 amsdu:1, first_amsdu:1, last_amsdu:1, skip_pn_check:1;
 	u8 rate_idx;
 	u8 nss:5, band:3;
 	u8 chains;
@@ -1842,6 +1842,7 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
 void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q,
 			   struct napi_struct *napi);
 void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames);
+void mt76_check_ccmp_pn(struct sk_buff *skb);
 void mt76_testmode_tx_pending(struct mt76_phy *phy);
 void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q,
 			    struct mt76_queue_entry *e);
Signature · 1 line
2.47.3
author maintainer
#22 lore raw

PATCH 13/19 wifi: mt76: check the RX PN of CCMP-256, GCMP and GCMP-256 keys

In reply to Felix Fietkau

mt76_wcid_key_link_setup() enables the RX PN check for CCMP keys only. mac80211 does not check the PN either, because the IV is stripped, so on mt7996, whose hardware does not check it, replayed frames of the other AES ciphers reach the stack.

Check the PN for all four ciphers. Keep the PN state of a wcid when an IGTK or BIGTK is installed on it, since these keys do not use it.

Fixes 04b8e65922f6 ("mt76: add mac80211 driver for MT7615 PCIe-based chipsets")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 13 +++++--
 drivers/net/wireless/mediatek/mt76/mt76.h     | 34 ++++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +10 -3
index b1789be134d6..6b496dfda5cc 100644
@@ -1279,21 +1279,28 @@ void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
 			 struct ieee80211_key_conf *key)
 {
 	struct ieee80211_key_seq seq;
+	u8 *pn;
 	int i;
 
 	mt76_wcid_key_link_setup(wcid, key);
-	if (!wcid->rx_check_pn)
+	if (!key || !mt76_key_has_rx_pn(key))
 		return;
 
+	if (key->cipher == WLAN_CIPHER_SUITE_GCMP ||
+	    key->cipher == WLAN_CIPHER_SUITE_GCMP_256)
+		pn = seq.gcmp.pn;
+	else
+		pn = seq.ccmp.pn;
+
 	/* data frame */
 	for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
 		ieee80211_get_key_rx_seq(key, i, &seq);
-		memcpy(wcid->rx_key_pn[i], seq.ccmp.pn, sizeof(seq.ccmp.pn));
+		memcpy(wcid->rx_key_pn[i], pn, sizeof(wcid->rx_key_pn[i]));
 	}
 
 	/* robust management frame */
 	ieee80211_get_key_rx_seq(key, -1, &seq);
-	memcpy(wcid->rx_key_pn[i], seq.ccmp.pn, sizeof(seq.ccmp.pn));
+	memcpy(wcid->rx_key_pn[i], pn, sizeof(wcid->rx_key_pn[i]));
 
 }
 EXPORT_SYMBOL(mt76_wcid_key_setup);
drivers/net/wireless/mediatek/mt76/mt76.h +33 -1
index 0b16567920fa..7a2a6afc3c21 100644
@@ -1590,11 +1590,43 @@ int mt76_rx_aggr_start(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid,
 		       u16 ssn, u16 size);
 void mt76_rx_aggr_stop(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid);
 
+static inline bool
+mt76_key_has_rx_pn(struct ieee80211_key_conf *key)
+{
+	switch (key->cipher) {
+	case WLAN_CIPHER_SUITE_CCMP:
+	case WLAN_CIPHER_SUITE_CCMP_256:
+	case WLAN_CIPHER_SUITE_GCMP:
+	case WLAN_CIPHER_SUITE_GCMP_256:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool
+mt76_key_is_bip(struct ieee80211_key_conf *key)
+{
+	switch (key->cipher) {
+	case WLAN_CIPHER_SUITE_AES_CMAC:
+	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
+	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
+	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
+		return true;
+	default:
+		return false;
+	}
+}
+
 static inline void
 mt76_wcid_key_link_setup(struct mt76_wcid *wcid,
 			 struct ieee80211_key_conf *key)
 {
-	wcid->rx_check_pn = key && key->cipher == WLAN_CIPHER_SUITE_CCMP;
+	/* an IGTK or BIGTK shares the wcid of the GTK */
+	if (key && mt76_key_is_bip(key))
+		return;
+
+	wcid->rx_check_pn = key && mt76_key_has_rx_pn(key);
 }
 
 void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
Signature · 1 line
2.47.3
author maintainer
#23 lore raw

PATCH 14/19 wifi: mt76: connac: return a negative error for a firmware status

In reply to Felix Fietkau

The parse_response functions of mt7615, mt7921 and mt7925 return the status of a UNI event unchanged, so callers that test for a negative return take a firmware failure as success. For example, mt76_connac_mcu_uni_add_dev() activates the BSS after the firmware failed the device activation.

Return -EREMOTEIO for a non-zero status, and -ENOLINK for the WLAN failure status, which mt76_connac_mcu_bss_deact_err() ignores because the firmware also returns it for the deactivation of an inactive BSS.

Fixes df5ab0d58b2e ("mt76: mt7615: parse mcu return code for unified commands")
Fixes 1c099ab44727 ("mt76: mt7921: add MCU support")
Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 drivers/net/wireless/mediatek/mt76/mt7615/mcu.c    |  2 +-
 .../net/wireless/mediatek/mt76/mt76_connac_mcu.h   | 14 +++++++++++++-
 drivers/net/wireless/mediatek/mt76/mt7921/mcu.c    |  3 ++-
 drivers/net/wireless/mediatek/mt76/mt7925/mcu.c    |  3 ++-
 4 files changed, 18 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +1 -1
index e5c2ad5fb458..65c57d5a480a 100644
@@ -178,7 +178,7 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			return -EMSGSIZE;
 		skb_pull(skb, sizeof(*rxd));
 		event = (struct mt76_connac_mcu_uni_event *)skb->data;
-		ret = le32_to_cpu(event->status);
+		ret = mt76_connac_mcu_status_err(le32_to_cpu(event->status));
 	} else if (cmd == MCU_CE_QUERY(REG_READ)) {
 		struct mt76_connac_mcu_reg_event *event;
 
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +13 -1
index 2acaae9830fb..cac47c8702e3 100644
@@ -1960,10 +1960,22 @@ mt76_connac_mcu_get_wlan_idx(struct mt76_dev *dev, struct mt76_wcid *wcid,
 
 #define MT76_CONNAC_MCU_STATUS_WLAN_FAILURE	0xc0000001
 
+static inline int
+mt76_connac_mcu_status_err(u32 status)
+{
+	if (!status)
+		return 0;
+
+	if (status == MT76_CONNAC_MCU_STATUS_WLAN_FAILURE)
+		return -ENOLINK;
+
+	return -EREMOTEIO;
+}
+
 static inline int
 mt76_connac_mcu_bss_deact_err(struct mt76_dev *mdev, int err, bool enable)
 {
-	if (err != (int)MT76_CONNAC_MCU_STATUS_WLAN_FAILURE)
+	if (err != -ENOLINK)
 		return err;
 
 	/* Ignore wlan_failure state false alarm when deactivating an
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +2 -1
index 2bcd5f085cd4..a16f41eda2bb 100644
@@ -62,10 +62,11 @@ int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 
 		skb_pull(skb, sizeof(*rxd));
 		event = (struct mt76_connac_mcu_uni_event *)skb->data;
-		ret = le32_to_cpu(event->status);
 		/* skip invalid event */
 		if (mcu_cmd != event->cid)
 			ret = -EAGAIN;
+		else
+			ret = mt76_connac_mcu_status_err(le32_to_cpu(event->status));
 	} else if (cmd == MCU_CE_QUERY(REG_READ)) {
 		struct mt76_connac_mcu_reg_event *event;
 
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +2 -1
index d3806d8dfbbf..bf8cc4b1f539 100644
@@ -77,10 +77,11 @@ int mt7925_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 
 		skb_pull(skb, sizeof(*rxd));
 		event = (struct mt7925_mcu_uni_event *)skb->data;
-		ret = le32_to_cpu(event->status);
 		/* skip invalid event */
 		if (mcu_cmd != event->cid)
 			ret = -EAGAIN;
+		else
+			ret = mt76_connac_mcu_status_err(le32_to_cpu(event->status));
 	} else {
 		skb_pull(skb, sizeof(*rxd));
 	}
Signature · 1 line
2.47.3
author maintainer
#24 lore raw

PATCH 15/19 wifi: mt76: guard the tx_list of every phy with one lock

In reply to Felix Fietkau

mt76_tx() lists a wcid on the tx_list of the phy its caller passes, under the tx_lock of that phy, while mt76_wcid_cleanup() unlists it under the tx_lock of wcid->phy_idx. mt7996_tx() and mt76_offchannel_send_nullfunc() can list a wcid on the phy of another link, so no common lock guards its node, and the tx_list gets corrupted.

Guard the tx_list of every phy with one lock per device.

Fixes ce35ecffc96e ("wifi: mt76: mt7996: fix MLD ID in MAC TXD and HIF TXP")
Fixes 381733b3a14a ("wifi: mt76: send nullfunc PS frames on offchannel transitions")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c |  7 +++----
 drivers/net/wireless/mediatek/mt76/mt76.h     |  3 ++-
 drivers/net/wireless/mediatek/mt76/tx.c       | 13 +++++++------
 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +3 -4
index 6b496dfda5cc..da1da160909a 100644
@@ -431,7 +431,6 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
 	int i;
 
 	INIT_LIST_HEAD(&phy->tx_list);
-	spin_lock_init(&phy->tx_lock);
 	for (i = 0; i < ARRAY_SIZE(phy->rx_amsdu); i++)
 		spin_lock_init(&phy->rx_amsdu[i].lock);
 	INIT_DELAYED_WORK(&phy->roc_work, mt76_roc_complete_work);
@@ -753,6 +752,7 @@ mt76_alloc_device(struct device *pdev, unsigned int size,
 	spin_lock_init(&dev->cc_lock);
 	spin_lock_init(&dev->status_lock);
 	spin_lock_init(&dev->wed_lock);
+	spin_lock_init(&dev->tx_lock);
 	mutex_init(&dev->mutex);
 	init_waitqueue_head(&dev->tx_wait);
 
@@ -1837,7 +1837,6 @@ EXPORT_SYMBOL_GPL(mt76_wcid_init);
 
 void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid)
 {
-	struct mt76_phy *phy = mt76_dev_phy(dev, wcid->phy_idx);
 	struct ieee80211_hw *hw;
 	struct sk_buff_head list;
 	struct sk_buff *skb;
@@ -1859,7 +1858,7 @@ void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid)
 		list_del_init(&wcid->poll_list);
 	spin_unlock_bh(&dev->sta_poll_lock);
 
-	spin_lock_bh(&phy->tx_lock);
+	spin_lock_bh(&dev->tx_lock);
 
 	if (!list_empty(&wcid->tx_list))
 		list_del_init(&wcid->tx_list);
@@ -1872,7 +1871,7 @@ void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid)
 	skb_queue_splice_tail_init(&wcid->tx_offchannel, &list);
 	spin_unlock(&wcid->tx_offchannel.lock);
 
-	spin_unlock_bh(&phy->tx_lock);
+	spin_unlock_bh(&dev->tx_lock);
 
 	while ((skb = __skb_dequeue(&list)) != NULL) {
 		hw = mt76_tx_status_get_hw(dev, skb);
drivers/net/wireless/mediatek/mt76/mt76.h +2 -1
index 7a2a6afc3c21..77bfecb7d49b 100644
@@ -872,7 +872,6 @@ struct mt76_phy {
 	unsigned int num_sta;
 	u8 band_idx;
 
-	spinlock_t tx_lock;
 	struct list_head tx_list;
 	struct mt76_queue *q_tx[__MT_TXQ_MAX];
 
@@ -988,6 +987,8 @@ struct mt76_dev {
 
 	struct mt76_worker tx_worker;
 	struct napi_struct tx_napi;
+	/* protects the tx_list of every phy */
+	spinlock_t tx_lock;
 
 	spinlock_t token_lock;
 	struct idr token;
drivers/net/wireless/mediatek/mt76/tx.c +7 -6
index 0085b7a29fce..9eafc86ec288 100644
@@ -392,10 +392,10 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
 	__skb_queue_tail(head, skb);
 	spin_unlock_bh(&head->lock);
 
-	spin_lock_bh(&phy->tx_lock);
+	spin_lock_bh(&phy->dev->tx_lock);
 	if (list_empty(&wcid->tx_list))
 		list_add_tail(&wcid->tx_list, &phy->tx_list);
-	spin_unlock_bh(&phy->tx_lock);
+	spin_unlock_bh(&phy->dev->tx_lock);
 
 	mt76_worker_schedule(&phy->dev->tx_worker);
 }
@@ -740,6 +740,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,
 
 void mt76_txq_schedule_pending(struct mt76_phy *phy)
 {
+	struct mt76_dev *dev = phy->dev;
 	LIST_HEAD(tx_list);
 	int ret = 0;
 
@@ -749,7 +750,7 @@ void mt76_txq_schedule_pending(struct mt76_phy *phy)
 	local_bh_disable();
 	rcu_read_lock();
 
-	spin_lock(&phy->tx_lock);
+	spin_lock(&dev->tx_lock);
 	list_splice_init(&phy->tx_list, &tx_list);
 	while (!list_empty(&tx_list)) {
 		struct mt76_wcid *wcid;
@@ -757,19 +758,19 @@ void mt76_txq_schedule_pending(struct mt76_phy *phy)
 		wcid = list_first_entry(&tx_list, struct mt76_wcid, tx_list);
 		list_del_init(&wcid->tx_list);
 
-		spin_unlock(&phy->tx_lock);
+		spin_unlock(&dev->tx_lock);
 		if (ret >= 0)
 			ret = mt76_txq_schedule_pending_wcid(phy, wcid, &wcid->tx_offchannel);
 		if (ret >= 0 && !phy->offchannel)
 			ret = mt76_txq_schedule_pending_wcid(phy, wcid, &wcid->tx_pending);
-		spin_lock(&phy->tx_lock);
+		spin_lock(&dev->tx_lock);
 
 		if ((!skb_queue_empty(&wcid->tx_pending) ||
 		     !skb_queue_empty(&wcid->tx_offchannel)) &&
 		    list_empty(&wcid->tx_list))
 			list_add_tail(&wcid->tx_list, &phy->tx_list);
 	}
-	spin_unlock(&phy->tx_lock);
+	spin_unlock(&dev->tx_lock);
 
 	rcu_read_unlock();
 	local_bh_enable();
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 15/19
#25 lore raw

Re: [PATCH mt76-next 15/19] wifi: mt76: guard the tx_list of every phy with one lock

Quoted 11 lines

mt76_tx() lists a wcid on the tx_list of the phy its caller passes, under the tx_lock of that phy, while mt76_wcid_cleanup() unlists it under the tx_lock of wcid->phy_idx. mt7996_tx() and mt76_offchannel_send_nullfunc() can list a wcid on the phy of another link, so no common lock guards its node, and the tx_list gets corrupted.

Guard the tx_list of every phy with one lock per device.

Fixes ce35ecffc96e ("wifi: mt76: mt7996: fix MLD ID in MAC TXD and HIF TXP")
Fixes 381733b3a14a ("wifi: mt76: send nullfunc PS frames on offchannel transitions")
Quoted 134 lines
---
 drivers/net/wireless/mediatek/mt76/mac80211.c |  7 +++----
 drivers/net/wireless/mediatek/mt76/mt76.h     |  3 ++-
 drivers/net/wireless/mediatek/mt76/tx.c       | 13 +++++++------
 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +3 -4
index 6b496dfda5cc..da1da160909a 100644
@@ -431,7 +431,6 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
 	int i;
 
 	INIT_LIST_HEAD(&phy->tx_list);
-	spin_lock_init(&phy->tx_lock);
 	for (i = 0; i < ARRAY_SIZE(phy->rx_amsdu); i++)
 		spin_lock_init(&phy->rx_amsdu[i].lock);
 	INIT_DELAYED_WORK(&phy->roc_work, mt76_roc_complete_work);
@@ -753,6 +752,7 @@ mt76_alloc_device(struct device *pdev, unsigned int size,
 	spin_lock_init(&dev->cc_lock);
 	spin_lock_init(&dev->status_lock);
 	spin_lock_init(&dev->wed_lock);
+	spin_lock_init(&dev->tx_lock);
 	mutex_init(&dev->mutex);
 	init_waitqueue_head(&dev->tx_wait);
 
@@ -1837,7 +1837,6 @@ EXPORT_SYMBOL_GPL(mt76_wcid_init);
 
 void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid)
 {
-	struct mt76_phy *phy = mt76_dev_phy(dev, wcid->phy_idx);
 	struct ieee80211_hw *hw;
 	struct sk_buff_head list;
 	struct sk_buff *skb;
@@ -1859,7 +1858,7 @@ void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid)
 		list_del_init(&wcid->poll_list);
 	spin_unlock_bh(&dev->sta_poll_lock);
 
-	spin_lock_bh(&phy->tx_lock);
+	spin_lock_bh(&dev->tx_lock);
 
 	if (!list_empty(&wcid->tx_list))
 		list_del_init(&wcid->tx_list);
@@ -1872,7 +1871,7 @@ void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid)
 	skb_queue_splice_tail_init(&wcid->tx_offchannel, &list);
 	spin_unlock(&wcid->tx_offchannel.lock);
 
-	spin_unlock_bh(&phy->tx_lock);
+	spin_unlock_bh(&dev->tx_lock);
 
 	while ((skb = __skb_dequeue(&list)) != NULL) {
 		hw = mt76_tx_status_get_hw(dev, skb);
drivers/net/wireless/mediatek/mt76/mt76.h +2 -1
index 7a2a6afc3c21..77bfecb7d49b 100644
@@ -872,7 +872,6 @@ struct mt76_phy {
 	unsigned int num_sta;
 	u8 band_idx;
 
-	spinlock_t tx_lock;
 	struct list_head tx_list;
 	struct mt76_queue *q_tx[__MT_TXQ_MAX];
 
@@ -988,6 +987,8 @@ struct mt76_dev {
 
 	struct mt76_worker tx_worker;
 	struct napi_struct tx_napi;
+	/* protects the tx_list of every phy */
+	spinlock_t tx_lock;
 
 	spinlock_t token_lock;
 	struct idr token;
drivers/net/wireless/mediatek/mt76/tx.c +7 -6
index 0085b7a29fce..9eafc86ec288 100644
@@ -392,10 +392,10 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
 	__skb_queue_tail(head, skb);
 	spin_unlock_bh(&head->lock);
 
-	spin_lock_bh(&phy->tx_lock);
+	spin_lock_bh(&phy->dev->tx_lock);
 	if (list_empty(&wcid->tx_list))
 		list_add_tail(&wcid->tx_list, &phy->tx_list);
-	spin_unlock_bh(&phy->tx_lock);
+	spin_unlock_bh(&phy->dev->tx_lock);
 
 	mt76_worker_schedule(&phy->dev->tx_worker);
 }
@@ -740,6 +740,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,
 
 void mt76_txq_schedule_pending(struct mt76_phy *phy)
 {
+	struct mt76_dev *dev = phy->dev;
 	LIST_HEAD(tx_list);
 	int ret = 0;
 
@@ -749,7 +750,7 @@ void mt76_txq_schedule_pending(struct mt76_phy *phy)
 	local_bh_disable();
 	rcu_read_lock();
 
-	spin_lock(&phy->tx_lock);
+	spin_lock(&dev->tx_lock);
 	list_splice_init(&phy->tx_list, &tx_list);
 	while (!list_empty(&tx_list)) {
 		struct mt76_wcid *wcid;
@@ -757,19 +758,19 @@ void mt76_txq_schedule_pending(struct mt76_phy *phy)
 		wcid = list_first_entry(&tx_list, struct mt76_wcid, tx_list);
 		list_del_init(&wcid->tx_list);
 
-		spin_unlock(&phy->tx_lock);
+		spin_unlock(&dev->tx_lock);
 		if (ret >= 0)
 			ret = mt76_txq_schedule_pending_wcid(phy, wcid, &wcid->tx_offchannel);
 		if (ret >= 0 && !phy->offchannel)
 			ret = mt76_txq_schedule_pending_wcid(phy, wcid, &wcid->tx_pending);
-		spin_lock(&phy->tx_lock);
+		spin_lock(&dev->tx_lock);
 
 		if ((!skb_queue_empty(&wcid->tx_pending) ||
 		     !skb_queue_empty(&wcid->tx_offchannel)) &&
 		    list_empty(&wcid->tx_list))
 			list_add_tail(&wcid->tx_list, &phy->tx_list);
 	}
-	spin_unlock(&phy->tx_lock);
+	spin_unlock(&dev->tx_lock);
 
 	rcu_read_unlock();
 	local_bh_enable();
Signature · 1 line
2.47.3
author maintainer
#26 lore raw

PATCH 16/19 wifi: mt76: keep an unpublished wcid off the TX and poll lists

In reply to Felix Fietkau

A TX or RX path that looked up a wcid before the driver unpublished it can call mt76_tx() or mt76_wcid_add_poll() after mt76_wcid_cleanup(). This lists the wcid again, and where the driver frees the wcid after the cleanup, the TX worker or the poll later uses freed memory.

Drop the frame and skip the poll for a wcid that dev->wcid[] no longer holds, like mt76_tx_status_skb_add() does for a TX status request. Both tests run under the lock that the cleanup takes to unlist the wcid. The global wcid lives as long as the device, and mt76x02 never publishes it, so its frames are always queued. mt7996 unpublishes a station link that it removes outside of a station removal only after the cleanup, so unpublish it before.

Fixes 0335c034e726 ("wifi: mt76: fix race condition related to checking tx queue fill status")
Fixes f520eceacd24 ("wifi: mt76: mt7996: Add mt7996_mac_sta_change_links callback")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c |  3 ++-
 .../net/wireless/mediatek/mt76/mt7996/main.c  |  4 +++-
 drivers/net/wireless/mediatek/mt76/tx.c       | 20 +++++++++++++------
 3 files changed, 19 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +2 -1
index da1da160909a..12089dca01b2 100644
@@ -1886,7 +1886,8 @@ void mt76_wcid_add_poll(struct mt76_dev *dev, struct mt76_wcid *wcid)
 		return;
 
 	spin_lock_bh(&dev->sta_poll_lock);
-	if (list_empty(&wcid->poll_list))
+	if (rcu_access_pointer(dev->wcid[wcid->idx]) == wcid &&
+	    list_empty(&wcid->poll_list))
 		list_add_tail(&wcid->poll_list, &dev->sta_poll_list);
 	spin_unlock_bh(&dev->sta_poll_lock);
 }
drivers/net/wireless/mediatek/mt76/mt7996/main.c +3 -1
index 90a074ffa7dc..ba7a0553e34a 100644
@@ -1385,6 +1385,9 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev,
 	if (!msta_link)
 		return;
 
+	if (flush)
+		rcu_assign_pointer(dev->mt76.wcid[msta_link->wcid.idx], NULL);
+
 	spin_lock_bh(&dev->mt76.sta_poll_lock);
 	if (!list_empty(&msta_link->wcid.poll_list))
 		list_del_init(&msta_link->wcid.poll_list);
@@ -1411,7 +1414,6 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev,
 			phy->mt76->num_sta--;
 
 		rcu_assign_pointer(msta->link[link_id], NULL);
-		rcu_assign_pointer(dev->mt76.wcid[msta_link->wcid.idx], NULL);
 		mt76_wcid_mask_clear(dev->mt76.wcid_mask, msta_link->wcid.idx);
 		if (msta_link != &msta->deflink)
 			kfree_rcu(msta_link, rcu_head);
drivers/net/wireless/mediatek/mt76/tx.c +14 -6
index 9eafc86ec288..84ab3d428001 100644
@@ -365,6 +365,7 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
 {
 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
 	struct ieee80211_hdr *hdr = (void *)skb->data;
+	struct mt76_dev *dev = phy->dev;
 	struct sk_buff_head *head;
 
 	if (mt76_testmode_enabled(phy)) {
@@ -388,16 +389,23 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
 	else
 		head = &wcid->tx_pending;
 
-	spin_lock_bh(&head->lock);
-	__skb_queue_tail(head, skb);
-	spin_unlock_bh(&head->lock);
+	spin_lock_bh(&dev->tx_lock);
+	if (wcid != &dev->global_wcid &&
+	    rcu_access_pointer(dev->wcid[wcid->idx]) != wcid) {
+		spin_unlock_bh(&dev->tx_lock);
+		ieee80211_free_txskb(phy->hw, skb);
+		return;
+	}
+
+	spin_lock(&head->lock);
+	__skb_queue_tail(head, skb);
+	spin_unlock(&head->lock);
 
-	spin_lock_bh(&phy->dev->tx_lock);
 	if (list_empty(&wcid->tx_list))
 		list_add_tail(&wcid->tx_list, &phy->tx_list);
-	spin_unlock_bh(&phy->dev->tx_lock);
+	spin_unlock_bh(&dev->tx_lock);
 
-	mt76_worker_schedule(&phy->dev->tx_worker);
+	mt76_worker_schedule(&dev->tx_worker);
 }
 EXPORT_SYMBOL_GPL(mt76_tx);
 
Signature · 1 line
2.47.3
author maintainer
#27 lore raw

PATCH 17/19 wifi: mt76: mt7925: do not take iflist_mtx under the mutex

In reply to Felix Fietkau

The ROC abort paths and the runtime PM write of debugfs walk the interfaces with iterators that take iflist_mtx while they hold dev->mt76.mutex. mac80211 calls driver ops under iflist_mtx, and mt7925_mlo_pm_iter() takes the mutex inside an interface walk, so a ROC request that reclaims a stale ROC deadlocks against mt7925_mlo_pm_work().

Collect the BSS indexes with the atomic iterator and send the aborts after the walk, which leaves out interfaces that are not running. In the runtime PM write, take the mutex in the walk callback for each interface, and read the monitor state under it.

Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
Fixes 45064d19fd3a ("wifi: mt76: mt7925: fix a potential association failure upon resuming")
Fixes 7e54ebad64d8 ("wifi: mt76: mt7925: harden the ROC channel-grant handshake")
---
 .../wireless/mediatek/mt76/mt7925/debugfs.c   |  5 +-
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 75 ++++++++++---------
 .../net/wireless/mediatek/mt76/mt7925/mcu.c   |  5 +-
 .../wireless/mediatek/mt76/mt7925/mt7925.h    |  3 +-
 4 files changed, 48 insertions(+), 40 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/debugfs.c +4 -1
index d01ff49de47a..d0677a24e080 100644
@@ -203,8 +203,11 @@ mt7925_pm_set(void *data, u64 val)
 	mt76_connac_pm_wake(&dev->mphy, pm);
 
 	pm->enable_user = val;
+	mutex_unlock(&dev->mt76.mutex);
+
 	mt7925_set_runtime_pm(dev);
-	mt76_connac_power_save_sched(&dev->mphy, pm);
+
+	return 0;
 out:
 	mutex_unlock(&dev->mt76.mutex);
 
drivers/net/wireless/mediatek/mt76/mt7925/main.c +41 -34

167 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +2 -3
index bf8cc4b1f539..54e504a76812 100644
@@ -1714,8 +1714,7 @@ int mt7925_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
 				 &req, sizeof(req), true);
 }
 
-int mt7925_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
-			 u8 token_id)
+int mt7925_mcu_abort_roc(struct mt792x_phy *phy, u8 bss_idx, u8 token_id)
 {
 	struct mt792x_dev *dev = phy->dev;
 	struct {
@@ -1735,7 +1734,7 @@ int mt7925_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
 			.tag = cpu_to_le16(UNI_ROC_ABORT),
 			.len = cpu_to_le16(sizeof(struct roc_abort_tlv)),
 			.tokenid = token_id,
-			.bss_idx = mconf->mt76.idx,
+			.bss_idx = bss_idx,
 			.dbdcband = 0xff, /* auto*/
 		},
 	};
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +1 -2
index 1c20b4ae7497..b18fb5d5bb6e 100644
@@ -416,8 +416,7 @@ int mt7925_mcu_set_mlo_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf
 int mt7925_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
 		       struct ieee80211_channel *chan, int duration,
 		       enum mt7925_roc_req type, u8 token_id);
-int mt7925_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
-			 u8 token_id);
+int mt7925_mcu_abort_roc(struct mt792x_phy *phy, u8 bss_idx, u8 token_id);
 void mt7925_roc_abort_sync(struct mt792x_dev *dev);
 int mt7925_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb,
 			    int cmd, int *wait_seq);
Signature · 1 line
2.47.3
author maintainer
#28 lore raw

PATCH 18/19 wifi: mt76: mt7925: take each polled link under sta_poll_lock

In reply to Felix Fietkau

mt7925_mac_sta_poll() tests its local copy of sta_poll_list and reads the first entry without sta_poll_lock, while a link removal takes the wcid off that list under the lock. If the removal takes the last link between the two reads, the poll takes the list head for a link and writes its airtime counters to the stack.

Test the list and take the link off it in one locked section, as mt7921_mac_sta_poll() does.

Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +4 -2
index 5518960e1375..2528c2f5d717 100644
@@ -54,12 +54,14 @@ static void mt7925_mac_sta_poll(struct mt792x_dev *dev)
 		u16 idx;
 		u8 bw;
 
-		if (list_empty(&sta_poll_list))
+		spin_lock_bh(&dev->mt76.sta_poll_lock);
+		if (list_empty(&sta_poll_list)) {
+			spin_unlock_bh(&dev->mt76.sta_poll_lock);
 			break;
+		}
 		mlink = list_first_entry(&sta_poll_list,
 					 struct mt792x_link_sta, wcid.poll_list);
 		msta = mlink->sta;
-		spin_lock_bh(&dev->mt76.sta_poll_lock);
 		list_del_init(&mlink->wcid.poll_list);
 		spin_unlock_bh(&dev->mt76.sta_poll_lock);
 
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 18/19
#29 lore raw

Re: [PATCH mt76-next 18/19] wifi: mt76: mt7925: take each polled link under sta_poll_lock

Quoted 11 lines · Felix Fietkau

mt7925_mac_sta_poll() tests its local copy of sta_poll_list and reads the first entry without sta_poll_lock, while a link removal takes the wcid off that list under the lock. If the removal takes the last link between the two reads, the poll takes the list head for a link and writes its airtime counters to the stack.

Test the list and take the link off it in one locked section, as mt7921_mac_sta_poll() does.

Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
Quoted 29 lines
---
 drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +4 -2
index 5518960e1375..2528c2f5d717 100644
@@ -54,12 +54,14 @@ static void mt7925_mac_sta_poll(struct mt792x_dev *dev)
 		u16 idx;
 		u8 bw;
 
-		if (list_empty(&sta_poll_list))
+		spin_lock_bh(&dev->mt76.sta_poll_lock);
+		if (list_empty(&sta_poll_list)) {
+			spin_unlock_bh(&dev->mt76.sta_poll_lock);
 			break;
+		}
 		mlink = list_first_entry(&sta_poll_list,
 					 struct mt792x_link_sta, wcid.poll_list);
 		msta = mlink->sta;
-		spin_lock_bh(&dev->mt76.sta_poll_lock);
 		list_del_init(&mlink->wcid.poll_list);
 		spin_unlock_bh(&dev->mt76.sta_poll_lock);
 
Signature · 1 line
2.47.3
author maintainer
#30 lore raw

PATCH 19/19 wifi: mt76: mt7615: take each polled station under sta_poll_lock

In reply to Felix Fietkau

mt7615_mac_sta_poll() tests its local copy of sta_poll_list and reads the first entry without sta_poll_lock, while a station removal takes the wcid off that list under the lock. If the removal takes the last station between the two reads, the poll takes the list head for a station and writes its airtime counters to the stack.

Test the list and take the station off it in one locked section.

Fixes a621372a04ac ("mt76: mt7615: rework mt7615_mac_sta_poll for usb code")
---
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +6 -3
index ada40b8a517a..8e81ebe3e2ca 100644
@@ -905,13 +905,16 @@ void mt7615_mac_sta_poll(struct mt7615_dev *dev)
 	list_splice_init(&dev->mt76.sta_poll_list, &sta_poll_list);
 	spin_unlock_bh(&dev->mt76.sta_poll_lock);
 
-	while (!list_empty(&sta_poll_list)) {
+	while (true) {
 		bool clear = false;
 
+		spin_lock_bh(&dev->mt76.sta_poll_lock);
+		if (list_empty(&sta_poll_list)) {
+			spin_unlock_bh(&dev->mt76.sta_poll_lock);
+			break;
+		}
 		msta = list_first_entry(&sta_poll_list, struct mt7615_sta,
 					wcid.poll_list);
-
-		spin_lock_bh(&dev->mt76.sta_poll_lock);
 		list_del_init(&msta->wcid.poll_list);
 		spin_unlock_bh(&dev->mt76.sta_poll_lock);
 
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 19/19
#31 lore raw

Re: [PATCH mt76-next 19/19] wifi: mt76: mt7615: take each polled station under sta_poll_lock

Quoted 10 lines

mt7615_mac_sta_poll() tests its local copy of sta_poll_list and reads the first entry without sta_poll_lock, while a station removal takes the wcid off that list under the lock. If the removal takes the last station between the two reads, the poll takes the list head for a station and writes its airtime counters to the stack.

Test the list and take the station off it in one locked section.

Fixes a621372a04ac ("mt76: mt7615: rework mt7615_mac_sta_poll for usb code")
Quoted 32 lines
---
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +6 -3
index ada40b8a517a..8e81ebe3e2ca 100644
@@ -905,13 +905,16 @@ void mt7615_mac_sta_poll(struct mt7615_dev *dev)
 	list_splice_init(&dev->mt76.sta_poll_list, &sta_poll_list);
 	spin_unlock_bh(&dev->mt76.sta_poll_lock);
 
-	while (!list_empty(&sta_poll_list)) {
+	while (true) {
 		bool clear = false;
 
+		spin_lock_bh(&dev->mt76.sta_poll_lock);
+		if (list_empty(&sta_poll_list)) {
+			spin_unlock_bh(&dev->mt76.sta_poll_lock);
+			break;
+		}
 		msta = list_first_entry(&sta_poll_list, struct mt7615_sta,
 					wcid.poll_list);
-
-		spin_lock_bh(&dev->mt76.sta_poll_lock);
 		list_del_init(&msta->wcid.poll_list);
 		spin_unlock_bh(&dev->mt76.sta_poll_lock);
 
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 1/19
#32 lore raw
In reply to Felix Fietkau
Quoted 6 lines

A power save station whose buffered frames cannot be delivered consumes no airtime, so its airtime deficit never goes negative, and ieee80211_return_txq() keeps it at the head of the active_txqs list. With all bands on one ieee80211_hw, each scheduling round then ends at that station, and all other stations starve.

Quoted 6 lines

Return the txq only when it sent frames or its queue is stopped. __mt76_tx_complete_skb() schedules it again when a buffered frame completes.

Fixes a547b414bf7e ("wifi: mt76: add PS buffering support for HW-managed TIM drivers")
Quoted 28 lines
---
 drivers/net/wireless/mediatek/mt76/tx.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/tx.c +5 -2
index ea9993e9a199..0085b7a29fce 100644
@@ -625,10 +625,13 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid)
 			if (!mt76_txq_stopped(q))
 				n_frames = mt76_txq_send_burst(phy, q, mtxq, wcid);
 
-			ieee80211_return_txq(phy->hw, txq, false);
-
 			if (unlikely(n_frames < 0))
 				return n_frames;
+
+			/* an undrainable PS station would starve all others */
+			if (n_frames > 0 || mt76_txq_stopped(q))
+				ieee80211_return_txq(phy->hw, txq, false);
+
 			ret += n_frames;
 			continue;
 		}
Signature · 1 line
2.47.3