IPsec performance improvements (discussion base for the IPsec performance BoF)
Subsystems (8)
Steffen Klassert
maintainerRFC PATCH 5/13 xfrm: Add callbacks for IPsec GSO offloading
In reply to Steffen KlassertThis patch prepares struct xfrm_type for IPsec GSO offloading by adding a encap() callback for encapsulation and a output_tail() callback to do the crypto operations after the return from the GSO layer. We need the output_tail() callback to handle async crypto operations.
--- include/net/xfrm.h | 2 ++ 1 file changed, 2 insertions(+)
include/net/xfrm.h +2 -0
@@ -375,6 +375,8 @@ struct xfrm_type {void (*destructor)(struct xfrm_state *);int (*input)(struct xfrm_state *,struct sk_buff *skb);int (*output)(struct xfrm_state *,struct sk_buff *pskb); +int (*output_tail)(struct xfrm_state *x,struct sk_buff *skb); +void (*encap)(struct xfrm_state *x,struct sk_buff *skb);int (*reject)(struct xfrm_state *,struct sk_buff *,const struct flowi *);int (*hdr_offset)(struct xfrm_state *,struct sk_buff *,u8 **);
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 6/13 net: Add xfrm offload callbacks to struct net_device
In reply to Steffen KlassertThis patch adds the callbacks we need for IPsec GSO and maybe also for IPsec hardware offload.
--- include/linux/netdevice.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/netdevice.h +9 -0
@@ -778,6 +778,12 @@ static inline bool netdev_phys_item_id_same(struct netdev_phys_item_id *a,typedef u16 (*select_queue_fallback_t )(struct net_device *dev,struct sk_buff *skb); +struct xfrmdev_ops { +int (*xdo_dev_encap) (struct sk_buff *skb); +int (*xdo_dev_prepare) (struct sk_buff *skb); +int (*xdo_dev_validate) (struct sk_buff *skb); +void (*xdo_dev_resume) (struct sk_buff *skb,int err); +};/* * This structure defines the management hooks for network devices.
@@ -1625,6 +1631,9 @@ struct net_device {#ifdef CONFIG_NET_L3_MASTER_DEV const struct l3mdev_ops *l3mdev_ops;#endif +#ifdef CONFIG_XFRM +const struct xfrmdev_ops *xfrmdev_ops; +#endif const struct header_ops *header_ops;
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 8/13 esp4: Add a software GSO codepath.
In reply to Steffen KlassertThis patch adds an esp4_gso_segment() callback and registers functions for the new ESP encapsulation and crypto callbacks.
The work to get transport mode ready was done by
Sowmini Varadhan <[email protected]>
--- include/linux/skbuff.h | 3 +- net/ipv4/af_inet.c | 1 + net/ipv4/esp4.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++-- net/ipv4/esp4_offload.c | 85 +++++++++++++++++++++++++++++++++++++++++++++ net/ipv4/tcp_offload.c | 1 + 5 files changed, 178 insertions(+), 4 deletions(-)
include/linux/skbuff.h +2 -1
@@ -724,7 +724,8 @@ struct sk_buff { __u8 inner_protocol_type:1; __u8 remcsum_offload:1; __u8 xfrm_gro:1; -/* 2 or 4 bit hole */ + __u8 hw_xfrm:1; +/* 1 or 3 bit hole */ #ifdef CONFIG_NET_SCHED __u16 tc_index;/* traffic control index */
net/ipv4/af_inet.c +1 -0
@@ -1220,6 +1220,7 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb,SKB_GSO_UDP_TUNNEL |SKB_GSO_UDP_TUNNEL_CSUM |SKB_GSO_TUNNEL_REMCSUM | +SKB_GSO_ESP | 0))) goto out;
net/ipv4/esp4.c +89 -3
138 lines not on this page · raw message
net/ipv4/esp4_offload.c +85 -0
95 lines not on this page · raw message
net/ipv4/tcp_offload.c +1 -0
@@ -97,6 +97,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,SKB_GSO_UDP_TUNNEL |SKB_GSO_UDP_TUNNEL_CSUM |SKB_GSO_TUNNEL_REMCSUM | +SKB_GSO_ESP | 0) || !(type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))) goto out;
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 10/13 xfrm: Add basic infrastructure for IPsec device offloading
In reply to Steffen KlassertThis patch fills the IPsec device offloading callbacks for software GSO.
We handle async crypto with the xfrm_dev_resume() function. This tries to do a direct call to dev_hard_start_xmit(). If the netdevice is busy, we defere the transmit to the NET_TX_SOFTIRQ softirq.
--- include/linux/netdevice.h | 4 + net/core/dev.c | 1 + net/xfrm/xfrm_device.c | 207 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+)
include/linux/netdevice.h +4 -0
@@ -2679,6 +2679,10 @@ struct softnet_data {struct Qdisc **output_queue_tailp;struct sk_buff *completion_queue; +#ifdef CONFIG_XFRM +struct sk_buff_head xfrm_backlog; +#endif +#ifdef CONFIG_RPS /* Elements below can be accessed between CPUs for RPS */ struct call_single_data csd____cacheline_aligned_in_smp ;
net/core/dev.c +1 -0
@@ -8078,6 +8078,7 @@ static int __init net_dev_init(void)skb_queue_head_init (&sd->input_pkt_queue);skb_queue_head_init (&sd->process_queue); +skb_queue_head_init (&sd->xfrm_backlog);INIT_LIST_HEAD (&sd->poll_list); sd->output_queue_tailp = &sd->output_queue;#ifdef CONFIG_RPS
net/xfrm/xfrm_device.c +207 -0
218 lines not on this page · raw message
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 12/13 crypto: Make the page handling of hash walk compatible to networking.
In reply to Steffen KlassertThe network layer tries to allocate high order pages for skb_buff fragments, this leads to problems if we pass such a buffer to crypto because crypto assumes to have always order null pages in the scatterlists.
This was not a problem so far, bacause the network stack linearized all buffers before passing them to crypto. Due to a recent change to IPsec "esp: Avoid skb_cow_data whenever possible" the linearization is avoided in most of the cases what made this incompatibility visible.
--- crypto/ahash.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
crypto/ahash.c +1 -4
@@ -44,8 +44,7 @@ static int hash_walk_next(struct crypto_hash_walk *walk) {unsigned int alignmask = walk->alignmask;unsigned int offset = walk->offset; -unsigned int nbytes =min (walk->entrylen, - ((unsigned int )(PAGE_SIZE )) - offset); +unsigned int nbytes = walk->entrylen;if (walk->flags &CRYPTO_ALG_ASYNC ) walk->data =kmap (walk->pg);
@@ -91,8 +90,6 @@ int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err) walk->offset =ALIGN (walk->offset, alignmask +1 ); walk->data += walk->offset; - nbytes =min (nbytes, - ((unsigned int )(PAGE_SIZE )) - walk->offset); walk->entrylen -= nbytes;return nbytes;
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 1/1 IPsec performance improvements (discussion base for the IPsec performance BoF)
This patchset adds some performance improvements for IPsec. It is a early stage RFC version and still contains bugs. I post this now just to have a discussion base for the IPsec performance BoF at the netdev conference next week.
The patchset adds a GRO/GSO codepath for IPsec and tries to avoid the linearization of the buffers whenever possible.
The GRO part seems to work well. GSO and avoiding linearization still have problems, in particular with async crypto operations.
Below are some performance numbers.
Transport mode (measured by Sowmini Varadhan):
Baseline:
2.6 Gbps ESP-NULL
2.17 Gbps AES-GCM-256
Avoid frame copy + GSO/GRO:
8 Gbps ESP-NULL
4.2 Gbps AES-GCM-256
Forwarding with tunnel mode (measured by myself):
Baseline:
3.63 Gbps prcypt(echainiv(authenc(hmac(sha1-ssse3),cbc-aes-aesni)))
Avoid frame copy + GSO/GRO:
4.33 Gbps pcrypt(echainiv(authenc(hmac(sha1-ssse3),cbc-aes-aesni)))
I used the following cpu bindings for the pcrypt setup:
---------- TCP ---------- ESP Tunnel --------- TCP ---------- |iperf -c|------->|IPsec TX|---------------->|IPsec RX|------->|iperf -s| ---------- ---------- ---------- ----------
cpu0 RX | | RX | | cpu1 | | TX | | TX cpu2 | crypto | | crypto | cpu3 | crypto | | crypto | cpu4 | crypto | | crypto | cpu5 | crypto | | crypto |
Packet forwarding is done with four machines.
The crypto operations are isolated from the networking path. Packets traverse the stack as follows:
- Packet is received on cpu0 (irqs pinned).
- cpu0 enqueues the crypto request to a pcrypt parallelization queue.
- Crypto is done on cpu 2-5, crypto requests are pinned round robin to the cpus. pcrypt ensures to keep the requests in the right order.
- After crypto is done, the requests are queued to a pcrypt serialization queue.
- cpu1 gets a callback from the crypto layer and does the final TX path.
Steffen Klassert
maintainerRFC PATCH 1/13 net: allow to leave the buffer fragmented in skb_cow_data()
From: Mathias Krause <[email protected]>
Do not linearize the buffer per se but only if we're expected to expand the tail. All callers can handle fragmented buffers and even expect them!
Not linearizing the buffer leads to a small performance improvement for the IPsec receive path in case the network driver passed us a fragmented buffer.
With this patch applied I was able to increase the throughput of an IPsec gateway from 7.12 Gbit/s to 7.28 Gbit/s.
--- net/core/skbuff.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
net/core/skbuff.c +18 -11
@@ -3445,7 +3445,7 @@ EXPORT_SYMBOL_GPL(skb_to_sgvec);* * If @tailbits is given, make sure that there is space to write @tailbits * bytes of data beyond current end of socket buffer. @trailer will be -* set to point to the skb in which this space begins. +* linearized and set to point to the skb in which this space begins. * * The number of scatterlist elements required to completely map the * COW'd and extended socket buffer will be returned.
@@ -3456,11 +3456,10 @@ int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer)int elt;struct sk_buff *skb1, **skb_p; -/* If skb is cloned or its head is paged, reallocate -* head pulling out all the pages (pages are considered not writable -* at the moment even if they are anonymous). +/* If skb is cloned reallocate head pulling out all the pages (pages are +* considered not writable at the moment even if they are anonymous). */ -if ((skb_cloned (skb) ||skb_shinfo (skb)->nr_frags) && +if (skb_cloned (skb) &&__pskb_pull_tail (skb,skb_pagelen (skb)-skb_headlen (skb)) ==NULL )return -ENOMEM ;
@@ -3471,18 +3470,26 @@ int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer)* good frames. OK, on miss we reallocate and reserve even more * space, 128 bytes is fair. */ -if (skb_tailroom (skb) < tailbits && -pskb_expand_head (skb,0 , tailbits-skb_tailroom (skb)+128 ,GFP_ATOMIC )) -return -ENOMEM ; +if (tailbits) { +if (skb_linearize (skb)) +return -ENOMEM ; + +if (skb_tailroom (skb) < tailbits) { +int ntail = tailbits -skb_tailroom (skb) +128 ; + +if (pskb_expand_head (skb,0 , ntail,GFP_ATOMIC )) +return -ENOMEM ; + } + }/* Voila! */ *trailer = skb; -return 1 ; +return skb_shinfo (skb)->nr_frags +1 ; }/* Misery. We are in troubles, going to mincer fragments... */ - elt =1 ; + elt =skb_shinfo (skb)->nr_frags +1 ; skb_p = &skb_shinfo (skb)->frag_list; copyflag =0 ;
@@ -3534,7 +3541,7 @@ int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer)kfree_skb (skb1); skb1 = skb2; } - elt++; + elt +=skb_shinfo (skb1)->nr_frags +1 ; *trailer = skb1; skb_p = &skb1->next; }
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 2/13 gro: Partly revert "net: gro: allow to build full sized skb"
In reply to Steffen KlassertThis partly reverts the below mentioned patch because on forwarding, such skbs can't be offloaded to a NIC.
This is just a hack to get IPsec GRO for forwarding to work. A real fix may consider the proposed solutions in the original patch, see below.
-------------------------------------------------------------------------
commit 8a29111c7ca68d928dfab58636f3f6acf0ac04f7
Author: Eric Dumazet <[email protected]> Date: Tue Oct 8 09:02:23 2013 -0700
net: gro: allow to build full sized skb
skb_gro_receive() is currently limited to 16 or 17 MSS per GRO skb, typically 24616 bytes, because it fills up to MAX_SKB_FRAGS frags.
It's relatively easy to extend the skb using frag_list to allow more frags to be appended into the last sk_buff.
This still builds very efficient skbs, and allows reaching 45 MSS per skb.
(45 MSS GRO packet uses one skb plus a frag_list containing 2 additional sk_buff)
High speed TCP flows benefit from this extension by lowering TCP stack cpu usage (less packets stored in receive queue, less ACK packets processed)
Forwarding setups could be hurt, as such skbs will need to be linearized, although its not a new problem, as GRO could already provide skbs with a frag_list.
We could make the 65536 bytes threshold a tunable to mitigate this.
(First time we need to linearize skb in skb_needs_linearize(), we could lower the tunable to ~16*1460 so that following skb_gro_receive() calls build smaller skbs)
---------------------------------------------------------------------------
--- net/core/skbuff.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/core/skbuff.c +2 -3
@@ -3224,7 +3224,7 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb)int nr_frags = pinfo->nr_frags + i;if (nr_frags >MAX_SKB_FRAGS ) - goto merge; +return -E2BIG ; offset -= headlen; pinfo->nr_frags = nr_frags;
@@ -3257,7 +3257,7 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb)unsigned int first_offset;if (nr_frags +1 + skbinfo->nr_frags >MAX_SKB_FRAGS ) - goto merge; +return -E2BIG ; first_offset = skb->data - (unsigned char *)page_address(page) +
@@ -3277,7 +3277,6 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb) goto done; } -merge: delta_truesize = skb->truesize;if (offset > headlen) {unsigned int eat = offset - headlen;
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 9/13 esp: Avoid skb_cow_data whenever possible
In reply to Steffen KlassertIf we are allowed to write the buffer and have enough free space on the lineaer part of the buffer, we add the IPsec tailbit to it. If there is no space on the linare part but we are allowed to write, we add a page fragment with the tailbits to the buffer.
With this, we can avoid a linearization of the buffer whenever we are allowed to write on it.
--- include/net/xfrm.h | 2 + net/ipv4/esp4.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 111 insertions(+), 16 deletions(-)
include/net/xfrm.h +2 -0
@@ -217,6 +217,8 @@ struct xfrm_state {/* Last used time */ unsigned long lastused; +struct page_frag xfrag; +/* Reference to data common to all the instances of this * transformer. */ const struct xfrm_type *type;
net/ipv4/esp4.c +109 -16
173 lines not on this page · raw message
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 11/13 net: Enable IPsec software GSO.
In reply to Steffen KlassertThis patch hooks the IPsec GSO code into the generic network stack.
--- include/linux/netdevice.h | 2 +- include/net/xfrm.h | 1 + net/core/dev.c | 40 +++++++++++++++++++++++++++++++++++----- net/ipv4/ip_output.c | 8 +++++--- net/ipv4/xfrm4_output.c | 2 +- net/sched/sch_generic.c | 2 +- net/xfrm/xfrm_output.c | 14 +++++++++++++- 7 files changed, 57 insertions(+), 12 deletions(-)
include/linux/netdevice.h +1 -1
@@ -3192,7 +3192,7 @@ int dev_get_phys_port_id(struct net_device *dev,int dev_get_phys_port_name (struct net_device *dev,char *name,size_t len);int dev_change_proto_down (struct net_device *dev,bool proto_down); -struct sk_buff *validate_xmit_skb_list (struct sk_buff *skb,struct net_device *dev); +struct sk_buff *validate_xmit_skb_list (struct sk_buff *skb,struct net_device *dev,int *ret);struct sk_buff *dev_hard_start_xmit (struct sk_buff *skb,struct net_device *dev,struct netdev_queue *txq,int *ret);int __dev_forward_skb (struct net_device *dev,struct sk_buff *skb);
include/net/xfrm.h +1 -0
@@ -1505,6 +1505,7 @@ struct xfrmk_spdinfo {u32 spdhmcnt; }; +void xfrm_dev_backlog (struct sk_buff_head *xfrm_backlog);struct xfrm_state *xfrm_find_acq_byseq (struct net *net,u32 mark,u32 seq);int xfrm_state_delete (struct xfrm_state *x);int xfrm_state_flush (struct net *net,u8 proto,bool task_valid);
net/core/dev.c +35 -5
@@ -2911,9 +2911,10 @@ static struct sk_buff *validate_xmit_vlan(struct sk_buff *skb,return skb; } -static struct sk_buff *validate_xmit_skb (struct sk_buff *skb,struct net_device *dev) +static struct sk_buff *validate_xmit_skb (struct sk_buff *skb,struct net_device *dev,int *ret) {netdev_features_t features; +int err =0 ;if (skb->next)return skb;
@@ -2925,6 +2926,7 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_deviceif (netif_needs_gso (skb, features)) {struct sk_buff *segs; +struct sk_buff *skb2; segs =skb_gso_segment (skb, features);if (IS_ERR (segs)) {
@@ -2932,7 +2934,25 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device }else if (segs) {consume_skb (skb); skb = segs; + +if (skb->hw_xfrm) { +do { + skb2 = segs->next; + segs->next =NULL ; + + err = dev->xfrmdev_ops->xdo_dev_validate (segs); +if (!err) + segs->next = skb2; +else if (err != -EINPROGRESS ) +kfree_skb (segs); +else if (skb == segs) + skb = skb2; + + segs = skb2; + }while (segs); + } } + }else {if (skb_needs_linearize (skb, features) &&__skb_linearize (skb))
@@ -2955,6 +2975,9 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device } } +if ((err == -EINPROGRESS ) && !skb) + *ret =NETDEV_TX_OK ; +return skb; out_kfree_skb:
@@ -2963,7 +2986,7 @@ out_null:return NULL ; } -struct sk_buff *validate_xmit_skb_list (struct sk_buff *skb,struct net_device *dev) +struct sk_buff *validate_xmit_skb_list (struct sk_buff *skb,struct net_device *dev,int *ret) {struct sk_buff *next, *head =NULL , *tail;
@@ -2974,7 +2997,7 @@ struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *d/* in case skb wont be segmented, point to itself */ skb->prev = skb; - skb =validate_xmit_skb (skb, dev); + skb =validate_xmit_skb (skb, dev, ret);if (!skb)continue ;
@@ -3347,8 +3370,10 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)if (__this_cpu_read (xmit_recursion) >RECURSION_LIMIT ) goto recursion_alert; - skb =validate_xmit_skb (skb, dev); -if (!skb) + skb =validate_xmit_skb (skb, dev, &rc); +if (!skb && rc ==NETDEV_TX_OK ) + goto out; +else if (!skb) goto drop;HARD_TX_LOCK (dev, txq, cpu);
@@ -3867,6 +3892,11 @@ static void net_tx_action(struct softirq_action *h) } } } + +#ifdef CONFIG_XFRM +if (!skb_queue_empty (&sd->xfrm_backlog)) +xfrm_dev_backlog (&sd->xfrm_backlog); +#endif } #if (defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)) && \
net/ipv4/ip_output.c +5 -3
@@ -173,7 +173,7 @@ EXPORT_SYMBOL_GPL(ip_build_and_send_pkt);static int ip_finish_output2 (struct net *net,struct sock *sk,struct sk_buff *skb) { -struct dst_entry *dst =skb_dst (skb); +struct dst_entry *dst =skb_dst (skb)->path;struct rtable *rt = (struct rtable *)dst;struct net_device *dev = dst->dev;unsigned int hh_len =LL_RESERVED_SPACE (dev);
@@ -269,7 +269,9 @@ static int ip_finish_output(struct net *net, struct sock *sk, struct sk_buff *sk#if defined(CONFIG_NETFILTER ) && defined(CONFIG_XFRM )/* Policy lookup after SNAT yielded a new policy */ -if (skb_dst (skb)->xfrm) { +if (skb_dst (skb)->xfrm && + !((skb_dst (skb)->dev->features &NETIF_F_ESP_OFFLOAD ) || + (skb_shinfo (skb)->gso_type &SKB_GSO_ESP ))) {IPCB (skb)->flags |=IPSKB_REROUTED ;return dst_output (net, sk, skb); }
@@ -348,7 +350,7 @@ int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb)int ip_output (struct net *net,struct sock *sk,struct sk_buff *skb) { -struct net_device *dev =skb_dst (skb)->dev; +struct net_device *dev =skb_dst (skb)->path->dev;IP_UPD_PO_STATS (net,IPSTATS_MIB_OUT , skb->len);
net/ipv4/xfrm4_output.c +1 -1
@@ -29,7 +29,7 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb) goto out; mtu =dst_mtu (skb_dst (skb)); -if (skb->len > mtu) { +if ((!skb_is_gso (skb) && skb->len > mtu) || (skb_is_gso (skb) &&skb_gso_network_seglen (skb) >ip_skb_dst_mtu (skb))) { skb->protocol =htons (ETH_P_IP );if (skb->sk)
net/sched/sch_generic.c +1 -1
@@ -157,7 +157,7 @@ int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,/* Note that we validate skb (GSO, checksum, ...) outside of locks */ if (validate) - skb =validate_xmit_skb_list (skb, dev); + skb =validate_xmit_skb_list (skb, dev, &ret);if (skb) {HARD_TX_LOCK (dev, txq,smp_processor_id ());
net/xfrm/xfrm_output.c +13 -1
@@ -196,9 +196,21 @@ static int xfrm_output_gso(struct net *net, struct sock *sk, struct sk_buff *skbint xfrm_output (struct sock *sk,struct sk_buff *skb) { -struct net *net =dev_net (skb_dst (skb)->dev); +struct net_device *dev =skb_dst (skb)->dev; +struct net *net =dev_net (dev);int err; +if ((dev->features &NETIF_F_ESP_OFFLOAD ) ||skb_is_gso (skb)) { + err =skb_dst (skb)->ops->local_out (net, skb->sk, skb); +if (unlikely (err !=1 )) +return err; + +if (skb_is_gso (skb)) +skb_shinfo (skb)->gso_type |=SKB_GSO_ESP ; + +return dev->xfrmdev_ops->xdo_dev_encap (skb); + } +if (skb_is_gso (skb))return xfrm_output_gso (net, sk, skb);
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 13/13 net: Allow IPsec GSO for locally sent traffic.
In reply to Steffen KlassertThis patch finally allows locally sent IPsec packets to use the GSO codepath.
--- net/core/sock.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
net/core/sock.c +3 -7
@@ -1583,13 +1583,9 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst) sk->sk_route_caps |=NETIF_F_GSO_SOFTWARE ; sk->sk_route_caps &= ~sk->sk_route_nocaps;if (sk_can_gso (sk)) { -if (dst->header_len) { - sk->sk_route_caps &= ~NETIF_F_GSO_MASK ; - }else { - sk->sk_route_caps |=NETIF_F_SG |NETIF_F_HW_CSUM ; - sk->sk_gso_max_size = dst->dev->gso_max_size; - max_segs =max_t (u32, dst->dev->gso_max_segs,1 ); - } + sk->sk_route_caps |=NETIF_F_SG |NETIF_F_HW_CSUM ; + sk->sk_gso_max_size = dst->dev->gso_max_size; + max_segs =max_t (u32, dst->dev->gso_max_segs,1 ); } sk->sk_gso_max_segs = max_segs; }
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 3/13 esp: Add a software GRO codepath
In reply to Steffen KlassertThis patch adds GRO callbacks for ESP on ipv4 and ipv6.
In case the GRO layer detects an ESP packet, the esp4_gro_receive() function calls the xfrm input layer which decapsulates the packet and reinject it into layer 2 by calling netif_rx(). We use on bit of the sk_buff to flag xfrm_gro. If this bit is set, the process_backlog() function calls napi_gro_receive() intead of __netif_receive_skb(). We could avoid the usage of xfrm_gro if we could call napi_gro_receive() unconditionaly from process_backlog().
--- include/linux/netdevice.h | 1 + include/linux/skbuff.h | 3 +- net/core/dev.c | 14 ++++++- net/ipv4/Makefile | 2 +- net/ipv4/esp4_offload.c | 77 +++++++++++++++++++++++++++++++++++++++ net/ipv4/xfrm4_input.c | 3 ++ net/ipv4/xfrm4_mode_transport.c | 3 +- net/ipv6/Makefile | 2 +- net/ipv6/esp6_offload.c | 81 +++++++++++++++++++++++++++++++++++++++++ net/ipv6/xfrm6_input.c | 3 ++ net/xfrm/xfrm_input.c | 8 +++- 11 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 net/ipv4/esp4_offload.c create mode 100644 net/ipv6/esp6_offload.c
include/linux/netdevice.h +1 -0
@@ -338,6 +338,7 @@ enum gro_result {GRO_HELD ,GRO_NORMAL ,GRO_DROP , + GRO_CONSUMED, };typedef enum gro_result gro_result_t ;
include/linux/skbuff.h +2 -1
@@ -721,7 +721,8 @@ struct sk_buff { __u8 ipvs_property:1; __u8 inner_protocol_type:1; __u8 remcsum_offload:1; -/* 3 or 5 bit hole */ + __u8 xfrm_gro:1; +/* 2 or 4 bit hole */ #ifdef CONFIG_NET_SCHED __u16 tc_index;/* traffic control index */
net/core/dev.c +13 -1
@@ -4453,6 +4453,11 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff }rcu_read_unlock (); +if (PTR_ERR (pp) == -EINPROGRESS ) { + ret =GRO_CONSUMED ; + goto ok; + } +if (&ptype->list == head) goto normal;
@@ -4559,6 +4564,7 @@ static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)case GRO_HELD :case GRO_MERGED : +case GRO_CONSUMED :break ; }
@@ -4629,6 +4635,7 @@ static gro_result_t napi_frags_finish(struct napi_struct *napi,break ;case GRO_MERGED : +case GRO_CONSUMED :break ; }
@@ -4770,7 +4777,12 @@ static int process_backlog(struct napi_struct *napi, int quota)while ((skb =__skb_dequeue (&sd->process_queue))) {rcu_read_lock ();local_irq_enable (); -__netif_receive_skb (skb); + +if (skb->xfrm_gro) +napi_gro_receive (napi, skb); +else +__netif_receive_skb (skb); +rcu_read_unlock ();local_irq_disable ();input_queue_head_incr (sd);
net/ipv4/Makefile +1 -1
@@ -28,7 +28,7 @@ obj-$(CONFIG_NET_UDP_TUNNEL) += udp_tunnel.o obj-$(CONFIG_NET_IPVTI) += ip_vti.o obj-$(CONFIG_SYN_COOKIES) += syncookies.o obj-$(CONFIG_INET_AH) += ah4.o -obj-$(CONFIG_INET_ESP) += esp4.o +obj-$(CONFIG_INET_ESP) += esp4.o esp4_offload.o obj-$(CONFIG_INET_IPCOMP) += ipcomp.o obj-$(CONFIG_INET_XFRM_TUNNEL) += xfrm4_tunnel.o obj-$(CONFIG_INET_XFRM_MODE_BEET) += xfrm4_mode_beet.o
net/ipv4/esp4_offload.c new file +77 -0
77 lines not on this page · raw message
net/ipv4/xfrm4_input.c +3 -0
@@ -53,6 +53,9 @@ int xfrm4_transport_finish(struct sk_buff *skb, int async) iph->tot_len =htons (skb->len);ip_send_check (iph); +if (skb->xfrm_gro) +return 0 ; +NF_HOOK (NFPROTO_IPV4 ,NF_INET_PRE_ROUTING ,dev_net (skb->dev),NULL , skb, skb->dev,NULL , xfrm4_rcv_encap_finish);
net/ipv4/xfrm4_mode_transport.c +2 -1
@@ -50,7 +50,8 @@ static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb) skb->network_header = skb->transport_header; }ip_hdr (skb)->tot_len =htons (skb->len + ihl); -skb_reset_transport_header (skb); +if (!skb->xfrm_gro) +skb_reset_transport_header (skb);return 0 ; }
net/ipv6/Makefile +1 -1
@@ -25,7 +25,7 @@ ipv6-$(CONFIG_SYN_COOKIES) += syncookies.o ipv6-objs += $(ipv6-y) obj-$(CONFIG_INET6_AH) += ah6.o -obj-$(CONFIG_INET6_ESP) += esp6.o +obj-$(CONFIG_INET6_ESP) += esp6.o esp6_offload.o obj-$(CONFIG_INET6_IPCOMP) += ipcomp6.o obj-$(CONFIG_INET6_XFRM_TUNNEL) += xfrm6_tunnel.o obj-$(CONFIG_INET6_TUNNEL) += tunnel6.o
net/ipv6/esp6_offload.c new file +81 -0
81 lines not on this page · raw message
net/ipv6/xfrm6_input.c +3 -0
@@ -42,6 +42,9 @@ int xfrm6_transport_finish(struct sk_buff *skb, int async)ipv6_hdr (skb)->payload_len =htons (skb->len);__skb_push (skb, skb->data -skb_network_header (skb)); +if (skb->xfrm_gro) +return -1 ; +NF_HOOK (NFPROTO_IPV6 ,NF_INET_PRE_ROUTING ,dev_net (skb->dev),NULL , skb, skb->dev,NULL , ip6_rcv_finish);
net/xfrm/xfrm_input.c +7 -1
@@ -371,7 +371,13 @@ resume:netif_rx (skb);return 0 ; }else { -return x->inner_mode->afinfo->transport_finish (skb, async); + err = x->inner_mode->afinfo->transport_finish (skb, async); +if (skb->xfrm_gro) { +netif_rx (skb); +return 0 ; + } + +return err; } drop_unlock:
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 4/13 xfrm: Move device notifications to a sepatate file
In reply to Steffen KlassertThis is needed for the upcomming IPsec device offloading.
--- include/net/xfrm.h | 1 + net/xfrm/Makefile | 2 +- net/xfrm/xfrm_device.c | 43 +++++++++++++++++++++++++++++++++++++++++++ net/xfrm/xfrm_policy.c | 17 +---------------- 4 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 net/xfrm/xfrm_device.c
include/net/xfrm.h +1 -0
@@ -1398,6 +1398,7 @@ struct xfrm6_tunnel {void xfrm_init (void );void xfrm4_init (void );int xfrm_state_init (struct net *net); +void xfrm_dev_init (void );void xfrm_state_fini (struct net *net);void xfrm4_state_init (void );void xfrm4_protocol_init (void );
net/xfrm/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-$(CONFIG_XFRM) := xfrm_policy.o xfrm_state.o xfrm_hash.o \ xfrm_input.o xfrm_output.o \ - xfrm_sysctl.o xfrm_replay.o + xfrm_sysctl.o xfrm_replay.o xfrm_device.o obj-$(CONFIG_XFRM_STATISTICS) += xfrm_proc.o obj-$(CONFIG_XFRM_ALGO) += xfrm_algo.o obj-$(CONFIG_XFRM_USER) += xfrm_user.o
net/xfrm/xfrm_device.c new file +43 -0
43 lines not on this page · raw message
net/xfrm/xfrm_policy.c +1 -16
@@ -2891,21 +2891,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo) }EXPORT_SYMBOL (xfrm_policy_unregister_afinfo); -static int xfrm_dev_event (struct notifier_block *this,unsigned long event,void *ptr) -{ -struct net_device *dev =netdev_notifier_info_to_dev (ptr); - -switch (event) { -case NETDEV_DOWN : -xfrm_garbage_collect (dev_net (dev)); - } -return NOTIFY_DONE ; -} - -static struct notifier_block xfrm_dev_notifier = { - .notifier_call = xfrm_dev_event, -}; -#ifdef CONFIG_XFRM_STATISTICS static int __net_init xfrm_statistics_init (struct net *net) {
@@ -2982,7 +2967,7 @@ static int __net_init xfrm_policy_init(struct net *net)INIT_WORK (&net->xfrm.policy_hash_work, xfrm_hash_resize);INIT_WORK (&net->xfrm.policy_hthresh.work, xfrm_hash_rebuild);if (net_eq (net, &init_net)) -register_netdevice_notifier (&xfrm_dev_notifier); +xfrm_dev_init ();return 0 ; out_bydst:
Signature · 1 line
1.9.1
Steffen Klassert
maintainerRFC PATCH 7/13 net: Add ESP offload features
In reply to Steffen KlassertThis patch adds netdev features to configure IPsec offloads.
--- include/linux/netdev_features.h | 6 +++++- include/linux/netdevice.h | 1 + include/linux/skbuff.h | 2 ++ net/core/ethtool.c | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-)
include/linux/netdev_features.h +5 -1
@@ -48,8 +48,9 @@ enum {NETIF_F_GSO_UDP_TUNNEL_BIT ,/* ... UDP TUNNEL with TSO */ NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT ,/* ... UDP TUNNEL with TSO & CSUM */ NETIF_F_GSO_TUNNEL_REMCSUM_BIT ,/* ... TUNNEL with TSO & REMCSUM */ +NETIF_F_GSO_ESP_BIT ,/* ... ESP with TSO */ /**/ NETIF_F_GSO_LAST =/* last bit, see GSO_MASK */ -NETIF_F_GSO_TUNNEL_REMCSUM_BIT , +NETIF_F_GSO_ESP_BIT ,NETIF_F_FCOE_CRC_BIT ,/* FCoE CRC32 */ NETIF_F_SCTP_CRC_BIT, /* SCTP checksum offload */
@@ -66,6 +67,7 @@ enum {NETIF_F_HW_VLAN_STAG_FILTER_BIT ,/* Receive filtering on VLAN STAGs */ NETIF_F_HW_L2FW_DOFFLOAD_BIT ,/* Allow L2 Forwarding in Hardware */ NETIF_F_BUSY_POLL_BIT ,/* Busy poll */ +NETIF_F_ESP_OFFLOAD_BIT ,/* ESP transformation offload */ /* * Add your fresh new feature above and remember to update
@@ -119,11 +121,13 @@ enum {#define NETIF_F_GSO_UDP_TUNNEL __NETIF_F(GSO_UDP_TUNNEL)#define NETIF_F_GSO_UDP_TUNNEL_CSUM __NETIF_F(GSO_UDP_TUNNEL_CSUM)#define NETIF_F_GSO_TUNNEL_REMCSUM __NETIF_F(GSO_TUNNEL_REMCSUM) +#define NETIF_F_GSO_ESP __NETIF_F(GSO_ESP)#define NETIF_F_HW_VLAN_STAG_FILTER __NETIF_F(HW_VLAN_STAG_FILTER)#define NETIF_F_HW_VLAN_STAG_RX __NETIF_F(HW_VLAN_STAG_RX)#define NETIF_F_HW_VLAN_STAG_TX __NETIF_F(HW_VLAN_STAG_TX)#define NETIF_F_HW_L2FW_DOFFLOAD __NETIF_F(HW_L2FW_DOFFLOAD)#define NETIF_F_BUSY_POLL __NETIF_F(BUSY_POLL) +#define NETIF_F_ESP_OFFLOAD __NETIF_F(ESP_OFFLOAD)#define for_each_netdev_feature (mask_addr, bit) \ for_each_set_bit(bit, (unsigned long *)mask_addr, NETDEV_FEATURE_COUNT)
include/linux/netdevice.h +1 -0
@@ -3938,6 +3938,7 @@ static inline bool net_gso_ok(netdev_features_t features, int gso_type)BUILD_BUG_ON (SKB_GSO_UDP_TUNNEL != (NETIF_F_GSO_UDP_TUNNEL >>NETIF_F_GSO_SHIFT ));BUILD_BUG_ON (SKB_GSO_UDP_TUNNEL_CSUM != (NETIF_F_GSO_UDP_TUNNEL_CSUM >>NETIF_F_GSO_SHIFT ));BUILD_BUG_ON (SKB_GSO_TUNNEL_REMCSUM != (NETIF_F_GSO_TUNNEL_REMCSUM >>NETIF_F_GSO_SHIFT )); +BUILD_BUG_ON (SKB_GSO_ESP != (NETIF_F_GSO_ESP >>NETIF_F_GSO_SHIFT ));return (features & feature) == feature; }
include/linux/skbuff.h +2 -0
@@ -481,6 +481,8 @@ enum {SKB_GSO_UDP_TUNNEL_CSUM =1 <<11 ,SKB_GSO_TUNNEL_REMCSUM =1 <<12 , + + SKB_GSO_ESP = 1 << 13, };#if BITS_PER_LONG >32
net/core/ethtool.c +2 -0
@@ -85,6 +85,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] [NETIF_F_GSO_IPIP_BIT] = "tx-ipip-segmentation", [NETIF_F_GSO_SIT_BIT] = "tx-sit-segmentation", [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation", + [NETIF_F_GSO_ESP_BIT] = "tx-esp-segmentation", [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc", [NETIF_F_SCTP_CRC_BIT] = "tx-checksum-sctp",
@@ -98,6 +99,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] [NETIF_F_RXALL_BIT] = "rx-all", [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload", [NETIF_F_BUSY_POLL_BIT] = "busy-poll", + [NETIF_F_ESP_OFFLOAD_BIT] = "tx-esp-offload", }; static const char
Signature · 1 line
1.9.1