From nobody Sat Feb 7 03:08:10 2026 Received: from e3i110.smtp2go.com (e3i110.smtp2go.com [158.120.84.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43C531AC896 for ; Tue, 24 Sep 2024 19:27:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=158.120.84.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727206051; cv=none; b=Q0nbmVWsff3GEz74U3J5ZSDKb/12RCicZmSJz8Hgf/Clg7r66mmLOwLvE7wQLY2E5hxISRiKdjVYHx1uTrFTcxiI0TlvX6rUoPNxwY9473lQyHvuw3ugxvBLoMtWC8XhN4nvCoZmwr9ySJ9qfQ5FU2S7yqyJi9ZdgrIwU0ImSvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727206051; c=relaxed/simple; bh=o9AheMXyJ5Cmyc7lZF52KShBkTdeQHX7e9sg1eH8R50=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QoIU+/bWkXsHw+cb5hThRV6+uOh/m6DSixKPN1WqUEDeU+XHq3BpjiYD21DCS0/msXk0x6N4HlvVncSsDuwtbmkV/z7Xcth/b8xl7VcVmaDPdcAHU8vplunENcWEYcL9zj9AYK9ZK1uImxsBh5jLEp5M+RAb1ueekxNRiLkDXYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=triplefau.lt; spf=pass smtp.mailfrom=em510616.triplefau.lt; dkim=pass (2048-bit key) header.d=smtpservice.net header.i=@smtpservice.net header.b=nIot1445; dkim=pass (2048-bit key) header.d=triplefau.lt header.i=@triplefau.lt header.b=TrXAzbuB; arc=none smtp.client-ip=158.120.84.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=triplefau.lt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=em510616.triplefau.lt Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=smtpservice.net header.i=@smtpservice.net header.b="nIot1445"; dkim=pass (2048-bit key) header.d=triplefau.lt header.i=@triplefau.lt header.b="TrXAzbuB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smtpservice.net; i=@smtpservice.net; q=dns/txt; s=a1-4; t=1727206039; h=feedback-id : x-smtpcorp-track : date : message-id : to : subject : from : reply-to : sender : list-unsubscribe : list-unsubscribe-post; bh=jHlTPG4NgHWnOrGLqSDIw8d/8MpR/1AQpbQk+oiNe2Q=; b=nIot1445T3M2Go+ukBYkDAcsg0qn/aNKs97xbdnvzfoFWbcRJiHFuuHJtBSSSURGukr6W EOi3qw/kyICkoI66FG21bcP2gqKmx7kyJy+Upwx2r2O9LIo8bjFvtkWq++OkzrTaeIor4co 6Dvz6g7cDOfyXd2A6IdjUEgej8HeNynaJIsJJvqBWaRq1nXzP+c9NfWWsZ4WBCjCLbdiRT5 C8LKZmSOOX9WSpLQQYBLX5tYQujNBTBm1GMNwXnJ+cNMEyUxeo2l6msEhLkKPpHVxxU0/I2 cyYFiaXneQnLiHX7ygKqXeLXnHL73DIHJrQGc4Ghf9RHcObEvAC81Z9+WXNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1727206039; h=from : subject : to : message-id : date; bh=jHlTPG4NgHWnOrGLqSDIw8d/8MpR/1AQpbQk+oiNe2Q=; b=TrXAzbuBNvNR3psAVDd+bQ9Loa3xIAPl7kuOuSVaOyzLJdyhMHXld3U8lkPgDnFwg1R6z OjffqFjcoNh35Pr//Tnr4ot5ani6XaRTbXj40cWXKMTFeeRmX/wys/AMMByVTTeIPc+0ouk 4rfjdXd7Lz9DJutdPH13T0rI1ZTcJr/cysi9uDe5K0XHATWETwEJlWgm2zhDDHw2dEiVmpe fkLAJ1j9vd9U8nEqkDtrWC61nxbtOG6ZGn+l0n3x4cVShSINZHBGQXOM2hUE9Rmaudxm2IK lMzSb8TRxgko3Fe307Qg/8cmuq3lZ146Hy5g0Nuxgth6WBqes+bSoYVoIcew== Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1stBBs-4o5NDgrlCD5-plB2; Tue, 24 Sep 2024 19:27:16 +0000 From: Remi Pommarel To: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Johannes Berg , Nicolas Cavallari , Nicolas Escande , Remi Pommarel Subject: [PATCH 1/2] wifi: cfg80211: Add wiphy_delayed_work_pending() Date: Tue, 24 Sep 2024 21:28:04 +0200 Message-Id: <20240924192805.13859-2-repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20240924192805.13859-1-repk@triplefau.lt> References: <20240924192805.13859-1-repk@triplefau.lt> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please forward a copy of this message, including all headers, to Feedback-ID: 510616m:510616apGKSTK:510616sPHEybd7wU X-smtpcorp-track: zzz-q7KFr31j.cexLJDwcJWnW.dJj51AiTsyY Content-Type: text/plain; charset="utf-8" Add wiphy_delayed_work_pending() to check if any delayed work timer is pending, that can be used to be sure that wiphy_delayed_work_queue() won't postpone an already pending delayed work. Signed-off-by: Remi Pommarel --- include/net/cfg80211.h | 44 ++++++++++++++++++++++++++++++++++++++++++ net/wireless/core.c | 7 +++++++ 2 files changed, 51 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 192d72c8b465..01697b624095 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -6129,6 +6129,50 @@ void wiphy_delayed_work_cancel(struct wiphy *wiphy, void wiphy_delayed_work_flush(struct wiphy *wiphy, struct wiphy_delayed_work *dwork); =20 +/** + * wiphy_delayed_work_pending - Find out whether a wiphy delayable + * work item is currently pending. + * + * @wiphy: the wiphy, for debug purposes + * @dwork: the delayed work in question + * + * return value: true if timer is pending, false otherwise + * + * How wiphy_delayed_work_queue() works is by setting a timer which + * when it expires calls wiphy_work_queue() to queue the wiphy work. + * Because wiphy_delayed_work_queue() uses mod_timer(), if it is + * called twice and the second call happens before the first call + * deadline, the work will rescheduled for the second deadline and + * won't run before that. + * + * wiphy_delayed_work_pending() can be used to detect if calling + * wiphy_work_delayed_work_queue() would start a new work schedule + * or delayed a previous one. As seen below it cannot be used to + * detect precisely if the work has finished to execute nor if it + * is currently executing. + * + * CPU0 CPU1 + * wiphy_delayed_work_queue(wk) + * mod_timer(wk->timer) + * wiphy_delayed_work_pending(wk) -> t= rue + * + * [...] + * expire_timers(wk->timer) + * detach_timer(wk->timer) + * wiphy_delayed_work_pending(wk) -> f= alse + * wk->timer->function() | + * wiphy_work_queue(wk) | delayed work pending + * list_add_tail() | returns false but + * queue_work(cfg80211_wiphy_work) | wk->func() has not + * | been run yet + * [...] | + * cfg80211_wiphy_work() | + * wk->func() V + * + */ +bool wiphy_delayed_work_pending(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork); + /** * enum ieee80211_ap_reg_power - regulatory power for an Access Point * diff --git a/net/wireless/core.c b/net/wireless/core.c index 4d5d351bd0b5..c9a1158dbdd1 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -1704,6 +1704,13 @@ void wiphy_delayed_work_flush(struct wiphy *wiphy, } EXPORT_SYMBOL_GPL(wiphy_delayed_work_flush); =20 +bool wiphy_delayed_work_pending(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork) +{ + return timer_pending(&dwork->timer); +} +EXPORT_SYMBOL_GPL(wiphy_delayed_work_pending); + static int __init cfg80211_init(void) { int err; --=20 2.46.0 From nobody Sat Feb 7 03:08:10 2026 Received: from e3i110.smtp2go.com (e3i110.smtp2go.com [158.120.84.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1116E1ACDF5 for ; Tue, 24 Sep 2024 19:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=158.120.84.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727206056; cv=none; b=SOLN5vnVG0go3LrUY63Nn2QTQ4uGeVnNse2jZ+IdgLiVbh94rqrqXAvYXC5MDmmnY5jC60Yh2hOkdXGp9WUFMTtZf/KDY486readtBGx07gC3982co3Fzitpxk5kUob27KLKpXcrNVYsk5LXlafO58RGmMYI1cUXFq1GdRsKyb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727206056; c=relaxed/simple; bh=9gCvAmkQ+McMEqsM1XwBcX6PfPT1TaDQAb9TmK5M5vA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AKpKTPM0fgNA4oQDL89HQUNnFIgS+Ge4PhgTDpg3MsnxrNELH7Y0CBqNiKZvxGLcg4CUYoxQLoGPaEUxVT9RFK1q2vH6Nvy00uKKFzjXXz6nYX1A1WwdTbdYle6eFFsS5QMIqsdDPBMxnFGj3GT+x168KFZUWcYa8jYUmHf0slo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=triplefau.lt; spf=pass smtp.mailfrom=em510616.triplefau.lt; dkim=pass (2048-bit key) header.d=smtpservice.net header.i=@smtpservice.net header.b=OU/kdyrq; dkim=pass (2048-bit key) header.d=triplefau.lt header.i=@triplefau.lt header.b=T7ZRvlbf; arc=none smtp.client-ip=158.120.84.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=triplefau.lt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=em510616.triplefau.lt Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=smtpservice.net header.i=@smtpservice.net header.b="OU/kdyrq"; dkim=pass (2048-bit key) header.d=triplefau.lt header.i=@triplefau.lt header.b="T7ZRvlbf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smtpservice.net; i=@smtpservice.net; q=dns/txt; s=a1-4; t=1727206040; h=feedback-id : x-smtpcorp-track : date : message-id : to : subject : from : reply-to : sender : list-unsubscribe : list-unsubscribe-post; bh=r7mBfgbkSHPGjlsNaa8FSid+n6LiX6fLZWRk2WuEUPE=; b=OU/kdyrqcK4hmHOd/RcKybqtqED5Jr/fc4xA1swTuckpyKaOqYRQtFPSx1+JPirEF6sOB 4L3TFlEXTs10Lfk/2rxNtDCbASgv7CPH8F2Z7FxbmktQIKt1yj5upPS3raQfvy4bA2IB0af wUKwhJcwq3XYXu+hIGqM6E/bkqGc+BGvQD14O5hvVrRi6qu/nGNgjbVKd5DGoYCPop1Sy5r 4735uawmEWSQGzCbUejGiJHjxqvPHcSrVuW11Gs12UFyhufIkKu28fmP34sM1r6/Fr3NQ4N 7o+Rrrpz/7WEF45vcueNmC1nqfLkblOj9oJH9phKww0r/3EagFR63yAhf3GQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1727206040; h=from : subject : to : message-id : date; bh=r7mBfgbkSHPGjlsNaa8FSid+n6LiX6fLZWRk2WuEUPE=; b=T7ZRvlbfHIXed7ECFGz8qrYT7kDX/NitBexnJyjuoOT66rDhsBH7vRQ06HIZyNOtJ0Up+ aUY4q8TJb4e1z5SAVMwEjj75QmOjvPUul3kytSEtGAL9ySWg5k3GZmKN9WT0UFKLjif1mEo kdwa8rbqLbkf0GUJgKSqkbOULjhGvCUXzEGfq0J5+vEQdOdX1puSqF/rVgj57W7ukfQyzPv Znq1XP8V3uTE0QkpkaQhZkprZ6CEAKOohVPhBUUnN13Ex2ZMlBMRE+KlkboQElwQrloviMp +4n6RiJizPf5Z1HoPorL1+qABadG3YtpWm3bwCE7CPechFScSPYg5n6WbLrw== Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1stBBs-4o5NDgruoYJ-mxiC; Tue, 24 Sep 2024 19:27:16 +0000 From: Remi Pommarel To: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Johannes Berg , Nicolas Cavallari , Nicolas Escande , Remi Pommarel Subject: [PATCH 2/2] wifi: mac80211: Convert color collision detection to wiphy work Date: Tue, 24 Sep 2024 21:28:05 +0200 Message-Id: <20240924192805.13859-3-repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20240924192805.13859-1-repk@triplefau.lt> References: <20240924192805.13859-1-repk@triplefau.lt> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please forward a copy of this message, including all headers, to Feedback-ID: 510616m:510616apGKSTK:510616seT2XkfLmR X-smtpcorp-track: c5kmSiwqy1Hx.EupDPlyQkV7g.cRffBw6dr2J Content-Type: text/plain; charset="utf-8" Call to ieee80211_color_collision_detection_work() needs wiphy lock to be held (see lockdep assert in cfg80211_bss_color_notify()). Not locking wiphy causes the following lockdep error: WARNING: CPU: 2 PID: 42 at net/wireless/nl80211.c:19505 cfg80211_bss_colo= r_notify+0x1a4/0x25c Modules linked in: CPU: 2 PID: 42 Comm: kworker/u8:3 Tainted: G W 6.4.0-0232= 7-g36c6cb260481 #1048 Hardware name: Workqueue: phy1 ieee80211_color_collision_detection_work pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=3D--) pc : cfg80211_bss_color_notify+0x1a4/0x25c lr : cfg80211_bss_color_notify+0x1a0/0x25c sp : ffff000002947d00 x29: ffff000002947d00 x28: ffff800008e1a000 x27: ffff000002bd4705 x26: ffff00000d034000 x25: ffff80000903cf40 x24: 0000000000000000 x23: ffff00000cb70720 x22: 0000000000800000 x21: ffff800008dfb008 x20: 000000000000008d x19: ffff00000d035fa8 x18: 0000000000000010 x17: 0000000000000001 x16: 000003564b1ce96a x15: 000d69696d057970 x14: 000000000000003b x13: 0000000000000001 x12: 0000000000040000 x11: 0000000000000001 x10: ffff80000978f9c0 x9 : ffff0000028d3174 x8 : ffff800008e30000 x7 : 0000000000000000 x6 : 0000000000000028 x5 : 000000000002f498 x4 : ffff00000d034a80 x3 : 0000000000800000 x2 : ffff800016143000 x1 : 0000000000000000 x0 : 0000000000000000 Call trace: cfg80211_bss_color_notify+0x1a4/0x25c ieee80211_color_collision_detection_work+0x20/0x118 process_one_work+0x294/0x554 worker_thread+0x70/0x440 kthread+0xf4/0xf8 ret_from_fork+0x10/0x20 irq event stamp: 77372 hardirqs last enabled at (77371): [] _raw_spin_unlock_= irq+0x2c/0x4c hardirqs last disabled at (77372): [] el1_dbg+0x20/0x48 softirqs last enabled at (77350): [] batadv_send_outst= anding_bcast_packet+0xb8/0x120 softirqs last disabled at (77348): [] batadv_send_outst= anding_bcast_packet+0x80/0x120 The wiphy lock cannot be taken directly from color collision detection delayed work (ieee80211_color_collision_detection_work()) because this work is cancel_delayed_work_sync() under this wiphy lock causing a potential deadlock( see [0] for details). To fix that ieee80211_color_collision_detection_work() could be converted to a wiphy work and cancel_delayed_work_sync() can be simply replaced by wiphy_delayed_work_cancel() serving the same purpose under wiphy lock. This could potentially fix [1]. [0]: https://lore.kernel.org/linux-wireless/D4A40Q44OAY2.W3SIF6UEPBUN@freeb= ox.fr/ [1]: https://lore.kernel.org/lkml/000000000000612f290618eee3e5@google.com/ Reported-by: Nicolas Escande Signed-off-by: Remi Pommarel --- net/mac80211/cfg.c | 17 +++++++++-------- net/mac80211/ieee80211_i.h | 5 +++-- net/mac80211/link.c | 7 ++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index b02b84ce2130..09025d59cdbe 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -4819,12 +4819,12 @@ void ieee80211_color_change_finalize_work(struct wi= phy *wiphy, ieee80211_color_change_finalize(link); } =20 -void ieee80211_color_collision_detection_work(struct work_struct *work) +void ieee80211_color_collision_detection_work(struct wiphy *wiphy, + struct wiphy_work *work) { - struct delayed_work *delayed_work =3D to_delayed_work(work); struct ieee80211_link_data *link =3D - container_of(delayed_work, struct ieee80211_link_data, - color_collision_detect_work); + container_of(work, struct ieee80211_link_data, + color_collision_detect_work.work); struct ieee80211_sub_if_data *sdata =3D link->sdata; =20 cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap, @@ -4877,7 +4877,8 @@ ieee80211_obss_color_collision_notify(struct ieee8021= 1_vif *vif, return; } =20 - if (delayed_work_pending(&link->color_collision_detect_work)) { + if (wiphy_delayed_work_pending(sdata->local->hw.wiphy, + &link->color_collision_detect_work)) { rcu_read_unlock(); return; } @@ -4886,9 +4887,9 @@ ieee80211_obss_color_collision_notify(struct ieee8021= 1_vif *vif, /* queue the color collision detection event every 500 ms in order to * avoid sending too much netlink messages to userspace. */ - ieee80211_queue_delayed_work(&sdata->local->hw, - &link->color_collision_detect_work, - msecs_to_jiffies(500)); + wiphy_delayed_work_queue(sdata->local->hw.wiphy, + &link->color_collision_detect_work, + msecs_to_jiffies(500)); =20 rcu_read_unlock(); } diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index a3485e4c6132..8650b3e8f1a9 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -1051,7 +1051,7 @@ struct ieee80211_link_data { } csa; =20 struct wiphy_work color_change_finalize_work; - struct delayed_work color_collision_detect_work; + struct wiphy_delayed_work color_collision_detect_work; u64 color_bitmap; =20 /* context reservation -- protected with wiphy mutex */ @@ -2004,7 +2004,8 @@ int ieee80211_channel_switch(struct wiphy *wiphy, str= uct net_device *dev, /* color change handling */ void ieee80211_color_change_finalize_work(struct wiphy *wiphy, struct wiphy_work *work); -void ieee80211_color_collision_detection_work(struct work_struct *work); +void ieee80211_color_collision_detection_work(struct wiphy *wiphy, + struct wiphy_work *work); =20 /* interface handling */ #define MAC80211_SUPPORTED_FEATURES_TX (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSU= M | \ diff --git a/net/mac80211/link.c b/net/mac80211/link.c index 1a211b8d4057..67f65ff79a71 100644 --- a/net/mac80211/link.c +++ b/net/mac80211/link.c @@ -41,8 +41,8 @@ void ieee80211_link_init(struct ieee80211_sub_if_data *sd= ata, ieee80211_csa_finalize_work); wiphy_work_init(&link->color_change_finalize_work, ieee80211_color_change_finalize_work); - INIT_DELAYED_WORK(&link->color_collision_detect_work, - ieee80211_color_collision_detection_work); + wiphy_delayed_work_init(&link->color_collision_detect_work, + ieee80211_color_collision_detection_work); INIT_LIST_HEAD(&link->assigned_chanctx_list); INIT_LIST_HEAD(&link->reserved_chanctx_list); =20 @@ -70,7 +70,8 @@ void ieee80211_link_stop(struct ieee80211_link_data *link) if (link->sdata->vif.type =3D=3D NL80211_IFTYPE_STATION) ieee80211_mgd_stop_link(link); =20 - cancel_delayed_work_sync(&link->color_collision_detect_work); + wiphy_delayed_work_cancel(link->sdata->local->hw.wiphy, + &link->color_collision_detect_work); wiphy_work_cancel(link->sdata->local->hw.wiphy, &link->color_change_finalize_work); wiphy_work_cancel(link->sdata->local->hw.wiphy, --=20 2.46.0