tipc: Minor optimizations to name table translation code
Subsystems (3)
PATCH 1/4 tipc: Minor optimizations to name table translation code
From: Allan Stephens <[email protected]>
Optimizes TIPC's name table translation code to avoid unnecessary manipulation of the node address field of the resulting port id when name translation fails. This change is possible because a valid port id cannot have a reference field of zero, so examining the reference only is sufficient to determine if the translation was successful.
--- net/tipc/name_table.c | 4 +--- net/tipc/port.c | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-)
net/tipc/name_table.c +1 -3
@@ -613,8 +613,7 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, }/* -* tipc_nametbl_translate(): Translate tipc_name -> tipc_portid. -* Very time-critical. +* tipc_nametbl_translate - translate name to port id * * Note: on entry 'destnode' is the search domain used during translation; * on exit it passes back the node address of the matching port (if any)
@@ -685,7 +684,6 @@ found: }spin_unlock_bh (&seq->lock); not_found: - *destnode =0 ;read_unlock_bh (&tipc_nametbl_lock);return 0 ; }
net/tipc/port.c +2 -2
@@ -1464,7 +1464,7 @@ int tipc_forward2name(u32 ref,msg_set_destnode (msg, destnode);msg_set_destport (msg, destport); -if (likely (destport || destnode)) { +if (likely (destport)) { p_ptr->sent++;if (likely (destnode == tipc_own_addr))return tipc_port_recv_sections (p_ptr, num_sect, msg_sect);
@@ -1542,7 +1542,7 @@ int tipc_forward_buf2name(u32 ref,skb_push (buf,LONG_H_SIZE );skb_copy_to_linear_data (buf, msg,LONG_H_SIZE );msg_dbg (buf_msg (buf),"PREP:" ); -if (likely (destport || destnode)) { +if (likely (destport)) { p_ptr->sent++;if (destnode == tipc_own_addr)return tipc_port_recv_msg (buf);
Signature · 1 line
1.7.2.1
PATCH 2/4 tipc: Ensure outgoing messages on Ethernet have sufficient headroom
From: Allan Stephens <[email protected]>
Add code to expand the headroom of an outgoing TIPC message if the sk_buff has insufficient room to hold the header for the associated Ethernet device. This change is necessary to ensure that messages TIPC does not create itself (eg. incoming messages that are being routed to another node) do not cause problems, since TIPC has no control over the amount of headroom available in such messages.
--- net/tipc/eth_media.c | 25 +++++++++++++++++-------- 1 files changed, 17 insertions(+), 8 deletions(-)
net/tipc/eth_media.c +17 -8
@@ -72,17 +72,26 @@ static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr, {struct sk_buff *clone;struct net_device *dev; +int delta; clone =skb_clone (buf,GFP_ATOMIC ); -if (clone) { -skb_reset_network_header (clone); - dev = ((struct eth_bearer *)(tb_ptr->usr_handle))->dev; - clone->dev = dev; -dev_hard_header (clone, dev,ETH_P_TIPC , - &dest->dev_addr.eth_addr, - dev->dev_addr, clone->len); -dev_queue_xmit (clone); +if (!clone) +return 0 ; + + dev = ((struct eth_bearer *)(tb_ptr->usr_handle))->dev; + delta = dev->hard_header_len -skb_headroom (buf); + +if ((delta >0 ) && +pskb_expand_head (clone,SKB_DATA_ALIGN (delta),0 ,GFP_ATOMIC )) { +kfree_skb (clone); +return 0 ; } + +skb_reset_network_header (clone); + clone->dev = dev; +dev_hard_header (clone, dev,ETH_P_TIPC , &dest->dev_addr.eth_addr, + dev->dev_addr, clone->len); +dev_queue_xmit (clone);return 0 ; }
Signature · 1 line
1.7.2.1
Re: [PATCH net-next 2/4] tipc: Ensure outgoing messages on Ethernet have sufficient headroom
From: Paul Gortmaker <[email protected]>
Date: Fri, 3 Sep 2010 14:33:40 -0400
Quoted 11 lines
From: Allan Stephens <[email protected]>
Add code to expand the headroom of an outgoing TIPC message if the
sk_buffhas insufficient room to hold the header for the associated Ethernet device. This change is necessary to ensure that messages TIPC does not create itself (eg. incoming messages that are being routed to another node) do not cause problems, since TIPC has no control over the amount of headroom available in such messages.Signed-off-by Allan Stephens <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Applied.
PATCH 3/4 tipc: Optimize handling excess content on incoming messages
In reply to Paul GortmakerFrom: Allan Stephens <[email protected]>
Remove code that trimmed excess trailing info from incoming messages arriving over an Ethernet interface. TIPC now ignores the extra info while the message is being processed by the node, and only trims it off if the message is retransmitted to another node. (This latter step is done to ensure the extra info doesn't cause the sk_buff to exceed the outgoing interface's MTU limit.)
--- net/tipc/eth_media.c | 13 +++---------- net/tipc/net.c | 1 + 2 files changed, 4 insertions(+), 10 deletions(-)
net/tipc/eth_media.c +3 -10
@@ -101,15 +101,12 @@ static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr,* Accept only packets explicitly sent to this node, or broadcast packets; * ignores packets sent using Ethernet multicast, and traffic sent to other * nodes (which can happen if interface is running in promiscuous mode). -* Routine truncates any Ethernet padding/CRC appended to the message, -* and ensures message size matches actual length */ static int recv_msg (struct sk_buff *buf,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev) {struct eth_bearer *eb_ptr = (struct eth_bearer *)pt->af_packet_priv; -u32 size;if (!net_eq (dev_net (dev), &init_net)) {kfree_skb (buf);
@@ -118,13 +115,9 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,if (likely (eb_ptr->bearer)) {if (likely (buf->pkt_type <=PACKET_BROADCAST )) { - size =msg_size ((struct tipc_msg *)buf->data); -skb_trim (buf, size); -if (likely (buf->len == size)) { - buf->next =NULL ; -tipc_recv_msg (buf, eb_ptr->bearer); -return 0 ; - } + buf->next =NULL ; +tipc_recv_msg (buf, eb_ptr->bearer); +return 0 ; } }kfree_skb (buf);
net/tipc/net.c +1 -0
@@ -248,6 +248,7 @@ void tipc_net_route_msg(struct sk_buff *buf)/* Handle message for another node */ msg_dbg (msg,"NET>SEND>: " ); +pskb_trim (buf,msg_size (msg));tipc_link_send (buf, dnode,msg_link_selector (msg)); }
Signature · 1 line
1.7.2.1
David Miller
maintainerRe: [PATCH net-next 3/4] tipc: Optimize handling excess content on incoming messages
From: Paul Gortmaker <[email protected]>
Date: Fri, 3 Sep 2010 14:33:41 -0400
net/tipc/net.c void tipc_net_route_msg(struct sk_buff *buf) · line 253
Quoted 7 lines
net/tipc/net.c +1
-0@@ -248,6 +248,7 @@ void tipc_net_route_msg(struct sk_buff *buf)/* Handle message for another node */ msg_dbg (msg,"NET>SEND>: " ); +pskb_trim (buf,msg_size (msg));tipc_link_send (buf, dnode,msg_link_selector (msg)); }
1) pskb_trim() can fail, you need to check the return value and act appropriately.
2) pskb_trim() can change all of the packet data pointers, so after you call it you need to reload any pointers to the packet data area. At a minimum, you woull need to reload 'msg' in this code snippet.
Otherwise 'msg' can point to freed up memory after the call.
Re: [PATCH net-next 3/4] tipc: Optimize handling excess content on incoming messages
Quoted 14 lines · [Re: [PATCH net-next 3/4] tipc: Optimize handling excess content on incoming…
From: Paul Gortmaker <[email protected]>
Date: Fri, 3 Sep 2010 14:33:41 -0400Review void tipc_net_route_msg(struct sk_buff *buf) · line 253
Quoted 7 lines
(quoted diff) +1
-0@@ -248,6 +248,7 @@ void tipc_net_route_msg(struct sk_buff *buf) /* Handle message for another node */ msg_dbg(msg, "NET>SEND>: "); + pskb_trim(buf, msg_size(msg)); tipc_link_send(buf, dnode, msg_link_selector(msg)); }1)
pskb_trim()can fail, you need to check the return value and act appropriately.
Quoted 6 lines
2)
pskb_trim()can change all of the packet data pointers, so after you call it you need to reload any pointers to the packet data area. At a minimum, you woull need to reload 'msg' in this code snippet.Otherwise 'msg' can point to freed up memory after the call.
Looking at it again, it isn't clear to me why this change switched over to using pskb_trim in the 1st place. The rework below just stays with the simpler skb_trim that it was using previously.
Thanks,
Paul.
Quoted 1 line
From
3a93344bd2cad3142c81f0304fdb28404c0d7ff1Mon Sep 17 00:00:00 2001
From: Allan Stephens <[email protected]>
Date: Wed, 8 Sep 2010 10:30:42 -0400
Subject: [PATCH] tipc: Optimize handling excess content on incoming messages
Remove code that trimmed excess trailing info from incoming messages arriving over an Ethernet interface. TIPC now ignores the extra info while the message is being processed by the node, and only trims it off if the message is retransmitted to another node. (This latter step is done to ensure the extra info doesn't cause the sk_buff to exceed the outgoing interface's MTU limit.) The outgoing buffer is guaranteed to be linear.
---
V2: maintain skb_trim usage; dont invoke pskb_trim needlessly
net/tipc/eth_media.c | 13 +++---------- net/tipc/net.c | 1 + 2 files changed, 4 insertions(+), 10 deletions(-)
net/tipc/eth_media.c +3 -10
@@ -101,15 +101,12 @@ static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr,* Accept only packets explicitly sent to this node, or broadcast packets; * ignores packets sent using Ethernet multicast, and traffic sent to other * nodes (which can happen if interface is running in promiscuous mode). -* Routine truncates any Ethernet padding/CRC appended to the message, -* and ensures message size matches actual length */ static int recv_msg (struct sk_buff *buf,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev) {struct eth_bearer *eb_ptr = (struct eth_bearer *)pt->af_packet_priv; -u32 size;if (!net_eq (dev_net (dev), &init_net)) {kfree_skb (buf);
@@ -118,13 +115,9 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,if (likely (eb_ptr->bearer)) {if (likely (buf->pkt_type <=PACKET_BROADCAST )) { - size =msg_size ((struct tipc_msg *)buf->data); -skb_trim (buf, size); -if (likely (buf->len == size)) { - buf->next =NULL ; -tipc_recv_msg (buf, eb_ptr->bearer); -return 0 ; - } + buf->next =NULL ; +tipc_recv_msg (buf, eb_ptr->bearer); +return 0 ; } }kfree_skb (buf);
net/tipc/net.c +1 -0
@@ -248,6 +248,7 @@ void tipc_net_route_msg(struct sk_buff *buf)/* Handle message for another node */ msg_dbg (msg,"NET>SEND>: " ); +skb_trim (buf,msg_size (msg));tipc_link_send (buf, dnode,msg_link_selector (msg)); }
Signature · 1 line
1.7.2.1
Re: [PATCH net-next 3/4] tipc: Optimize handling excess content on incoming messages
From: Paul Gortmaker <[email protected]>
Date: Wed, 8 Sep 2010 19:31:24 -0400
Quoted 10 lines
Subject: [PATCH] tipc: Optimize handling excess content on incoming messages
Remove code that trimmed excess trailing info from incoming messages arriving over an Ethernet interface. TIPC now ignores the extra info while the message is being processed by the node, and only trims it off if the message is retransmitted to another node. (This latter step is done to ensure the extra info doesn't cause the
sk_buffto exceed the outgoing interface's MTU limit.) The outgoing buffer is guaranteed to be linear.
Quoted 2 lines
Signed-off-by Allan Stephens <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Applied, thanks.
PATCH 4/4 tipc: Fix misleading error code when enabling Ethernet bearers
In reply to Paul GortmakerFrom: Allan Stephens <[email protected]>
Cause TIPC to return EAGAIN if it is unable to enable a new Ethernet bearer because one or more recently disabled Ethernet bearers are temporarily consuming resources during shut down. (The previous error code, EDQUOT, is now returned only if all available Ethernet bearer data structures are fully enabled at the time the request to enable an additional bearer is received.)
--- net/tipc/eth_media.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
net/tipc/eth_media.c +10 -0
@@ -135,6 +135,16 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)struct eth_bearer *eb_ptr = ð_bearers[0 ];struct eth_bearer *stop = ð_bearers[MAX_ETH_BEARERS ];char *driver_name =strchr ((const char *)tb_ptr->name,':' ) +1 ; +int pending_dev =0 ; + +/* Find unused Ethernet bearer structure */ + +while (eb_ptr->dev) { +if (!eb_ptr->bearer) + pending_dev++; +if (++eb_ptr == stop) +return pending_dev ? -EAGAIN : -EDQUOT ; + }/* Find device with specified name */
Signature · 1 line
1.7.2.1
Re: [PATCH net-next 4/4] tipc: Fix misleading error code when enabling Ethernet bearers
From: Paul Gortmaker <[email protected]>
Date: Fri, 3 Sep 2010 14:33:42 -0400
Quoted 11 lines
From: Allan Stephens <[email protected]>
Cause TIPC to return EAGAIN if it is unable to enable a new Ethernet bearer because one or more recently disabled Ethernet bearers are temporarily consuming resources during shut down. (The previous error code, EDQUOT, is now returned only if all available Ethernet bearer data structures are fully enabled at the time the request to enable an additional bearer is received.)
Signed-off-by Allan Stephens <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Applied.
From: Paul Gortmaker <[email protected]>
Date: Fri, 3 Sep 2010 14:33:39 -0400
Quoted 10 lines
From: Allan Stephens <[email protected]>
Optimizes TIPC's name table translation code to avoid unnecessary manipulation of the node address field of the resulting port id when name translation fails. This change is possible because a valid port id cannot have a reference field of zero, so examining the reference only is sufficient to determine if the translation was successful.
Signed-off-by Allan Stephens <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Applied.