netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kirill Tkhai <tkhai@ya.ru>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: tkhai@ya.ru
Subject: [PATCH NET-PREV 35/51] cfg80211: Use fallback_nd_lock for registered devices
Date: Sat, 22 Mar 2025 17:42:14 +0300	[thread overview]
Message-ID: <174265453410.356712.9874476765501764676.stgit@pro.pro> (raw)
In-Reply-To: <174265415457.356712.10472727127735290090.stgit@pro.pro>

For now we use fallback_nd_lock for all drivers registering
via cfg80211_register_netdevice().

One of the reasons is that they are used as a bunch
in cfg80211_switch_netns(), while we want to call
dev_change_net_namespace() under nd_lock in one of
next patches.

Signed-off-by: Kirill Tkhai <tkhai@ya.ru>
---
 drivers/net/wireless/ath/ath6kl/core.c        |    2 ++
 drivers/net/wireless/ath/wil6210/netdev.c     |    2 ++
 drivers/net/wireless/marvell/mwifiex/main.c   |    5 +++++
 drivers/net/wireless/quantenna/qtnfmac/core.c |    2 ++
 net/mac80211/main.c                           |    2 ++
 net/wireless/core.c                           |   10 ++++++++--
 net/wireless/nl80211.c                        |   14 ++++++++++++++
 7 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath6kl/core.c b/drivers/net/wireless/ath/ath6kl/core.c
index 4f0a7a185fc9..8c28f5a476ef 100644
--- a/drivers/net/wireless/ath/ath6kl/core.c
+++ b/drivers/net/wireless/ath/ath6kl/core.c
@@ -212,6 +212,7 @@ int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
 		ar->avail_idx_map |= BIT(i);
 
 	rtnl_lock();
+	mutex_lock(&fallback_nd_lock.mutex);
 	wiphy_lock(ar->wiphy);
 
 	/* Add an initial station interface */
@@ -219,6 +220,7 @@ int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
 				    NL80211_IFTYPE_STATION, 0, INFRA_NETWORK);
 
 	wiphy_unlock(ar->wiphy);
+	mutex_unlock(&fallback_nd_lock.mutex);
 	rtnl_unlock();
 
 	if (!wdev) {
diff --git a/drivers/net/wireless/ath/wil6210/netdev.c b/drivers/net/wireless/ath/wil6210/netdev.c
index d5d364683c0e..57958b44717d 100644
--- a/drivers/net/wireless/ath/wil6210/netdev.c
+++ b/drivers/net/wireless/ath/wil6210/netdev.c
@@ -474,9 +474,11 @@ int wil_if_add(struct wil6210_priv *wil)
 	wil_update_net_queues_bh(wil, vif, NULL, true);
 
 	rtnl_lock();
+	mutex_lock(&fallback_nd_lock.mutex);
 	wiphy_lock(wiphy);
 	rc = wil_vif_add(wil, vif);
 	wiphy_unlock(wiphy);
+	mutex_unlock(&fallback_nd_lock.mutex);
 	rtnl_unlock();
 	if (rc < 0)
 		goto free_dummy;
diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wireless/marvell/mwifiex/main.c
index 96d1f6039fbc..c4b112d2f0b2 100644
--- a/drivers/net/wireless/marvell/mwifiex/main.c
+++ b/drivers/net/wireless/marvell/mwifiex/main.c
@@ -623,6 +623,7 @@ static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
 	}
 
 	rtnl_lock();
+	mutex_lock(&fallback_nd_lock.mutex);
 	wiphy_lock(adapter->wiphy);
 	/* Create station interface by default */
 	wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", NET_NAME_ENUM,
@@ -631,6 +632,7 @@ static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
 		mwifiex_dbg(adapter, ERROR,
 			    "cannot create default STA interface\n");
 		wiphy_unlock(adapter->wiphy);
+		mutex_unlock(&fallback_nd_lock.mutex);
 		rtnl_unlock();
 		goto err_add_intf;
 	}
@@ -642,6 +644,7 @@ static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
 			mwifiex_dbg(adapter, ERROR,
 				    "cannot create AP interface\n");
 			wiphy_unlock(adapter->wiphy);
+			mutex_unlock(&fallback_nd_lock.mutex);
 			rtnl_unlock();
 			goto err_add_intf;
 		}
@@ -654,11 +657,13 @@ static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
 			mwifiex_dbg(adapter, ERROR,
 				    "cannot create p2p client interface\n");
 			wiphy_unlock(adapter->wiphy);
