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 02/40] wifi: mac80211: hold wiphy lock in netdev/link debugfs
Date: Mon, 28 Aug 2023 13:59:30 +0200	[thread overview]
Message-ID: <20230828135927.e3c99daad33e.Ic09414bfe7e6b523aca469e402877b3a85bc12af@changeid> (raw)
In-Reply-To: <20230828115927.116700-41-johannes@sipsolutions.net>

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

It's no longer really needed to ensure that the debugfs
file isn't going away, debugfs handles that. So there's
no point in holding dev_base_lock or RTNL here, but we
should instead hold the wiphy lock since drivers will
be allowed to depend on that. Do that, which requires
splitting the sdata and link macros a bit.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 net/mac80211/debugfs_netdev.c | 123 +++++++++++++++++++++++++---------
 1 file changed, 90 insertions(+), 33 deletions(-)

diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 63250286dc8b..706330fadc97 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -22,18 +22,18 @@
 #include "debugfs_netdev.h"
 #include "driver-ops.h"
 
-static ssize_t ieee80211_if_read(
-	void *data,
+static ssize_t ieee80211_if_read_sdata(
+	struct ieee80211_sub_if_data *sdata,
 	char __user *userbuf,
 	size_t count, loff_t *ppos,
-	ssize_t (*format)(const void *, char *, int))
+	ssize_t (*format)(const struct ieee80211_sub_if_data *sdata, char *, int))
 {
 	char buf[200];
 	ssize_t ret = -EINVAL;
 
-	read_lock(&dev_base_lock);
-	ret = (*format)(data, buf, sizeof(buf));
-	read_unlock(&dev_base_lock);
+	wiphy_lock(sdata->local->hw.wiphy);
+	ret = (*format)(sdata, buf, sizeof(buf));
+	wiphy_unlock(sdata->local->hw.wiphy);
 
 	if (ret >= 0)
 		ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
@@ -41,11 +41,11 @@ static ssize_t ieee80211_if_read(
 	return ret;
 }
 
-static ssize_t ieee80211_if_write(
-	void *data,
+static ssize_t ieee80211_if_write_sdata(
+	struct ieee80211_sub_if_data *sdata,
 	const char __user *userbuf,
 	size_t count, loff_t *ppos,
-	ssize_t (*write)(void *, const char *, int))
+	ssize_t (*write)(struct ieee80211_sub_if_data *sdata, const char *, int))
 {
 	char buf[64];
 	ssize_t ret;
@@ -57,9 +57,51 @@ static ssize_t ieee80211_if_write(
 		return -EFAULT;
 	buf[count] = '\0';
 
-	rtnl_lock();
-	ret = (*write)(data, buf, count);
-	rtnl_unlock();
+	wiphy_lock(sdata->local->hw.wiphy);
+	ret = (*write)(sdata, buf, count);
+	wiphy_unlock(sdata->local->hw.wiphy);
+
+	return ret;
+}
+
+static ssize_t ieee80211_if_read_link(
+	struct ieee80211_link_data *link,
+	char __user *userbuf,
+	size_t count, loff_t *ppos,
+	ssize_t (*format)(const struct ieee80211_link_data *link, char *, int))
+{
+	char buf[200];
+	ssize_t ret = -EINVAL;
+
+	wiphy_lock(link->sdata->local->hw.wiphy);
+	ret = (*format)(link, buf, sizeof(buf));
+	wiphy_unlock(link->sdata->local->hw.wiphy);
+
+	if (ret >= 0)
+		ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+
+	return ret;
+}
+
+static ssize_t ieee80211_if_write_link(
+	struct ieee80211_link_data *link,
+	const char __user *userbuf,
+	size_t count, loff_t *ppos,
+	ssize_t (*write)(struct ieee80211_link_data *link, const char *, int))
+{
+	char buf[64];
+	ssize_t ret;
+
+	if (count >= sizeof(buf))
+		return -E2BIG;
+
+	if (copy_from_user(buf, userbuf, count))
+		return -EFAULT;
+	buf[count] = '\0';
+
+	wiphy_lock(link->sdata->local->hw.wiphy);
+	ret = (*write)(link, buf, count);
+	wiphy_unlock(link->sdata->local->hw.wiphy);
 
 	return ret;
 }
@@ -126,41 +168,37 @@ static const struct file_operations name##_ops = {			\
 	.llseek = generic_file_llseek,					\
 }
 
-#define _IEEE80211_IF_FILE_R_FN(name, type)				\
+#define _IEEE80211_IF_FILE_R_FN(name)					\
 static ssize_t ieee80211_if_read_##name(struct file *file,		\
 					char __user *userbuf,		\
 					size_t count, loff_t *ppos)	\
 {									\
-	ssize_t (*fn)(const void *, char *, int) = (void *)		\
-		((ssize_t (*)(const type, char *, int))			\
-		 ieee80211_if_fmt_##name);				\
-	return ieee80211_if_read(file->private_data,			\
-				 userbuf, count, ppos, fn);		\
+	return ieee80211_if_read_sdata(file->private_data,		\
+				       userbuf, count, ppos,		\
+				       ieee80211_if_fmt_##name);	\
 }
 
-#define _IEEE80211_IF_FILE_W_FN(name, type)				\
+#define _IEEE80211_IF_FILE_W_FN(name)					\
 static ssize_t ieee80211_if_write_##name(struct file *file,		\
 					 const char __user *userbuf,	\
 					 size_t count, loff_t *ppos)	\
 {									\
-	ssize_t (*fn)(void *, const char *, int) = (void *)		\
-		((ssize_t (*)(type, const char *, int))			\
-		 ieee80211_if_parse_##name);				\
-	return ieee80211_if_write(file->private_data, userbuf, count,	\
-				  ppos, fn);				\
+	return ieee80211_if_write_sdata(file->private_data, userbuf,	\
+					count, ppos,			\
+					ieee80211_if_parse_##name);	\
 }
 
 #define IEEE80211_IF_FILE_R(name)					\
-	_IEEE80211_IF_FILE_R_FN(name, struct ieee80211_sub_if_data *)	\
+	_IEEE80211_IF_FILE_R_FN(name)					\
 	_IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
 
 #define IEEE80211_IF_FILE_W(name)					\
-	_IEEE80211_IF_FILE_W_FN(name, struct ieee80211_sub_if_data *)	\
+	_IEEE80211_IF_FILE_W_FN(name)					\
 	_IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
 
 #define IEEE80211_IF_FILE_RW(name)					\
-	_IEEE80211_IF_FILE_R_FN(name, struct ieee80211_sub_if_data *)	\
-	_IEEE80211_IF_FILE_W_FN(name, struct ieee80211_sub_if_data *)	\
+	_IEEE80211_IF_FILE_R_FN(name)					\
+	_IEEE80211_IF_FILE_W_FN(name)					\
 	_IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name,		\
 			       ieee80211_if_write_##name)
 
@@ -168,18 +206,37 @@ static ssize_t ieee80211_if_write_##name(struct file *file,		\
 	IEEE80211_IF_FMT_##format(name, struct ieee80211_sub_if_data, field) \
 	IEEE80211_IF_FILE_R(name)
 
-/* Same but with a link_ prefix in the ops variable name and different type */
+#define _IEEE80211_IF_LINK_R_FN(name)					\
+static ssize_t ieee80211_if_read_##name(struct file *file,		\
+					char __user *userbuf,		\
+					size_t count, loff_t *ppos)	\
+{									\
+	return ieee80211_if_read_link(file->private_data,		\
+				      userbuf, count, ppos,		\
+				      ieee80211_if_fmt_##name);	\
+}
+
+#define _IEEE80211_IF_LINK_W_FN(name)					\
+static ssize_t ieee80211_if_write_##name(struct file *file,		\
+					 const char __user *userbuf,	\
+					 size_t count, loff_t *ppos)	\
+{									\
+	return ieee80211_if_write_link(file->private_data, userbuf,	\
+				       count, ppos,			\
+				       ieee80211_if_parse_##name);	\
+}
+
 #define IEEE80211_IF_LINK_FILE_R(name)					\
-	_IEEE80211_IF_FILE_R_FN(name, struct ieee80211_link_data *)	\
+	_IEEE80211_IF_LINK_R_FN(name)					\
 	_IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, NULL)
 
 #define IEEE80211_IF_LINK_FILE_W(name)					\
-	_IEEE80211_IF_FILE_W_FN(name)					\
+	_IEEE80211_IF_LINK_W_FN(name)					\
 	_IEEE80211_IF_FILE_OPS(link_##name, NULL, ieee80211_if_write_##name)
 
 #define IEEE80211_IF_LINK_FILE_RW(name)					\
-	_IEEE80211_IF_FILE_R_FN(name, struct ieee80211_link_data *)	\
-	_IEEE80211_IF_FILE_W_FN(name, struct ieee80211_link_data *)	\
+	_IEEE80211_IF_LINK_R_FN(name)					\
+	_IEEE80211_IF_LINK_W_FN(name)					\
 	_IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name,	\
 			       ieee80211_if_write_##name)
 
-- 
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 ` Johannes Berg [this message]
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 ` [PATCH 05/40] wifi: cfg80211: add flush functions for wiphy work Johannes Berg
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.e3c99daad33e.Ic09414bfe7e6b523aca469e402877b3a85bc12af@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).