1 From 6cb5f3ea4654faf8c28b901266e960b1a4787b26 Mon Sep 17 00:00:00 2001
2 From: Johannes Berg <johannes.berg@intel.com>
3 Date: Thu, 23 Apr 2020 11:13:49 +0200
4 Subject: [PATCH] mac80211: populate debugfs only after cfg80211 init
6 When fixing the initialization race, we neglected to account for
7 the fact that debugfs is initialized in wiphy_register(), and
8 some debugfs things went missing (or rather were rerooted to the
11 Fix this by adding debugfs entries only after wiphy_register().
12 This requires some changes in the rate control code since it
13 currently adds debugfs at alloc time, which can no longer be
14 done after the reordering.
16 Reported-by: Jouni Malinen <j@w1.fi>
17 Reported-by: kernel test robot <rong.a.chen@intel.com>
18 Reported-by: Hauke Mehrtens <hauke@hauke-m.de>
19 Reported-by: Felix Fietkau <nbd@nbd.name>
20 Cc: stable@vger.kernel.org
21 Fixes: 52e04b4ce5d0 ("mac80211: fix race in ieee80211_register_hw()")
22 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
23 Acked-by: Sumit Garg <sumit.garg@linaro.org>
24 Link: https://lore.kernel.org/r/20200423111344.0e00d3346f12.Iadc76a03a55093d94391fc672e996a458702875d@changeid
25 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
27 drivers/net/wireless/intel/iwlegacy/3945-rs.c | 2 +-
28 drivers/net/wireless/intel/iwlegacy/4965-rs.c | 2 +-
29 drivers/net/wireless/intel/iwlwifi/dvm/rs.c | 2 +-
30 drivers/net/wireless/intel/iwlwifi/mvm/rs.c | 2 +-
31 drivers/net/wireless/realtek/rtlwifi/rc.c | 2 +-
32 include/net/mac80211.h | 4 +++-
33 net/mac80211/main.c | 5 ++--
34 net/mac80211/rate.c | 15 ++++--------
35 net/mac80211/rate.h | 23 +++++++++++++++++++
36 net/mac80211/rc80211_minstrel_ht.c | 19 ++++++++++-----
37 10 files changed, 51 insertions(+), 25 deletions(-)
39 --- a/drivers/net/wireless/intel/iwlegacy/3945-rs.c
40 +++ b/drivers/net/wireless/intel/iwlegacy/3945-rs.c
41 @@ -374,7 +374,7 @@ out:
45 -il3945_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
46 +il3945_rs_alloc(struct ieee80211_hw *hw)
50 --- a/drivers/net/wireless/intel/iwlegacy/4965-rs.c
51 +++ b/drivers/net/wireless/intel/iwlegacy/4965-rs.c
52 @@ -2474,7 +2474,7 @@ il4965_rs_fill_link_cmd(struct il_priv *
56 -il4965_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
57 +il4965_rs_alloc(struct ieee80211_hw *hw)
61 --- a/drivers/net/wireless/intel/iwlwifi/dvm/rs.c
62 +++ b/drivers/net/wireless/intel/iwlwifi/dvm/rs.c
63 @@ -3019,7 +3019,7 @@ static void rs_fill_link_cmd(struct iwl_
64 cpu_to_le16(priv->lib->bt_params->agg_time_limit);
67 -static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
68 +static void *rs_alloc(struct ieee80211_hw *hw)
72 --- a/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
73 +++ b/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
74 @@ -3665,7 +3665,7 @@ static void rs_fill_lq_cmd(struct iwl_mv
75 cpu_to_le16(iwl_mvm_coex_agg_time_limit(mvm, sta));
78 -static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
79 +static void *rs_alloc(struct ieee80211_hw *hw)
83 --- a/drivers/net/wireless/realtek/rtlwifi/rc.c
84 +++ b/drivers/net/wireless/realtek/rtlwifi/rc.c
85 @@ -261,7 +261,7 @@ static void rtl_rate_update(void *ppriv,
89 -static void *rtl_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
90 +static void *rtl_rate_alloc(struct ieee80211_hw *hw)
92 struct rtl_priv *rtlpriv = rtl_priv(hw);
94 --- a/include/net/mac80211.h
95 +++ b/include/net/mac80211.h
96 @@ -5969,7 +5969,9 @@ enum rate_control_capabilities {
97 struct rate_control_ops {
100 - void *(*alloc)(struct ieee80211_hw *hw, struct dentry *debugfsdir);
101 + void *(*alloc)(struct ieee80211_hw *hw);
102 + void (*add_debugfs)(struct ieee80211_hw *hw, void *priv,
103 + struct dentry *debugfsdir);
104 void (*free)(void *priv);
106 void *(*alloc_sta)(void *priv, struct ieee80211_sta *sta, gfp_t gfp);
107 --- a/net/mac80211/main.c
108 +++ b/net/mac80211/main.c
109 @@ -1163,8 +1163,6 @@ int ieee80211_register_hw(struct ieee802
110 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
111 IEEE80211_TX_STATUS_HEADROOM);
113 - debugfs_hw_add(local);
116 * if the driver doesn't specify a max listen interval we
117 * use 5 which should be a safe default
118 @@ -1256,6 +1254,9 @@ int ieee80211_register_hw(struct ieee802
120 goto fail_wiphy_register;
122 + debugfs_hw_add(local);
123 + rate_control_add_debugfs(local);
127 /* add one default STA interface if supported */
128 --- a/net/mac80211/rate.c
129 +++ b/net/mac80211/rate.c
130 @@ -214,17 +214,16 @@ static ssize_t rcname_read(struct file *
131 ref->ops->name, len);
134 -static const struct file_operations rcname_ops = {
135 +const struct file_operations rcname_ops = {
138 .llseek = default_llseek,
142 -static struct rate_control_ref *rate_control_alloc(const char *name,
143 - struct ieee80211_local *local)
144 +static struct rate_control_ref *
145 +rate_control_alloc(const char *name, struct ieee80211_local *local)
147 - struct dentry *debugfsdir = NULL;
148 struct rate_control_ref *ref;
150 ref = kmalloc(sizeof(struct rate_control_ref), GFP_KERNEL);
151 @@ -234,13 +233,7 @@ static struct rate_control_ref *rate_con
155 -#ifdef CPTCFG_MAC80211_DEBUGFS
156 - debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
157 - local->debugfs.rcdir = debugfsdir;
158 - debugfs_create_file("name", 0400, debugfsdir, ref, &rcname_ops);
161 - ref->priv = ref->ops->alloc(&local->hw, debugfsdir);
162 + ref->priv = ref->ops->alloc(&local->hw);
166 --- a/net/mac80211/rate.h
167 +++ b/net/mac80211/rate.h
168 @@ -60,6 +60,29 @@ static inline void rate_control_add_sta_
172 +extern const struct file_operations rcname_ops;
174 +static inline void rate_control_add_debugfs(struct ieee80211_local *local)
176 +#ifdef CPTCFG_MAC80211_DEBUGFS
177 + struct dentry *debugfsdir;
179 + if (!local->rate_ctrl)
182 + if (!local->rate_ctrl->ops->add_debugfs)
185 + debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
186 + local->debugfs.rcdir = debugfsdir;
187 + debugfs_create_file("name", 0400, debugfsdir,
188 + local->rate_ctrl, &rcname_ops);
190 + local->rate_ctrl->ops->add_debugfs(&local->hw, local->rate_ctrl->priv,
195 void ieee80211_check_rate_mask(struct ieee80211_sub_if_data *sdata);
197 /* Get a reference to the rate control algorithm. If `name' is NULL, get the
198 --- a/net/mac80211/rc80211_minstrel_ht.c
199 +++ b/net/mac80211/rc80211_minstrel_ht.c
200 @@ -1635,7 +1635,7 @@ minstrel_ht_init_cck_rates(struct minstr
204 -minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
205 +minstrel_ht_alloc(struct ieee80211_hw *hw)
207 struct minstrel_priv *mp;
209 @@ -1673,7 +1673,17 @@ minstrel_ht_alloc(struct ieee80211_hw *h
210 mp->update_interval = HZ / 10;
213 + minstrel_ht_init_cck_rates(mp);
218 #ifdef CPTCFG_MAC80211_DEBUGFS
219 +static void minstrel_ht_add_debugfs(struct ieee80211_hw *hw, void *priv,
220 + struct dentry *debugfsdir)
222 + struct minstrel_priv *mp = priv;
224 mp->fixed_rate_idx = (u32) -1;
225 debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
226 &mp->fixed_rate_idx);
227 @@ -1681,12 +1691,8 @@ minstrel_ht_alloc(struct ieee80211_hw *h
229 debugfs_create_bool("new_avg", S_IRUGO | S_IWUSR, debugfsdir,
233 - minstrel_ht_init_cck_rates(mp);
240 minstrel_ht_free(void *priv)
241 @@ -1725,6 +1731,7 @@ static const struct rate_control_ops mac
242 .alloc = minstrel_ht_alloc,
243 .free = minstrel_ht_free,
244 #ifdef CPTCFG_MAC80211_DEBUGFS
245 + .add_debugfs = minstrel_ht_add_debugfs,
246 .add_sta_debugfs = minstrel_ht_add_sta_debugfs,
248 .get_expected_throughput = minstrel_ht_get_expected_throughput,