Skip to contentSkip to conversation

GRE: Add TCP segmentation offload for GRE

PATCH In review Pravin B Shelar 3 participants 5 messages Feb 15, 2013

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 GRE: Add TCP segmentation offload for GRE

Following patch adds GRE protocol offload handler so that skb_gso_segment() can segment GRE packets.
SKB GSO CB is added to keep track of total header length so that skb_segment can push entire header. e.g. in case of GRE, skb_segment need to push inner and outer headers to every segment.
New NETIF_F_GRE_GSO feature is added for devices which support HW GRE TSO offload. Currently none of devices support it therefore GRE GSO always fall backs to software GSO.

---
Fixed according to comments from Jesse and Eric.
v2-v3:
- Use device features to segment inner packet.
- Moved skb_mac_gso_segment to separate patch.
- simplified gre_gso_segment().
- Added NETIF_F_GRE_GSO feature.

v1-v2:
- Factored a MAC layer handler out of skb_gso_segment().
- Eliminated copy operation from gre_gso_segment().
- Refresh header pointer after pskb_may_pull().

---
 include/linux/netdev_features.h |    3 +-
 include/linux/skbuff.h          |   17 ++++++
 net/core/dev.c                  |    1 +
 net/core/ethtool.c              |    1 +
 net/core/skbuff.c               |    6 ++-
 net/ipv4/af_inet.c              |    1 +
 net/ipv4/gre.c                  |  118 +++++++++++++++++++++++++++++++++++++++
 net/ipv4/ip_gre.c               |   83 +++++++++++++++++++++++++--
 net/ipv4/tcp.c                  |    1 +
 net/ipv4/udp.c                  |    3 +-
 net/ipv6/ip6_offload.c          |    1 +
 net/ipv6/udp_offload.c          |    3 +-
 12 files changed, 227 insertions(+), 11 deletions(-)
include/linux/netdev_features.h +2 -1
index 5ac3212..3dd3934 100644
@@ -41,7 +41,7 @@ enum {
 	NETIF_F_TSO_ECN_BIT,		/* ... TCP ECN support */
 	NETIF_F_TSO6_BIT,		/* ... TCPv6 segmentation */
 	NETIF_F_FSO_BIT,		/* ... FCoE segmentation */
-	NETIF_F_GSO_RESERVED1,		/* ... free (fill GSO_MASK to 8 bits) */
+	NETIF_F_GSO_GRE_BIT,		/* ... GRE with TSO */
 	/**/NETIF_F_GSO_LAST,		/* [can't be last bit, see GSO_MASK] */
 	NETIF_F_GSO_RESERVED2		/* ... free (fill GSO_MASK to 8 bits) */
 		= NETIF_F_GSO_LAST,
@@ -102,6 +102,7 @@ enum {
 #define NETIF_F_VLAN_CHALLENGED	__NETIF_F(VLAN_CHALLENGED)
 #define NETIF_F_RXFCS		__NETIF_F(RXFCS)
 #define NETIF_F_RXALL		__NETIF_F(RXALL)
+#define NETIF_F_GRE_GSO		__NETIF_F(GSO_GRE)
 
 /* Features valid for ethtool to change */
 /* = all defined minus driver/device-class-related */
include/linux/skbuff.h +17 -0
index ca6ee7d..12c8b99 100644
@@ -314,6 +314,8 @@ enum {
 	SKB_GSO_TCPV6 = 1 << 4,
 
 	SKB_GSO_FCOE = 1 << 5,
+
+	SKB_GSO_GRE = 1 << 6,
 };
 
 #if BITS_PER_LONG > 32
@@ -2732,6 +2734,21 @@ static inline struct sec_path *skb_sec_path(struct sk_buff *skb)
 }
 #endif
 
+/* Keeps track of mac header offset relative to skb->head.
+ * It is useful for TSO of Tunneling protocol. e.g. GRE.
+ * For non-tunnel skb it points to skb_mac_header() and for
+ * tunnel skb it points to outer mac header. */
+struct skb_gso_cb {
+	int mac_offset;
+};
+#define SKB_GSO_CB(skb) ((struct skb_gso_cb *)(skb)->cb)
+
+static inline int skb_tnl_header_len(const struct sk_buff *inner_skb)
+{
+	return (skb_mac_header(inner_skb) - inner_skb->head) -
+		SKB_GSO_CB(inner_skb)->mac_offset;
+}
+
 static inline bool skb_is_gso(const struct sk_buff *skb)
 {
 	return skb_shinfo(skb)->gso_size;
net/core/dev.c +1 -0
index 5425e41..a184f24 100644
@@ -2413,6 +2413,7 @@ struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
 			return ERR_PTR(err);
 	}
 
+	SKB_GSO_CB(skb)->mac_offset = skb_headroom(skb);
 	skb_reset_mac_header(skb);
 	skb->mac_len = skb->network_header - skb->mac_header;
 
net/core/ethtool.c +1 -0
index d9d5520..3e9b2c3 100644
@@ -77,6 +77,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN]
 	[NETIF_F_TSO_ECN_BIT] =          "tx-tcp-ecn-segmentation",
 	[NETIF_F_TSO6_BIT] =             "tx-tcp6-segmentation",
 	[NETIF_F_FSO_BIT] =              "tx-fcoe-segmentation",
