netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 2/2] gre: add GSO support
@ 2012-09-14  7:25 Eric Dumazet
  2012-09-14 17:12 ` Maciej Żenczykowski
  2012-09-19 19:41 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2012-09-14  7:25 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Maciej Żenczykowski

From: Eric Dumazet <edumazet@google.com>

Add GSO support to GRE tunnels.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Maciej Żenczykowski <maze@google.com>
---
 net/ipv4/ip_gre.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index b062a98..f233c1d 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -745,6 +745,10 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
 	__be32 dst;
 	int    mtu;
 
+	if (skb->ip_summed == CHECKSUM_PARTIAL &&
+	    skb_checksum_help(skb))
+		goto tx_error;
+
 	if (dev->type == ARPHRD_ETHER)
 		IPCB(skb)->flags = 0;
 
@@ -1296,6 +1300,11 @@ static void ipgre_dev_free(struct net_device *dev)
 	free_netdev(dev);
 }
 
+#define GRE_FEATURES (NETIF_F_SG |		\
+		      NETIF_F_FRAGLIST |	\
+		      NETIF_F_HIGHDMA |		\
+		      NETIF_F_HW_CSUM)
+
 static void ipgre_tunnel_setup(struct net_device *dev)
 {
 	dev->netdev_ops		= &ipgre_netdev_ops;
@@ -1309,6 +1318,9 @@ static void ipgre_tunnel_setup(struct net_device *dev)
 	dev->addr_len		= 4;
 	dev->features		|= NETIF_F_NETNS_LOCAL;
 	dev->priv_flags		&= ~IFF_XMIT_DST_RELEASE;
+
+	dev->features		|= GRE_FEATURES;
+	dev->hw_features	|= GRE_FEATURES;
 }
 
 static int ipgre_tunnel_init(struct net_device *dev)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 2/2] gre: add GSO support
  2012-09-14  7:25 [PATCH net-next 2/2] gre: add GSO support Eric Dumazet
@ 2012-09-14 17:12 ` Maciej Żenczykowski
  2012-09-14 17:45   ` Eric Dumazet
  2012-09-19 19:41 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Maciej Żenczykowski @ 2012-09-14 17:12 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David Miller, netdev

Thanks!

So I'm guessing it should be easy to add support like this to IPIP and
SIT now as well
(not sure if they're missing, but I'd assume so)?

On Fri, Sep 14, 2012 at 12:25 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> Add GSO support to GRE tunnels.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Maciej Żenczykowski <maze@google.com>
> ---
>  net/ipv4/ip_gre.c |   12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
> index b062a98..f233c1d 100644
> --- a/net/ipv4/ip_gre.c
> +++ b/net/ipv4/ip_gre.c
> @@ -745,6 +745,10 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
>         __be32 dst;
>         int    mtu;
>
> +       if (skb->ip_summed == CHECKSUM_PARTIAL &&
> +           skb_checksum_help(skb))
> +               goto tx_error;
> +
>         if (dev->type == ARPHRD_ETHER)
>                 IPCB(skb)->flags = 0;
>
> @@ -1296,6 +1300,11 @@ static void ipgre_dev_free(struct net_device *dev)
>         free_netdev(dev);
>  }
>
> +#define GRE_FEATURES (NETIF_F_SG |             \
> +                     NETIF_F_FRAGLIST |        \
> +                     NETIF_F_HIGHDMA |         \
> +                     NETIF_F_HW_CSUM)
> +
>  static void ipgre_tunnel_setup(struct net_device *dev)
>  {
>         dev->netdev_ops         = &ipgre_netdev_ops;
> @@ -1309,6 +1318,9 @@ static void ipgre_tunnel_setup(struct net_device *dev)
>         dev->addr_len           = 4;
>         dev->features           |= NETIF_F_NETNS_LOCAL;
>         dev->priv_flags         &= ~IFF_XMIT_DST_RELEASE;
> +
> +       dev->features           |= GRE_FEATURES;
> +       dev->hw_features        |= GRE_FEATURES;
>  }
>
>  static int ipgre_tunnel_init(struct net_device *dev)
>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 2/2] gre: add GSO support
  2012-09-14 17:12 ` Maciej Żenczykowski
@ 2012-09-14 17:45   ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2012-09-14 17:45 UTC (permalink / raw)
  To: Maciej Żenczykowski; +Cc: David Miller, netdev

On Fri, 2012-09-14 at 10:12 -0700, Maciej Żenczykowski wrote:
> Thanks!
> 
> So I'm guessing it should be easy to add support like this to IPIP and
> SIT now as well
> (not sure if they're missing, but I'd assume so)?

Yes, absolutely.

I was also playing adding GRO support to tunnels.

Here the prototype patch I currently have, it gives very nice speedups

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index b062a98..ca6ab66 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -589,6 +589,65 @@ ipgre_ecn_encapsulate(u8 tos, const struct iphdr *old_iph, struct sk_buff *skb)
 	return INET_ECN_encapsulate(tos, inner);
 }
 
