Skip to contentSkip to conversation

wifi: nxpwifi: fix AP channel-switch lifetime and failures

PATCH New Zhao Li 1 participant 5 messages Nov 18

Subsystems (3)
lore
Share & tools
lore

Zhao Li

author
#0 lore raw

v2 cover wifi: nxpwifi: fix AP channel-switch lifetime and failures

Fix four problems in the nxpwifi AP channel-switch path: the delayed work survives an AP stop, TX is stopped before the switch is prepared, the work reads beacon data after the nl80211 request is freed, and a failed switch leaves TX enabled over a stopped AP.

Changes in v2:
- Include v1 patch 1, which is not in wireless or nxpwifi-current yet and which patch 3 builds on. It now also clears uap_stop_tx when the AP stops.
- Patch 2: keep nxpwifi_queue_delayed_wiphy_work() instead of switching to wiphy_delayed_work_queue(). v1 patch 2 is the one with review comments; v1 patch 3 had none.
- Patch 3: minor style cleanup in nxpwifi_dup_csa_update().
- Patch 4: free the beacon update on every exit of the work, and clear uap_stop_tx when the switch fails.
- Shorten the changelogs and move the AI assistance note below "---".

v1: https://lore.kernel.org/r/[email protected]

Zhao Li (4):
wifi: nxpwifi: cancel channel switch work on teardown
wifi: nxpwifi: stop AP TX after preparing channel switch
wifi: nxpwifi: own beacon data used by channel switch work
wifi: nxpwifi: stop AP when delayed channel switch fails

 drivers/net/wireless/nxp/nxpwifi/11h.c      | 23 +++++--
 drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 72 +++++++++++++++++++--
 drivers/net/wireless/nxp/nxpwifi/main.h     |  2 +-
 3 files changed, 83 insertions(+), 14 deletions(-)

base-commit: 763b13f622e2758726e8e3ecaef819db8fa0430a

Signature · 1 line
2.56.1
author
#1 lore raw

PATCH v2 1/4 wifi: nxpwifi: cancel channel switch work on teardown

Stopping an AP while channel-switch work is pending leaves the delayed work armed, and the callback later runs on an AP that is gone, or on freed driver state after removal.

Cancel the work when the AP stops, and clear uap_stop_tx, which a pending switch with block_tx has set. Interface deletion, type changes and driver removal all stop a running AP first.

Found by code review. Compile-tested with W=1.

Fixes 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")

---
No new W=1, sparse or smatch warnings.

AI assistance was used.

 drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +2 -0
index ba54078b082c..5b8fb37c3f3d 100644
@@ -1639,6 +1639,8 @@ static int nxpwifi_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
 	struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
 	int ret;
 
+	wiphy_delayed_work_cancel(wiphy, &priv->dfs_chan_sw_work);
+	priv->uap_stop_tx = false;
 	nxpwifi_abort_cac(priv);
 
 	if (nxpwifi_del_mgmt_ies(priv))
Signature · 1 line
2.56.1
author
#2 lore raw

PATCH v2 2/4 wifi: nxpwifi: stop AP TX after preparing channel switch

In reply to Zhao Li

A channel switch with block_tx set disables the carrier and TX queues before the CSA management IEs are installed. If installing them fails, the request is rejected but TX stays stopped.

Stop TX only after the IEs are installed.

Found by code review. Compile-tested with W=1.

Fixes 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")

---
No new W=1, sparse or smatch warnings.

AI assistance was used.

 drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +6 -6
index 5b8fb37c3f3d..a9cee7e602f0 100644
@@ -3117,12 +3117,6 @@ nxpwifi_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
 				       &priv->dfs_chandef))
 		return -EINVAL;
 
-	if (params->block_tx) {
-		netif_carrier_off(priv->netdev);
-		nxpwifi_stop_net_dev_queue(priv->netdev, priv->adapter);
-		priv->uap_stop_tx = true;
-	}
-
 	ret = nxpwifi_del_mgmt_ies(priv);
 	if (ret)
 		nxpwifi_dbg(priv->adapter, ERROR,
@@ -3139,6 +3133,12 @@ nxpwifi_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
 	memcpy(&priv->ap_update_info.beacon, &params->beacon_after,
 	       sizeof(priv->ap_update_info.beacon));
 
+	if (params->block_tx) {
+		netif_carrier_off(priv->netdev);
+		nxpwifi_stop_net_dev_queue(priv->netdev, priv->adapter);
+		priv->uap_stop_tx = true;
+	}
+
 	chsw_msec = max(params->count * priv->bss_cfg.beacon_period, 100);
 
 	nxpwifi_queue_delayed_wiphy_work(priv->adapter,
Signature · 1 line
2.56.1
author
#3 lore raw

PATCH v2 3/4 wifi: nxpwifi: own beacon data used by channel switch work

In reply to Zhao Li

The channel-switch work reads the new beacon data after the cfg80211 callback has returned, but the driver keeps only pointers into the request, which can be freed by then. The IE parser then reads freed memory.

Copy the beacon buffers used by nxpwifi_set_mgmt_ies() into an owned cfg80211_ap_update. Free it when the work finishes or is canceled, and return -EBUSY while a switch is pending.

Found by code review. Compile-tested with W=1.

Fixes 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")

---
No new W=1, sparse or smatch warnings.

AI assistance was used.

 drivers/net/wireless/nxp/nxpwifi/11h.c      | 14 +++--
 drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 60 ++++++++++++++++++++-
 drivers/net/wireless/nxp/nxpwifi/main.h     |  2 +-
 3 files changed, 68 insertions(+), 8 deletions(-)
drivers/net/wireless/nxp/nxpwifi/11h.c +9 -5
index 058c319ff910..a6c87dfad9ee 100644
@@ -301,21 +301,21 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)
 	if (!bss_cfg->beacon_period) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "channel switch: AP already stopped\n");
