wifi: mac80211: keep the monitor chanreq empty without a channel
PATCH v2 1/4 wifi: mac80211: keep the monitor chanreq empty without a channel
ieee80211_do_stop() releases the channel of a monitor, but leaves its chanreq filled. When the monitor comes back up it has no channel, yet the RX path still filters on the old chanreq and drops all frames received on other frequencies.
Only keep the chanreq filled while a channel is set on the monitor.
---
v2: drop unnecessary condition for memset
net/mac80211/cfg.c | 5 ++++- net/mac80211/iface.c | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)
net/mac80211/cfg.c +4 -1
@@ -1165,8 +1165,11 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,ieee80211_link_release_channel (&sdata->deflink); ret =ieee80211_link_use_channel (&sdata->deflink, &chanreq,IEEE80211_CHANCTX_SHARED ); -if (ret) +if (ret) { +memset (&sdata->vif.bss_conf.chanreq,0 , +sizeof (sdata->vif.bss_conf.chanreq));return ret; + } done: local->monitor_chanreq = chanreq;return 0 ;
net/mac80211/iface.c +2 -0
@@ -758,6 +758,8 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_dobreak ;ieee80211_link_release_channel (&sdata->deflink); +memset (&sdata->vif.bss_conf.chanreq,0 , +sizeof (sdata->vif.bss_conf.chanreq)); fallthrough;default :if (!going_down)
Signature · 1 line
2.47.3
PATCH v2 2/4 wifi: mac80211: release monitor channels on suspend
A monitor with its own channel keeps its channel context across suspend, which triggers the warning in __ieee80211_suspend() about remaining channel contexts.
Release the channel on suspend and acquire it again on resume, like for the virtual monitor.
--- net/mac80211/pm.c | 2 ++ net/mac80211/util.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)
net/mac80211/pm.c +2 -0
@@ -151,7 +151,9 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan,continue ;switch (sdata->vif.type) {case NL80211_IFTYPE_AP_VLAN : +continue ;case NL80211_IFTYPE_MONITOR : +ieee80211_link_release_channel (&sdata->deflink);continue ;case NL80211_IFTYPE_STATION :ieee80211_mgd_quiesce (sdata);
net/mac80211/util.c +26 -0
@@ -1748,6 +1748,30 @@ static void ieee80211_assign_chanctx(struct ieee80211_local *local, } } +static void ieee80211_reconfig_monitors (struct ieee80211_local *local) +{ +struct ieee80211_sub_if_data *sdata; + +lockdep_assert_wiphy (local->hw.wiphy); + +list_for_each_entry (sdata, &local->interfaces, list) { +struct ieee80211_chan_req chanreq = sdata->vif.bss_conf.chanreq; + +if (sdata->vif.type !=NL80211_IFTYPE_MONITOR || + !chanreq.oper.chan || +rcu_access_pointer (sdata->deflink.conf->chanctx_conf)) +continue ; + +if (!ieee80211_link_use_channel (&sdata->deflink, &chanreq, +IEEE80211_CHANCTX_SHARED )) +continue ; + +sdata_info (sdata,"failed to restore monitor channel\n" ); +memset (&sdata->vif.bss_conf.chanreq,0 , +sizeof (sdata->vif.bss_conf.chanreq)); + } +} +static void ieee80211_reconfig_stations (struct ieee80211_sub_if_data *sdata) {struct ieee80211_local *local = sdata->local;
@@ -2382,6 +2406,8 @@ int ieee80211_reconfig(struct ieee80211_local *local) local->virt_monitors == local->open_count)ieee80211_add_virtual_monitor (local,NULL ); +ieee80211_reconfig_monitors (local); +if (!suspended)return 0 ;
Signature · 1 line
2.47.3
Re: [PATCH wireless v2 2/4] wifi: mac80211: release monitor channels on suspend
Quoted 3 lines · Felix Fietkau
A monitor with its own channel keeps its channel context across suspend, which triggers the warning in
__ieee80211_suspend()about remaining channel contexts.
Tested with the rest of the series; details in my reply to 1/4.
PATCH v2 3/4 wifi: mac80211: remove real monitors from the driver on suspend
In reply to Felix FietkauWith NO_VIRTUAL_MONITOR, ieee80211_reconfig() adds running monitors to the driver on resume, but __ieee80211_suspend() does not remove them. Each resume without WoWLAN thus adds an interface that the driver already has.
Remove these monitors on suspend, like all other interfaces that ieee80211_reconfig() adds.
--- net/mac80211/pm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/mac80211/pm.c +3 -1
@@ -154,7 +154,9 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan,continue ;case NL80211_IFTYPE_MONITOR :ieee80211_link_release_channel (&sdata->deflink); -continue ; +if (!ieee80211_hw_check (hw,NO_VIRTUAL_MONITOR )) +continue ; +break ;case NL80211_IFTYPE_STATION :ieee80211_mgd_quiesce (sdata);break ;
Signature · 1 line
2.47.3
Re: [PATCH wireless v2 3/4] wifi: mac80211: remove real monitors from the driver on suspend
Quoted 4 lines · Felix Fietkau
With
NO_VIRTUAL_MONITOR,ieee80211_reconfig()adds running monitors to the driver on resume, but__ieee80211_suspend()does not remove them. Each resume without WoWLAN thus adds an interface that the driver already has.
Tested with the rest of the series; details in my reply to 1/4.
PATCH v2 4/4 wifi: mac80211: reject a monitor channel without a running interface
In reply to Felix FietkauWith NO_VIRTUAL_MONITOR, ieee80211_set_monitor_channel() applies the channel to the interface of the request. While a monitor is running, nl80211_set_wiphy() can send a request without an interface, and sdata is then invalid. A request for another monitor that is down triggers the warning in check_sdata_in_driver().
Reject both requests, since the channel can only be applied to a running monitor.
--- net/mac80211/cfg.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mac80211/cfg.c +4 -0
@@ -1155,6 +1155,10 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy, sdata =wiphy_dereference (wiphy, local->monitor_sdata);if (!sdata) goto done; + }else if (!dev) { +return -EOPNOTSUPP ; + }else if (!ieee80211_sdata_running (sdata)) { +return -ENETDOWN ; } if (rcu_access_pointer(sdata->deflink.conf->chanctx_conf) &&
Signature · 1 line
2.47.3
Re: [PATCH wireless v2 4/4] wifi: mac80211: reject a monitor channel without a running interface
Quoted 5 lines · Felix Fietkau
With
NO_VIRTUAL_MONITOR,ieee80211_set_monitor_channel()applies the channel to the interface of the request. While a monitor is running,nl80211_set_wiphy()can send a request without an interface, and sdata is then invalid. A request for another monitor that is down triggers the warning incheck_sdata_in_driver().
Tested with the rest of the series; details in my reply to 1/4.
Quoted 4 lines · Felix Fietkau
ieee80211_do_stop()releases the channel of a monitor, but leaves its chanreq filled. When the monitor comes back up it has no channel, yet the RX path still filters on the old chanreq and drops all frames received on other frequencies.
I tested all four on two machines:
mini PC your mt76 tree at afe54fd58a87, MT7922 and MT7925,
monitors passed to the driver by the mt792x active monitor series (v2 coming)
laptop Framework 13, 7.3.5, MT7927 (stock already passes its
monitors to the driver), MT7925 as a control
without with
monitor on another channel, taken 0 beacons from 87 to 88
down and up; a second monitor on the AP in 10 s
the AP's channel
channel set on a monitor that is down -EIO, warning -ENETDOWN
channel set on the phy, a monitor up oops -EOPNOTSUPP
s2idle with monitors up warning, added clean, all
again on resume hear again
five s2idle cycles the add fails 0 failures with -ENOSPC on the fourth
The stock s2idle rows and the oops come from the mini PC alone; I kept the laptop out of those. The five cycles and the oops ran on the MT7922. The laptop's MT7925, which still uses the virtual monitor, read the same with and without.