linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: linux-wireless@vger.kernel.org
Cc: Johannes Berg <johannes.berg@intel.com>
Subject: [PATCH 05/40] wifi: cfg80211: add flush functions for wiphy work
Date: Mon, 28 Aug 2023 13:59:33 +0200	[thread overview]
Message-ID: <20230828135927.16f4b838a4dd.I93b2697ae20e7ff04b96d624664b21b5084703ca@changeid> (raw)
In-Reply-To: <20230828115927.116700-41-johannes@sipsolutions.net>

From: Johannes Berg <johannes.berg@intel.com>

There may be sometimes reasons to actually run the work
if it's pending, add flush functions for both regular and
delayed wiphy work that will do this.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/net/cfg80211.h | 21 +++++++++++++++++++++
 net/wireless/core.c    | 34 ++++++++++++++++++++++++++++++++--
 net/wireless/core.h    |  3 ++-
 net/wireless/sysfs.c   |  4 ++--
 4 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 3a4b684f89bf..d1964a6d0b35 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -5826,6 +5826,16 @@ void wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *work);
  */
 void wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *work);
 
+/**
+ * wiphy_work_flush - flush previously queued work
+ * @wiphy: the wiphy, for debug purposes
+ * @work: the work to flush, this can be %NULL to flush all work
+ *
+ * Flush the work (i.e. run it if pending). This must be called
+ * under the wiphy mutex acquired by wiphy_lock().
+ */
+void wiphy_work_flush(struct wiphy *wiphy, struct wiphy_work *work);
+
 struct wiphy_delayed_work {
 	struct wiphy_work work;
 	struct wiphy *wiphy;
@@ -5869,6 +5879,17 @@ void wiphy_delayed_work_queue(struct wiphy *wiphy,
 void wiphy_delayed_work_cancel(struct wiphy *wiphy,
 			       struct wiphy_delayed_work *dwork);
 
+/**
+ * wiphy_delayed work_flush - flush previously queued delayed work
+ * @wiphy: the wiphy, for debug purposes
+ * @work: the work to flush
+ *
+ * Flush the work (i.e. run it if pending). This must be called
+ * under the wiphy mutex acquired by wiphy_lock().
+ */
+void wiphy_delayed_work_flush(struct wiphy *wiphy,
+			      struct wiphy_delayed_work *dwork);
+
 /**
  * struct wireless_dev - wireless device state
  *
diff --git a/net/wireless/core.c b/net/wireless/core.c
index fdb9d736a2e8..88042a647aaa 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -1049,7 +1049,8 @@ void wiphy_rfkill_start_polling(struct wiphy *wiphy)
 }
 EXPORT_SYMBOL(wiphy_rfkill_start_polling);
 
-void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev)
+void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev,
+				  struct wiphy_work *end)
 {
 	unsigned int runaway_limit = 100;
 	unsigned long flags;
@@ -1068,6 +1069,10 @@ void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev)
 		wk->func(&rdev->wiphy, wk);
 
 		spin_lock_irqsave(&rdev->wiphy_work_lock, flags);
+
+		if (wk == end)
+			break;
+
 		if (WARN_ON(--runaway_limit == 0))
 			INIT_LIST_HEAD(&rdev->wiphy_work_list);
 	}
@@ -1118,7 +1123,7 @@ void wiphy_unregister(struct wiphy *wiphy)
 #endif
 
 	/* surely nothing is reachable now, clean up work */
-	cfg80211_process_wiphy_works(rdev);
+	cfg80211_process_wiphy_works(rdev, NULL);
 	wiphy_unlock(&rdev->wiphy);
 	rtnl_unlock();
 
@@ -1640,6 +1645,21 @@ void wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *work)
 }
 EXPORT_SYMBOL_GPL(wiphy_work_cancel);
 
