efe216c530922918245c54fccb1c4f68e125f11f
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / subsys / 250-mac80211-populate-debugfs-only-after-cfg80211-init.patch
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
5
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
9 global debugfs root).
10
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.
15
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>
26 ---
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(-)
38
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:
42 }
43
44 static void *
45 -il3945_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
46 +il3945_rs_alloc(struct ieee80211_hw *hw)
47 {
48 return hw->priv;
49 }
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 *
53 }
54
55 static void *
56 -il4965_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
57 +il4965_rs_alloc(struct ieee80211_hw *hw)
58 {
59 return hw->priv;
60 }
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);
65 }
66
67 -static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
68 +static void *rs_alloc(struct ieee80211_hw *hw)
69 {
70 return hw->priv;
71 }
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));
76 }
77
78 -static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
79 +static void *rs_alloc(struct ieee80211_hw *hw)
80 {
81 return hw->priv;
82 }
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,
86 {
87 }
88
89 -static void *rtl_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
90 +static void *rtl_rate_alloc(struct ieee80211_hw *hw)
91 {
92 struct rtl_priv *rtlpriv = rtl_priv(hw);
93 return rtlpriv;
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 {
98 unsigned long capa;
99 const char *name;
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);
105
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);
112
113 - debugfs_hw_add(local);
114 -
115 /*
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
119 if (result < 0)
120 goto fail_wiphy_register;
121
122 + debugfs_hw_add(local);
123 + rate_control_add_debugfs(local);
124 +
125 rtnl_lock();
126
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);
132 }
133
134 -static const struct file_operations rcname_ops = {
135 +const struct file_operations rcname_ops = {
136 .read = rcname_read,
137 .open = simple_open,
138 .llseek = default_llseek,
139 };
140 #endif
141
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)
146 {
147 - struct dentry *debugfsdir = NULL;
148 struct rate_control_ref *ref;
149
150 ref = kmalloc(sizeof(struct rate_control_ref), GFP_KERNEL);
151 @@ -234,13 +233,7 @@ static struct rate_control_ref *rate_con
152 if (!ref->ops)
153 goto free;
154
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);
159 -#endif
160 -
161 - ref->priv = ref->ops->alloc(&local->hw, debugfsdir);
162 + ref->priv = ref->ops->alloc(&local->hw);
163 if (!ref->priv)
164 goto free;
165 return ref;
166 --- a/net/mac80211/rate.h
167 +++ b/net/mac80211/rate.h
168 @@ -60,6 +60,29 @@ static inline void rate_control_add_sta_
169 #endif
170 }
171
172 +extern const struct file_operations rcname_ops;
173 +
174 +static inline void rate_control_add_debugfs(struct ieee80211_local *local)
175 +{
176 +#ifdef CPTCFG_MAC80211_DEBUGFS
177 + struct dentry *debugfsdir;
178 +
179 + if (!local->rate_ctrl)
180 + return;
181 +
182 + if (!local->rate_ctrl->ops->add_debugfs)
183 + return;
184 +
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);
189 +
190 + local->rate_ctrl->ops->add_debugfs(&local->hw, local->rate_ctrl->priv,
191 + debugfsdir);
192 +#endif
193 +}
194 +
195 void ieee80211_check_rate_mask(struct ieee80211_sub_if_data *sdata);
196
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
201 }
202
203 static void *
204 -minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
205 +minstrel_ht_alloc(struct ieee80211_hw *hw)
206 {
207 struct minstrel_priv *mp;
208
209 @@ -1673,7 +1673,17 @@ minstrel_ht_alloc(struct ieee80211_hw *h
210 mp->update_interval = HZ / 10;
211 mp->new_avg = true;
212
213 + minstrel_ht_init_cck_rates(mp);
214 +
215 + return mp;
216 +}
217 +
218 #ifdef CPTCFG_MAC80211_DEBUGFS
219 +static void minstrel_ht_add_debugfs(struct ieee80211_hw *hw, void *priv,
220 + struct dentry *debugfsdir)
221 +{
222 + struct minstrel_priv *mp = priv;
223 +
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
228 &mp->sample_switch);
229 debugfs_create_bool("new_avg", S_IRUGO | S_IWUSR, debugfsdir,
230 &mp->new_avg);
231 -#endif
232 -
233 - minstrel_ht_init_cck_rates(mp);
234 -
235 - return mp;
236 }
237 +#endif
238
239 static void
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,
247 #endif
248 .get_expected_throughput = minstrel_ht_get_expected_throughput,