net: hsr: use hlist_head instead of list_head for mac addresses
Subsystems (3)
PATCH v4 1/1 net: hsr: use hlist_head instead of list_head for mac addresses
Currently, HSR manages mac addresses of known HSR nodes by using list_head. It takes a lot of time when there are a lot of registered nodes due to finding specific mac address nodes by using linear search. We can be reducing the time by using hlist. Thus, this patch moves list_head to hlist_head for mac addresses and this allows for further improvement of network performance.
Condition: registered 10,000 known HSR nodes
Before:
# iperf3 -c 192.168.10.1 -i 1 -t 10
Connecting to host 192.168.10.1, port 5201
[ 5] local 192.168.10.2 port 59442 connected to 192.168.10.1 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.49 sec 3.75 MBytes 21.1 Mbits/sec 0 158 KBytes
[ 5] 1.49-2.05 sec 1.25 MBytes 18.7 Mbits/sec 0 166 KBytes
[ 5] 2.05-3.06 sec 2.44 MBytes 20.3 Mbits/sec 56 16.9 KBytes
[ 5] 3.06-4.08 sec 1.43 MBytes 11.7 Mbits/sec 11 38.0 KBytes
[ 5] 4.08-5.00 sec 951 KBytes 8.49 Mbits/sec 0 56.3 KBytes
After:
# iperf3 -c 192.168.10.1 -i 1 -t 10
Connecting to host 192.168.10.1, port 5201
[ 5] local 192.168.10.2 port 36460 connected to 192.168.10.1 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 7.39 MBytes 62.0 Mbits/sec 3 130 KBytes
[ 5] 1.00-2.00 sec 5.06 MBytes 42.4 Mbits/sec 16 113 KBytes
[ 5] 2.00-3.00 sec 8.58 MBytes 72.0 Mbits/sec 42 94.3 KBytes
[ 5] 3.00-4.00 sec 7.44 MBytes 62.4 Mbits/sec 2 131 KBytes
[ 5] 4.00-5.07 sec 8.13 MBytes 63.5 Mbits/sec 38 92.9 KBytes---
v4:
- fix indent warnings
v3:
- rebase current net-next tree
v2:
- fix rcu warning
net/hsr/hsr_debugfs.c | 40 +++++---- net/hsr/hsr_device.c | 10 ++- net/hsr/hsr_forward.c | 7 +- net/hsr/hsr_framereg.c | 200 ++++++++++++++++++++++++----------------- net/hsr/hsr_framereg.h | 8 +- net/hsr/hsr_main.h | 9 +- net/hsr/hsr_netlink.c | 4 +- 7 files changed, 171 insertions(+), 107 deletions(-)
net/hsr/hsr_debugfs.c +24 -16
@@ -17,6 +17,7 @@#include <linux/module.h> #include <linux/errno.h> #include <linux/debugfs.h> +#include <linux/jhash.h> #include "hsr_main.h" #include "hsr_framereg.h"
@@ -28,6 +29,7 @@ hsr_node_table_show(struct seq_file *sfp, void *data) {struct hsr_priv *priv = (struct hsr_priv *)sfp->private;struct hsr_node *node; +int i;seq_printf (sfp,"Node Table entries for (%s) device\n" , (priv->prot_version ==PRP_V1 ?"PRP" :"HSR" ));
@@ -39,22 +41,28 @@ hsr_node_table_show(struct seq_file *sfp, void *data)seq_puts (sfp,"DAN-H\n" );rcu_read_lock (); -list_for_each_entry_rcu (node, &priv->node_db, mac_list) { -/* skip self node */ -if (hsr_addr_is_self (priv, node->macaddress_A)) -continue ; -seq_printf (sfp,"%pM " , &node->macaddress_A[0 ]); -seq_printf (sfp,"%pM " , &node->macaddress_B[0 ]); -seq_printf (sfp,"%10lx, " , node->time_in[HSR_PT_SLAVE_A ]); -seq_printf (sfp,"%10lx, " , node->time_in[HSR_PT_SLAVE_B ]); -seq_printf (sfp,"%14x, " , node->addr_B_port); - -if (priv->prot_version ==PRP_V1 ) -seq_printf (sfp,"%5x, %5x, %5x\n" , - node->san_a, node->san_b, - (node->san_a ==0 && node->san_b ==0 )); -else -seq_printf (sfp,"%5x\n" ,1 ); + +for (i =0 ; i < priv->hash_buckets; i++) { +hlist_for_each_entry_rcu (node, &priv->node_db[i], mac_list) { +/* skip self node */ +if (hsr_addr_is_self (priv, node->macaddress_A)) +continue ; +seq_printf (sfp,"%pM " , &node->macaddress_A[0 ]); +seq_printf (sfp,"%pM " , &node->macaddress_B[0 ]); +seq_printf (sfp,"%10lx, " , + node->time_in[HSR_PT_SLAVE_A ]); +seq_printf (sfp,"%10lx, " , + node->time_in[HSR_PT_SLAVE_B ]); +seq_printf (sfp,"%14x, " , node->addr_B_port); + +if (priv->prot_version ==PRP_V1 ) +seq_printf (sfp,"%5x, %5x, %5x\n" , + node->san_a, node->san_b, + (node->san_a ==0 && + node->san_b ==0 )); +else +seq_printf (sfp,"%5x\n" ,1 ); + } }rcu_read_unlock ();return 0 ;
net/hsr/hsr_device.c +7 -3
@@ -485,12 +485,16 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], {bool unregister = false;struct hsr_priv *hsr; -int res; +int res, i; hsr =netdev_priv (hsr_dev);INIT_LIST_HEAD (&hsr->ports); -INIT_LIST_HEAD (&hsr->node_db); -INIT_LIST_HEAD (&hsr->self_node_db); +INIT_HLIST_HEAD (&hsr->self_node_db); + hsr->hash_buckets =HSR_HSIZE ; +get_random_bytes (&hsr->hash_seed,sizeof (hsr->hash_seed)); +for (i =0 ; i < hsr->hash_buckets; i++) +INIT_HLIST_HEAD (&hsr->node_db[i]); +spin_lock_init (&hsr->list_lock);eth_hw_addr_set (hsr_dev, slave[0 ]->dev_addr);
net/hsr/hsr_forward.c +5 -2
@@ -570,20 +570,23 @@ static int fill_frame_info(struct hsr_frame_info *frame,struct ethhdr *ethhdr;__be16 proto;int ret; +u32 hash;/* Check if skb contains ethhdr */ if (skb->mac_len <sizeof (struct ethhdr ))return -EINVAL ;memset (frame,0 ,sizeof (*frame)); + + ethhdr = (struct ethhdr *)skb_mac_header (skb); + hash =hsr_mac_hash (port->hsr, ethhdr->h_source); frame->is_supervision =is_supervision_frame (port->hsr, skb); - frame->node_src =hsr_get_node (port, &hsr->node_db, skb, + frame->node_src =hsr_get_node (port, &hsr->node_db[hash], skb, frame->is_supervision, port->type);if (!frame->node_src)return -1 ;/* Unknown node and !is_supervision, or no mem */ - ethhdr = (struct ethhdr *)skb_mac_header (skb); frame->is_vlan = false; proto = ethhdr->h_proto;
net/hsr/hsr_framereg.c +120 -80
365 lines not on this page · raw message
net/hsr/hsr_framereg.h +5 -3
@@ -28,9 +28,11 @@ struct hsr_frame_info {bool is_from_san; }; +u32 hsr_mac_hash (struct hsr_priv *hsr,const unsigned char *addr); +struct hsr_node *hsr_node_get_first (struct hlist_head *head);void hsr_del_self_node (struct hsr_priv *hsr); -void hsr_del_nodes (struct list_head *node_db); -struct hsr_node *hsr_get_node (struct hsr_port *port,struct list_head *node_db, +void hsr_del_nodes (struct hlist_head *node_db); +struct hsr_node *hsr_get_node (struct hsr_port *port,struct hlist_head *node_db,struct sk_buff *skb,bool is_sup,enum hsr_port_type rx_port);void hsr_handle_sup_frame (struct hsr_frame_info *frame);
@@ -68,7 +70,7 @@ void prp_handle_san_frame(bool san, enum hsr_port_type port,void prp_update_san_info (struct hsr_node *node,bool is_sup);struct hsr_node { -struct list_head mac_list; +struct hlist_node mac_list;unsigned char macaddress_A[ETH_ALEN ];unsigned char macaddress_B[ETH_ALEN ];/* Local slave through which AddrB frames are received from this node */
net/hsr/hsr_main.h +7 -2
@@ -63,6 +63,9 @@ struct hsr_tag {#define HSR_V1_SUP_LSDUSIZE 52 +#define HSR_HSIZE_SHIFT 8 +#define HSR_HSIZE BIT(HSR_HSIZE_SHIFT) +/* The helper functions below assumes that 'path' occupies the 4 most * significant bits of the 16-bit field shared by 'path' and 'LSDU_size' (or * equivalently, the 4 most significant bits of HSR tag byte 14).
@@ -201,8 +204,8 @@ struct hsr_proto_ops {struct hsr_priv {struct rcu_head rcu_head;struct list_head ports; -struct list_head node_db;/* Known HSR nodes */ -struct list_head self_node_db;/* MACs of slaves */ +struct hlist_head node_db[HSR_HSIZE ];/* Known HSR nodes */ +struct hlist_head self_node_db;/* MACs of slaves */ struct timer_list announce_timer;/* Supervision frame dispatch */ struct timer_list prune_timer;int announce_count;
@@ -212,6 +215,8 @@ struct hsr_priv {spinlock_t seqnr_lock;/* locking for sequence_nr */ spinlock_t list_lock;/* locking for node list */ struct hsr_proto_ops *proto_ops; +u32 hash_buckets; +u32 hash_seed;#define PRP_LAN_ID 0x5/* 0x1010 for A and 0x1011 for B. Bit 0 is set * based on SLAVE_A or SLAVE_B */
net/hsr/hsr_netlink.c +3 -1
@@ -105,6 +105,7 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,static void hsr_dellink (struct net_device *dev,struct list_head *head) {struct hsr_priv *hsr =netdev_priv (dev); +int i;del_timer_sync (&hsr->prune_timer);del_timer_sync (&hsr->announce_timer);
@@ -113,7 +114,8 @@ static void hsr_dellink(struct net_device *dev, struct list_head *head)hsr_del_ports (hsr);hsr_del_self_node (hsr); -hsr_del_nodes (&hsr->node_db); +for (i =0 ; i < hsr->hash_buckets; i++) +hsr_del_nodes (&hsr->node_db[i]);unregister_netdevice_queue (dev, head); }
Signature · 1 line
2.25.1
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 8 lines · On Sat, 5 Feb 2022 15:40:38 +0000 you wrote:
Currently, HSR manages mac addresses of known HSR nodes by using
list_head. It takes a lot of time when there are a lot of registered nodes due to finding specific mac address nodes by using linear search. We can be reducing the time by using hlist. Thus, this patch moveslist_headtohlist_headfor mac addresses and this allows for further improvement of network performance.[...]
Here is the summary with links:
- [v4,net-next] net: hsr: use hlist_head instead of list_head for mac addresses
https://git.kernel.org/netdev/net-next/c/4acc45db7115
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 13 lines · On 2/6/22 03:10, [email protected] wrote:
Hello:
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 7 lines · On Sat, 5 Feb 2022 15:40:38 +0000 you wrote:
Currently, HSR manages mac addresses of known HSR nodes by using
list_head. It takes a lot of time when there are a lot of registered nodes due to finding specific mac address nodes by using linear search. We can be reducing the time by using hlist. Thus, this patch moveslist_headtohlist_headfor mac addresses and this allows for further improvement of network performance.
Quoted 6 lines
Quoted 1 line
[...]
Here is the summary with links:
- [v4,net-next] net: hsr: usehlist_headinstead oflist_headfor mac addresseshttps://git.kernel.org/netdev/net-next/c/4acc45db7115You are awesome, thank you!
I think this patch has not been tested with CONFIG_PROVE_RCU=y
WARNING: suspicious RCU usage 5.17.0-rc3-next-20220207-syzkaller #0 Not tainted
-----------------------------net/hsr/hsr_framereg.c:34 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
2 locks held by syz-executor.0/3603:
#0: ffffffff8d3353a8 (rtnl_mutex){+.+.}-{3:3}, at: rtnl_lock net/core/rtnetlink.c:72 [inline] #0: ffffffff8d3353a8 (rtnl_mutex){+.+.}-{3:3}, at: rtnetlink_rcv_msg+0x3be/0xb80 net/core/rtnetlink.c:5591 #1: ffff88806e13d5f0 (&hsr->list_lock){+...}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:359 [inline] #1: ffff88806e13d5f0 (&hsr->list_lock){+...}-{2:2}, at: hsr_create_self_node+0x225/0x650 net/hsr/hsr_framereg.c:108
stack backtrace: CPU: 0 PID: 3603 Comm: syz-executor.0 Not tainted 5.17.0-rc3-next-20220207-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 hsr_node_get_first+0x9b/0xb0 net/hsr/hsr_framereg.c:34 hsr_create_self_node+0x22d/0x650 net/hsr/hsr_framereg.c:109 hsr_dev_finalize+0x2c1/0x7d0 net/hsr/hsr_device.c:514 hsr_newlink+0x315/0x730 net/hsr/hsr_netlink.c:102 __rtnl_newlink+0x107c/0x1760 net/core/rtnetlink.c:3481 rtnl_newlink+0x64/0xa0 net/core/rtnetlink.c:3529 rtnetlink_rcv_msg+0x413/0xb80 net/core/rtnetlink.c:5594 netlink_rcv_skb+0x153/0x420 net/netlink/af_netlink.c:2494 netlink_unicast_kernel net/netlink/af_netlink.c:1317 [inline] netlink_unicast+0x539/0x7e0 net/netlink/af_netlink.c:1343 netlink_sendmsg+0x904/0xe00 net/netlink/af_netlink.c:1919 sock_sendmsg_nosec net/socket.c:705 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:725 __sys_sendto+0x21c/0x320 net/socket.c:2040 __do_sys_sendto net/socket.c:2052 [inline] __se_sys_sendto net/socket.c:2048 [inline] __x64_sys_sendto+0xdd/0x1b0 net/socket.c:2048 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae
Quoted 77 lines · Eric Dumazet
Quoted 13 lines · On 2/6/22 03:10, [email protected] wrote:
Hello:
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 7 lines · On Sat, 5 Feb 2022 15:40:38 +0000 you wrote:
Currently, HSR manages mac addresses of known HSR nodes by using
list_head. It takes a lot of time when there are a lot of registered nodes due to finding specific mac address nodes by using linear search. We can be reducing the time by using hlist. Thus, this patch moveslist_headtohlist_headfor mac addresses and this allows for further improvement of network performance.Quoted 6 lines
Quoted 1 line
[...]
Here is the summary with links:
- [v4,net-next] net: hsr: usehlist_headinstead oflist_headfor mac addresseshttps://git.kernel.org/netdev/net-next/c/4acc45db7115You are awesome, thank you!
I think this patch has not been tested with
CONFIG_PROVE_RCU=yWARNING: suspicious RCU usage 5.17.0-rc3-next-20220207-syzkaller #0 Not tainted
-----------------------------net/hsr/hsr_framereg.c:34suspiciousrcu_dereference_check()usage!other info that might help us debug this:
rcu_scheduler_active= 2,debug_locks= 1
2 locks held by syz-executor.0/3603:
#0:ffffffff8d3353a8(rtnl_mutex){+.+.}-{3:3}, at:rtnl_locknet/core/rtnetlink.c:72[inline]
#0:ffffffff8d3353a8(rtnl_mutex){+.+.}-{3:3}, at:rtnetlink_rcv_msg+0x3be/0xb80 net/core/rtnetlink.c:5591 #1: ffff88806e13d5f0 (&hsr->list_lock){+...}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:359 [inline] #1: ffff88806e13d5f0 (&hsr->list_lock){+...}-{2:2}, at: hsr_create_self_node+0x225/0x650 net/hsr/hsr_framereg.c:108 stack backtrace: CPU: 0 PID: 3603 Comm: syz-executor.0 Not tainted 5.17.0-rc3-next-20220207-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 hsr_node_get_first+0x9b/0xb0 net/hsr/hsr_framereg.c:34 hsr_create_self_node+0x22d/0x650 net/hsr/hsr_framereg.c:109 hsr_dev_finalize+0x2c1/0x7d0 net/hsr/hsr_device.c:514 hsr_newlink+0x315/0x730 net/hsr/hsr_netlink.c:102 __rtnl_newlink+0x107c/0x1760 net/core/rtnetlink.c:3481 rtnl_newlink+0x64/0xa0 net/core/rtnetlink.c:3529 rtnetlink_rcv_msg+0x413/0xb80 net/core/rtnetlink.c:5594 netlink_rcv_skb+0x153/0x420 net/netlink/af_netlink.c:2494 netlink_unicast_kernel net/netlink/af_netlink.c:1317 [inline] netlink_unicast+0x539/0x7e0 net/netlink/af_netlink.c:1343 netlink_sendmsg+0x904/0xe00 net/netlink/af_netlink.c:1919 sock_sendmsg_nosec net/socket.c:705 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:725 __sys_sendto+0x21c/0x320 net/socket.c:2040 __do_sys_sendto net/socket.c:2052 [inline] __se_sys_sendto net/socket.c:2048 [inline] __x64_sys_sendto+0xdd/0x1b0 net/socket.c:2048 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae
Signature · 7 lines
Hi Eric, Thank you so much for catching it. I will send a new patch after fixing this problem and some tests. Best regards, Juhee Kang