+void wiphy_work_flush(struct wiphy *wiphy, struct wiphy_work *work)
+{
+	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
+	unsigned long flags;
+	bool run;
+
+	spin_lock_irqsave(&rdev->wiphy_work_lock, flags);
+	run = !work || !list_empty(&work->entry);
+	spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags);
+
+	if (run)
+		cfg80211_process_wiphy_works(rdev, work);
+}
+EXPORT_SYMBOL_GPL(wiphy_work_flush);
+
 void wiphy_delayed_work_timer(struct timer_list *t)
 {
 	struct wiphy_delayed_work *dwork = from_timer(dwork, t, timer);
@@ -1672,6 +1692,16 @@ void wiphy_delayed_work_cancel(struct wiphy *wiphy,
 }
 EXPORT_SYMBOL_GPL(wiphy_delayed_work_cancel);
 
+void wiphy_delayed_work_flush(struct wiphy *wiphy,
+			      struct wiphy_delayed_work *dwork)
+{
+	lockdep_assert_held(&wiphy->mtx);
+
+	del_timer_sync(&dwork->timer);
+	wiphy_work_flush(wiphy, &dwork->work);
+}
+EXPORT_SYMBOL_GPL(wiphy_delayed_work_flush);
+
 static int __init cfg80211_init(void)
 {
 	int err;
diff --git a/net/wireless/core.h b/net/wireless/core.h
index d4976550e7f6..b9876b444e1b 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -469,7 +469,8 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
 			  struct net_device *dev, enum nl80211_iftype ntype,
 			  struct vif_params *params);
 void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
-void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev);
+void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev,
+				  struct wiphy_work *end);
 void cfg80211_process_wdev_events(struct wireless_dev *wdev);
 
 bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range,
diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c
index c629bac3f298..565511a3f461 100644
--- a/net/wireless/sysfs.c
+++ b/net/wireless/sysfs.c
@@ -105,14 +105,14 @@ static int wiphy_suspend(struct device *dev)
 			cfg80211_leave_all(rdev);
 			cfg80211_process_rdev_events(rdev);
 		}
-		cfg80211_process_wiphy_works(rdev);
+		cfg80211_process_wiphy_works(rdev, NULL);
 		if (rdev->ops->suspend)
 			ret = rdev_suspend(rdev, rdev->wiphy.wowlan_config);
 		if (ret == 1) {
 			/* Driver refuse to configure wowlan */
 			cfg80211_leave_all(rdev);
 			cfg80211_process_rdev_events(rdev);
-			cfg80211_process_wiphy_works(rdev);
+			cfg80211_process_wiphy_works(rdev, NULL);
 			ret = rdev_suspend(rdev, NULL);
 		}
 		if (ret == 0)
