RFC: Should net namespaces scale up (>10k) ?
(thanks Simon, reposting with another account to avoid the offending disclaimer)
Hi,
Currently, netns don't really scale beyond a few thousands, for mundane reasons (see below). But should they ? Is there, in the design, an assumption that tens of thousands of network namespaces are considered "unreasonable" ?
A typical use case for such ridiculous numbers is a tester for firewalls or carrier-grade NATs. In these, you typically want tens of thousands of tunnels, each of which is perfectly instantiated as an interface. And, to avoid an explosion in source routing rules, you want them in separate namespaces.
Now why don't they scale *today* ? For two independent, seemingly accidental, O(N) scans of the netns list.
1. The "netdevice notifier" from the Wireless Extensions subsystem insists on scanning the whole list regardless of the nature of the change, nor wondering whether all these namespaces hold any wireless interface, nor even whether the system has _any_ wireless hardware...
for_each_net(net) {
while ((skb = skb_dequeue(&net->wext_nlevents)))
rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL,
GFP_KERNEL);
}2. When moving an interface (eg an IPVLAN slave) to another netns, __dev_change_net_namespace() calls peernet2id_alloc() in order to get an ID for the target namespace. This again incurs a full scan of the netns list:
int id = idr_for_each(&net->netns_ids, net_eq_idr, peer);
Note that, while IDR is very fast when going from ID to pointer, the reverse path is awfully slow... But why are IDs needed in the first place, instead of the simple netns pointers ?
Any insight on the (possibly very good) reasons those two apparent warts stand in the way of netns scaling up ?
-Alex
Quoted 29 lines · Alexandre Ferrieux
(thanks Simon, reposting with another account to avoid the offending disclaimer)
Hi,
Currently, netns don't really scale beyond a few thousands, for mundane reasons (see below). But should they ? Is there, in the design, an assumption that tens of thousands of network namespaces are considered "unreasonable" ?
A typical use case for such ridiculous numbers is a tester for firewalls or carrier-grade NATs. In these, you typically want tens of thousands of tunnels, each of which is perfectly instantiated as an interface. And, to avoid an explosion in source routing rules, you want them in separate namespaces.
Now why don't they scale *today* ? For two independent, seemingly accidental, O(N) scans of the netns list.
1. The "netdevice notifier" from the Wireless Extensions subsystem insists on scanning the whole list regardless of the nature of the change, nor wondering whether all these namespaces hold any wireless interface, nor even whether the system has _any_ wireless hardware...
for_each_net(net) { while ((skb = skb_dequeue(&net->wext_nlevents))) rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL); }
Quoted 6 lines
2. When moving an interface (eg an IPVLAN slave) to another netns,
__dev_change_net_namespace()callspeernet2id_alloc()in order to get an ID for the target namespace. This again incurs a full scan of the netns list:int id = idr_for_each(&net->netns_ids, net_eq_idr, peer);
this piece is inside of __peernet2id(), which is called in for_each_net loop, making it O(n^2):
548│ for_each_net(tmp) {
549│ int id;
550│
551│ spin_lock_bh(&tmp->nsid_lock);
552│ id = __peernet2id(tmp, net);Quoted 10 lines
Note that, while IDR is very fast when going from ID to pointer, the reverse path is awfully slow... But why are IDs needed in the first place, instead of the simple netns pointers ?
Any insight on the (possibly very good) reasons those two apparent warts stand in the way of netns scaling up ?
-Alex
I guess that the reason is more pragmatic, net namespaces are decade older than xarray, thus list-based implementation.
Simon Horman
reviewerQuoted 51 lines · Przemek Kitszel
Quoted 29 lines · Alexandre Ferrieux
(thanks Simon, reposting with another account to avoid the offending disclaimer)
Hi,
Currently, netns don't really scale beyond a few thousands, for mundane reasons (see below). But should they ? Is there, in the design, an assumption that tens of thousands of network namespaces are considered "unreasonable" ?
A typical use case for such ridiculous numbers is a tester for firewalls or carrier-grade NATs. In these, you typically want tens of thousands of tunnels, each of which is perfectly instantiated as an interface. And, to avoid an explosion in source routing rules, you want them in separate namespaces.
Now why don't they scale *today* ? For two independent, seemingly accidental, O(N) scans of the netns list.
1. The "netdevice notifier" from the Wireless Extensions subsystem insists on scanning the whole list regardless of the nature of the change, nor wondering whether all these namespaces hold any wireless interface, nor even whether the system has _any_ wireless hardware...
for_each_net(net) { while ((skb = skb_dequeue(&net->wext_nlevents))) rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL); }Quoted 6 lines
2. When moving an interface (eg an IPVLAN slave) to another netns,
__dev_change_net_namespace()callspeernet2id_alloc()in order to get an ID for the target namespace. This again incurs a full scan of the netns list:int id = idr_for_each(&net->netns_ids, net_eq_idr, peer);this piece is inside of
__peernet2id(), which is called infor_each_netloop, making it O(n^2):548│ for_each_net(tmp) { 549│ int id; 550│ 551│ spin_lock_bh(&tmp->nsid_lock); 552│ id = __peernet2id(tmp, net);Quoted 5 lines
Note that, while IDR is very fast when going from ID to pointer, the reverse path is awfully slow... But why are IDs needed in the first place, instead of the simple netns pointers ?
Quoted 8 lines
Quoted 5 lines
Any insight on the (possibly very good) reasons those two apparent warts stand in the way of netns scaling up ?
-Alex
I guess that the reason is more pragmatic, net namespaces are decade older than xarray, thus list-based implementation.
Yes, I would also guess that the reason is not that these limitations were part of the design. But just that the implementation scaled sufficiently at the time. And that if further scale is required, then the implementation can be updated.
Quoted 11 lines · Simon Horman
Quoted 6 lines
Quoted 3 lines
Any insight on the (possibly very good) reasons those two apparent warts stand in the way of netns scaling up ?
I guess that the reason is more pragmatic, net namespaces are decade older than xarray, thus list-based implementation.
Yes, I would also guess that the reason is not that these limitations were part of the design. But just that the implementation scaled sufficiently at the time. And that if further scale is required, then the implementation can be updated.
Okay, thank you for confirming my fears :}
Now, what shall we do:
1. Ignore this corner case and carve the "few netns" assumption in stone;
2. Migrate netns IDs to xarrays (not to mention other leftover uses of IDR).
Note that this funny workload of mine is a typical situation where the "DPDK beats Linux" myth gets reinforced. I find this pretty disappointing, as it implies reinventing the whole network stack in userspace. All the more so, as the other typical case for DPDK is now moot thanks to XDP.
What do you think ?
Quoted 18 lines · Alexandre Ferrieux
Quoted 11 lines · Simon Horman
Quoted 6 lines
Quoted 3 lines
Any insight on the (possibly very good) reasons those two apparent warts stand in the way of netns scaling up ?
I guess that the reason is more pragmatic, net namespaces are decade older than xarray, thus list-based implementation.
Yes, I would also guess that the reason is not that these limitations were part of the design. But just that the implementation scaled sufficiently at the time. And that if further scale is required, then the implementation can be updated.
Okay, thank you for confirming my fears :}
Now, what shall we do:1. Ignore this corner case and carve the "few netns" assumption in stone;
Quoted 8 lines
2. Migrate netns IDs to xarrays (not to mention other leftover uses of IDR).
Note that this funny workload of mine is a typical situation where the "DPDK beats Linux" myth gets reinforced. I find this pretty disappointing, as it implies reinventing the whole network stack in userspace. All the more so, as the other typical case for DPDK is now moot thanks to XDP.
What do you think ?
I would describe (here) more what is this typical scenario where users bother to set up DPDK for perf gains.
With that I think that is a legitimate reason to rewrite parts of netns, if only to allow companies to shuffle engineers out from DPDK-support teams into upstream-related ones :) [in the long term ofc]
Quoted 12 lines · Przemek Kitszel
Quoted 11 lines · Alexandre Ferrieux
Now, what shall we do:
1. Ignore this corner case and carve the "few netns" assumption in stone;
2. Migrate netns IDs to xarrays (not to mention other leftover uses of IDR).
Note that this funny workload of mine is a typical situation where the "DPDK beats Linux" myth gets reinforced. I find this pretty disappointing, as it implies reinventing the whole network stack in userspace. All the more so, as the other typical case for DPDK is now moot thanks to XDP.
Quoted 4 lines
Quoted 1 line
What do you think ?
I would describe (here) more what is this typical scenario where users bother to set up DPDK for perf gains.
Two cases from my experience:
(1) "Bump-in-the-wire" rx/tx on same port, trying to reach line-rate on one or several 100Gbps interfaces. On this one, Linux performs beautifully, with "no fat", just use XDP (verdict XDP_TX) along with some packet tweaking in a kfunc. Of course you need to get queue number, coalescence, IRQ and NUMA right. And you need a well-written native-XDP mode in the driver (not all NICs have one). Here, the "DPDK advantage" is a lie.
(2) "Many-tunnels" as in my CGNAT tester case. Due to the limitations we are talking about, people are right (so far) to turn to DPDK, as they do for example in TRex https://trex-tgn.cisco.com/ .
Quoted 3 lines
With that I think that is a legitimate reason to rewrite parts of netns, if only to allow companies to shuffle engineers out from DPDK-support teams into upstream-related ones :) [in the long term ofc]
I violently agree :)
Quoted 19 lines · Alexandre Ferrieux
Quoted 11 lines · Simon Horman
Quoted 6 lines
Quoted 3 lines
Any insight on the (possibly very good) reasons those two apparent warts stand in the way of netns scaling up ?
I guess that the reason is more pragmatic, net namespaces are decade older than xarray, thus list-based implementation.
Yes, I would also guess that the reason is not that these limitations were part of the design. But just that the implementation scaled sufficiently at the time. And that if further scale is required, then the implementation can be updated.
Okay, thank you for confirming my fears :}
Now, what shall we do:1. Ignore this corner case and carve the "few netns" assumption in stone;
Quoted 8 lines
2. Migrate netns IDs to xarrays (not to mention other leftover uses of IDR).
Note that this funny workload of mine is a typical situation where the "DPDK beats Linux" myth gets reinforced. I find this pretty disappointing, as it implies reinventing the whole network stack in userspace. All the more so, as the other typical case for DPDK is now moot thanks to XDP.
What do you think ?
I do not see any blocker for making things more scalable.
It is only a matter of time and interest. I think that 99.99 % of linux hosts around the world
have less than 10 netns.
RTNL removal is a little bit harder (and we hit RTNL contention even with less than 10 netns around)
Le 17/09/2024 à 08:59, Eric Dumazet a écrit :
[snip]
Quoted 2 lines
I do not see any blocker for making things more scalable.
+1
Quoted 4 lines
It is only a matter of time and interest. I think that 99.99 % of linux hosts around the world
have less than 10 netns.
I agree. My target was 4k netns at the time I pushed these ids.
Quoted 3 lines
RTNL removal is a little bit harder (and we hit RTNL contention even with less than 10 netns around)
+1
Massive hash collisions on FIB
In reply to Eric DumazetQuoted 11 lines · Eric Dumazet
Quoted 2 lines
What do you think ?
I do not see any blocker for making things more scalable.
It is only a matter of time and interest. I think that 99.99 % of linux hosts around the world
have less than 10 netns.RTNL removal is a little bit harder (and we hit RTNL contention even with less than 10 netns around)
Given this encouragement, I'm proceeding towards the the "million-tunnel baby". And knowing where the current road bumps are, workarounds are possible: instead of a direct 1M fanout of (netns+interface), I'm doing 10k netns with 100 interfaces each, which works like a charm.
But doing this I met an entirely new kind of bottleneck: the single FIB hashtable, shared by all netns, lends itself to massive collision if many netns contain the same local address.
Indeed, in this situation, the fib_inetaddr_notifier ends up inserting a local route for the address, and the only "moving part" in the hash input is the address itself.
As an example, after creating 7000 veth pairs and moving their "right half" to 7000 namespaces, an "ip addr add 192.168.1.2/32 dev $D" on one of them hits a bucket of depth 7000.
To solve this, I'd naively inject a few bits of entropy from the netns itself (inode number, middle bits of (struct net *) address, etc.), by XORing them to the hash value. Unless I'm mistaken, the netns is always unambiguous when a FIB decision is made, be it for a packet or for some interface configuration task.
Would that be acceptable ?
Re: Massive hash collisions on FIB
Quoted 23 lines · Alexandre Ferrieux
Quoted 11 lines · Eric Dumazet
Quoted 2 lines
What do you think ?
I do not see any blocker for making things more scalable.
It is only a matter of time and interest. I think that 99.99 % of linux hosts around the world
have less than 10 netns.RTNL removal is a little bit harder (and we hit RTNL contention even with less than 10 netns around)
Given this encouragement, I'm proceeding towards the the "million-tunnel baby". And knowing where the current road bumps are, workarounds are possible: instead of a direct 1M fanout of (netns+interface), I'm doing 10k netns with 100 interfaces each, which works like a charm.
But doing this I met an entirely new kind of bottleneck: the single FIB hashtable, shared by all netns, lends itself to massive collision if many netns contain the same local address.
Quoted 7 lines
Indeed, in this situation, the
fib_inetaddr_notifierends up inserting a local route for the address, and the only "moving part" in the hash input is the address itself.As an example, after creating 7000 veth pairs and moving their "right half" to 7000 namespaces, an "ip addr add 192.168.1.2/32 dev $D" on one of them hits a bucket of depth 7000.
Shocking
Quoted 7 lines
To solve this, I'd naively inject a few bits of entropy from the netns itself (inode number, middle bits of (struct net *) address, etc.), by XORing them to the hash value. Unless I'm mistaken, the netns is always unambiguous when a FIB decision is made, be it for a packet or for some interface configuration task.
Would that be acceptable ?
Sure, but please use the standard way : net_hash_mix(net)
Re: Massive hash collisions on FIB
Quoted 7 lines · Eric Dumazet
Quoted 4 lines
[...] the single FIB
hashtable, shared by all netns, lends itself to massive collision if many netns contain the same local address.Shocking
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
To solve this, I'd naively inject a few bits of entropy from the netns itself (inode number, middle bits of (struct net *) address, etc.), by XORing them to the hash value. Unless I'm mistaken, the netns is always unambiguous when a FIB decision is made, be it for a packet or for some interface configuration task.
Would that be acceptable ?
Sure, but please use the standard way :
net_hash_mix(net)
I see you did the work for the two other hashes (laddr and devindex). I tried to inject the dispersion the same way as you did, just before the final scrambling. Is this what you'd do ?
net/ipv4/fib_semantics.c +0 -0
@@ -347,10 +347,12 @@ static unsigned int fib_info_hashfn_1(int init_val, u8
protocol, u8 scope,
return val;
}
-static unsigned int fib_info_hashfn_result(unsigned int val) +static unsigned int fib_info_hashfn_result(struct net *net, unsigned int val)
{
unsigned int mask = (fib_info_hash_size - 1);+ val ^= net_hash_mix(net);
+
return (val ^ (val >> 7) ^ (val >> 12)) & mask;
}
@@ -370,7 +372,7 @@ static inline unsigned int fib_info_hashfn(struct fib_info *fi)
} endfor_nexthops(fi)
}- return fib_info_hashfn_result(val);
+ return fib_info_hashfn_result(fi->fib_net, val);
}
/* no metrics, only nexthop id */
@@ -385,7 +387,7 @@ static struct fib_info *fib_find_info_nh(struct net *net,
cfg->fc_protocol, cfg->fc_scope,
(__force u32)cfg->fc_prefsrc,
cfg->fc_priority);
- hash = fib_info_hashfn_result(hash);
+ hash = fib_info_hashfn_result(net, hash);
head = &fib_info_hash[hash];
hlist_for_each_entry(fi, head, fib_hash) {Re: Massive hash collisions on FIB
net/ipv4/fib_semantics.c
Quoted 6 lines · Alexandre Ferrieux
I see you did the work for the two other hashes (laddr and devindex). I tried to inject the dispersion the same way as you did, just before the final scrambling. Is this what you'd do ?
net/ipv4/fib_semantics.c +0
-0
Doing this, I discovered with surprise that the job was already done in IPv6, as inet6_addr_hash() uses net_hash_mix() too. Which leads to the question: why are the IPv4 and IPv6 FIB-exact-lookup implementations different/duplicated ?
Re: Massive hash collisions on FIB
Quoted 11 lines · Alexandre Ferrieux
net/ipv4/fib_semantics.c
Quoted 6 lines · Alexandre Ferrieux
I see you did the work for the two other hashes (laddr and devindex). I tried to inject the dispersion the same way as you did, just before the final scrambling. Is this what you'd do ?
net/ipv4/fib_semantics.c +0
-0Doing this, I discovered with surprise that the job was already done in IPv6, as
inet6_addr_hash()usesnet_hash_mix()too. Which leads to the question: why are the IPv4 and IPv6 FIB-exact-lookup implementations different/duplicated ?
inet_addr_hash() is also using net_hash_mix()
fib_info_laddrhash_bucket() is also using net_hash_mix()
You know we make these kinds of changes whenever they are needed for our workload.
For example
d07418afea8f1d9896aaf9dc5ae47ac4f45b220c ipv4: avoid quadratic behavior in netns dismantle
Just submit a patch, stop wondering why it was not already done.
Re: Massive hash collisions on FIB
Quoted 9 lines · Eric Dumazet
On Wed, Sep 25, 2024 at 9:06 PM Alexandre Ferrieux
Quoted 2 lines
[...] why are
the IPv4 and IPv6 FIB-exact-lookup implementations different/duplicated ?You know we make these kinds of changes whenever they are needed for our workload.
Just submit a patch, stop wondering why it was not already done.
Sure, will do shortly.
However, I was not wondering about the history behind net_hash_mix(), but more generally why there are two parallel implementations of FIB insertion.
Re: Massive hash collisions on FIB
Quoted 10 lines · Alexandre Ferrieux
Quoted 8 lines · Eric Dumazet
On Wed, Sep 25, 2024 at 9:06 PM Alexandre Ferrieux
Quoted 2 lines
[...] why are
the IPv4 and IPv6 FIB-exact-lookup implementations different/duplicated ?You know we make these kinds of changes whenever they are needed for our workload.
Quoted 6 lines
Quoted 1 line
Just submit a patch, stop wondering why it was not already done.
Sure, will do shortly.
However, I was not wondering about the history behind
net_hash_mix(), but more generally why there are two parallel implementations of FIB insertion.
ipv6 has been done after ipv4, and by different contributors.
BTW, inet6_addr_hash() does not really need the net_hash_mix() because ipv6 uses a per-netns hashtable (net->ipv6.inet6_addr_lst[]), with pros and cons (vs IPv4 resizable hashtable)
Re: Massive hash collisions on FIB
Quoted 7 lines · Eric Dumazet
On Wed, Sep 25, 2024 at 9:46 PM Alexandre Ferrieux
Quoted 4 lines
[...] I was not wondering about the history behind
net_hash_mix(), but more generally why there are two parallel implementations of FIB insertion.ipv6 has been done after ipv4, and by different contributors.
Okay :}
Quoted 3 lines
BTW,
inet6_addr_hash()does not really need thenet_hash_mix()because ipv6 uses a per-netns hashtable (net->ipv6.inet6_addr_lst[]), with pros and cons (vs IPv4 resizable hashtable)
Interesting. I somehow felt that the system-wide IPv4 resizable table was a good idea in terms of scaling, as it amortizes the necessary overheads in the case of many-netns (though it is monotonic: grows but never shrinks !)... But now I
wonder: why is it a good idea for v4 and not for v6 ?
Quoted 9 lines · Przemek Kitszel
Quoted 7 lines · Alexandre Ferrieux
2. When moving an interface (eg an IPVLAN slave) to another netns,
__dev_change_net_namespace()callspeernet2id_alloc()in order to get an ID for the target namespace. This again incurs a full scan of the netns list:int id =
idr_for_each(&net->netns_ids, net_eq_idr, peer);
Quoted 8 lines
this piece is inside of
__peernet2id(), which is called infor_each_netloop, making it O(n^2):548│ for_each_net(tmp) { 549│ int id; 550│ 551│ spin_lock_bh(&tmp->nsid_lock); 552│ id = __peernet2id(tmp, net);
You're right, though that happens only within unhash_nsid(), which is called when deleting an nsnet.
Obviously this quadratic horror you found is even worse than the linear one I reported, but it can arguably be worked around in tester-like workloads (just never delete the namespaces). While the linear one cannot, as long as you need to move any interface into the newly created thousands of namespaces.
+Johannes and wireless ML.
From: Alexandre Ferrieux <[email protected]>
Date: Sun, 15 Sep 2024 22:49:22 +0200
Quoted 23 lines
(thanks Simon, reposting with another account to avoid the offending disclaimer)
Hi,
Currently, netns don't really scale beyond a few thousands, for mundane reasons (see below). But should they ? Is there, in the design, an assumption that tens of thousands of network namespaces are considered "unreasonable" ?
A typical use case for such ridiculous numbers is a tester for firewalls or carrier-grade NATs. In these, you typically want tens of thousands of tunnels, each of which is perfectly instantiated as an interface. And, to avoid an explosion in source routing rules, you want them in separate namespaces.
Now why don't they scale *today* ? For two independent, seemingly accidental, O(N) scans of the netns list.
1. The "netdevice notifier" from the Wireless Extensions subsystem insists on scanning the whole list regardless of the nature of the change, nor wondering whether all these namespaces hold any wireless interface, nor even whether the system has _any_ wireless hardware...
Quoted 6 lines
for_each_net(net) {
while ((skb = skb_dequeue(&net->wext_nlevents)))
rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL,
GFP_KERNEL);
}Alex forwarded this mail to me and asked about 1.
I checked 8bf862739a778, but I didn't see why wext_netdev_notifier_call() needs to iterate all netns.
Is there a case where flushing messages in the notified dev's netns is not enough for wext dev ?
---8<---
net/wireless/wext-core.c +14 -7
@@ -343,17 +343,22 @@ static const int compat_event_type_size[] = {/* IW event code */ -void wireless_nlevent_flush (void ) +static void wireless_nlevent_flush_net (struct net *net) {struct sk_buff *skb; + +while ((skb =skb_dequeue (&net->wext_nlevents))) +rtnl_notify (skb, net,0 ,RTNLGRP_LINK ,NULL , +GFP_KERNEL ); +} + +void wireless_nlevent_flush (void ) +{struct net *net;down_read (&net_rwsem); -for_each_net (net) { -while ((skb =skb_dequeue (&net->wext_nlevents))) -rtnl_notify (skb, net,0 ,RTNLGRP_LINK ,NULL , -GFP_KERNEL ); - } +for_each_net (net) +wireless_nlevent_flush_net (net);up_read (&net_rwsem); }EXPORT_SYMBOL_GPL (wireless_nlevent_flush);
@@ -361,6 +366,8 @@ 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
@@ -368,7 +375,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_net (dev_net (dev));return NOTIFY_OK ; }
---8<---
Johannes Berg
maintainerQuoted 12 lines · Kuniyuki Iwashima
Quoted 11 lines
1. The "netdevice notifier" from the Wireless Extensions subsystem insists on scanning the whole list regardless of the nature of the change, nor wondering whether all these namespaces hold any wireless interface, nor even whether the system has _any_ wireless hardware...
for_each_net(net) { while ((skb = skb_dequeue(&net->wext_nlevents))) rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL); }
Quoted 4 lines
Alex forwarded this mail to me and asked about 1.
I checked
8bf862739a778, but I didn't see whywext_netdev_notifier_call()needs to iterate all netns.
Agree. That code is ancient, and I don't remember why, but I'd think it's just because I was lazy then.
Quoted 23 lines
net/wireless/wext-core.c +9
-1@@ -343,17 +343,22 @@ static const int compat_event_type_size[] = {/* IW event code */ -void wireless_nlevent_flush (void ) +static void wireless_nlevent_flush_net (struct net *net) {struct sk_buff *skb; + +while ((skb =skb_dequeue (&net->wext_nlevents))) +rtnl_notify (skb, net,0 ,RTNLGRP_LINK ,NULL , +GFP_KERNEL ); +} + +void wireless_nlevent_flush (void ) +{struct net *net;down_read (&net_rwsem);
net/wireless/wext-core.c static const int compat_event_type_size[] = { · line 364
Quoted 10 lines
net/wireless/wext-core.c +2
-5-for_each_net (net) { -while ((skb =skb_dequeue (&net->wext_nlevents))) -rtnl_notify (skb, net,0 ,RTNLGRP_LINK ,NULL , -GFP_KERNEL ); - } +for_each_net (net) +wireless_nlevent_flush_net (net);up_read (&net_rwsem); }EXPORT_SYMBOL_GPL (wireless_nlevent_flush);
Note 1: I just posted this patch yesterday:
https://lore.kernel.org/linux-wireless/20241007214715.3dd736dc3ac0.I1388536e99c37f28a007dd753c473ad21513d9a9@changeid/
so that would conflict here, I'd think.
Note 2: the only other caller to wireless_nlevent_flush() is from wireless_nlevent_process()/wireless_nlevent_work, and that work could easily be made per netns since it comes along with net->wext_nlevents, and then we don't need any global function at all. Seems this could be implemented in wext_pernet_init()/wext_pernet_exit() pretty easily?
johannes
From: Johannes Berg <[email protected]>
Date: Tue, 08 Oct 2024 20:22:38 +0200
Quoted 59 lines · Kuniyuki Iwashima
Quoted 13 lines
Quoted 6 lines
1. The "netdevice notifier" from the Wireless Extensions subsystem insists on scanning the whole list regardless of the nature of the change, nor wondering whether all these namespaces hold any wireless interface, nor even whether the system has _any_ wireless hardware...
Quoted 6 lines
for_each_net(net) { while ((skb = skb_dequeue(&net->wext_nlevents))) rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL); }Quoted 4 lines
Alex forwarded this mail to me and asked about 1.
I checked
8bf862739a778, but I didn't see whywext_netdev_notifier_call()needs to iterate all netns.Agree. That code is ancient, and I don't remember why, but I'd think it's just because I was lazy then.
Quoted 23 lines
net/wireless/wext-core.c +9
-1@@ -343,17 +343,22 @@ static const int compat_event_type_size[] = {/* IW event code */ -void wireless_nlevent_flush (void ) +static void wireless_nlevent_flush_net (struct net *net) {struct sk_buff *skb; + +while ((skb =skb_dequeue (&net->wext_nlevents))) +rtnl_notify (skb, net,0 ,RTNLGRP_LINK ,NULL , +GFP_KERNEL ); +} + +void wireless_nlevent_flush (void ) +{struct net *net;down_read (&net_rwsem);net/wireless/wext-core.c static const int compat_event_type_size[] = { · line 364
Quoted 10 lines
net/wireless/wext-core.c +2
-5-for_each_net (net) { -while ((skb =skb_dequeue (&net->wext_nlevents))) -rtnl_notify (skb, net,0 ,RTNLGRP_LINK ,NULL , -GFP_KERNEL ); - } +for_each_net (net) +wireless_nlevent_flush_net (net);up_read (&net_rwsem); }EXPORT_SYMBOL_GPL (wireless_nlevent_flush);Note 1: I just posted this patch yesterday:
https://lore.kernel.org/linux-wireless/20241007214715.3dd736dc3ac0.I1388536e99c37f28a007dd753c473ad21513d9a9@changeid/
Quoted 7 lines
so that would conflict here, I'd think.
Note 2: the only other caller to
wireless_nlevent_flush()is from wireless_nlevent_process()/wireless_nlevent_work, and that work could easily be made per netns since it comes along withnet->wext_nlevents, and then we don't need any global function at all. Seems this could be implemented in wext_pernet_init()/wext_pernet_exit() pretty easily?
Sounds good.
I'll post a patch after yours lands on wireless-next.
Thanks!