Skip to content

Commit 6cb5f3e

Browse files
committed
mac80211: populate debugfs only after cfg80211 init
When fixing the initialization race, we neglected to account for the fact that debugfs is initialized in wiphy_register(), and some debugfs things went missing (or rather were rerooted to the global debugfs root). Fix this by adding debugfs entries only after wiphy_register(). This requires some changes in the rate control code since it currently adds debugfs at alloc time, which can no longer be done after the reordering. Reported-by: Jouni Malinen <[email protected]> Reported-by: kernel test robot <[email protected]> Reported-by: Hauke Mehrtens <[email protected]> Reported-by: Felix Fietkau <[email protected]> Cc: [email protected] Fixes: 52e04b4 ("mac80211: fix race in ieee80211_register_hw()") Signed-off-by: Johannes Berg <[email protected]> Acked-by: Sumit Garg <[email protected]> Link: https://lore.kernel.org/r/20200423111344.0e00d3346f12.Iadc76a03a55093d94391fc672e996a458702875d@changeid Signed-off-by: Johannes Berg <[email protected]>
1 parent 0379861 commit 6cb5f3e

File tree

10 files changed

+51
-25
lines changed

10 files changed

+51
-25
lines changed

drivers/net/wireless/intel/iwlegacy/3945-rs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ il3945_rs_rate_init(struct il_priv *il, struct ieee80211_sta *sta, u8 sta_id)
374374
}
375375

376376
static void *
377-
il3945_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
377+
il3945_rs_alloc(struct ieee80211_hw *hw)
378378
{
379379
return hw->priv;
380380
}

drivers/net/wireless/intel/iwlegacy/4965-rs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ il4965_rs_fill_link_cmd(struct il_priv *il, struct il_lq_sta *lq_sta,
24742474
}
24752475

24762476
static void *
2477-
il4965_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
2477+
il4965_rs_alloc(struct ieee80211_hw *hw)
24782478
{
24792479
return hw->priv;
24802480
}

drivers/net/wireless/intel/iwlwifi/dvm/rs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
30193019
cpu_to_le16(priv->lib->bt_params->agg_time_limit);
30203020
}
30213021

3022-
static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
3022+
static void *rs_alloc(struct ieee80211_hw *hw)
30233023
{
30243024
return hw->priv;
30253025
}

drivers/net/wireless/intel/iwlwifi/mvm/rs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3665,7 +3665,7 @@ static void rs_fill_lq_cmd(struct iwl_mvm *mvm,
36653665
cpu_to_le16(iwl_mvm_coex_agg_time_limit(mvm, sta));
36663666
}
36673667

3668-
static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
3668+
static void *rs_alloc(struct ieee80211_hw *hw)
36693669
{
36703670
return hw->priv;
36713671
}

