net: use net->dev_by_index in two places
Subsystems (2)
v2 cover net: use net->dev_by_index in two places
Bring "ip link" ordering to /proc/net/dev one (by ifindexes).
Do the same for /proc/net/vlan/config
v2: added suggestions from Jakub Kicinski and Ido Schimmel, thanks !
Eric Dumazet (2):
vlan: use xarray iterator to implement /proc/net/vlan/config
rtnetlink: use xarray iterator to implement rtnl_dump_ifinfo()
net/8021q/vlanproc.c | 46 ++++++++++++----------------------- net/core/rtnetlink.c | 58 +++++++++++++++----------------------------- 2 files changed, 36 insertions(+), 68 deletions(-)
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
PATCH v2 1/2 vlan: use xarray iterator to implement /proc/net/vlan/config
Adopt net->dev_by_index as I did in commit 0e0939c0adf9 ("net-procfs: use xarray iterator to implement /proc/net/dev")
Not only this removes quadratic behavior, it also makes sure an existing vlan device is always visible in the dump, regardless of concurrent net->dev_base_head changes.
--- net/8021q/vlanproc.c | 46 +++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 30 deletions(-)
net/8021q/vlanproc.c +16 -30
@@ -163,48 +163,34 @@ void vlan_proc_rem_dev(struct net_device *vlandev)* The following few functions build the content of /proc/net/vlan/config */ -/* start read of /proc/net/vlan/config */ -static void *vlan_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (rcu) +static void *vlan_seq_from_index (struct seq_file *seq,loff_t *pos) { +unsigned long ifindex = *pos;struct net_device *dev; -struct net *net =seq_file_net (seq); -loff_t i =1 ; - -rcu_read_lock (); -if (*pos ==0 ) -return SEQ_START_TOKEN ; -for_each_netdev_rcu (net, dev) { +for_each_netdev_dump (seq_file_net (seq), dev, ifindex) {if (!is_vlan_dev (dev))continue ; - -if (i++ == *pos) -return dev; + *pos = dev->ifindex; +return dev; } +return NULL ; +} + +static void *vlan_seq_start (struct seq_file *seq,loff_t *pos) +__acquires (rcu) +{ +rcu_read_lock (); +if (*pos ==0 ) +return SEQ_START_TOKEN ; -return NULL ; +return vlan_seq_from_index (seq, pos); }static void *vlan_seq_next (struct seq_file *seq,void *v,loff_t *pos) { -struct net_device *dev; -struct net *net =seq_file_net (seq); - ++*pos; - - dev = v; -if (v ==SEQ_START_TOKEN ) - dev =net_device_entry (&net->dev_base_head); - -for_each_netdev_continue_rcu (net, dev) { -if (!is_vlan_dev (dev)) -continue ; - -return dev; - } - -return NULL ; +return vlan_seq_from_index (seq, pos); }static void vlan_seq_stop (struct seq_file *seq,void *v)
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Re: [PATCH v2 net-next 1/2] vlan: use xarray iterator to implement /proc/net/vlan/config
Quoted 9 lines · Eric Dumazet
Adopt
net->dev_by_indexas I did in commit0e0939c0adf9("net-procfs: use xarray iterator to implement/proc/net/dev")Not only this removes quadratic behavior, it also makes sure an existing vlan device is always visible in the dump, regardless of concurrent
net->dev_base_headchanges.Signed-off-by Eric Dumazet <[email protected]>Reviewed-by Jakub Kicinski <[email protected]>
PATCH v2 2/2 rtnetlink: use xarray iterator to implement rtnl_dump_ifinfo()
In reply to Eric DumazetAdopt net->dev_by_index as I did in commit 0e0939c0adf9 ("net-procfs: use xarray iterator to implement /proc/net/dev")
This makes sure an existing device is always visible in the dump, regardless of concurrent insertions/deletions.
v2: added suggestions from Jakub Kicinski and Ido Schimmel,
thanks for the help !
--- net/core/rtnetlink.c | 58 +++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 38 deletions(-)
net/core/rtnetlink.c +20 -38
@@ -2188,25 +2188,22 @@ static int rtnl_valid_dump_ifinfo_req(const struct nlmsghdr *nlh,static int rtnl_dump_ifinfo (struct sk_buff *skb,struct netlink_callback *cb) { +const struct rtnl_link_ops *kind_ops =NULL ;struct netlink_ext_ack *extack = cb->extack;const struct nlmsghdr *nlh = cb->nlh;struct net *net =sock_net (skb->sk); -struct net *tgt_net = net; -int h, s_h; -int idx =0 , s_idx; -struct net_device *dev; -struct hlist_head *head; +unsigned int flags =NLM_F_MULTI ;struct nlattr *tb[IFLA_MAX +1 ]; +struct { +unsigned long ifindex; + } *ctx = (void *)cb->ctx; +struct net *tgt_net = net;u32 ext_filter_mask =0 ; -const struct rtnl_link_ops *kind_ops =NULL ; -unsigned int flags =NLM_F_MULTI ; +struct net_device *dev;int master_idx =0 ;int netnsid =-1 ;int err, i; - s_h = cb->args[0 ]; - s_idx = cb->args[1 ]; - err =rtnl_valid_dump_ifinfo_req (nlh, cb->strict_check, tb, extack);if (err <0 ) {if (cb->strict_check)
@@ -2250,36 +2247,21 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) flags |=NLM_F_DUMP_FILTERED ; walk_entries: -for (h = s_h; h <NETDEV_HASHENTRIES ; h++, s_idx =0 ) { - idx =0 ; - head = &tgt_net->dev_index_head[h]; -hlist_for_each_entry (dev, head, index_hlist) { -if (link_dump_filtered (dev, master_idx, kind_ops)) - goto cont; -if (idx < s_idx) - goto cont; - err =rtnl_fill_ifinfo (skb, dev, net, -RTM_NEWLINK , -NETLINK_CB (cb->skb).portid, - nlh->nlmsg_seq,0 , flags, - ext_filter_mask,0 ,NULL ,0 , - netnsid,GFP_KERNEL ); - -if (err <0 ) { -if (likely (skb->len)) - goto out; - - goto out_err; - } -cont: - idx++; + err =0 ; +for_each_netdev_dump (tgt_net, dev, ctx->ifindex) { +if (link_dump_filtered (dev, master_idx, kind_ops)) +continue ; + err =rtnl_fill_ifinfo (skb, dev, net,RTM_NEWLINK , +NETLINK_CB (cb->skb).portid, + nlh->nlmsg_seq,0 , flags, + ext_filter_mask,0 ,NULL ,0 , + netnsid,GFP_KERNEL ); +if (err <0 ) { +if (likely (skb->len)) + err = skb->len; +break ; } } -out: - err = skb->len; -out_err: - cb->args[1 ] = idx; - cb->args[0 ] = h; cb->seq = tgt_net->dev_base_seq;nl_dump_check_consistent (cb,nlmsg_hdr (skb));if (netnsid >=0 )
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Re: [PATCH v2 net-next 2/2] rtnetlink: use xarray iterator to implement rtnl_dump_ifinfo()
Quoted 6 lines · Eric Dumazet
Adopt
net->dev_by_indexas I did in commit0e0939c0adf9("net-procfs: use xarray iterator to implement/proc/net/dev")This makes sure an existing device is always visible in the dump, regardless of concurrent insertions/deletions.
Quoted 6 lines
v2: added suggestions from Jakub Kicinski and Ido Schimmel,
thanks for the help !
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Sun, 11 Feb 2024 21:44:02 +0000 you wrote:
Bring "ip link" ordering to
/proc/net/devone (by ifindexes).Do the same for
/proc/net/vlan/configv2: added suggestions from Jakub Kicinski and Ido Schimmel, thanks !
[...]
Here is the summary with links:
- [v2,net-next,1/2] vlan: use xarray iterator to implement /proc/net/vlan/config
https://git.kernel.org/netdev/net-next/c/f383ced24d6a - [v2,net-next,2/2] rtnetlink: use xarray iterator to implement rtnl_dump_ifinfo() https://git.kernel.org/netdev/net-next/c/3e41af90767d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html