-- 
2.41.0


  parent reply	other threads:[~2023-08-28 12:06 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-28 11:59 [PATCH 00/40] wifi: cfg80211/mac80211: locking cleanups Johannes Berg
2023-08-28 11:59 ` [PATCH 01/40] wifi: mac80211: debugfs: lock wiphy instead of RTNL Johannes Berg
2023-08-28 11:59 ` [PATCH 02/40] wifi: mac80211: hold wiphy lock in netdev/link debugfs Johannes Berg
2023-08-28 11:59 ` [PATCH 03/40] wifi: mac80211: lock wiphy for aggregation debugfs Johannes Berg
2023-08-28 11:59 ` [PATCH 04/40] wifi: cfg80211: check RTNL when iterating devices Johannes Berg
2023-08-28 11:59 ` Johannes Berg [this message]
2023-08-28 11:59 ` [PATCH 06/40] wifi: mac80211: flush wiphy work where appropriate Johannes Berg
2023-08-28 11:59 ` [PATCH 07/40] wifi: mac80211: convert A-MPDU work to wiphy work Johannes Berg
2023-08-28 11:59 ` [PATCH 08/40] wifi: mac80211: add more ops assertions Johannes Berg
2023-08-28 11:59 ` [PATCH 09/40] wifi: mac80211: move DFS CAC work to wiphy work Johannes Berg
2023-08-28 11:59 ` [PATCH 10/40] wifi: mac80211: move radar detect " Johannes Berg
2023-08-28 11:59 ` [PATCH 11/40] wifi: mac80211: move scan " Johannes Berg
2023-08-28 11:59 ` [PATCH 12/40] wifi: mac80211: move monitor " Johannes Berg
2023-08-28 11:59 ` [PATCH 13/40] wifi: mac80211: lock wiphy in IP address notifier Johannes Berg
2023-08-28 11:59 ` [PATCH 14/40] wifi: mac80211: move offchannel works to wiphy work Johannes Berg
2023-08-28 11:59 ` [PATCH 15/40] wifi: mac80211: move link activation work " Johannes Berg
2023-08-28 11:59 ` [PATCH 16/40] wifi: mac80211: move dynamic PS " Johannes Berg
2023-08-28 11:59 ` [PATCH 17/40] wifi: mac80211: move sched-scan stop work " Johannes Berg
2023-08-28 11:59 ` [PATCH 18/40] wifi: mac80211: move TDLS " Johannes Berg
2023-08-28 11:59 ` [PATCH 19/40] wifi: mac80211: move key tailroom " Johannes Berg
2023-08-28 11:59 ` [PATCH 20/40] wifi: mac80211: move tspec " Johannes Berg
2023-08-28 11:59 ` [PATCH 21/40] wifi: mac80211: move filter reconfig " Johannes Berg
2023-08-28 11:59 ` [PATCH 22/40] wifi: mac80211: move CSA finalize " Johannes Berg
2023-08-28 11:59 ` [PATCH 23/40] wifi: mac80211: move color change " Johannes Berg
2023-08-28 11:59 ` [PATCH 24/40] wifi: mac80211: check wiphy mutex in ops Johannes Berg
2023-08-28 11:59 ` [PATCH 25/40] wifi: cfg80211: reg: hold wiphy mutex for wdev iteration Johannes Berg
2023-08-28 11:59 ` [PATCH 26/40] wifi: cfg80211: sme: hold wiphy lock " Johannes Berg
2023-08-28 11:59 ` [PATCH 27/40] wifi: cfg80211: hold wiphy lock in cfg80211_any_wiphy_oper_chan() Johannes Berg
2023-08-28 11:59 ` [PATCH 28/40] wifi: cfg80211: check wiphy mutex is held for wdev mutex Johannes Berg
2023-08-28 11:59 ` [PATCH 29/40] wifi: mac80211: ethtool: hold wiphy mutex Johannes Berg
2023-08-28 11:59 ` [PATCH 30/40] wifi: mac80211: hold wiphy_lock around concurrency checks Johannes Berg
2023-08-28 11:59 ` [PATCH 31/40] wifi: mac80211: extend wiphy lock in interface removal Johannes Berg
2023-08-28 12:00 ` [PATCH 32/40] wifi: mac80211: take wiphy lock for MAC addr change Johannes Berg
2023-08-28 12:00 ` [PATCH 33/40] wifi: mac80211: remove sta_mtx Johannes Berg
2023-08-28 12:00 ` [PATCH 34/40] wifi: mac80211: remove key_mtx Johannes Berg
2023-08-28 12:00 ` [PATCH 35/40] wifi: mac80211: remove chanctx_mtx Johannes Berg
2023-08-28 12:00 ` [PATCH 36/40] wifi: mac80211: remove ampdu_mlme.mtx Johannes Berg
2023-08-28 12:00 ` [PATCH 37/40] wifi: mac80211: remove local->mtx Johannes Berg
2023-08-28 12:00 ` [PATCH 38/40] wifi: mac80211: reduce iflist_mtx Johannes Berg
2023-08-28 12:00 ` [PATCH 39/40] wifi: mac80211: set wiphy for virtual monitors Johannes Berg
2023-08-28 12:00 ` [PATCH 40/40] wifi: cfg80211: remove wdev mutex Johannes Berg
2023-08-29 10:18   ` [PATCH v2 " Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230828135927.16f4b838a4dd.I93b2697ae20e7ff04b96d624664b21b5084703ca@changeid \
    --to=johannes@sipsolutions.net \
    --cc=johannes.berg@intel.com \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).