+			mutex_unlock(&fallback_nd_lock.mutex);
 			rtnl_unlock();
 			goto err_add_intf;
 		}
 	}
 	wiphy_unlock(adapter->wiphy);
+	mutex_unlock(&fallback_nd_lock.mutex);
 	rtnl_unlock();
 
 	mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
diff --git a/drivers/net/wireless/quantenna/qtnfmac/core.c b/drivers/net/wireless/quantenna/qtnfmac/core.c
index 825b05dd3271..7952e3314aca 100644
--- a/drivers/net/wireless/quantenna/qtnfmac/core.c
+++ b/drivers/net/wireless/quantenna/qtnfmac/core.c
@@ -597,9 +597,11 @@ static int qtnf_core_mac_attach(struct qtnf_bus *bus, unsigned int macid)
 	mac->wiphy_registered = 1;
 
 	rtnl_lock();
+	mutex_lock(&fallback_nd_lock.mutex);
 	wiphy_lock(priv_to_wiphy(mac));
 	ret = qtnf_core_net_attach(mac, vif, "wlan%d", NET_NAME_ENUM);
 	wiphy_unlock(priv_to_wiphy(mac));
+	mutex_unlock(&fallback_nd_lock.mutex);
 	rtnl_unlock();
 
 	if (ret) {
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index a3104b6ea6f0..bacea2473a21 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -1582,6 +1582,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
 	ieee80211_check_wbrf_support(local);
 
 	rtnl_lock();
+	mutex_lock(&fallback_nd_lock.mutex);
 	wiphy_lock(hw->wiphy);
 
 	/* add one default STA interface if supported */
@@ -1597,6 +1598,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
 	}
 
 	wiphy_unlock(hw->wiphy);
+	mutex_unlock(&fallback_nd_lock.mutex);
 	rtnl_unlock();
 
 #ifdef CONFIG_INET
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 4d5d351bd0b5..8ba0ada86678 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -1439,7 +1439,11 @@ int cfg80211_register_netdevice(struct net_device *dev)
 	/* we'll take care of this */
 	wdev->registered = true;
 	wdev->registering = true;
-	ret = register_netdevice(dev);
+
+	if (!mutex_is_locked(&fallback_nd_lock.mutex))
+		return -EXDEV;
+	attach_nd_lock(dev, &fallback_nd_lock);
+	ret = __register_netdevice(dev);
 	if (ret)
 		goto out;
 
@@ -1447,8 +1451,10 @@ int cfg80211_register_netdevice(struct net_device *dev)
 	ret = 0;
 out:
 	wdev->registering = false;
-	if (ret)
+	if (ret) {
+		detach_nd_lock(dev);
 		wdev->registered = false;
+	}
 	return ret;
 }
 EXPORT_SYMBOL(cfg80211_register_netdevice);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 7397a372c78e..0fd66f75eace 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -16455,6 +16455,7 @@ nl80211_set_ttlm(struct sk_buff *skb, struct genl_info *info)
 #define NL80211_FLAG_NO_WIPHY_MTX	0x40
 #define NL80211_FLAG_MLO_VALID_LINK_ID	0x80
 #define NL80211_FLAG_MLO_UNSUPPORTED	0x100
+#define NL80211_FLAG_NEED_FALLBACK_ND_LOCK	0x200
 
 #define INTERNAL_FLAG_SELECTORS(__sel)			\
 	SELECTOR(__sel, NONE, 0) /* must be first */	\
@@ -16477,6 +16478,11 @@ nl80211_set_ttlm(struct sk_buff *skb, struct genl_info *info)
 		 NL80211_FLAG_NEED_WIPHY |		\
 		 NL80211_FLAG_NEED_RTNL |		\
 		 NL80211_FLAG_NO_WIPHY_MTX)		\
+	SELECTOR(__sel, WIPHY_RTNL_ND_LOCK,		\
+		 NL80211_FLAG_NEED_WIPHY |		\
+		 NL80211_FLAG_NEED_FALLBACK_ND_LOCK |	\
+		 NL80211_FLAG_NEED_RTNL |		\
+		 NL80211_FLAG_NO_WIPHY_MTX)		\
 	SELECTOR(__sel, WDEV_RTNL,			\
 		 NL80211_FLAG_NEED_WDEV |		\
 		 NL80211_FLAG_NEED_RTNL)		\