-		return;
+		goto out;
 	}
 
 	if (nxpwifi_send_cmd(priv, HOST_CMD_UAP_BSS_STOP,
 			     HOST_ACT_GEN_SET, 0, NULL, true)) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "channel switch: Failed to stop the BSS\n");
-		return;
+		goto out;
 	}
 
 	if (nxpwifi_cfg80211_change_beacon(adapter->wiphy, priv->netdev,
-					   &priv->ap_update_info)) {
+					   priv->ap_update_info)) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "channel switch: Failed to set beacon\n");
-		return;
+		goto out;
 	}
 
 	nxpwifi_uap_set_channel(priv, bss_cfg, priv->dfs_chandef);
@@ -323,7 +323,7 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)
 	if (nxpwifi_config_start_uap(priv, bss_cfg)) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "Failed to start AP after channel switch\n");
-		return;
+		goto out;
 	}
 
 	nxpwifi_dbg(adapter, MSG,
@@ -336,4 +336,8 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)
 		nxpwifi_wake_up_net_dev_queue(priv->netdev, adapter);
 		priv->uap_stop_tx = false;
 	}
+
+out:
+	kfree(priv->ap_update_info);
+	priv->ap_update_info = NULL;
 }
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +58 -2

97 lines not on this page · raw message

drivers/net/wireless/nxp/nxpwifi/main.h +1 -1
index b25a6a4f2936..4d5718ed5031 100644
@@ -619,7 +619,7 @@ struct nxpwifi_private {
 	struct wiphy_delayed_work dfs_cac_work;
 	struct wiphy_delayed_work dfs_chan_sw_work;
 	bool uap_stop_tx;
-	struct cfg80211_ap_update ap_update_info;
+	struct cfg80211_ap_update *ap_update_info;
 	struct nxpwifi_11h_intf_state state_11h;
 	struct nxpwifi_ds_mem_rw mem_rw;
 	struct sk_buff_head bypass_txq;
Signature · 1 line
2.56.1
author
#4 lore raw

PATCH v2 4/4 wifi: nxpwifi: stop AP when delayed channel switch fails

In reply to Zhao Li

The delayed channel-switch work can fail while stopping the BSS, setting the beacon or restarting the AP. It then returns without telling cfg80211, and TX stays enabled over the stopped BSS unless the request set block_tx.

On each failure, stop the carrier and TX queues, clear uap_stop_tx and request interface shutdown, then free the beacon update as on success.

Found by code review. Compile-tested with W=1.

Fixes 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")

---
No new W=1, sparse or smatch warnings.

AI assistance was used.

 drivers/net/wireless/nxp/nxpwifi/11h.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/net/wireless/nxp/nxpwifi/11h.c +12 -5
index a6c87dfad9ee..d83f36b1c8a5 100644
@@ -300,22 +300,22 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)
 	bss_cfg = &priv->bss_cfg;
 	if (!bss_cfg->beacon_period) {
 		nxpwifi_dbg(adapter, ERROR,
-			    "channel switch: AP already stopped\n");
-		goto out;
+			    "channel switch: AP configuration is missing\n");
+		goto stop_iface;
 	}
 
 	if (nxpwifi_send_cmd(priv, HOST_CMD_UAP_BSS_STOP,
 			     HOST_ACT_GEN_SET, 0, NULL, true)) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "channel switch: Failed to stop the BSS\n");
-		goto out;
+		goto stop_iface;
 	}
 
 	if (nxpwifi_cfg80211_change_beacon(adapter->wiphy, priv->netdev,
 					   priv->ap_update_info)) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "channel switch: Failed to set beacon\n");
-		goto out;
+		goto stop_iface;
 	}
 
 	nxpwifi_uap_set_channel(priv, bss_cfg, priv->dfs_chandef);
@@ -323,7 +323,7 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)
 	if (nxpwifi_config_start_uap(priv, bss_cfg)) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "Failed to start AP after channel switch\n");
-		goto out;
+		goto stop_iface;
 	}
 
 	nxpwifi_dbg(adapter, MSG,
@@ -337,6 +337,13 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)
 		priv->uap_stop_tx = false;
 	}
 
+	goto out;
+
+stop_iface:
+	netif_carrier_off(priv->netdev);
+	nxpwifi_stop_net_dev_queue(priv->netdev, adapter);
+	priv->uap_stop_tx = false;
+	cfg80211_stop_iface(wiphy, &priv->wdev, GFP_KERNEL);
 out:
 	kfree(priv->ap_update_info);
 	priv->ap_update_info = NULL;
Signature · 1 line
2.56.1