+	[NETIF_F_GSO_GRE_BIT] =		 "tx-gre-segmentation",
 
 	[NETIF_F_FCOE_CRC_BIT] =         "tx-checksum-fcoe-crc",
 	[NETIF_F_SCTP_CSUM_BIT] =        "tx-checksum-sctp",
net/core/skbuff.c +5 -1
index 6c1ad09..2a3ca33 100644
@@ -2738,6 +2738,7 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
 	unsigned int mss = skb_shinfo(skb)->gso_size;
 	unsigned int doffset = skb->data - skb_mac_header(skb);
 	unsigned int offset = doffset;
+	unsigned int tnl_hlen = skb_tnl_header_len(skb);
 	unsigned int headroom;
 	unsigned int len;
 	int sg = !!(features & NETIF_F_SG);
@@ -2814,7 +2815,10 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
 		skb_set_network_header(nskb, skb->mac_len);
 		nskb->transport_header = (nskb->network_header +
 					  skb_network_header_len(skb));
-		skb_copy_from_linear_data(skb, nskb->data, doffset);
+
+		skb_copy_from_linear_data_offset(skb, -tnl_hlen,
+						 nskb->data - tnl_hlen,
+						 doffset + tnl_hlen);
 
 		if (fskb != skb_shinfo(skb)->frag_list)
 			continue;
net/ipv4/af_inet.c +1 -0
index e6e5d85..e225a4e 100644
@@ -1287,6 +1287,7 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb,
 		       SKB_GSO_UDP |
 		       SKB_GSO_DODGY |
 		       SKB_GSO_TCP_ECN |
+		       SKB_GSO_GRE |
 		       0)))
 		goto out;
 
net/ipv4/gre.c +118 -0

153 lines not on this page · raw message

net/ipv4/ip_gre.c +76 -7

136 lines not on this page · raw message

net/ipv4/tcp.c +1 -0
index 1f0bedb..7a5ba48 100644
@@ -3043,6 +3043,7 @@ struct sk_buff *tcp_tso_segment(struct sk_buff *skb,
 			       SKB_GSO_DODGY |
 			       SKB_GSO_TCP_ECN |
 			       SKB_GSO_TCPV6 |
+			       SKB_GSO_GRE |
 			       0) ||
 			     !(type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))))
 			goto out;
net/ipv4/udp.c +2 -1
index 6791aac..39a5e7a 100644
@@ -2305,7 +2305,8 @@ struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb,
 		/* Packet is from an untrusted source, reset gso_segs. */
 		int type = skb_shinfo(skb)->gso_type;
 
-		if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY) ||
+		if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY |
+				      SKB_GSO_GRE) ||
 			     !(type & (SKB_GSO_UDP))))
 			goto out;
 
net/ipv6/ip6_offload.c +1 -0
index f26f0da..8234c1d 100644
@@ -99,6 +99,7 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
 		     ~(SKB_GSO_UDP |
 		       SKB_GSO_DODGY |
 		       SKB_GSO_TCP_ECN |
+		       SKB_GSO_GRE |
 		       SKB_GSO_TCPV6 |
 		       0)))
 		goto out;
net/ipv6/udp_offload.c +2 -1
index 0c8934a..cf05cf0 100644
@@ -56,7 +56,8 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb,
 		/* Packet is from an untrusted source, reset gso_segs. */
 		int type = skb_shinfo(skb)->gso_type;
 
-		if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY) ||
+		if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY |
+				      SKB_GSO_GRE) ||
 			     !(type & (SKB_GSO_UDP))))
 			goto out;
 
Signature · 1 line
1.7.1
#1 lore raw
Quoted 18 lines · Pravin B Shelar

Following patch adds GRE protocol offload handler so that skb_gso_segment() can segment GRE packets.
SKB GSO CB is added to keep track of total header length so that skb_segment can push entire header. e.g. in case of GRE, skb_segment need to push inner and outer headers to every segment.
New NETIF_F_GRE_GSO feature is added for devices which support HW GRE TSO offload. Currently none of devices support it therefore GRE GSO always fall backs to software GSO.

---
Fixed according to comments from Jesse and Eric.
v2-v3:
- Use device features to segment inner packet.
- Moved skb_mac_gso_segment to separate patch.
- simplified gre_gso_segment().
- Added NETIF_F_GRE_GSO feature.

Quoted 5 lines

v1-v2:
- Factored a MAC layer handler out of skb_gso_segment().
- Eliminated copy operation from gre_gso_segment().
- Refresh header pointer after pskb_may_pull().
---

Seems very good to me, thanks !

The only thing that puzzles me is the ip_select_ident() in ipgre_tunnel_xmit()

Do we care of the IP identifiers being 0, 1, 2, 3, ... on the outer headers ?