drivers/net/wireless/realtek/rtlwifi/rc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static void rtl_rate_update(void *ppriv,
261261
{
262262
}
263263

264-
static void *rtl_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
264+
static void *rtl_rate_alloc(struct ieee80211_hw *hw)
265265
{
266266
struct rtl_priv *rtlpriv = rtl_priv(hw);
267267
return rtlpriv;

include/net/mac80211.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6007,7 +6007,9 @@ enum rate_control_capabilities {
60076007
struct rate_control_ops {
60086008
unsigned long capa;
60096009
const char *name;
6010-
void *(*alloc)(struct ieee80211_hw *hw, struct dentry *debugfsdir);
6010+
void *(*alloc)(struct ieee80211_hw *hw);
6011+
void (*add_debugfs)(struct ieee80211_hw *hw, void *priv,
6012+
struct dentry *debugfsdir);
60116013
void (*free)(void *priv);
60126014

60136015
void *(*alloc_sta)(void *priv, struct ieee80211_sta *sta, gfp_t gfp);

net/mac80211/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
11831183
local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
11841184
IEEE80211_TX_STATUS_HEADROOM);
11851185

1186-
debugfs_hw_add(local);
1187-
11881186
/*
11891187
* if the driver doesn't specify a max listen interval we
11901188
* use 5 which should be a safe default
@@ -1273,6 +1271,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
12731271
if (result < 0)
12741272
goto fail_wiphy_register;
12751273

1274+
debugfs_hw_add(local);
1275+
rate_control_add_debugfs(local);
1276+
12761277
rtnl_lock();
12771278

12781279
/* add one default STA interface if supported */

net/mac80211/rate.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,16 @@ static ssize_t rcname_read(struct file *file, char __user *userbuf,
214214
ref->ops->name, len);
215215
}
216216

217-
static const struct file_operations rcname_ops = {
217+
const struct file_operations rcname_ops = {
218218
.read = rcname_read,
219219
.open = simple_open,
220220
.llseek = default_llseek,
221221
};
222222
#endif
223223

224-
static struct rate_control_ref *rate_control_alloc(const char *name,
225-
struct ieee80211_local *local)
224+
static struct rate_control_ref *
225+
rate_control_alloc(const char *name, struct ieee80211_local *local)
226226
{
227-
struct dentry *debugfsdir = NULL;
228227
struct rate_control_ref *ref;
229228

230229
ref = kmalloc(sizeof(struct rate_control_ref), GFP_KERNEL);
@@ -234,13 +233,7 @@ static struct rate_control_ref *rate_control_alloc(const char *name,
234233
if (!ref->ops)
235234
goto free;
236235

237-
#ifdef CONFIG_MAC80211_DEBUGFS
238-
debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
239-
local->debugfs.rcdir = debugfsdir;
240-
debugfs_create_file("name", 0400, debugfsdir, ref, &rcname_ops);
241-
#endif
242-
243-
ref->priv = ref->ops->alloc(&local->hw, debugfsdir);
236+
ref->priv = ref->ops->alloc(&local->hw);
244237
if (!ref->priv)
245238
goto free;
246239
return ref;

net/mac80211/rate.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,29 @@ static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
6060
#endif
6161
}
6262

63+
extern const struct file_operations rcname_ops;
64+
65+
static inline void rate_control_add_debugfs(struct ieee80211_local *local)
66+
{
67+
#ifdef CONFIG_MAC80211_DEBUGFS
68+
struct dentry *debugfsdir;
69+
70+
if (!local->rate_ctrl)
71+
return;
72+
73+
if (!local->rate_ctrl->ops->add_debugfs)
74+
return;
75+
76+
debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
77+
local->debugfs.rcdir = debugfsdir;
78+
debugfs_create_file("name", 0400, debugfsdir,
79+
local->rate_ctrl, &rcname_ops);
80+
81+
local->rate_ctrl->ops->add_debugfs(&local->hw, local->rate_ctrl->priv,
82+
debugfsdir);
83+
#endif
84+
}
85+
6386
void ieee80211_check_rate_mask(struct ieee80211_sub_if_data *sdata);
6487

6588
/* Get a reference to the rate control algorithm. If `name' is NULL, get the

net/mac80211/rc80211_minstrel_ht.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ minstrel_ht_init_cck_rates(struct minstrel_priv *mp)
16351635
}
16361636

16371637
static void *
1638-
minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
1638+
minstrel_ht_alloc(struct ieee80211_hw *hw)
16391639
{
16401640
struct minstrel_priv *mp;
16411641

@@ -1673,20 +1673,26 @@ minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
16731673
mp->update_interval = HZ / 10;
16741674
mp->new_avg = true;
16751675

1676+
minstrel_ht_init_cck_rates(mp);
1677+
1678+
return mp;
1679+
}
1680+
16761681
#ifdef CONFIG_MAC80211_DEBUGFS
1682+
static void minstrel_ht_add_debugfs(struct ieee80211_hw *hw, void *priv,
1683+
struct dentry *debugfsdir)
1684+
{
1685+
struct minstrel_priv *mp = priv;
1686+
16771687
mp->fixed_rate_idx = (u32) -1;
16781688
debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
16791689
&mp->fixed_rate_idx);
16801690
debugfs_create_u32("sample_switch", S_IRUGO | S_IWUSR, debugfsdir,
16811691
&mp->sample_switch);
16821692
debugfs_create_bool("new_avg", S_IRUGO | S_IWUSR, debugfsdir,
16831693
&mp->new_avg);
1684-
#endif
1685-
1686-
minstrel_ht_init_cck_rates(mp);
1687-
1688-
return mp;
16891694
}
1695+
#endif
16901696

16911697
static void
16921698
minstrel_ht_free(void *priv)
@@ -1725,6 +1731,7 @@ static const struct rate_control_ops mac80211_minstrel_ht = {
17251731
.alloc = minstrel_ht_alloc,
17261732
.free = minstrel_ht_free,
17271733
#ifdef CONFIG_MAC80211_DEBUGFS
1734+
.add_debugfs = minstrel_ht_add_debugfs,
17281735
.add_sta_debugfs = minstrel_ht_add_sta_debugfs,
17291736
#endif
17301737
.get_expected_throughput = minstrel_ht_get_expected_throughput,

0 commit comments

Comments
 (0)