llc enhancements
Subsystems (3)
PATCH v2 1/1 llc enhancements
This patch modifies the LLC code to scale the socket lookup code for a large number of interfaces and large number of sockets bound to the same SAP. We use it for STP traffic generation from a large number of virtual STP ports, via virtual network interfaces.
In the process we converted the socket lookup code and sap list to use RCU. It also contains some general cleanups (use dev_hard_header instead of handcrafting the headers) and enhancements (LLC_OPT_PKTINFO).
This is the 2nd version. Changes from the previous version:
- added SO_BINDTODEVICE support for faster bind operations
- converted the socket lookup code and sap list to RCU
- optimized multicast delivery ala Eric
- remove some unused APIs (which should be private anyway)
Many thanks to Eric Dumazet for his continuous guidance and to Jarek Poplawski for spotting a locking bug in the previous version.
PATCH v2 1/9 llc: use dev_hard_header
Using dev_hard_header allows us to use LLC with VLANs and potentially other Ethernet/TokernRing specific encapsulations. It also removes code duplication between LLC and Ethernet/TokenRing core code.
--- drivers/net/myri_sbus.c | 6 +++--- net/8021q/vlan_dev.c | 7 +++---- net/ethernet/eth.c | 6 +++--- net/llc/llc_output.c | 45 ++++++++------------------------------------- 4 files changed, 17 insertions(+), 47 deletions(-)
drivers/net/myri_sbus.c +3 -3
@@ -716,10 +716,10 @@ static int myri_header(struct sk_buff *skb, struct net_device *dev, pad[0 ] =MYRI_PAD_LEN ; pad[1 ] =0xab ; -/* Set the protocol type. For a packet of type ETH_P_802_3 we put the length -* in here instead. It is up to the 802.2 layer to carry protocol information. +/* Set the protocol type. For a packet of type ETH_P_802_3/2 we put the +* length in here instead. */ -if (type !=ETH_P_802_3 ) +if (type !=ETH_P_802_3 && type !=ETH_P_802_2 ) eth->h_proto =htons (type);else eth->h_proto =htons (len);
net/8021q/vlan_dev.c +3 -4
@@ -263,11 +263,10 @@ static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev, vhdr->h_vlan_TCI =htons (vlan_tci);/* -* Set the protocol type. For a packet of type ETH_P_802_3 we -* put the length in here instead. It is up to the 802.2 -* layer to carry protocol information. +* Set the protocol type. For a packet of type ETH_P_802_3/2 we +* put the length in here instead. */ -if (type !=ETH_P_802_3 ) +if (type !=ETH_P_802_3 && type !=ETH_P_802_2 ) vhdr->h_vlan_encapsulated_proto =htons (type);else vhdr->h_vlan_encapsulated_proto =htons (len);
net/ethernet/eth.c +3 -3
@@ -73,8 +73,8 @@ __setup("ether=", netdev_boot_setup);* @len: packet length (<= skb->len) * * -* Set the protocol type. For a packet of type ETH_P_802_3 we put the length -* in here instead. It is up to the 802.2 layer to carry protocol information. +* Set the protocol type. For a packet of type ETH_P_802_3/2 we put the length +* in here instead. */ int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
@@ -82,7 +82,7 @@ int eth_header(struct sk_buff *skb, struct net_device *dev, {struct ethhdr *eth = (struct ethhdr *)skb_push (skb,ETH_HLEN ); -if (type !=ETH_P_802_3 ) +if (type !=ETH_P_802_3 && type !=ETH_P_802_2 ) eth->h_proto =htons (type);else eth->h_proto =htons (len);
net/llc/llc_output.c +8 -37
56 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH v2 2/9 llc: add support for LLC_OPT_PKTINFO
In reply to Octavian Purdila--- include/linux/llc.h | 7 +++++++ include/net/llc_conn.h | 1 + net/llc/af_llc.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 0 deletions(-)
include/linux/llc.h +7 -0
@@ -36,6 +36,7 @@ enum llc_sockopts {LLC_OPT_BUSY_TMR_EXP ,/* busy state expire time (secs). */ LLC_OPT_TX_WIN ,/* tx window size. */ LLC_OPT_RX_WIN ,/* rx window size. */ +LLC_OPT_PKTINFO ,/* ancillary packet information. */ LLC_OPT_MAX };
@@ -70,6 +71,12 @@ enum llc_sockopts {#define LLC_SAP_RM 0xD4/* Resource Management */ #define LLC_SAP_GLOBAL 0xFF/* Global SAP. */ +struct llc_pktinfo { +int lpi_ifindex; +unsigned char lpi_sap; +unsigned char lpi_mac[IFHWADDRLEN ]; +}; +#ifdef __KERNEL__#define LLC_SAP_DYN_START 0xC0#define LLC_SAP_DYN_STOP 0xDE
include/net/llc_conn.h +1 -0
@@ -76,6 +76,7 @@ struct llc_sock {u32 rx_pdu_hdr;/* used for saving header of last pdu received and caused sending FRMR. Used for resending FRMR */ +u32 cmsg_flags; };static inline struct llc_sock *llc_sk (const struct sock *sk)
net/llc/af_llc.c +29 -0
@@ -47,6 +47,10 @@ static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout); #define dprintk(args...)#endif +/* Maybe we'll add some more in the future. */ +#define LLC_CMSG_PKTINFO 1 + +/** * llc_ui_next_link_no - return the next unused link number for a sap * @sap: Address of sap to get link number from.
@@ -591,6 +595,20 @@ static int llc_wait_data(struct sock *sk, long timeo)return rc; } +static void llc_cmsg_rcv (struct msghdr *msg,struct sk_buff *skb) +{ +struct llc_sock *llc =llc_sk (skb->sk); + +if (llc->cmsg_flags &LLC_CMSG_PKTINFO ) { +struct llc_pktinfo info; + + info.lpi_ifindex =llc_sk (skb->sk)->dev->ifindex; +llc_pdu_decode_dsap (skb, &info.lpi_sap); +llc_pdu_decode_da (skb, info.lpi_mac); +put_cmsg (msg,SOL_LLC ,LLC_OPT_PKTINFO ,sizeof (info), &info); + } +} +/** * llc_ui_accept - accept a new incoming connection. * @sock: Socket which connections arrive on.
@@ -812,6 +830,8 @@ copy_uaddr:memcpy (uaddr,llc_ui_skb_cb (skb),sizeof (*uaddr)); msg->msg_namelen =sizeof (*uaddr); } +if (llc_sk (sk)->cmsg_flags) +llc_cmsg_rcv (msg, skb); goto out; }
@@ -1030,6 +1050,12 @@ static int llc_ui_setsockopt(struct socket *sock, int level, int optname, goto out; llc->rw = opt;break ; +case LLC_OPT_PKTINFO : +if (opt) + llc->cmsg_flags |=LLC_CMSG_PKTINFO ; +else + llc->cmsg_flags &= ~LLC_CMSG_PKTINFO ; +break ;default : rc = -ENOPROTOOPT ; goto out;
@@ -1083,6 +1109,9 @@ static int llc_ui_getsockopt(struct socket *sock, int level, int optname, val = llc->k;break ;case LLC_OPT_RX_WIN : val = llc->rw;break ; +case LLC_OPT_PKTINFO : + val = (llc->cmsg_flags &LLC_CMSG_PKTINFO ) !=0 ; +break ;default : rc = -ENOPROTOOPT ; goto out;
Signature · 1 line
1.5.6.5
PATCH v2 3/9 llc: add support for SO_BINDTODEVICE
In reply to Octavian PurdilaUsing bind(MAC address) with LLC sockets has O(n) complexity, where n is the number of interfaces. To overcome this, we add support for SO_BINDTODEVICE which drops the complexity to O(1).
--- net/llc/af_llc.c | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-)
net/llc/af_llc.c +27 -2
@@ -259,7 +259,14 @@ static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)if (!sock_flag (sk,SOCK_ZAPPED )) goto out; rc = -ENODEV ; - llc->dev =dev_getfirstbyhwtype (&init_net, addr->sllc_arphrd); +if (sk->sk_bound_dev_if) { + llc->dev =dev_get_by_index (&init_net, sk->sk_bound_dev_if); +if (llc->dev && addr->sllc_arphrd != llc->dev->type) { +dev_put (llc->dev); + llc->dev =NULL ; + } + }else + llc->dev =dev_getfirstbyhwtype (&init_net, addr->sllc_arphrd);if (!llc->dev) goto out; rc = -EUSERS ;
@@ -310,7 +317,25 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen) goto out; rc = -ENODEV ;rtnl_lock (); - llc->dev =dev_getbyhwaddr (&init_net, addr->sllc_arphrd, addr->sllc_mac); +if (sk->sk_bound_dev_if) { + llc->dev =dev_get_by_index (&init_net, sk->sk_bound_dev_if); +if (llc->dev) { +if (!addr->sllc_arphrd) + addr->sllc_arphrd = llc->dev->type; +if (llc_mac_null (addr->sllc_mac)) +memcpy (addr->sllc_mac, llc->dev->dev_addr, +IFHWADDRLEN ); +if (addr->sllc_arphrd != llc->dev->type || + !llc_mac_match (addr->sllc_mac, + llc->dev->dev_addr)) { + rc = -EINVAL ; +dev_put (llc->dev); + llc->dev =NULL ; + } + } + }else + llc->dev =dev_getbyhwaddr (&init_net, addr->sllc_arphrd, + addr->sllc_mac);rtnl_unlock ();if (!llc->dev) goto out;
Signature · 1 line
1.5.6.5
PATCH v2 4/9 llc: convert the socket list to RCU locking
In reply to Octavian PurdilaFor the reclamation phase we use the SLAB_DESTROY_BY_RCU mechanism, which require some extra checks in the lookup code:
a) If the current socket was released, reallocated & inserted in another list it will short circuit the iteration for the current list, thus we need to restart the lookup.
b) If the current socket was released, reallocated & inserted in the same list we just need to recheck it matches the look-up criteria and if not we can skip to the next element.
In this case there is no need to restart the lookup, since sockets are inserted at the start of the list and the worst that will happen is that we will iterate throught some of the list elements more then once.
Note that the /proc and multicast delivery was not yet converted to RCU, it still uses spinlocks for protection.
--- include/net/llc.h | 7 ++-- net/llc/af_llc.c | 1 + net/llc/llc_conn.c | 93 ++++++++++++++++++++++++++++++++++----------------- net/llc/llc_core.c | 5 ++- net/llc/llc_proc.c | 22 ++++++------ net/llc/llc_sap.c | 66 ++++++++++++++++++++++++------------- 6 files changed, 123 insertions(+), 71 deletions(-)
include/net/llc.h +3 -4
@@ -16,6 +16,7 @@#include <linux/if_ether.h> #include <linux/list.h> #include <linux/spinlock.h> +#include <linux/rculist_nulls.h> #include <asm/atomic.h>
@@ -53,10 +54,8 @@ struct llc_sap { struct net_device *orig_dev);struct llc_addr laddr;struct list_head node; -struct { -rwlock_t lock; -struct hlist_head list; - } sk_list; +spinlock_t sk_lock; +struct hlist_nulls_head sk_list; };#define LLC_DEST_INVALID 0/* Invalid LLC PDU type */
net/llc/af_llc.c +1 -0
@@ -140,6 +140,7 @@ static struct proto llc_proto = { .name = "LLC", .owner = THIS_MODULE, .obj_size = sizeof(struct llc_sock), + .slab_flags = SLAB_DESTROY_BY_RCU, };/**
net/llc/llc_conn.c +62 -31
144 lines not on this page · raw message
net/llc/llc_core.c +3 -2
@@ -37,7 +37,8 @@ static struct llc_sap *llc_sap_alloc(void)if (sap) {/* sap->laddr.mac - leave as a null, it's filled by bind */ sap->state =LLC_SAP_STATE_ACTIVE ; -rwlock_init (&sap->sk_list.lock); +spin_lock_init (&sap->sk_lock); +INIT_HLIST_NULLS_HEAD (&sap->sk_list,0 );atomic_set (&sap->refcnt,1 ); }return sap;
@@ -142,7 +143,7 @@ out:*/ void llc_sap_close (struct llc_sap *sap) { -WARN_ON (!hlist_empty (&sap->sk_list.list)); +WARN_ON (!hlist_nulls_empty (&sap->sk_list));llc_del_sap (sap);kfree (sap); }
net/llc/llc_proc.c +11 -11
@@ -34,19 +34,19 @@ static struct sock *llc_get_sk_idx(loff_t pos) {struct list_head *sap_entry;struct llc_sap *sap; -struct hlist_node *node; +struct hlist_nulls_node *node;struct sock *sk =NULL ;list_for_each (sap_entry, &llc_sap_list) { sap = list_entry(sap_entry, struct llc_sap, node); -read_lock_bh (&sap->sk_list.lock); -sk_for_each (sk, node, &sap->sk_list.list) { +spin_lock_bh (&sap->sk_lock); +sk_nulls_for_each (sk, node, &sap->sk_list) {if (!pos) goto found; --pos; } -read_unlock_bh (&sap->sk_list.lock); +spin_unlock_bh (&sap->sk_lock); } sk =NULL ; found:
@@ -73,25 +73,25 @@ static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos) goto out; } sk = v; - next =sk_next (sk); + next =sk_nulls_next (sk);if (next) { sk = next; goto out; } llc =llc_sk (sk); sap = llc->sap; -read_unlock_bh (&sap->sk_list.lock); +spin_unlock_bh (&sap->sk_lock); sk =NULL ;for (;;) {if (sap->node.next == &llc_sap_list)break ; sap = list_entry(sap->node.next, struct llc_sap, node); -read_lock_bh (&sap->sk_list.lock); -if (!hlist_empty (&sap->sk_list.list)) { - sk =sk_head (&sap->sk_list.list); +spin_lock_bh (&sap->sk_lock); +if (!hlist_nulls_empty (&sap->sk_list)) { + sk =sk_nulls_head (&sap->sk_list);break ; } -read_unlock_bh (&sap->sk_list.lock); +spin_unlock_bh (&sap->sk_lock); } out:return sk;
@@ -104,7 +104,7 @@ static void llc_seq_stop(struct seq_file *seq, void *v)struct llc_sock *llc =llc_sk (sk);struct llc_sap *sap = llc->sap; -read_unlock_bh (&sap->sk_list.lock); +spin_unlock_bh (&sap->sk_lock); }read_unlock_bh (&llc_sap_list_lock); }
net/llc/llc_sap.c +43 -23
101 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH v2 5/9 llc: optimize multicast delivery
In reply to Octavian PurdilaOptimize multicast delivery by doing the actual delivery without holding the lock. Based on the same approach used in UDP code.
--- net/llc/llc_sap.c | 36 ++++++++++++++++++++++++++++-------- 1 files changed, 28 insertions(+), 8 deletions(-)
net/llc/llc_sap.c +28 -8
@@ -355,6 +355,24 @@ static inline bool llc_mcast_match(const struct llc_sap *sap, llc->dev == skb->dev; } +static void llc_do_mcast (struct llc_sap *sap,struct sk_buff *skb, +struct sock **stack,int count) +{ +struct sk_buff *skb1; +int i; + +for (i =0 ; i < count; i++) { + skb1 =skb_clone (skb,GFP_ATOMIC ); +if (!skb1) { +sock_put (stack[i]); +continue ; + } + +llc_sap_rcv (sap, skb1, stack[i]); +sock_put (stack[i]); + } +} +/** * llc_sap_mcast - Deliver multicast PDU's to all matching datagram sockets. * @sap: SAP
@@ -367,25 +385,27 @@ static void llc_sap_mcast(struct llc_sap *sap,const struct llc_addr *laddr, struct sk_buff *skb) { - struct sock *sk; + int i = 0, count = 256 / sizeof(struct sock *); +struct sock *sk, *stack[count];struct hlist_nulls_node *node;spin_lock_bh (&sap->sk_lock);sk_nulls_for_each_rcu (sk, node, &sap->sk_list) { -struct sk_buff *skb1;if (!llc_mcast_match (sap, laddr, skb, sk))continue ; - skb1 =skb_clone (skb,GFP_ATOMIC ); -if (!skb1) -break ; -sock_hold (sk); -llc_sap_rcv (sap, skb1, sk); -sock_put (sk); +if (i < count) + stack[i++] = sk; +else { +llc_do_mcast (sap, skb, stack, i); + i =0 ; + } }spin_unlock_bh (&sap->sk_lock); + +llc_do_mcast (sap, skb, stack, i); }
Signature · 1 line
1.5.6.5
PATCH v2 6/9 llc: use a device based hash table to speed up multicast delivery
In reply to Octavian PurdilaThis patch adds a per SAP device based hash table to solve the multicast delivery scalability issue when we have large number of interfaces and a large number of sockets bound to the same SAP.
--- include/net/llc.h | 11 +++++++++++ include/net/llc_conn.h | 1 + net/llc/llc_conn.c | 10 +++++++++- net/llc/llc_sap.c | 8 ++++++-- 4 files changed, 27 insertions(+), 3 deletions(-)
include/net/llc.h +11 -0
@@ -32,6 +32,9 @@ struct llc_addr {#define LLC_SAP_STATE_INACTIVE 1#define LLC_SAP_STATE_ACTIVE 2 +#define LLC_SK_DEV_HASH_BITS 6 +#define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS) +/** * struct llc_sap - Defines the SAP component *
@@ -56,8 +59,16 @@ struct llc_sap {struct list_head node;spinlock_t sk_lock;struct hlist_nulls_head sk_list; +struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES ]; }; +static inline +struct hlist_head *llc_sk_dev_hash (struct llc_sap *sap,int ifindex) +{ +return &sap->sk_dev_hash[ifindex %LLC_SK_DEV_HASH_ENTRIES ]; +} + +#define LLC_DEST_INVALID 0/* Invalid LLC PDU type */ #define LLC_DEST_SAP 1/* Type 1 goes here */ #define LLC_DEST_CONN 2/* Type 2 goes here */
include/net/llc_conn.h +1 -0
@@ -77,6 +77,7 @@ struct llc_sock {received and caused sending FRMR. Used for resending FRMR */ u32 cmsg_flags; +struct hlist_node dev_hash_node; };static inline struct llc_sock *llc_sk (const struct sock *sk)
net/llc/llc_conn.c +9 -1
@@ -682,10 +682,15 @@ static int llc_find_offset(int state, int ev_type)*/ void llc_sap_add_socket (struct llc_sap *sap,struct sock *sk) { +struct llc_sock *llc =llc_sk (sk); +struct hlist_head *dev_hb =llc_sk_dev_hash (sap, llc->dev->ifindex); +llc_sap_hold (sap); -spin_lock_bh (&sap->sk_lock);llc_sk (sk)->sap = sap; + +spin_lock_bh (&sap->sk_lock);sk_nulls_add_node_rcu (sk, &sap->sk_list); +hlist_add_head (&llc->dev_hash_node, dev_hb);spin_unlock_bh (&sap->sk_lock); }
@@ -699,8 +704,11 @@ void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk)*/ void llc_sap_remove_socket (struct llc_sap *sap,struct sock *sk) { +struct llc_sock *llc =llc_sk (sk); +spin_lock_bh (&sap->sk_lock);sk_nulls_del_node_init_rcu (sk); +hlist_del (&llc->dev_hash_node);spin_unlock_bh (&sap->sk_lock);llc_sap_put (sap); }
net/llc/llc_sap.c +6 -2
@@ -387,10 +387,14 @@ static void llc_sap_mcast(struct llc_sap *sap, {int i =0 , count =256 /sizeof (struct sock *);struct sock *sk, *stack[count]; -struct hlist_nulls_node *node; +struct hlist_node *node; +struct llc_sock *llc; +struct hlist_head *dev_hb =llc_sk_dev_hash (sap, skb->dev->ifindex);spin_lock_bh (&sap->sk_lock); -sk_nulls_for_each_rcu (sk, node, &sap->sk_list) { +hlist_for_each_entry (llc, node, dev_hb, dev_hash_node) { + + sk = &llc->sk;if (!llc_mcast_match (sap, laddr, skb, sk))continue ;
Signature · 1 line
1.5.6.5
PATCH v2 7/9 llc: replace the socket list with a local address based hash
In reply to Octavian PurdilaFor the cases where a lot of interfaces are used in conjunction with a lot of LLC sockets bound to the same SAP, the iteration of the socket list becomes prohibitively expensive.
Replacing the list with a a local address based hash significantly improves the bind and listener lookup operations as well as the datagram delivery.
Connected sockets delivery is also improved, but this patch does not address the case where we have lots of sockets with the same local address connected to different remote addresses.
--- include/net/llc.h | 20 ++++++++++++++- net/llc/llc_conn.c | 68 +++++++++++++++++++++++++++++++++++++-------------- net/llc/llc_core.c | 5 ++- net/llc/llc_proc.c | 44 +++++++++++++++++++++++---------- net/llc/llc_sap.c | 11 +++++++- 5 files changed, 111 insertions(+), 37 deletions(-)
include/net/llc.h +19 -1
@@ -17,6 +17,8 @@#include <linux/list.h> #include <linux/spinlock.h> #include <linux/rculist_nulls.h> +#include <linux/hash.h> +#include <linux/jhash.h> #include <asm/atomic.h>
@@ -35,6 +37,9 @@ struct llc_addr {#define LLC_SK_DEV_HASH_BITS 6#define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS) +#define LLC_SK_LADDR_HASH_BITS 6 +#define LLC_SK_LADDR_HASH_ENTRIES (1<<LLC_SK_LADDR_HASH_BITS) +/** * struct llc_sap - Defines the SAP component *
@@ -58,7 +63,7 @@ struct llc_sap {struct llc_addr laddr;struct list_head node;spinlock_t sk_lock; -struct hlist_nulls_head sk_list; +struct hlist_nulls_head sk_laddr_hash[LLC_SK_LADDR_HASH_ENTRIES ];struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES ]; };
@@ -68,6 +73,19 @@ struct hlist_head *llc_sk_dev_hash(struct llc_sap *sap, int ifindex)return &sap->sk_dev_hash[ifindex %LLC_SK_DEV_HASH_ENTRIES ]; } +static inline +u32 llc_sk_laddr_hashfn (struct llc_sap *sap,const struct llc_addr *laddr) +{ +return hash_32 (jhash (laddr->mac,sizeof (laddr->mac),0 ), +LLC_SK_LADDR_HASH_BITS ); +} + +static inline +struct hlist_nulls_head *llc_sk_laddr_hash (struct llc_sap *sap, +const struct llc_addr *laddr) +{ +return &sap->sk_laddr_hash[llc_sk_laddr_hashfn (sap, laddr)]; +}#define LLC_DEST_INVALID 0/* Invalid LLC PDU type */ #define LLC_DEST_SAP 1/* Type 1 goes here */
net/llc/llc_conn.c +49 -19
130 lines not on this page · raw message
net/llc/llc_core.c +3 -2
@@ -33,12 +33,14 @@ DEFINE_RWLOCK(llc_sap_list_lock);static struct llc_sap *llc_sap_alloc (void ) {struct llc_sap *sap =kzalloc (sizeof (*sap),GFP_ATOMIC ); +int i;if (sap) {/* sap->laddr.mac - leave as a null, it's filled by bind */ sap->state =LLC_SAP_STATE_ACTIVE ;spin_lock_init (&sap->sk_lock); -INIT_HLIST_NULLS_HEAD (&sap->sk_list,0 ); +for (i =0 ; i <LLC_SK_LADDR_HASH_ENTRIES ; i++) +INIT_HLIST_NULLS_HEAD (&sap->sk_laddr_hash[i], i);atomic_set (&sap->refcnt,1 ); }return sap;
@@ -143,7 +145,6 @@ out:*/ void llc_sap_close (struct llc_sap *sap) { -WARN_ON (!hlist_nulls_empty (&sap->sk_list));llc_del_sap (sap);kfree (sap); }
net/llc/llc_proc.c +30 -14
70 lines not on this page · raw message
net/llc/llc_sap.c +10 -1
@@ -321,10 +321,12 @@ static struct sock *llc_lookup_dgram(struct llc_sap *sap, {struct sock *rc;struct hlist_nulls_node *node; +int slot =llc_sk_laddr_hashfn (sap, laddr); +struct hlist_nulls_head *laddr_hb = &sap->sk_laddr_hash[slot];rcu_read_lock_bh (); again: -sk_nulls_for_each_rcu (rc, node, &sap->sk_list) { +sk_nulls_for_each_rcu (rc, node, laddr_hb) {if (llc_dgram_match (sap, laddr, rc)) {/* Extra checks required by SLAB_DESTROY_BY_RCU */ if (unlikely(!atomic_inc_not_zero(&rc->sk_refcnt) ||
@@ -338,6 +340,13 @@ again: } } rc =NULL ; +/* +* if the nulls value we got at the end of this lookup is +* not the expected one, we must restart lookup. +* We probably met an item that was moved to another chain. +*/ +if (unlikely (get_nulls_value (node) != slot)) + goto again; found:rcu_read_unlock_bh ();return rc;
Signature · 1 line
1.5.6.5
PATCH v2 8/9 llc: convert llc_sap_list to RCU
In reply to Octavian Purdila--- include/net/llc.h | 2 +- net/llc/llc_core.c | 43 +++++++++++-------------------------------- net/llc/llc_proc.c | 11 ++++------- 3 files changed, 16 insertions(+), 40 deletions(-)
include/net/llc.h +1 -1
@@ -92,7 +92,7 @@ struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap,#define LLC_DEST_CONN 2/* Type 2 goes here */ extern struct list_head llc_sap_list; -extern rwlock_t llc_sap_list_lock; +extern spinlock_t llc_sap_list_lock;extern int llc_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev);
net/llc/llc_core.c +11 -32
84 lines not on this page · raw message
net/llc/llc_proc.c +4 -7
@@ -32,14 +32,11 @@ static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)static struct sock *llc_get_sk_idx (loff_t pos) { -struct list_head *sap_entry;struct llc_sap *sap;struct sock *sk =NULL ;int i; -list_for_each (sap_entry, &llc_sap_list) { - sap = list_entry(sap_entry, struct llc_sap, node); - +list_for_each_entry_rcu (sap, &llc_sap_list, node) {spin_lock_bh (&sap->sk_lock);for (i =0 ; i <LLC_SK_LADDR_HASH_ENTRIES ; i++) {struct hlist_nulls_head *head = &sap->sk_laddr_hash[i];
@@ -62,7 +59,7 @@ static void *llc_seq_start(struct seq_file *seq, loff_t *pos) {loff_t l = *pos; -read_lock_bh (&llc_sap_list_lock); +rcu_read_lock_bh ();return l ?llc_get_sk_idx (--l) :SEQ_START_TOKEN ; }
@@ -102,7 +99,7 @@ static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)if (sk) goto out;spin_unlock_bh (&sap->sk_lock); -list_for_each_entry_continue (sap, &llc_sap_list, node) { +list_for_each_entry_continue_rcu (sap, &llc_sap_list, node) {spin_lock_bh (&sap->sk_lock); sk =laddr_hash_next (sap,-1 );if (sk)
@@ -122,7 +119,7 @@ static void llc_seq_stop(struct seq_file *seq, void *v)spin_unlock_bh (&sap->sk_lock); } -read_unlock_bh (&llc_sap_list_lock); +rcu_read_unlock_bh (); }static int llc_seq_socket_show (struct seq_file *seq,void *v)
Signature · 1 line
1.5.6.5
PATCH v2 9/9 llc: remove unused APIs (which should be private anyway)
In reply to Octavian PurdilaRemove the list & lock from the exported API - it is not used anywhere in the tree and most operations should be covered by llc_sap_open(), llc_sap_close() and llc_sap_find().
--- include/net/llc.h | 1 - net/llc/llc_core.c | 4 +--- 2 files changed, 1 insertions(+), 4 deletions(-)
include/net/llc.h +0 -1
@@ -92,7 +92,6 @@ struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap,#define LLC_DEST_CONN 2/* Type 2 goes here */ extern struct list_head llc_sap_list; -extern spinlock_t llc_sap_list_lock;extern int llc_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev);
net/llc/llc_core.c +1 -3
@@ -23,7 +23,7 @@#include <net/llc.h> LIST_HEAD (llc_sap_list); -DEFINE_SPINLOCK (llc_sap_list_lock); +static DEFINE_SPINLOCK (llc_sap_list_lock);/** * llc_sap_alloc - allocates and initializes sap.
@@ -160,8 +160,6 @@ static void __exit llc_exit(void)module_init (llc_init);module_exit (llc_exit); -EXPORT_SYMBOL (llc_sap_list); -EXPORT_SYMBOL (llc_sap_list_lock);EXPORT_SYMBOL (llc_sap_find);EXPORT_SYMBOL (llc_sap_open);EXPORT_SYMBOL (llc_sap_close);
Signature · 1 line
1.5.6.5
Quoted 11 lines · Octavian Purdila
This patch modifies the LLC code to scale the socket lookup code for a large number of interfaces and large number of sockets bound to the same SAP. We use it for STP traffic generation from a large number of virtual STP ports, via virtual network interfaces.
In the process we converted the socket lookup code and sap list to use RCU. It also contains some general cleanups (use
dev_hard_headerinstead of handcrafting the headers) and enhancements (LLC_OPT_PKTINFO).This is the 2nd version. Changes from the previous version:
Quoted 9 lines
- added
SO_BINDTODEVICEsupport for faster bind operations
- converted the socket lookup code and sap list to RCU
- optimized multicast delivery ala Eric
- remove some unused APIs (which should be private anyway)Many thanks to Eric Dumazet for his continuous guidance and to Jarek Poplawski for spotting a locking bug in the previous version.
Pretty impressive work Octavian !
My only concerns (before drinking my coffee, I might be wrong...) are :
1) Patch 7/9 : __llc_lookup_established()
Checking slot number is not enough I am afraid. A socket can be freed, re-allocated, inserted in another sap hash list on _same_ slot number. We dont have this problem with UDP/TCP since we have only
one hash table on machine, but with llc, we might have many sap hash tables.
So before if (llc_estab_match(sap, daddr, laddr, rc)) test, you probably need to check if we found a socket hashed on a different hash table and restart the lookup.
2) the WARN_ON() removal in patch 7/9 :
void llc_sap_close(struct llc_sap *sap)
{
- WARN_ON(!hlist_nulls_empty(&sap->sk_list));
llc_del_sap(sap);
kfree(sap);
}
I believe we should keep the sanity test some time, converted to sk_laddr_hash[] variant.
Thanks
Quoted 31 lines · On Thursday 24 December 2009 10:35:31 you wrote:
Quoted 11 lines · Octavian Purdila
This patch modifies the LLC code to scale the socket lookup code for a large number of interfaces and large number of sockets bound to the same SAP. We use it for STP traffic generation from a large number of virtual STP ports, via virtual network interfaces.
In the process we converted the socket lookup code and sap list to use RCU. It also contains some general cleanups (use
dev_hard_headerinstead of handcrafting the headers) and enhancements (LLC_OPT_PKTINFO).This is the 2nd version. Changes from the previous version:
Quoted 7 lines
- added
SO_BINDTODEVICEsupport for faster bind operations
- converted the socket lookup code and sap list to RCU
- optimized multicast delivery ala Eric
- remove some unused APIs (which should be private anyway)Many thanks to Eric Dumazet for his continuous guidance and to Jarek Poplawski for spotting a locking bug in the previous version.
Pretty impressive work Octavian !
My only concerns (before drinking my coffee, I might be wrong...) are :
1) Patch 7/9 :
__llc_lookup_established()
Checking slot number is not enough I am afraid. A socket can be freed, re-allocated, inserted in another sap hash list on _same_ slot number. We dont have this problem with UDP/TCP since we have only one hash table on machine, but with llc, we might have many sap hash
tables.
Quoted 4 lines
So before if (
llc_estab_match(sap, daddr, laddr, rc)) test, you probably need to check if we found a socket hashed on a different hash table and restart the lookup.
Woudn't the sap check after the the atomic_inc check take care of this?
rcu_read_lock();
again:
sk_nulls_for_each_rcu(rc, node, laddr_hb) {
if (llc_estab_match(sap, daddr, laddr, rc)) {
/* Extra checks required by SLAB_DESTROY_BY_RCU */
if (unlikely(!atomic_inc_not_zero(&rc->sk_refcnt) ||
llc_sk(rc)->sap != sap))
goto again;
if (unlikely(!llc_estab_match(sap, daddr, laddr, rc))) {
sock_put(rc);
continue;
}
goto found;
}
}But, I found a leak issue: if the sap check fails we should sock_put the socket before trying again !
Quoted 11 lines
2) the
WARN_ON()removal in patch 7/9 :void
llc_sap_close(struct llc_sap *sap)
{(quoted diff) +0
-1- WARN_ON(!hlist_nulls_empty(&sap->sk_list)); llc_del_sap(sap); kfree(sap); }I believe we should keep the sanity test some time, converted to
sk_laddr_hash[] variant.
I think adding counter would be necessary for this - to avoid iterating over all the hash buckets. Does that sound ok?
Thanks !
David Miller
maintainerFrom: Octavian Purdila <[email protected]>
Date: Thu, 24 Dec 2009 14:17:02 +0200
Quoted 2 lines
But, I found a leak issue: if the sap check fails we should
sock_putthe socket before trying again !
Octavian, please resubmit your patch series after you've sorted out these issues/leaks/etc.
Thanks a lot!