Without TSO, we are using 0 IP identifiers (DF being set)

Also if we can't unclone the skb in handle_offloads(), we should increment tx_dropped or tx_errors.

#2 lore raw
Quoted 27 lines · Eric Dumazet
Quoted 18 lines · Pravin B Shelar

Following patch adds GRE protocol offload handler so that skb_gso_segment() can segment GRE packets.
SKB GSO CB is added to keep track of total header length so that skb_segment can push entire header. e.g. in case of GRE, skb_segment need to push inner and outer headers to every segment.
New NETIF_F_GRE_GSO feature is added for devices which support HW GRE TSO offload. Currently none of devices support it therefore GRE GSO always fall backs to software GSO.

---
Fixed according to comments from Jesse and Eric.
v2-v3:
- Use device features to segment inner packet.
- Moved skb_mac_gso_segment to separate patch.
- simplified gre_gso_segment().
- Added NETIF_F_GRE_GSO feature.

Quoted 5 lines

v1-v2:
- Factored a MAC layer handler out of skb_gso_segment().
- Eliminated copy operation from gre_gso_segment().
- Refresh header pointer after pskb_may_pull().
---

Seems very good to me, thanks !

Quoted 8 lines

The only thing that puzzles me is the ip_select_ident() in ipgre_tunnel_xmit()

Do we care of the IP identifiers being 0, 1, 2, 3, ... on the outer headers ?

Without TSO, we are using 0 IP identifiers (DF being set)

right. I will keep id as zero for all cases.

Quoted 3 lines

Also if we can't unclone the skb in handle_offloads(), we should increment tx_dropped or tx_errors.

ok.

Quoted 3 lines
#3 lore raw
In reply to Pravin B Shelar

2013/2/14 Pravin B Shelar <[email protected]>:

Quoted 8 lines

Following patch adds GRE protocol offload handler so that skb_gso_segment() can segment GRE packets.
SKB GSO CB is added to keep track of total header length so that skb_segment can push entire header. e.g. in case of GRE, skb_segment need to push inner and outer headers to every segment.
New NETIF_F_GRE_GSO feature is added for devices which support HW GRE TSO offload. Currently none of devices support it therefore GRE GSO always fall backs to software GSO.

[...]

net/ipv4/ip_gre.c static int ipgre_tunnel_bind_dev(struct net_device *dev) · line 1112

Quoted 12 lines
net/ipv4/ip_gre.c +8 -0
@@ -1044,6 +1102,14 @@ static int ipgre_tunnel_bind_dev(struct net_device *dev)
                mtu = 68;
 
        tunnel->hlen = addend;
+       if (tunnel->parms.o_flags & GRE_SEQ) {
+               /* TCP offload with GRE SEQ is not supported. */
+               dev->features &= ~NETIF_F_GSO_SOFTWARE;
+               dev->hw_features &= ~NETIF_F_GSO_SOFTWARE;
+       } else {
+               dev->features |= NETIF_F_GSO_SOFTWARE;
+               dev->hw_features |= NETIF_F_GSO_SOFTWARE;
+       }

Feature clipping belongs to ndo_fix_features. Here, netdev_update_features() for the tunnel device should be called.

Wishing You Good Night,
Michał Mirosław

#4 lore raw
Quoted 13 lines · Michał Mirosław

2013/2/14 Pravin B Shelar <[email protected]>:

Quoted 8 lines

Following patch adds GRE protocol offload handler so that skb_gso_segment() can segment GRE packets.
SKB GSO CB is added to keep track of total header length so that skb_segment can push entire header. e.g. in case of GRE, skb_segment need to push inner and outer headers to every segment.
New NETIF_F_GRE_GSO feature is added for devices which support HW GRE TSO offload. Currently none of devices support it therefore GRE GSO always fall backs to software GSO.

[...]

Quoted 3 lines
net/ipv4/ip_gre.c +0 -0
@@ -1044,6 +1102,14 @@ static int ipgre_tunnel_bind_dev(struct net_device *dev)
                mtu = 68;
 
Quoted 13 lines

net/ipv4/ip_gre.c static int ipgre_tunnel_bind_dev(struct net_device *dev) · line 1112

Quoted 9 lines
net/ipv4/ip_gre.c +8 -0
        tunnel->hlen = addend;
+       if (tunnel->parms.o_flags & GRE_SEQ) {
+               /* TCP offload with GRE SEQ is not supported. */
+               dev->features &= ~NETIF_F_GSO_SOFTWARE;
+               dev->hw_features &= ~NETIF_F_GSO_SOFTWARE;
+       } else {
+               dev->features |= NETIF_F_GSO_SOFTWARE;
+               dev->hw_features |= NETIF_F_GSO_SOFTWARE;
+       }

Feature clipping belongs to ndo_fix_features. Here, netdev_update_features() for the tunnel device should be called.

Actually no clipping is required. After creating tunnel device features do not change. In short code above is setting features not updating it. I will remove GRE_SEQ case since it is not required and it is less confusing.