From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: Johannes Berg <johannes.berg@intel.com>
Cc: Alexandre Ferrieux <alexandre.ferrieux@gmail.com>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>,
<linux-wireless@vger.kernel.org>
Subject: [PATCH v1 wl-next 3/3] wifi: wext: Don't iterate all netns in wireless_nlevent_flush().
Date: Mon, 14 Oct 2024 13:55:43 -0700 [thread overview]
Message-ID: <20241014205543.94787-4-kuniyu@amazon.com> (raw)
In-Reply-To: <20241014205543.94787-1-kuniyu@amazon.com>
Commit 8bf862739a77 ("wext: fix message delay/ordering") introduced
wext_netdev_notifier_call() to avoid message delay and out-of-order.
The notifier calls wireless_nlevent_flush(), which iterates all netns.
The problem is that this happens for any event and netdev, even if
the host does not have a wext device.
This is too noisy, especially on a host with thousands of netns as
reported by Alexandre Ferrieux.
Given that the wext event queue was implemented in struct net,
wireless_nlevent_flush() does not need to iterate all netns.
Let's avoid unnecessary netns iteration in wireless_nlevent_flush().
Reported-by: Alexandre Ferrieux <alexandre.ferrieux@gmail.com>
Closes: https://lore.kernel.org/netdev/CAKYWH0Ti3=4GeeuVyWKJ9LyTuRnf3Wy9GKg4Jb7tdeaT39qADA@mail.gmail.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
include/net/iw_handler.h | 4 ++--
net/wireless/core.c | 2 +-
net/wireless/wext-core.c | 25 +++++++++++++------------
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/include/net/iw_handler.h b/include/net/iw_handler.h
index b80e474cb0aa..e6acff086d39 100644
--- a/include/net/iw_handler.h
+++ b/include/net/iw_handler.h
@@ -412,9 +412,9 @@ void wireless_send_event(struct net_device *dev, unsigned int cmd,
union iwreq_data *wrqu, const char *extra);
#ifdef CONFIG_WEXT_CORE
/* flush all previous wext events - if work is done from netdev notifiers */
-void wireless_nlevent_flush(void);
+void wireless_nlevent_flush(struct net *net);
#else
-static inline void wireless_nlevent_flush(void) {}
+static inline void wireless_nlevent_flush(struct net *net) {}
#endif
/* We may need a function to send a stream of events to user space.
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 4c8d8f167409..a864ec889de3 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -1629,7 +1629,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
return NOTIFY_DONE;
}
- wireless_nlevent_flush();
+ wireless_nlevent_flush(dev_net(dev));
return NOTIFY_OK;
}
diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
index 4d7699135f46..28033211c9e3 100644
--- a/net/wireless/wext-core.c
+++ b/net/wireless/wext-core.c
@@ -345,6 +345,7 @@ static const int compat_event_type_size[] = {
/* IW event code */
struct wext_net {
+ struct net *net;
struct sk_buff_head nlevents;
struct work_struct nlevent_work;
};
@@ -356,26 +357,22 @@ static struct wext_net *wext_net(struct net *net)
return net_generic(net, wext_net_id);
}
-void wireless_nlevent_flush(void)
+void wireless_nlevent_flush(struct net *net)
{
+ struct wext_net *wnet = wext_net(net);
struct sk_buff *skb;
- struct net *net;
- down_read(&net_rwsem);
- for_each_net(net) {
- struct wext_net *wnet = wext_net(net);
- while ((skb = skb_dequeue(&wnet->nlevents)))
- rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL,
- GFP_KERNEL);
- }
- up_read(&net_rwsem);
+ while ((skb = skb_dequeue(&wnet->nlevents)))
+ rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL);
}
EXPORT_SYMBOL_GPL(wireless_nlevent_flush);
static int wext_netdev_notifier_call(struct notifier_block *nb,
unsigned long state, void *ptr)
{
+ struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+
/*
* When a netdev changes state in any way, flush all pending messages
* to avoid them going out in a strange order, e.g. RTM_NEWLINK after
@@ -383,7 +380,7 @@ static int wext_netdev_notifier_call(struct notifier_block *nb,
* or similar - all of which could otherwise happen due to delays from
* schedule_work().
*/
- wireless_nlevent_flush();
+ wireless_nlevent_flush(dev_net(dev));
return NOTIFY_OK;
}
@@ -395,13 +392,17 @@ static struct notifier_block wext_netdev_notifier = {
/* Process events generated by the wireless layer or the driver. */
static void wireless_nlevent_process(struct work_struct *work)
{
- wireless_nlevent_flush();
+ struct wext_net *wnet;
+
+ wnet = container_of(work, struct wext_net, nlevent_work);
+ wireless_nlevent_flush(wnet->net);
}
static int __net_init wext_pernet_init(struct net *net)
{
struct wext_net *wnet = wext_net(net);
+ wnet->net = net;
skb_queue_head_init(&wnet->nlevents);
INIT_WORK(&wnet->nlevent_work, wireless_nlevent_process);
--
2.39.5 (Apple Git-154)
prev parent reply other threads:[~2024-10-14 20:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 20:55 [PATCH v1 wl-next 0/3] wifi: wext: Namespacify wireless_nlevent_flush() calls Kuniyuki Iwashima
2024-10-14 20:55 ` [PATCH v1 wl-next 1/3] wifi: wext: Move wext_nlevents to net->gen[] Kuniyuki Iwashima
2024-10-15 6:36 ` Johannes Berg
2024-10-16 0:49 ` Kuniyuki Iwashima
2024-10-16 8:56 ` Johannes Berg
2024-10-16 23:58 ` Kuniyuki Iwashima
2024-10-17 8:06 ` Johannes Berg
2024-10-14 20:55 ` [PATCH v1 wl-next 2/3] wifi: wext: Convert wireless_nlevent_work to per-netns work Kuniyuki Iwashima
2024-10-14 20:55 ` Kuniyuki Iwashima [this message]
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=20241014205543.94787-4-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=alexandre.ferrieux@gmail.com \
--cc=johannes.berg@intel.com \
--cc=kuni1840@gmail.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