Skip to content

Commit 9975aee

Browse files
Maharaja Kennadyrajanjmberg-intel
authored andcommitted
wifi: mac80211: use RCU-safe iteration in ieee80211_csa_finish
The ieee80211_csa_finish() function currently uses for_each_sdata_link() to iterate over links of sdata. However, this macro internally uses wiphy_dereference(), which expects the wiphy->mtx lock to be held. When ieee80211_csa_finish() is invoked under an RCU read-side critical section (e.g., under rcu_read_lock()), this leads to a warning from the RCU debugging framework. WARNING: suspicious RCU usage net/mac80211/cfg.c:3830 suspicious rcu_dereference_protected() usage! This warning is triggered because wiphy_dereference() is not safe to use without holding the wiphy mutex, and it is being used in an RCU context without the required locking. Fix this by introducing and using a new macro, for_each_sdata_link_rcu(), which performs RCU-safe iteration over sdata links using list_for_each_entry_rcu() and rcu_dereference(). This ensures that the link pointers are accessed safely under RCU and eliminates the warning. Fixes: f600832 ("wifi: mac80211: restructure tx profile retrieval for MLO MBSSID") Signed-off-by: Maharaja Kennadyrajan <[email protected]> Link: https://patch.msgid.link/[email protected] [unindent like the non-RCU macro] Signed-off-by: Johannes Berg <[email protected]>
1 parent 3df924c commit 9975aee

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

net/mac80211/cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3841,7 +3841,7 @@ void ieee80211_csa_finish(struct ieee80211_vif *vif, unsigned int link_id)
38413841
*/
38423842
struct ieee80211_link_data *iter;
38433843

3844-
for_each_sdata_link(local, iter) {
3844+
for_each_sdata_link_rcu(local, iter) {
38453845
if (iter->sdata == sdata ||
38463846
rcu_access_pointer(iter->conf->tx_bss_conf) != tx_bss_conf)
38473847
continue;

net/mac80211/ieee80211_i.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,21 @@ struct ieee80211_sub_if_data *vif_to_sdata(struct ieee80211_vif *p)
12261226
if ((_link = wiphy_dereference((_local)->hw.wiphy, \
12271227
___sdata->link[___link_id])))
12281228

1229+
/*
1230+
* for_each_sdata_link_rcu() must be used under RCU read lock.
1231+
*/
1232+
#define for_each_sdata_link_rcu(_local, _link) \
1233+
/* outer loop just to define the variables ... */ \
1234+
for (struct ieee80211_sub_if_data *___sdata = NULL; \
1235+
!___sdata; \
1236+
___sdata = (void *)~0 /* always stop */) \
1237+
list_for_each_entry_rcu(___sdata, &(_local)->interfaces, list) \
1238+
if (ieee80211_sdata_running(___sdata)) \
1239+
for (int ___link_id = 0; \
1240+
___link_id < ARRAY_SIZE((___sdata)->link); \
1241+
___link_id++) \
1242+
if ((_link = rcu_dereference((___sdata)->link[___link_id])))
1243+
12291244
#define for_each_link_data(sdata, __link) \
12301245
struct ieee80211_sub_if_data *__sdata = sdata; \
12311246
for (int __link_id = 0; \

0 commit comments

Comments
 (0)