ae72441c4688199f550a915254efaceafb09cbd8
[openwrt/openwrt.git] /
1 From: Remi Pommarel <repk@triplefau.lt>
2 Date: Tue, 24 Sep 2024 21:28:05 +0200
3 Subject: [PATCH] wifi: mac80211: Convert color collision detection to wiphy
4 work
5
6 Call to ieee80211_color_collision_detection_work() needs wiphy lock to
7 be held (see lockdep assert in cfg80211_bss_color_notify()). Not locking
8 wiphy causes the following lockdep error:
9
10 WARNING: CPU: 2 PID: 42 at net/wireless/nl80211.c:19505 cfg80211_bss_color_notify+0x1a4/0x25c
11 Modules linked in:
12 CPU: 2 PID: 42 Comm: kworker/u8:3 Tainted: G W 6.4.0-02327-g36c6cb260481 #1048
13 Hardware name:
14 Workqueue: phy1 ieee80211_color_collision_detection_work
15 pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
16 pc : cfg80211_bss_color_notify+0x1a4/0x25c
17 lr : cfg80211_bss_color_notify+0x1a0/0x25c
18 sp : ffff000002947d00
19 x29: ffff000002947d00 x28: ffff800008e1a000 x27: ffff000002bd4705
20 x26: ffff00000d034000 x25: ffff80000903cf40 x24: 0000000000000000
21 x23: ffff00000cb70720 x22: 0000000000800000 x21: ffff800008dfb008
22 x20: 000000000000008d x19: ffff00000d035fa8 x18: 0000000000000010
23 x17: 0000000000000001 x16: 000003564b1ce96a x15: 000d69696d057970
24 x14: 000000000000003b x13: 0000000000000001 x12: 0000000000040000
25 x11: 0000000000000001 x10: ffff80000978f9c0 x9 : ffff0000028d3174
26 x8 : ffff800008e30000 x7 : 0000000000000000 x6 : 0000000000000028
27 x5 : 000000000002f498 x4 : ffff00000d034a80 x3 : 0000000000800000
28 x2 : ffff800016143000 x1 : 0000000000000000 x0 : 0000000000000000
29 Call trace:
30 cfg80211_bss_color_notify+0x1a4/0x25c
31 ieee80211_color_collision_detection_work+0x20/0x118
32 process_one_work+0x294/0x554
33 worker_thread+0x70/0x440
34 kthread+0xf4/0xf8
35 ret_from_fork+0x10/0x20
36 irq event stamp: 77372
37 hardirqs last enabled at (77371): [<ffff800008a346fc>] _raw_spin_unlock_irq+0x2c/0x4c
38 hardirqs last disabled at (77372): [<ffff800008a28754>] el1_dbg+0x20/0x48
39 softirqs last enabled at (77350): [<ffff8000089e120c>] batadv_send_outstanding_bcast_packet+0xb8/0x120
40 softirqs last disabled at (77348): [<ffff8000089e11d4>] batadv_send_outstanding_bcast_packet+0x80/0x120
41
42 The wiphy lock cannot be taken directly from color collision detection
43 delayed work (ieee80211_color_collision_detection_work()) because this
44 work is cancel_delayed_work_sync() under this wiphy lock causing a
45 potential deadlock( see [0] for details).
46
47 To fix that ieee80211_color_collision_detection_work() could be
48 converted to a wiphy work and cancel_delayed_work_sync() can be simply
49 replaced by wiphy_delayed_work_cancel() serving the same purpose under
50 wiphy lock.
51
52 This could potentially fix [1].
53
54 [0]: https://lore.kernel.org/linux-wireless/D4A40Q44OAY2.W3SIF6UEPBUN@freebox.fr/
55 [1]: https://lore.kernel.org/lkml/000000000000612f290618eee3e5@google.com/
56
57 Reported-by: Nicolas Escande <nescande@freebox.fr>
58 Signed-off-by: Remi Pommarel <repk@triplefau.lt>
59 Link: https://patch.msgid.link/20240924192805.13859-3-repk@triplefau.lt
60 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
61 ---
62
63 --- a/net/mac80211/cfg.c
64 +++ b/net/mac80211/cfg.c
65 @@ -4836,12 +4836,12 @@ void ieee80211_color_change_finalize_wor
66 ieee80211_color_change_finalize(link);
67 }
68
69 -void ieee80211_color_collision_detection_work(struct work_struct *work)
70 +void ieee80211_color_collision_detection_work(struct wiphy *wiphy,
71 + struct wiphy_work *work)
72 {
73 - struct delayed_work *delayed_work = to_delayed_work(work);
74 struct ieee80211_link_data *link =
75 - container_of(delayed_work, struct ieee80211_link_data,
76 - color_collision_detect_work);
77 + container_of(work, struct ieee80211_link_data,
78 + color_collision_detect_work.work);
79 struct ieee80211_sub_if_data *sdata = link->sdata;
80
81 cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap,
82 @@ -4894,7 +4894,8 @@ ieee80211_obss_color_collision_notify(st
83 return;
84 }
85
86 - if (delayed_work_pending(&link->color_collision_detect_work)) {
87 + if (wiphy_delayed_work_pending(sdata->local->hw.wiphy,
88 + &link->color_collision_detect_work)) {
89 rcu_read_unlock();
90 return;
91 }
92 @@ -4903,9 +4904,9 @@ ieee80211_obss_color_collision_notify(st
93 /* queue the color collision detection event every 500 ms in order to
94 * avoid sending too much netlink messages to userspace.
95 */
96 - ieee80211_queue_delayed_work(&sdata->local->hw,
97 - &link->color_collision_detect_work,
98 - msecs_to_jiffies(500));
99 + wiphy_delayed_work_queue(sdata->local->hw.wiphy,
100 + &link->color_collision_detect_work,
101 + msecs_to_jiffies(500));
102
103 rcu_read_unlock();
104 }
105 --- a/net/mac80211/ieee80211_i.h
106 +++ b/net/mac80211/ieee80211_i.h
107 @@ -1056,7 +1056,7 @@ struct ieee80211_link_data {
108 } csa;
109
110 struct wiphy_work color_change_finalize_work;
111 - struct delayed_work color_collision_detect_work;
112 + struct wiphy_delayed_work color_collision_detect_work;
113 u64 color_bitmap;
114
115 /* context reservation -- protected with wiphy mutex */
116 @@ -2010,7 +2010,8 @@ int ieee80211_channel_switch(struct wiph
117 /* color change handling */
118 void ieee80211_color_change_finalize_work(struct wiphy *wiphy,
119 struct wiphy_work *work);
120 -void ieee80211_color_collision_detection_work(struct work_struct *work);
121 +void ieee80211_color_collision_detection_work(struct wiphy *wiphy,
122 + struct wiphy_work *work);
123
124 /* interface handling */
125 #define MAC80211_SUPPORTED_FEATURES_TX (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | \
126 --- a/net/mac80211/link.c
127 +++ b/net/mac80211/link.c
128 @@ -41,8 +41,8 @@ void ieee80211_link_init(struct ieee8021
129 ieee80211_csa_finalize_work);
130 wiphy_work_init(&link->color_change_finalize_work,
131 ieee80211_color_change_finalize_work);
132 - INIT_DELAYED_WORK(&link->color_collision_detect_work,
133 - ieee80211_color_collision_detection_work);
134 + wiphy_delayed_work_init(&link->color_collision_detect_work,
135 + ieee80211_color_collision_detection_work);
136 INIT_LIST_HEAD(&link->assigned_chanctx_list);
137 INIT_LIST_HEAD(&link->reserved_chanctx_list);
138 wiphy_delayed_work_init(&link->dfs_cac_timer_work,
139 @@ -72,7 +72,8 @@ void ieee80211_link_stop(struct ieee8021
140 if (link->sdata->vif.type == NL80211_IFTYPE_STATION)
141 ieee80211_mgd_stop_link(link);
142
143 - cancel_delayed_work_sync(&link->color_collision_detect_work);
144 + wiphy_delayed_work_cancel(link->sdata->local->hw.wiphy,
145 + &link->color_collision_detect_work);
146 wiphy_work_cancel(link->sdata->local->hw.wiphy,
147 &link->color_change_finalize_work);
148 wiphy_work_cancel(link->sdata->local->hw.wiphy,