@@ -16545,6 +16551,7 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops,
 	internal_flags = nl80211_internal_flags[ops->internal_flags];
 
 	rtnl_lock();
+	mutex_lock(&fallback_nd_lock.mutex);
 	if (internal_flags & NL80211_FLAG_NEED_WIPHY) {
 		rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
 		if (IS_ERR(rdev)) {
@@ -16621,11 +16628,15 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops,
 		/* we keep the mutex locked until post_doit */
 		__release(&rdev->wiphy.mtx);
 	}
+
+	if (!(internal_flags & NL80211_FLAG_NEED_FALLBACK_ND_LOCK))
+		mutex_unlock(&fallback_nd_lock.mutex);
 	if (!(internal_flags & NL80211_FLAG_NEED_RTNL))
 		rtnl_unlock();
 
 	return 0;
 out_unlock:
+	mutex_unlock(&fallback_nd_lock.mutex);
 	rtnl_unlock();
 	dev_put(dev);
 	return err;
@@ -16656,6 +16667,8 @@ static void nl80211_post_doit(const struct genl_split_ops *ops,
 		wiphy_unlock(&rdev->wiphy);
 	}
 
+	if (internal_flags & NL80211_FLAG_NEED_FALLBACK_ND_LOCK)
+		mutex_unlock(&fallback_nd_lock.mutex);
 	if (internal_flags & NL80211_FLAG_NEED_RTNL)
 		rtnl_unlock();
 
@@ -16821,6 +16834,7 @@ static const struct genl_small_ops nl80211_small_ops[] = {
 		.flags = GENL_UNS_ADMIN_PERM,
 		.internal_flags =
 			IFLAGS(NL80211_FLAG_NEED_WIPHY |
+			       NL80211_FLAG_NEED_FALLBACK_ND_LOCK |
 			       NL80211_FLAG_NEED_RTNL |
 			       /* we take the wiphy mutex later ourselves */
 			       NL80211_FLAG_NO_WIPHY_MTX),


  parent reply	other threads:[~2025-03-22 14:42 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-22 14:37 [PATCH NET-PREV 00/51] Kill rtnl_lock using fine-grained nd_lock Kirill Tkhai
2025-03-22 14:37 ` [PATCH NET-PREV 01/51] net: Move some checks from __rtnl_newlink() to caller Kirill Tkhai
2025-03-22 14:38 ` [PATCH NET-PREV 02/51] net: Add nlaattr check to rtnl_link_get_net_capable() Kirill Tkhai
2025-03-22 14:38 ` [PATCH NET-PREV 03/51] net: do_setlink() refactoring: move target_net acquiring to callers Kirill Tkhai
2025-03-22 14:38 ` [PATCH NET-PREV 04/51] net: Extract some code from __rtnl_newlink() to separate func Kirill Tkhai
2025-03-22 14:38 ` [PATCH NET-PREV 05/51] net: Move dereference of tb[IFLA_MASTER] up Kirill Tkhai
2025-03-22 14:38 ` [PATCH NET-PREV 06/51] net: Use unregister_netdevice_many() for both error cases in rtnl_newlink_create() Kirill Tkhai
2025-03-22 14:38 ` [PATCH NET-PREV 07/51] net: Introduce nd_lock and primitives to work with it Kirill Tkhai
2025-03-22 14:38 ` [PATCH NET-PREV 08/51] net: Initially attaching and detaching nd_lock Kirill Tkhai
2025-03-22 14:39 ` [PATCH NET-PREV 09/51] net: Use register_netdevice() in loopback() Kirill Tkhai
2025-03-22 14:39 ` [PATCH NET-PREV 10/51] net: Underline newlink and changelink dependencies Kirill Tkhai
2025-03-22 14:39 ` [PATCH NET-PREV 11/51] net: Make master and slaves (any dependent devices) share the same nd_lock in .setlink etc Kirill Tkhai
2025-03-22 14:39 ` [PATCH NET-PREV 12/51] net: Use __register_netdevice in trivial .newlink cases Kirill Tkhai
2025-03-22 14:39 ` [PATCH NET-PREV 13/51] infiniband_ipoib: Use __register_netdevice in .newlink Kirill Tkhai
2025-03-22 14:39 ` [PATCH NET-PREV 14/51] vxcan: " Kirill Tkhai
2025-03-22 14:39 ` [PATCH NET-PREV 15/51] iavf: Use __register_netdevice() Kirill Tkhai
2025-03-22 14:39 ` [PATCH NET-PREV 16/51] geneve: Use __register_netdevice in .newlink Kirill Tkhai
2025-03-22 14:40 ` [PATCH NET-PREV 17/51] netkit: " Kirill Tkhai
2025-03-22 14:40 ` [PATCH NET-PREV 18/51] qmi_wwan: " Kirill Tkhai
2025-03-22 14:40 ` [PATCH NET-PREV 19/51] bpqether: Provide determined context in __register_netdevice() Kirill Tkhai
2025-03-22 14:40 ` [PATCH NET-PREV 20/51] ppp: Use __register_netdevice in .newlink Kirill Tkhai
2025-03-22 14:40 ` [PATCH NET-PREV 21/51] veth: " Kirill Tkhai
2025-03-22 14:40 ` [PATCH NET-PREV 22/51] vxlan: " Kirill Tkhai
2025-03-22 14:40 ` [PATCH NET-PREV 23/51] hdlc_fr: Use __register_netdevice Kirill Tkhai
2025-03-22 14:40 ` [PATCH NET-PREV 24/51] lapbeth: Provide determined context in __register_netdevice() Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 25/51] wwan: Use __register_netdevice in .newlink Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 26/51] 6lowpan: " Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 27/51] vlan: " Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 28/51] dsa: Use __register_netdevice() Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 29/51] ip6gre: Use __register_netdevice() in .changelink Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 30/51] ip6_tunnel: Use __register_netdevice() in .newlink and .changelink Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 31/51] ip6_vti: " Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 32/51] ip6_sit: " Kirill Tkhai
2025-03-22 14:41 ` [PATCH NET-PREV 33/51] net: Now check nobody calls register_netdevice() with nd_lock attached Kirill Tkhai
2025-03-22 14:42 ` [PATCH NET-PREV 34/51] dsa: Make all switch tree ports relate to same nd_lock Kirill Tkhai
2025-03-22 14:42 ` Kirill Tkhai [this message]
2025-03-22 14:42 ` [PATCH NET-PREV 36/51] ieee802154: Use fallback_nd_lock for registered devices Kirill Tkhai
2025-03-22 14:42 ` [PATCH NET-PREV 37/51] net: Introduce delayed event work Kirill Tkhai
2025-03-22 14:42 ` [PATCH NET-PREV 38/51] failover: Link master and slave under nd_lock Kirill Tkhai
2025-03-22 14:42 ` [PATCH NET-PREV 39/51] netvsc: Make joined device to share master's nd_lock Kirill Tkhai
2025-03-22 14:42 ` [PATCH NET-PREV 40/51] openvswitch: Make ports share nd_lock of master device Kirill Tkhai
2025-03-22 14:42 ` [PATCH NET-PREV 41/51] bridge: Make port to have the same nd_lock as bridge Kirill Tkhai
2025-03-22 14:43 ` [PATCH NET-PREV 42/51] bond: Make master and slave relate to the same nd_lock Kirill Tkhai
2025-03-22 14:43 ` [PATCH NET-PREV 43/51] net: Now check nobody calls netdev_master_upper_dev_link() without nd_lock attached Kirill Tkhai
2025-03-22 14:43 ` [PATCH NET-PREV 44/51] net: Call dellink with nd_lock is held Kirill Tkhai
2025-03-22 14:43 ` [PATCH NET-PREV 45/51] t7xx: Use __unregister_netdevice() Kirill Tkhai
2025-03-22 14:43 ` [PATCH NET-PREV 46/51] 6lowpan: " Kirill Tkhai
2025-03-22 14:43 ` [PATCH NET-PREV 47/51] netvsc: Call dev_change_net_namespace() under nd_lock Kirill Tkhai
2025-03-22 14:43 ` [PATCH NET-PREV 48/51] default_device: " Kirill Tkhai
2025-03-22 14:43 ` [PATCH NET-PREV 49/51] ieee802154: " Kirill Tkhai
2025-03-22 14:44 ` [PATCH NET-PREV 50/51] cfg80211: " Kirill Tkhai
2025-03-22 14:44 ` [PATCH NET-PREV 51/51] net: Make all NETDEV_REGISTER events to be called " Kirill Tkhai
2025-03-24  2:51 ` [PATCH NET-PREV 00/51] Kill rtnl_lock using fine-grained nd_lock Stanislav Fomichev
2025-03-25 11:15 ` Jakub Kicinski

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=174265453410.356712.9874476765501764676.stgit@pro.pro \
    --to=tkhai@ya.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@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).