+static void tunnel_prequeue(struct ip_tunnel *tunnel, struct sk_buff *skb)
+{
+	unsigned long flags;
+	const struct iphdr *iph;
+
+	if (skb_cloned(skb)) {
+		netif_rx(skb);
+		return;
+	}
+	if (!pskb_may_pull(skb, sizeof(*iph)) ||
+	    skb_queue_len(&tunnel->napi_skbs) > 1000) {
+drop:
+		atomic_long_inc(&tunnel->dev->rx_dropped);
+		kfree_skb(skb);
+		return;
+	}
+	iph = ip_hdr(skb);
+	if (*(u8 *)iph == 0x45 &&
+	    iph->protocol == IPPROTO_TCP &&
+	    skb->ip_summed == CHECKSUM_NONE) {
+		__skb_pull(skb, sizeof(*iph));
+
+		skb->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
+					       skb->len, IPPROTO_TCP, 0);
+		if (__skb_checksum_complete(skb))
+			goto drop;
+
+		__skb_push(skb, sizeof(*iph));
+	}
+
+	spin_lock_irqsave(&tunnel->napi_skbs.lock, flags);
+
+	__skb_queue_tail(&tunnel->napi_skbs, skb);
+	if (skb_queue_len(&tunnel->napi_skbs) == 1)
+		napi_schedule(&tunnel->napi);
+
+	spin_unlock_irqrestore(&tunnel->napi_skbs.lock, flags);
+}
+
+static int tunnel_napi_poll(struct napi_struct *napi, int budget)
+{
+	struct ip_tunnel *tunnel = container_of(napi, struct ip_tunnel, napi);
+	struct sk_buff *skb;
+	int work_done = 0;
+
+	while (work_done < budget) {
+		skb = skb_dequeue(&tunnel->napi_skbs);
+		if (!skb)
+			break;
+		skb->next = NULL;
+		napi_gro_receive(napi, skb);
+		work_done++;
+	}
+
+	if (work_done < budget)
+		napi_complete(napi);
+	return work_done;
+}
+
 static int ipgre_rcv(struct sk_buff *skb)
 {
 	const struct iphdr *iph;
@@ -714,8 +773,7 @@ static int ipgre_rcv(struct sk_buff *skb)
 		skb_reset_network_header(skb);
 		ipgre_ecn_decapsulate(iph, skb);
 
-		netif_rx(skb);
-
+		tunnel_prequeue(tunnel, skb);
 		rcu_read_unlock();
 		return 0;
 	}
@@ -745,6 +803,10 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
 	__be32 dst;
 	int    mtu;
 
+	if (skb->ip_summed == CHECKSUM_PARTIAL &&
+	    skb_checksum_help(skb))
+		goto tx_error;
+
 	if (dev->type == ARPHRD_ETHER)
 		IPCB(skb)->flags = 0;
 
@@ -1292,10 +1354,19 @@ static const struct net_device_ops ipgre_netdev_ops = {
 
 static void ipgre_dev_free(struct net_device *dev)
 {
+	struct ip_tunnel *tunnel = netdev_priv(dev);
+
+	netif_napi_del(&tunnel->napi);
+	skb_queue_purge(&tunnel->napi_skbs);
 	free_percpu(dev->tstats);
 	free_netdev(dev);
 }
 
+#define GRE_FEATURES (NETIF_F_SG |		\
+		      NETIF_F_FRAGLIST |	\
+		      NETIF_F_HIGHDMA |		\
+		      NETIF_F_HW_CSUM)
+
 static void ipgre_tunnel_setup(struct net_device *dev)
 {
 	dev->netdev_ops		= &ipgre_netdev_ops;
@@ -1309,6 +1380,9 @@ static void ipgre_tunnel_setup(struct net_device *dev)
 	dev->addr_len		= 4;
 	dev->features		|= NETIF_F_NETNS_LOCAL;
 	dev->priv_flags		&= ~IFF_XMIT_DST_RELEASE;
+
+	dev->features		|= GRE_FEATURES;
+	dev->hw_features	|= GRE_FEATURES;
 }
 
 static int ipgre_tunnel_init(struct net_device *dev)
@@ -1340,7 +1414,9 @@ static int ipgre_tunnel_init(struct net_device *dev)
 	dev->tstats = alloc_percpu(struct pcpu_tstats);
 	if (!dev->tstats)
 		return -ENOMEM;
-
+	skb_queue_head_init(&tunnel->napi_skbs);
+	netif_napi_add(dev, &tunnel->napi, tunnel_napi_poll, 64);
+	napi_enable(&tunnel->napi);
 	return 0;
 }
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 2/2] gre: add GSO support
  2012-09-14  7:25 [PATCH net-next 2/2] gre: add GSO support Eric Dumazet
  2012-09-14 17:12 ` Maciej Żenczykowski
@ 2012-09-19 19:41 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2012-09-19 19:41 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, maze

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 14 Sep 2012 09:25:33 +0200

> From: Eric Dumazet <edumazet@google.com>
> 
> Add GSO support to GRE tunnels.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Maciej Żenczykowski <maze@google.com>

Also applied, thanks again.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-09-19 19:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-14  7:25 [PATCH net-next 2/2] gre: add GSO support Eric Dumazet
2012-09-14 17:12 ` Maciej Żenczykowski
2012-09-14 17:45   ` Eric Dumazet
2012-09-19 19:41 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).