New fast forwarding path
Subsystems (5)
Pablo Neira Ayuso
maintainercover New fast forwarding path
Hi,
This patchset proposes a new fast forwarding path infrastructure that combines the GRO/GSO and the flowtable infrastructures. The idea is to add a hook at the GRO layer that is invoked before the standard GRO protocol offloads. This allows us to build custom packet chains that we can quickly pass in one go to the neighbour layer to define fast forwarding path for flows.
For each packet that gets into the GRO layer, we first check if there is an entry in the flowtable, if so, the packet is placed in a list until the GRO infrastructure decides to send the batch from gro_complete to the neighbour layer. The first packet in the list takes the route from the flowtable entry, so we avoid reiterative routing lookups.
In case no entry is found in the flowtable, the packet is passed up to the classic GRO offload handlers. Thus, this packet follows the standard forwarding path. Note that the initial packets of the flow always go through the standard IPv4/IPv6 netfilter forward hook, that is used to configure what flows are placed in the flowtable. Therefore, only a few (initial) packets follow the standard forwarding path while most of the follow up packets take this new fast forwarding path.
The fast forwarding path is enabled through explicit user policy, so the user needs to request this behaviour from control plane, the following example shows how to place flows in the new fast forwarding path from the netfilter forward chain:
table x {
flowtable f {
hook early_ingress priority 0; devices = { eth0, eth1 }
}
chain y {
type filter hook forward priority 0;
ip protocol tcp flow offload @f
}}
The example above defines a fastpath for TCP flows that are placed in the flowtable 'f', this flowtable is hooked at the new early_ingress hook. The initial TCP packets that match this rule from the standard fowarding path create an entry in the flowtable, thus, GRO creates chain of packets for those that find an entry in the flowtable and send them through the neighbour layer.
This new hook is happening before the ingress taps, therefore, packets that follow this new fast forwarding path are not shown by tcpdump.
This patchset supports both layer 3 IPv4 and IPv6, and layer 4 TCP and UDP protocols. This fastpath also integrates with the IPSec infrastructure and the ESP protocol.
We have collected performance numbers:
TCP TSO TCP Fast Forward
32.5 Gbps 35.6 Gbps
UDP UDP Fast Forward
17.6 Gbps 35.6 Gbps
ESP ESP Fast Forward
6 Gbps 7.5 Gbps
For UDP, this is doubling performance, and we almost achieve line rate with one single CPU using the Intel i40e NIC. We got similar numbers with the Mellanox ConnectX-4. For TCP, this is slightly improving things even if TSO is being defeated given that we need to segment the packet chain in software. We would like to explore HW GRO support with hardware vendors with this new mode, we think that should improve the TCP numbers we are showing above even more. For ESP traffic, performance improvement is ~25%, in this case, perf shows the bottleneck becomes the crypto layer.
This patchset is co-authored work with Steffen Klassert.
Comments are welcome, thanks.
Pablo Neira Ayuso (6):
netfilter: nft_chain_filter: add support for early ingress
netfilter: nf_flow_table: add hooknum to flowtable type
netfilter: nf_flow_table: add flowtable for early ingress hook
netfilter: nft_flow_offload: enable offload after second packet is seen
netfilter: nft_flow_offload: remove secpath check
netfilter: nft_flow_offload: make sure route is not stale
Steffen Klassert (7):
net: Add a helper to get the packet offload callbacks by priority.
net: Change priority of ipv4 and ipv6 packet offloads.
net: Add a GSO feature bit for the netfilter forward fastpath.
net: Use one bit of NAPI_GRO_CB for the netfilter fastpath.
netfilter: add early ingress hook for IPv4
netfilter: add early ingress support for IPv6
netfilter: add ESP support for early ingress
include/linux/netdev_features.h | 4 +- include/linux/netdevice.h | 6 +- include/linux/netfilter.h | 6 + include/linux/netfilter_ingress.h | 1 + include/linux/skbuff.h | 2 + include/net/netfilter/early_ingress.h | 24 +++ include/net/netfilter/nf_flow_table.h | 4 + include/uapi/linux/netfilter.h | 1 + net/core/dev.c | 50 ++++- net/ipv4/af_inet.c | 1 + net/ipv4/netfilter/Makefile | 1 + net/ipv4/netfilter/early_ingress.c | 327 +++++++++++++++++++++++++++++ net/ipv4/netfilter/nf_flow_table_ipv4.c | 12 ++ net/ipv6/ip6_offload.c | 1 + net/ipv6/netfilter/Makefile | 1 + net/ipv6/netfilter/early_ingress.c | 315 ++++++++++++++++++++++++++++ net/ipv6/netfilter/nf_flow_table_ipv6.c | 1 + net/netfilter/Kconfig | 8 + net/netfilter/Makefile | 1 + net/netfilter/core.c | 35 +++- net/netfilter/early_ingress.c | 361 ++++++++++++++++++++++++++++++++ net/netfilter/nf_flow_table_inet.c | 1 + net/netfilter/nf_flow_table_ip.c | 72 +++++++ net/netfilter/nf_tables_api.c | 120 ++++++----- net/netfilter/nft_chain_filter.c | 6 +- net/netfilter/nft_flow_offload.c | 13 +- net/xfrm/xfrm_output.c | 4 + 27 files changed, 1297 insertions(+), 81 deletions(-) create mode 100644 include/net/netfilter/early_ingress.h create mode 100644 net/ipv4/netfilter/early_ingress.c create mode 100644 net/ipv6/netfilter/early_ingress.c create mode 100644 net/netfilter/early_ingress.c
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 1/13 net: Add a helper to get the packet offload callbacks by priority.
From: Steffen Klassert <[email protected]>
With this helper it is possible to request callbacks with a certain priority. This will be used in the upcoming forward fastpath to pass packets to the standard GRO path.
--- include/linux/netdevice.h | 1 + net/core/dev.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
include/linux/netdevice.h +1 -0
@@ -2523,6 +2523,7 @@ void dev_remove_pack(struct packet_type *pt);void __dev_remove_pack (struct packet_type *pt);void dev_add_offload (struct packet_offload *po);void dev_remove_offload (struct packet_offload *po); +struct packet_offload *dev_get_packet_offload (__be16 type,int priority);int dev_get_iflink (const struct net_device *dev);int dev_fill_metadata_dst (struct net_device *dev,struct sk_buff *skb);
net/core/dev.c +14 -0
@@ -468,7 +468,21 @@ void dev_remove_pack(struct packet_type *pt) }EXPORT_SYMBOL (dev_remove_pack); +struct packet_offload *dev_get_packet_offload (__be16 type,int priority) +{ +struct list_head *offload_head = &offload_base; +struct packet_offload *ptype; + +list_for_each_entry_rcu (ptype, offload_head, list) { +if (ptype->type != type || !ptype->callbacks.gro_receive || !ptype->callbacks.gro_complete || ptype->priority < priority) +continue ; +return ptype; + } + +return NULL ; +} +EXPORT_SYMBOL (dev_get_packet_offload);/** * dev_add_offload - register offload handlers * @po: protocol offload declaration
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 2/13 net: Change priority of ipv4 and ipv6 packet offloads.
In reply to Pablo Neira AyusoFrom: Steffen Klassert <[email protected]>
The forward fastpath needs to insert callbacks with higher priority than the standard callbacks. So change the priority of ipv4 and ipv6 packet offloads from zero to one. With this we are able to insert callbacks with priotity zero if needed.
--- net/ipv4/af_inet.c | 1 + net/ipv6/ip6_offload.c | 1 + 2 files changed, 2 insertions(+)
net/ipv4/af_inet.c +1 -0
@@ -1841,6 +1841,7 @@ static int ipv4_proc_init(void);static struct packet_offload ip_packet_offload__read_mostly = { .type =cpu_to_be16 (ETH_P_IP ), + .priority =1 , .callbacks = { .gso_segment = inet_gso_segment, .gro_receive = inet_gro_receive,
net/ipv6/ip6_offload.c +1 -0
@@ -343,6 +343,7 @@ static int ip4ip6_gro_complete(struct sk_buff *skb, int nhoff)static struct packet_offload ipv6_packet_offload__read_mostly = { .type =cpu_to_be16 (ETH_P_IPV6 ), + .priority =1 , .callbacks = { .gso_segment = ipv6_gso_segment, .gro_receive = ipv6_gro_receive,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 3/13 net: Add a GSO feature bit for the netfilter forward fastpath.
In reply to Pablo Neira AyusoFrom: Steffen Klassert <[email protected]>
The netfilter forward fastpath has its own logic to create GSO packets. So add a feature bit that we can catch GSO packets that are generated by the fastpath GRO handler.
--- include/linux/netdev_features.h | 4 +++- include/linux/netdevice.h | 1 + include/linux/skbuff.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-)
include/linux/netdev_features.h +3 -1
@@ -56,8 +56,9 @@ enum {NETIF_F_GSO_ESP_BIT ,/* ... ESP with TSO */ NETIF_F_GSO_UDP_BIT ,/* ... UFO, deprecated except tuntap */ NETIF_F_GSO_UDP_L4_BIT ,/* ... UDP payload GSO (not UFO) */ +NETIF_F_GSO_NFT_BIT ,/* ... NFT generic */ /**/ NETIF_F_GSO_LAST =/* last bit, see GSO_MASK */ -NETIF_F_GSO_UDP_L4_BIT , +NETIF_F_GSO_NFT_BIT ,NETIF_F_FCOE_CRC_BIT ,/* FCoE CRC32 */ NETIF_F_SCTP_CRC_BIT, /* SCTP checksum offload */
@@ -140,6 +141,7 @@ enum {#define NETIF_F_GSO_SCTP __NETIF_F(GSO_SCTP)#define NETIF_F_GSO_ESP __NETIF_F(GSO_ESP)#define NETIF_F_GSO_UDP __NETIF_F(GSO_UDP) +#define NETIF_F_GSO_NFT __NETIF_F(GSO_NFT)#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)
include/linux/netdevice.h +1 -0
@@ -4229,6 +4229,7 @@ static inline bool net_gso_ok(netdev_features_t features, int gso_type)BUILD_BUG_ON (SKB_GSO_ESP != (NETIF_F_GSO_ESP >>NETIF_F_GSO_SHIFT ));BUILD_BUG_ON (SKB_GSO_UDP != (NETIF_F_GSO_UDP >>NETIF_F_GSO_SHIFT ));BUILD_BUG_ON (SKB_GSO_UDP_L4 != (NETIF_F_GSO_UDP_L4 >>NETIF_F_GSO_SHIFT )); +BUILD_BUG_ON (SKB_GSO_NFT != (NETIF_F_GSO_NFT >>NETIF_F_GSO_SHIFT ));return (features & feature) == feature; }
include/linux/skbuff.h +2 -0
@@ -575,6 +575,8 @@ enum {SKB_GSO_UDP =1 <<16 ,SKB_GSO_UDP_L4 =1 <<17 , + + SKB_GSO_NFT = 1 << 18, };#if BITS_PER_LONG >32
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 4/13 net: Use one bit of NAPI_GRO_CB for the netfilter fastpath.
In reply to Pablo Neira AyusoFrom: Steffen Klassert <[email protected]>
This patch adds a is_ffwd bit to the NAPI_GRO_CB to indicate fastpath packtes in the GRO layer. It also implements the logic we need for this in the generic codepath. The rest of the needed logic is implemented within netfilter and introduced with a followup patch.
--- include/linux/netdevice.h | 2 +- net/core/dev.c | 36 +++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-)
include/linux/netdevice.h +1 -1
@@ -2238,7 +2238,7 @@ struct napi_gro_cb {/* Number of gro_receive callbacks this packet already went through */ u8 recursion_counter:4; -/* 1 bit hole */ + u8 is_ffwd:1;/* used to support CHECKSUM_COMPLETE for tunneling protocols */ __wsum csum;
net/core/dev.c +27 -9
@@ -4864,7 +4864,8 @@ static int napi_gro_complete(struct sk_buff *skb)BUILD_BUG_ON (sizeof (struct napi_gro_cb ) >sizeof (skb->cb)); -if (NAPI_GRO_CB (skb)->count ==1 ) { +if (NAPI_GRO_CB (skb)->count ==1 && + !(NAPI_GRO_CB (skb)->is_ffwd)) {skb_shinfo (skb)->gso_size =0 ; goto out; }
@@ -4880,8 +4881,10 @@ static int napi_gro_complete(struct sk_buff *skb)rcu_read_unlock ();if (err) { -WARN_ON (&ptype->list == head); -kfree_skb (skb); +if (err != -EINPROGRESS ) { +WARN_ON (&ptype->list == head); +kfree_skb (skb); + }return NET_RX_SUCCESS ; }
@@ -4936,8 +4939,10 @@ static void gro_list_prepare(struct napi_struct *napi, struct sk_buff *skb) diffs = (unsigned long )p->dev ^ (unsigned long )skb->dev; diffs |= p->vlan_tci ^ skb->vlan_tci; - diffs |=skb_metadata_dst_cmp (p, skb); - diffs |=skb_metadata_differs (p, skb); +if (!NAPI_GRO_CB (p)->is_ffwd) { + diffs |=skb_metadata_dst_cmp (p, skb); + diffs |=skb_metadata_differs (p, skb); + }if (maclen ==ETH_HLEN ) diffs |=compare_ether_header (skb_mac_header (p),skb_mac_header (skb));
@@ -5019,6 +5024,7 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buffNAPI_GRO_CB (skb)->is_fou =0 ;NAPI_GRO_CB (skb)->is_atomic =1 ;NAPI_GRO_CB (skb)->gro_remcsum_start =0 ; +NAPI_GRO_CB (skb)->is_ffwd =0 ;/* Setup for GRO checksum validation */ switch (skb->ip_summed) {
@@ -5044,9 +5050,14 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buffif (&ptype->list == head) goto normal; -if (IS_ERR (pp) &&PTR_ERR (pp) == -EINPROGRESS ) { - ret =GRO_CONSUMED ; - goto ok; +if (IS_ERR (pp)) { +int err; + + err =PTR_ERR (pp); +if (err == -EINPROGRESS || err == -EPERM ) { + ret =GRO_CONSUMED ; + goto ok; + } } same_flow =NAPI_GRO_CB (skb)->same_flow;
@@ -5064,8 +5075,15 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buffif (same_flow) goto ok; -if (NAPI_GRO_CB (skb)->flush) +if (NAPI_GRO_CB (skb)->flush) { +if (NAPI_GRO_CB (skb)->is_ffwd) { +napi_gro_complete (skb); + ret =GRO_CONSUMED ; + goto ok; + } + goto normal; + }if (unlikely (napi->gro_count >=MAX_GRO_SKBS )) {struct sk_buff *nskb = napi->gro_list;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 5/13 netfilter: add early ingress hook for IPv4
In reply to Pablo Neira AyusoFrom: Steffen Klassert <[email protected]>
Add the new early ingress hook for the netdev family, this new hook is called from the GRO layer before the standard ipv4 GRO layers.
This hook allows us to perform early packet filtering and to define fast forwarding path through packet chaining and flowtables using the new GSO netfilter type. Packet that don't follow the fast path are passed up to the standard GRO path for aggregation as usual.
This patch adds the GRO and GSO logic for this custom packet chaining. The chaining uses the frag_list pointer so this means we do not need to mangle the packets, therefore the aggregation strategy we follow does not modify the packet as in the standard GRO path - we have no need to recalculate checksum. This chain of packets is sent from the .gro_complete callback directly to the neighbour layer. The first packet in the chain holds a reference to the destination route.
Supported layer 4 protocols for this custom GRO packet chaining include TCP and UDP.
--- include/linux/netdevice.h | 2 + include/linux/netfilter.h | 6 + include/linux/netfilter_ingress.h | 1 + include/net/netfilter/early_ingress.h | 20 +++ include/uapi/linux/netfilter.h | 1 + net/ipv4/netfilter/Makefile | 1 + net/ipv4/netfilter/early_ingress.c | 319 +++++++++++++++++++++++++++++++++ net/netfilter/Kconfig | 8 + net/netfilter/Makefile | 1 + net/netfilter/core.c | 35 +++- net/netfilter/early_ingress.c | 323 ++++++++++++++++++++++++++++++++++ 11 files changed, 716 insertions(+), 1 deletion(-) create mode 100644 include/net/netfilter/early_ingress.h create mode 100644 net/ipv4/netfilter/early_ingress.c create mode 100644 net/netfilter/early_ingress.c
include/linux/netdevice.h +2 -0
@@ -1880,6 +1880,8 @@ struct net_device {rx_handler_func_t __rcu *rx_handler;void __rcu *rx_handler_data; +struct nf_hook_entries __rcu *nf_hooks_early_ingress; +#ifdef CONFIG_NET_CLS_ACT struct mini_Qdisc __rcu *miniq_ingress;#endif
include/linux/netfilter.h +6 -0
@@ -429,4 +429,10 @@ extern struct nfnl_ct_hook __rcu *nfnl_ct_hook;*/ DECLARE_PER_CPU (bool, nf_skb_duplicated); +int nf_hook_netdev (struct sk_buff *skb,struct nf_hook_state *state, +const struct nf_hook_entries *e); + +void nf_early_ingress_enable (void ); +void nf_early_ingress_disable (void ); +#endif /*__LINUX_NETFILTER_H*/
include/linux/netfilter_ingress.h +1 -0
@@ -40,6 +40,7 @@ static inline int nf_hook_ingress(struct sk_buff *skb)static inline void nf_hook_ingress_init (struct net_device *dev) { +RCU_INIT_POINTER (dev->nf_hooks_early_ingress,NULL );RCU_INIT_POINTER (dev->nf_hooks_ingress,NULL ); }#else /* CONFIG_NETFILTER_INGRESS */
include/net/netfilter/early_ingress.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef _NF_EARLY_INGRESS_H_ +#define _NF_EARLY_INGRESS_H_ + +#include <net/protocol.h> + +struct sk_buff *nft_skb_segment (struct sk_buff *head_skb); +struct sk_buff **nft_udp_gro_receive (struct sk_buff **head, +struct sk_buff *skb); +struct sk_buff **nft_tcp_gro_receive (struct sk_buff **head, +struct sk_buff *skb); + +int nf_hook_early_ingress (struct sk_buff *skb); + +void nf_early_ingress_ip_enable (void ); +void nf_early_ingress_ip_disable (void ); + +void nf_early_ingress_enable (void ); +void nf_early_ingress_disable (void ); + +#endif
include/uapi/linux/netfilter.h +1 -0
@@ -54,6 +54,7 @@ enum nf_inet_hooks {enum nf_dev_hooks {NF_NETDEV_INGRESS , +NF_NETDEV_EARLY_INGRESS ,NF_NETDEV_NUMHOOKS };
net/ipv4/netfilter/Makefile +1 -0
@@ -2,6 +2,7 @@ # # Makefile for the netfilter modules on top of IPv4. # +obj-$(CONFIG_NETFILTER_EARLY_INGRESS) += early_ingress.o # objects for l3 independent conntrack nf_conntrack_ipv4-y := nf_conntrack_l3proto_ipv4.o nf_conntrack_proto_icmp.o
net/ipv4/netfilter/early_ingress.c new file +319 -0
319 lines not on this page · raw message
net/netfilter/Kconfig +8 -0
@@ -9,6 +9,14 @@ config NETFILTER_INGRESS This allows you to classify packets from ingress using the Netfilter infrastructure. +config NETFILTER_EARLY_INGRESS + bool "Netfilter early ingress support" + default y + help + This allows you to perform very early filtering and packet aggregation + for fast forwarding bypass by exercising the GRO engine from the + Netfilter infrastructure. + config NETFILTER_NETLINK tristate
net/netfilter/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 netfilter-objs := core.o nf_log.o nf_queue.o nf_sockopt.o utils.o +netfilter-$(CONFIG_NETFILTER_EARLY_INGRESS) += early_ingress.o nf_conntrack-y := nf_conntrack_core.o nf_conntrack_standalone.o nf_conntrack_expect.o nf_conntrack_helper.o nf_conntrack_proto.o nf_conntrack_l3proto_generic.o nf_conntrack_proto_generic.o nf_conntrack_proto_tcp.o nf_conntrack_proto_udp.o nf_conntrack_extend.o nf_conntrack_acct.o nf_conntrack_seqadj.o nf_conntrack-$(CONFIG_NF_CONNTRACK_TIMEOUT) += nf_conntrack_timeout.o
net/netfilter/core.c +34 -1
@@ -306,6 +306,11 @@ nf_hook_entry_head(struct net *net, int pf, unsigned int hooknum, return &dev->nf_hooks_ingress; }#endif +if (hooknum ==NF_NETDEV_EARLY_INGRESS ) { +if (dev &&dev_net (dev) == net) +return &dev->nf_hooks_early_ingress; + } +WARN_ON_ONCE (1 );return NULL ; }
@@ -321,7 +326,8 @@ static int __nf_register_net_hook(struct net *net, int pf,if (reg->hooknum ==NF_NETDEV_INGRESS )return -EOPNOTSUPP ;#endif -if (reg->hooknum !=NF_NETDEV_INGRESS || +if ((reg->hooknum !=NF_NETDEV_INGRESS && + reg->hooknum !=NF_NETDEV_EARLY_INGRESS ) || !reg->dev ||dev_net (reg->dev) != net)return -EINVAL ; }
@@ -347,6 +353,9 @@ static int __nf_register_net_hook(struct net *net, int pf,if (pf ==NFPROTO_NETDEV && reg->hooknum ==NF_NETDEV_INGRESS )net_inc_ingress_queue ();#endif +if (pf ==NFPROTO_NETDEV && reg->hooknum ==NF_NETDEV_EARLY_INGRESS ) +nf_early_ingress_enable (); +#ifdef HAVE_JUMP_LABEL static_key_slow_inc (&nf_hooks_needed[pf][reg->hooknum]);#endif
@@ -404,6 +413,9 @@ static void __nf_unregister_net_hook(struct net *net, int pf,#ifdef CONFIG_NETFILTER_INGRESS if (pf ==NFPROTO_NETDEV && reg->hooknum ==NF_NETDEV_INGRESS )net_dec_ingress_queue (); + +if (pf ==NFPROTO_NETDEV && reg->hooknum ==NF_NETDEV_EARLY_INGRESS ) +nf_early_ingress_disable ();#endif #ifdef HAVE_JUMP_LABEL static_key_slow_dec (&nf_hooks_needed[pf][reg->hooknum]);
@@ -535,6 +547,27 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state, }EXPORT_SYMBOL (nf_hook_slow); +int nf_hook_netdev (struct sk_buff *skb,struct nf_hook_state *state, +const struct nf_hook_entries *e) +{ +unsigned int verdict, s, v =NF_ACCEPT ; + +for (s =0 ; s < e->num_hook_entries; s++) { + verdict =nf_hook_entry_hookfn (&e->hooks[s], skb, state); + v = verdict &NF_VERDICT_MASK ; +switch (v) { +case NF_ACCEPT : +break ; +case NF_DROP : +kfree_skb (skb); +/* Fall through */ +default : +return v; + } + } + +return v; +}int skb_make_writable (struct sk_buff *skb,unsigned int writable_len) {
net/netfilter/early_ingress.c new file +323 -0
323 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 6/13 netfilter: add early ingress support for IPv6
In reply to Pablo Neira AyusoFrom: Steffen Klassert <[email protected]>
This patch adds the custom GSO and GRO logic for the IPv6 early ingress hook. Layer 4 supports UDP and TCP at this stage.
--- include/net/netfilter/early_ingress.h | 2 + net/ipv6/netfilter/Makefile | 1 + net/ipv6/netfilter/early_ingress.c | 307 ++++++++++++++++++++++++++++++++++ net/netfilter/early_ingress.c | 2 + 4 files changed, 312 insertions(+) create mode 100644 net/ipv6/netfilter/early_ingress.c
include/net/netfilter/early_ingress.h +2 -0
@@ -13,6 +13,8 @@ int nf_hook_early_ingress(struct sk_buff *skb);void nf_early_ingress_ip_enable (void );void nf_early_ingress_ip_disable (void ); +void nf_early_ingress_ip6_enable (void ); +void nf_early_ingress_ip6_disable (void );void nf_early_ingress_enable (void );void nf_early_ingress_disable (void );
net/ipv6/netfilter/Makefile +1 -0
@@ -2,6 +2,7 @@ # # Makefile for the netfilter modules on top of IPv6. # +obj-$(CONFIG_NETFILTER_EARLY_INGRESS) += early_ingress.o # Link order matters here. obj-$(CONFIG_IP6_NF_IPTABLES) += ip6_tables.o
net/ipv6/netfilter/early_ingress.c new file +307 -0
307 lines not on this page · raw message
net/netfilter/early_ingress.c +2 -0
@@ -312,6 +312,7 @@ void nf_early_ingress_enable(void)if (nf_early_ingress_use++ ==0 ) { nf_early_ingress_use++;nf_early_ingress_ip_enable (); +nf_early_ingress_ip6_enable (); } }
@@ -319,5 +320,6 @@ void nf_early_ingress_disable(void) {if (--nf_early_ingress_use ==0 ) {nf_early_ingress_ip_disable (); +nf_early_ingress_ip6_disable (); } }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 7/13 netfilter: add ESP support for early ingress
In reply to Pablo Neira AyusoFrom: Steffen Klassert <[email protected]>
This patch adds the GSO logic for ESP and the codepath that allows the xfrm infrastructure to signal the GRO layer that the packet is following the fast forwarding path.
--- include/net/netfilter/early_ingress.h | 2 ++ net/ipv4/netfilter/early_ingress.c | 8 ++++++++ net/ipv6/netfilter/early_ingress.c | 8 ++++++++ net/netfilter/early_ingress.c | 36 +++++++++++++++++++++++++++++++++++ net/xfrm/xfrm_output.c | 4 ++++ 5 files changed, 58 insertions(+)
include/net/netfilter/early_ingress.h +2 -0
@@ -8,6 +8,8 @@ struct sk_buff **nft_udp_gro_receive(struct sk_buff **head, struct sk_buff *skb);struct sk_buff **nft_tcp_gro_receive (struct sk_buff **head,struct sk_buff *skb); +struct sk_buff *nft_esp_gso_segment (struct sk_buff *skb, +netdev_features_t features);int nf_hook_early_ingress (struct sk_buff *skb);
net/ipv4/netfilter/early_ingress.c +8 -0
@@ -5,6 +5,7 @@#include <net/arp.h> #include <net/udp.h> #include <net/tcp.h> +#include <net/esp.h> #include <net/protocol.h> #include <net/netfilter/early_ingress.h>
@@ -303,9 +304,16 @@ static const struct net_offload nft_tcp4_offload = { }, }; +static const struct net_offload nft_esp4_offload = { + .callbacks = { + .gso_segment = nft_esp_gso_segment, + }, +}; +static const struct net_offload __rcu *nft_ip_offloads[MAX_INET_PROTOS ]__read_mostly = { [IPPROTO_UDP ] = &nft_udp4_offload, [IPPROTO_TCP ] = &nft_tcp4_offload, + [IPPROTO_ESP ] = &nft_esp4_offload, };void nf_early_ingress_ip_enable (void )
net/ipv6/netfilter/early_ingress.c +8 -0
@@ -5,6 +5,7 @@#include <net/arp.h> #include <net/udp.h> #include <net/tcp.h> +#include <net/esp.h> #include <net/protocol.h> #include <net/netfilter/early_ingress.h> #include <net/ip6_route.h>
@@ -291,9 +292,16 @@ static const struct net_offload nft_tcp6_offload = { }, }; +static const struct net_offload nft_esp6_offload = { + .callbacks = { + .gso_segment = nft_esp_gso_segment, + }, +}; +static const struct net_offload __rcu *nft_ip6_offloads[MAX_INET_PROTOS ]__read_mostly = { [IPPROTO_UDP ] = &nft_udp6_offload, [IPPROTO_TCP ] = &nft_tcp6_offload, + [IPPROTO_ESP ] = &nft_esp6_offload, };void nf_early_ingress_ip6_enable (void )
net/netfilter/early_ingress.c +36 -0
@@ -5,6 +5,7 @@#include <net/arp.h> #include <net/udp.h> #include <net/tcp.h> +#include <net/esp.h> #include <net/protocol.h> #include <crypto/aead.h> #include <net/netfilter/early_ingress.h>
@@ -274,6 +275,41 @@ struct sk_buff **nft_tcp_gro_receive(struct sk_buff **head, struct sk_buff *skb)return pp; } +struct sk_buff *nft_esp_gso_segment (struct sk_buff *skb, +netdev_features_t features) +{ +struct xfrm_offload *xo =xfrm_offload (skb); +netdev_features_t esp_features = features; +struct crypto_aead *aead; +struct ip_esp_hdr *esph; +struct xfrm_state *x; + +if (!xo) +return ERR_PTR (-EINVAL ); + + x = skb->sp->xvec[skb->sp->len -1 ]; + aead = x->data; + esph =ip_esp_hdr (skb); + +if (esph->spi != x->id.spi) +return ERR_PTR (-EINVAL ); + +if (!pskb_may_pull (skb,sizeof (*esph) +crypto_aead_ivsize (aead))) +return ERR_PTR (-EINVAL ); + +__skb_pull (skb,sizeof (*esph) +crypto_aead_ivsize (aead)); + + skb->encap_hdr_csum =1 ; + +if (!(features &NETIF_F_HW_ESP ) || !x->xso.offload_handle || + (x->xso.dev != skb->dev)) + esp_features = features & ~(NETIF_F_SG |NETIF_F_CSUM_MASK ); + + xo->flags |=XFRM_GSO_SEGMENT ; + +return x->outer_mode->gso_segment (x, skb, esp_features); +} +static inline bool nf_hook_early_ingress_active (const struct sk_buff *skb) {#ifdef HAVE_JUMP_LABEL
net/xfrm/xfrm_output.c +4 -0
@@ -146,6 +146,10 @@ int xfrm_output_resume(struct sk_buff *skb, int err)while (likely ((err =xfrm_output_one (skb, err)) ==0 )) {nf_reset (skb); +if (!skb_dst (skb)->xfrm && skb->sp && + (skb_shinfo (skb)->gso_type &SKB_GSO_NFT )) +return -EREMOTE ; + err =skb_dst (skb)->ops->local_out (net, skb->sk, skb);if (unlikely (err !=1 )) goto out;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 8/13 netfilter: nft_chain_filter: add support for early ingress
In reply to Pablo Neira AyusoThis patch adds the new filter chain at the early ingress hook.
--- net/netfilter/nft_chain_filter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/nft_chain_filter.c +4 -2
@@ -277,9 +277,11 @@ static const struct nft_chain_type nft_chain_filter_netdev = { .name = "filter", .type = NFT_CHAIN_T_DEFAULT, .family = NFPROTO_NETDEV, - .hook_mask = (1 << NF_NETDEV_INGRESS), + .hook_mask = (1 << NF_NETDEV_INGRESS) | + (1 << NF_NETDEV_EARLY_INGRESS), .hooks = { - [NF_NETDEV_INGRESS] = nft_do_chain_netdev, + [NF_NETDEV_INGRESS] = nft_do_chain_netdev, + [NF_NETDEV_EARLY_INGRESS] = nft_do_chain_netdev, }, };
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 9/13 netfilter: nf_flow_table: add hooknum to flowtable type
In reply to Pablo Neira AyusoThis allows us to register different flowtable variants depending on the hook type, hence we can define flowtable for new hook types.
--- include/net/netfilter/nf_flow_table.h | 1 + net/ipv4/netfilter/nf_flow_table_ipv4.c | 1 + net/ipv6/netfilter/nf_flow_table_ipv6.c | 1 + net/netfilter/nf_flow_table_inet.c | 1 + net/netfilter/nf_tables_api.c | 120 +++++++++++++++++--------------- 5 files changed, 67 insertions(+), 57 deletions(-)
include/net/netfilter/nf_flow_table.h +1 -0
@@ -14,6 +14,7 @@ struct nf_flowtable;struct nf_flowtable_type {struct list_head list;int family; +unsigned int hooknum;int (*init)(struct nf_flowtable *ft);void (*free)(struct nf_flowtable *ft);nf_hookfn *hook;
net/ipv4/netfilter/nf_flow_table_ipv4.c +1 -0
@@ -7,6 +7,7 @@static struct nf_flowtable_type flowtable_ipv4 = { .family =NFPROTO_IPV4 , + .hooknum =NF_NETDEV_INGRESS , .init = nf_flow_table_init, .free = nf_flow_table_free, .hook = nf_flow_offload_ip_hook,
net/ipv6/netfilter/nf_flow_table_ipv6.c +1 -0
@@ -8,6 +8,7 @@static struct nf_flowtable_type flowtable_ipv6 = { .family =NFPROTO_IPV6 , + .hooknum =NF_NETDEV_INGRESS , .init = nf_flow_table_init, .free = nf_flow_table_free, .hook = nf_flow_offload_ipv6_hook,
net/netfilter/nf_flow_table_inet.c +1 -0
@@ -22,6 +22,7 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,static struct nf_flowtable_type flowtable_inet = { .family =NFPROTO_INET , + .hooknum =NF_NETDEV_INGRESS , .init = nf_flow_table_init, .free = nf_flow_table_free, .hook = nf_flow_offload_inet_hook,
net/netfilter/nf_tables_api.c +63 -57
197 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 10/13 netfilter: nf_flow_table: add flowtable for early ingress hook
In reply to Pablo Neira AyusoAdd the new flowtable type for the early ingress hook, this allows us to combine the custom GRO chaining with the flowtable abstraction to define fastpaths.
--- include/net/netfilter/nf_flow_table.h | 3 ++ net/ipv4/netfilter/nf_flow_table_ipv4.c | 11 ++++++ net/netfilter/nf_flow_table_ip.c | 62 +++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+)
include/net/netfilter/nf_flow_table.h +3 -0
@@ -126,6 +126,9 @@ unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state);unsigned int nf_flow_offload_ipv6_hook (void *priv,struct sk_buff *skb,const struct nf_hook_state *state); +unsigned int nf_flow_offload_early_ingress_ip_hook (void *priv, +struct sk_buff *skb, +const struct nf_hook_state *state);#define MODULE_ALIAS_NF_FLOWTABLE (family) \ MODULE_ALIAS("nf-flowtable-" __stringify(family))
net/ipv4/netfilter/nf_flow_table_ipv4.c +11 -0
@@ -14,15 +14,26 @@ static struct nf_flowtable_type flowtable_ipv4 = { .owner = THIS_MODULE, }; +static struct nf_flowtable_type flowtable_ipv4_early = { + .family =NFPROTO_IPV4 , + .hooknum =NF_NETDEV_EARLY_INGRESS , + .init = nf_flow_table_init, + .free = nf_flow_table_free, + .hook = nf_flow_offload_early_ingress_ip_hook, + .owner =THIS_MODULE , +}; +static int __init nf_flow_ipv4_module_init (void ) {nft_register_flowtable_type (&flowtable_ipv4); +nft_register_flowtable_type (&flowtable_ipv4_early);return 0 ; } static void __exit nf_flow_ipv4_module_exit(void) { +nft_unregister_flowtable_type (&flowtable_ipv4_early);nft_unregister_flowtable_type (&flowtable_ipv4); }
net/netfilter/nf_flow_table_ip.c +62 -0
71 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 11/13 netfilter: nft_flow_offload: enable offload after second packet is seen
In reply to Pablo Neira AyusoOnce we have a confirmed conntrack, ie. a packet went through the stack and a conntrack was added, then allow second packet to configure the flowtable offload.
This allows UDP media traffic going in only one direction to enable offloads.
--- net/netfilter/nft_flow_offload.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
net/netfilter/nft_flow_offload.c +3 -8
@@ -88,14 +88,9 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, goto out; } -if (test_bit (IPS_HELPER_BIT , &ct->status)) - goto out; - -if (ctinfo ==IP_CT_NEW || - ctinfo ==IP_CT_RELATED ) - goto out; - -if (test_and_set_bit (IPS_OFFLOAD_BIT , &ct->status)) +if (test_bit (IPS_HELPER_BIT , &ct->status) || + !test_bit (IPS_CONFIRMED_BIT , &ct->status) || +test_and_set_bit (IPS_OFFLOAD_BIT , &ct->status)) goto out; dir =CTINFO2DIR (ctinfo);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 12/13 netfilter: nft_flow_offload: remove secpath check
In reply to Pablo Neira AyusoIt is safe to place a flow that is coming from IPSec into the flowtable. So decapsulated can benefit from the flowtable fastpath.
--- net/netfilter/nft_flow_offload.c | 2 -- 1 file changed, 2 deletions(-)
net/netfilter/nft_flow_offload.c +0 -2
@@ -54,8 +54,6 @@ static bool nft_flow_offload_skip(struct sk_buff *skb)if (unlikely (opt->optlen))return true; -if (skb_sec_path (skb)) -return true;return false; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 13/13 netfilter: nft_flow_offload: make sure route is not stale
In reply to Pablo Neira AyusoUse dst_check() to validate that route is still valid, otherwise, tear down the flow entry and pass up packet to the standard forwarding path so we have a chance to cache the fresh route again.
--- net/netfilter/nf_flow_table_ip.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/netfilter/nf_flow_table_ip.c +10 -0
@@ -244,6 +244,11 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache; +if (dst_check (&rt->dst,0 )) { +flow_offload_teardown (flow); +return NF_ACCEPT ; + } +if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)) && (ip_hdr (skb)->frag_off &htons (IP_DF )) !=0 )return NF_ACCEPT ;
@@ -462,6 +467,11 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache; +if (dst_check (&rt->dst,0 )) { +flow_offload_teardown (flow); +return NF_ACCEPT ; + } +if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)))return NF_ACCEPT ;
Signature · 1 line
2.11.0
Quoted 12 lines
This patchset supports both layer 3 IPv4 and IPv6, and layer 4 TCP and UDP protocols. This fastpath also integrates with the IPSec infrastructure and the ESP protocol.
We have collected performance numbers:
TCP TSO TCP Fast Forward
32.5 Gbps 35.6 GbpsUDP UDP Fast Forward
17.6 Gbps 35.6 Gbps
Quoted 8 lines
ESP ESP Fast Forward
6 Gbps 7.5 GbpsFor UDP, this is doubling performance, and we almost achieve line rate with one single CPU using the Intel i40e NIC. We got similar numbers with the Mellanox ConnectX-4. For TCP, this is slightly improving things even if TSO is being defeated given that we need to segment the packet chain in software.
The difference between TCP and UDP stems from lack of GRO for UDP. We recently added UDP GSO to allow for batch traversal of the UDP stack on transmission. Adding a UDP GRO handler can probably extend batching to the forwarding path in a similar way without the need for a new infrastructure.
Steffen Klassert
maintainerQuoted 15 lines · Willem de Bruijn
Quoted 15 lines
This patchset supports both layer 3 IPv4 and IPv6, and layer 4 TCP and UDP protocols. This fastpath also integrates with the IPSec infrastructure and the ESP protocol.
We have collected performance numbers:
TCP TSO TCP Fast Forward
32.5 Gbps 35.6 GbpsUDP UDP Fast Forward
17.6 Gbps 35.6 GbpsESP ESP Fast Forward
6 Gbps 7.5 Gbps
Quoted 7 lines
Quoted 5 lines
For UDP, this is doubling performance, and we almost achieve line rate with one single CPU using the Intel i40e NIC. We got similar numbers with the Mellanox ConnectX-4. For TCP, this is slightly improving things even if TSO is being defeated given that we need to segment the packet chain in software.
The difference between TCP and UDP stems from lack of GRO for UDP.
Right.
Quoted 4 lines
We
recently added UDP GSO to allow for batch traversal of the UDP stack on transmission. Adding a UDP GRO handler can probably extend batching to the forwarding path in a similar way without the need for a new infrastructure.
That's more or less what we did. The batching method ist just optimized for the forwarding path. We are generating skb chains by chaning at the frag_list pointer of the first skb. With that, we don't need to mange packet. We keep the packets in the native form, so the 'segmentation' is rather easy.
The rest is just to be able to configure this and to make sure that we handle only flows that are going to be (fast) forwarded, as the upper stack can not (yet) handle such skb chains.
Quoted 14 lines · Pablo Neira Ayuso
Hi,
We have collected performance numbers:
TCP TSO TCP Fast Forward
32.5 Gbps 35.6 GbpsUDP UDP Fast Forward
17.6 Gbps 35.6 GbpsESP ESP Fast Forward
6 Gbps 7.5 Gbps
Quoted 7 lines
For UDP, this is doubling performance, and we almost achieve line rate with one single CPU using the Intel i40e NIC. We got similar numbers with the Mellanox ConnectX-4. For TCP, this is slightly improving things even if TSO is being defeated given that we need to segment the packet chain in software. We would like to explore HW GRO support with hardware vendors with this new mode, we think that should improve the TCP numbers we are showing above even more.
Hi Pablo
Not very convincing numbers, because it is unclear what traffic patterns were used.
We normally use packets per second to measure a forwarding workload, and it is not clear if you tried a DDOS, or/and a mix of packets being locally delivered and packets being forwarded.
Presumably adding cache line misses (to probe for flows) will slow down the things.
I suspect the NIC you use has some kind of bottleneck on sending TSO packets, or that you hit the issue that GRO might cook suboptimal packets for forwarding workloads (eg setting frag_list)
This path series add yet more code to GRO engine which is already very fat to the point many people advocate to turn it off.
Saving cpu cycles on moderate load is not okay if added complexity slows down the DDOS (or stress) by 10 % :/
To me, GRO is specialized to optimize the non-forwarding case, so it is counter-intuitive to base a fast forwarding path on top of it.
Steffen Klassert
maintainerQuoted 25 lines · Eric Dumazet
Quoted 14 lines · Pablo Neira Ayuso
Hi,
We have collected performance numbers:
TCP TSO TCP Fast Forward
32.5 Gbps 35.6 GbpsUDP UDP Fast Forward
17.6 Gbps 35.6 GbpsESP ESP Fast Forward
6 Gbps 7.5 GbpsQuoted 7 lines
For UDP, this is doubling performance, and we almost achieve line rate with one single CPU using the Intel i40e NIC. We got similar numbers with the Mellanox ConnectX-4. For TCP, this is slightly improving things even if TSO is being defeated given that we need to segment the packet chain in software. We would like to explore HW GRO support with hardware vendors with this new mode, we think that should improve the TCP numbers we are showing above even more.
Quoted 7 lines
Hi Pablo
Not very convincing numbers, because it is unclear what traffic patterns were used.
We normally use packets per second to measure a forwarding workload, and it is not clear if you tried a DDOS, or/and a mix of packets being locally delivered and packets being forwarded.
Yes, these number need some more explaination. We used my IPsec forwarding test setup for this. It looks like this:
------------ ------------ -->| router 1 |-------->| router 2 |-- | ------------ ------------ | | | | -------------------- | --------|Spirent Testcenter|<---------- --------------------
The numbers are from single stream forwarding tests, no local delivery. Packet size in the UDP case was 1460 byte. I used this packet size because such packets still fit into the mtu when encapsulated by IPsec.
Quoted 6 lines
Presumably adding cache line misses (to probe for flows) will slow down the things.
I suspect the NIC you use has some kind of bottleneck on sending TSO packets, or that you hit the issue that GRO might cook suboptimal packets for forwarding workloads (eg setting
frag_list)
That might be, I was a bit surprised about the TCP numbers myself. I was more focused on UDP and IPsec because these don't have hardware segmentation support. I've just added a TCP handler to see what happens, the numbers looked ok, so I kept it.
All this is based on the approach I pesented last year at the nefilter workshop.
Quoted 3 lines
This path series add yet more code to GRO engine which is already very fat to the point many people advocate to turn it off.
We tried to stay away from the generic codepath as much as possible. Currently we need five 'if' statements, two of them are in error paths (Patch 4).
Quoted 2 lines
Saving cpu cycles on moderate load is not okay if added complexity slows down the DDOS (or stress) by 10 % :/
Why 10%?
Quoted 3 lines
To me, GRO is specialized to optimize the non-forwarding case, so it is counter-intuitive to base a fast forwarding path on top of it.
It is optimized for the non-forwarding case, but it seems that forwarding can benefit from that too with very little cost for the non-forwarding case.
Quoted 8 lines · Steffen Klassert
Quoted 4 lines · Eric Dumazet
Saving cpu cycles on moderate load is not okay if added complexity slows down the DDOS (or stress) by 10 % :/
Why 10%?
GRO adds a ~6 % cost on UDP receive path at this moment, depending on the state of GRO engine (number of packets in the napi->gro_list)
Adding yet another conditions and icache pressure might raise the cost to 10%, but we do not know because the numbers presented in this RFC do not include that.
(Early demux is also adding extra costs for UDP on 'non connected sockets' BTW)
Most linux hosts are not routers, but end hosts, lets not forget this...
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Thu, 14 Jun 2018 16:19:34 +0200
Quoted 6 lines
This patchset proposes a new fast forwarding path infrastructure that combines the GRO/GSO and the flowtable infrastructures. The idea is to add a hook at the GRO layer that is invoked before the standard GRO protocol offloads. This allows us to build custom packet chains that we can quickly pass in one go to the neighbour layer to define fast forwarding path for flows.
We have full, complete, customizability of the packet path via XDP and eBPF.
XDP and eBPF supports everything necessary to accomplish that, there are implementations of forwarding implementations in the tree and elsewhere.
And most importantly, XDP and eBPF are optimized in drivers and offloaded to hardware.
There really is no need for something like what you are proposing.
Quoted 13 lines · David Miller
From: Pablo Neira Ayuso <[email protected]>
Date: Thu, 14 Jun 2018 16:19:34 +0200Quoted 6 lines
This patchset proposes a new fast forwarding path infrastructure that combines the GRO/GSO and the flowtable infrastructures. The idea is to add a hook at the GRO layer that is invoked before the standard GRO protocol offloads. This allows us to build custom packet chains that we can quickly pass in one go to the neighbour layer to define fast forwarding path for flows.
We have full, complete, customizability of the packet path via XDP and eBPF.
Quoted 9 lines
XDP and eBPF supports everything necessary to accomplish that, there are implementations of forwarding implementations in the tree and elsewhere.
And most importantly, XDP and eBPF are optimized in drivers and offloaded to hardware.
There really is no need for something like what you are proposing.
I see one possible upside to that approach here which is the low end MIPS/ARM/PowerPC 32-bit based routers that do not have an eBPF JIT available (that's only MIPS32 and PowerPC AFAICT), it would be great to see what happens on those systems and if we do get any performance improvements for a traditional forwarding/routing workload. On those platforms there are a number of things that just literally kill the routing performance: small I and D caches, small or not L2, limited bandwidth DRAM, huge call depths, big struct sk_buff layout, you name it.
Signature · 1 line
Florian
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Thu, 14 Jun 2018 11:14:37 -0700
Quoted 4 lines
On those platforms there are a number of things that just literally kill the routing performance: small I and D caches, small or not L2, limited bandwidth DRAM, huge call depths, big struct
sk_bufflayout, you name it.
Another reason to work on a 64-bit MIPS eBPF JIT.
We have a model, and game plan for this kind of application. And it's XDP and eBPF with JITs.
We are fully commited to this approach, and I see anything else that tries to slip in and approach some sub-part of the problem as a complete distraction and a step backwards.
All of the effort on this work could have been spent filling in the missing pieces you mention.
And guess what? Then millions of possibilities would have been openned up, rather than just this one special case.
So, I ask, please see the larger picture.
Thank you.
Quoted 4 lines · David Miller
And guess what? Then millions of possibilities would have been openned up, rather than just this one special case.
So, I ask, please see the larger picture.
+cc netdev/etc
This is perhaps unrelated to the topic at hand, but as someone who's shipped a bunch of devices over the years using the linux kernel forwarding path and needs performance but wants to avoid moving to out of tree userspace offload for all the reasons that you and many others have stated, is the long term vision that the existing kernel forwarding path will transparently take advantage of eBPF (ala bpfilter), or that users will write custom/individualized eBPF forwarding paths for their usecases as necessary?
I (and I suspect many others) will start on the latter anyways, I'm just curious whether it's desired/expected that such custom fastpath users will eventually be rolled back into/replaced by a transparent upstream in-kernel equivalent.
Steffen Klassert
maintainerQuoted 13 lines · David Miller
From: Pablo Neira Ayuso <[email protected]>
Date: Thu, 14 Jun 2018 16:19:34 +0200Quoted 6 lines
This patchset proposes a new fast forwarding path infrastructure that combines the GRO/GSO and the flowtable infrastructures. The idea is to add a hook at the GRO layer that is invoked before the standard GRO protocol offloads. This allows us to build custom packet chains that we can quickly pass in one go to the neighbour layer to define fast forwarding path for flows.
We have full, complete, customizability of the packet path via XDP and eBPF.
Quoted 8 lines
XDP and eBPF supports everything necessary to accomplish that, there are implementations of forwarding implementations in the tree and elsewhere.
And most importantly, XDP and eBPF are optimized in drivers and offloaded to hardware.
There really is no need for something like what you are proposing.
I started with this last year because I wanted to improve the IPsec (and UDP) forwarding path. Batching packets at layer2 and send them directly to the output path seemed to be a good method to improve this.
In particular, we need to do only one IPsec lookup for the whole packet chain. So it relaxes the pain from reomoving the IPsec flowcache a bit. It can be only a first step, but we need some improvements here as people start to complain about that.
Hi Steffen,
Quoted 28 lines · Steffen Klassert
Quoted 13 lines · David Miller
From: Pablo Neira Ayuso <[email protected]>
Date: Thu, 14 Jun 2018 16:19:34 +0200Quoted 6 lines
This patchset proposes a new fast forwarding path infrastructure that combines the GRO/GSO and the flowtable infrastructures. The idea is to add a hook at the GRO layer that is invoked before the standard GRO protocol offloads. This allows us to build custom packet chains that we can quickly pass in one go to the neighbour layer to define fast forwarding path for flows.
We have full, complete, customizability of the packet path via XDP and eBPF.
Quoted 8 lines
XDP and eBPF supports everything necessary to accomplish that, there are implementations of forwarding implementations in the tree and elsewhere.
And most importantly, XDP and eBPF are optimized in drivers and offloaded to hardware.
There really is no need for something like what you are proposing.
I started with this last year because I wanted to improve the IPsec (and UDP) forwarding path. Batching packets at layer2 and send them directly to the output path seemed to be a good method to improve this.
Quoted 5 lines
In particular, we need to do only one IPsec lookup for the whole packet chain. So it relaxes the pain from reomoving the IPsec flowcache a bit. It can be only a first step, but we need some improvements here as people start to complain about that.
But did you also experiment with XDP on this? Would be curious about the numbers. You'd get implicit batching for the forwarding via devmap as well if you're required to flush it out via different device with XDP_REDIRECT; otherwise XDP_TX of course. Given we have recently integrated helpers for XDP to do a FIB and neighbor lookup from the kernel tables, where it's thus shared and integrated with the rest of the stack and tooling, it would be awesome to get to the same point with xfrm as well. Eyal recently did a start on that for xfrm for tc progs; would be nice to have integration on XDP as well, potentially it might also result in a bigger plus on the forwarding numbers.
Thanks,
Daniel
Steffen Klassert
maintainerHi Daniel,
Quoted 9 lines · Daniel Borkmann
Hi Steffen,
Quoted 6 lines · Steffen Klassert
I started with this last year because I wanted to improve the IPsec (and UDP) forwarding path. Batching packets at layer2 and send them directly to the output path seemed to be a good method to improve this.
Quoted 7 lines
Quoted 5 lines
In particular, we need to do only one IPsec lookup for the whole packet chain. So it relaxes the pain from reomoving the IPsec flowcache a bit. It can be only a first step, but we need some improvements here as people start to complain about that.
But did you also experiment with XDP on this?
I've already tried to figure out what I have to to do to get XDP with forwarding, but still don't realy know how to set this up.
Maybe it is time to have a deeper look into BPF/XDP, but for now I feel a bit lost with this.
Quoted 10 lines
Would be curious about
the numbers. You'd get implicit batching for the forwarding via devmap as well if you're required to flush it out via different device withXDP_REDIRECT; otherwiseXDP_TXof course. Given we have recently integrated helpers for XDP to do a FIB and neighbor lookup from the kernel tables, where it's thus shared and integrated with the rest of the stack and tooling, it would be awesome to get to the same point with xfrm as well. Eyal recently did a start on that for xfrm for tc progs; would be nice to have integration on XDP as well, potentially it might also result in a bigger plus on the forwarding numbers.
It might make sense to intrgrate XDP with xfrm to be able to compare numbers etc. But I need a working XDP setup and some understanding about it first, what could take some time.
On 06/17/2018 11:23 AM, Steffen Klassert wrote:
[...]
Quoted 11 lines
Quoted 10 lines
Would be curious about
the numbers. You'd get implicit batching for the forwarding via devmap as well if you're required to flush it out via different device withXDP_REDIRECT; otherwiseXDP_TXof course. Given we have recently integrated helpers for XDP to do a FIB and neighbor lookup from the kernel tables, where it's thus shared and integrated with the rest of the stack and tooling, it would be awesome to get to the same point with xfrm as well. Eyal recently did a start on that for xfrm for tc progs; would be nice to have integration on XDP as well, potentially it might also result in a bigger plus on the forwarding numbers.
Quoted 4 lines
It might make sense to intrgrate XDP with xfrm to be able to compare numbers etc. But I need a working XDP setup and some understanding about it first, what could take some time.
Okay, no prob. If you have any questions feel free to shoot an email.
Thanks,
Daniel
Quoted 15 lines · Pablo Neira Ayuso
Hi,
This patchset proposes a new fast forwarding path infrastructure that combines the GRO/GSO and the flowtable infrastructures. The idea is to add a hook at the GRO layer that is invoked before the standard GRO protocol offloads. This allows us to build custom packet chains that we can quickly pass in one go to the neighbour layer to define fast forwarding path for flows.
For each packet that gets into the GRO layer, we first check if there is an entry in the flowtable, if so, the packet is placed in a list until the GRO infrastructure decides to send the batch from
gro_completeto the neighbour layer. The first packet in the list takes the route from the flowtable entry, so we avoid reiterative routing lookups.
Quoted 8 lines
In case no entry is found in the flowtable, the packet is passed up to the classic GRO offload handlers. Thus, this packet follows the standard forwarding path. Note that the initial packets of the flow always go through the standard IPv4/IPv6 netfilter forward hook, that is used to configure what flows are placed in the flowtable. Therefore, only a few (initial) packets follow the standard forwarding path while most of the follow up packets take this new fast forwarding path.
IIRC, there was a similar proposal a while back that want to bundle packets of the same flow together (without doing GRO) so that they could be processed by various functions by looking at just one representative packet in the group. The concept had some promise, but in the end it created quite a bit of complexity since at some point the packet bundle needed to be undone to go back to processing the individual packets.
Tom
Quoted 109 lines
The fast forwarding path is enabled through explicit user policy, so the user needs to request this behaviour from control plane, the following example shows how to place flows in the new fast forwarding path from the netfilter forward chain:
table x { flowtable f { hook early_ingress priority 0; devices = { eth0, eth1 } } chain y { type filter hook forward priority 0; ip protocol tcp flow offload @f }}
The example above defines a fastpath for TCP flows that are placed in the flowtable 'f', this flowtable is hooked at the new
early_ingresshook. The initial TCP packets that match this rule from the standard fowarding path create an entry in the flowtable, thus, GRO creates chain of packets for those that find an entry in the flowtable and send them through the neighbour layer.This new hook is happening before the ingress taps, therefore, packets that follow this new fast forwarding path are not shown by tcpdump.
This patchset supports both layer 3 IPv4 and IPv6, and layer 4 TCP and UDP protocols. This fastpath also integrates with the IPSec infrastructure and the ESP protocol.
We have collected performance numbers:
TCP TSO TCP Fast Forward
32.5 Gbps 35.6 GbpsUDP UDP Fast Forward
17.6 Gbps 35.6 GbpsESP ESP Fast Forward
6 Gbps 7.5 GbpsFor UDP, this is doubling performance, and we almost achieve line rate with one single CPU using the Intel i40e NIC. We got similar numbers with the Mellanox ConnectX-4. For TCP, this is slightly improving things even if TSO is being defeated given that we need to segment the packet chain in software. We would like to explore HW GRO support with hardware vendors with this new mode, we think that should improve the TCP numbers we are showing above even more. For ESP traffic, performance improvement is ~25%, in this case, perf shows the bottleneck becomes the crypto layer.
This patchset is co-authored work with Steffen Klassert.
Comments are welcome, thanks.
Pablo Neira Ayuso (6):
netfilter:nft_chain_filter: add support for early ingress
netfilter:nf_flow_table: add hooknum to flowtable type
netfilter:nf_flow_table: add flowtable for early ingress hook
netfilter:nft_flow_offload: enable offload after second packet is seen
netfilter:nft_flow_offload: remove secpath check
netfilter:nft_flow_offload: make sure route is not staleSteffen Klassert (7):
net: Add a helper to get the packet offload callbacks by priority.
net: Change priority of ipv4 and ipv6 packet offloads.
net: Add a GSO feature bit for the netfilter forward fastpath.
net: Use one bit ofNAPI_GRO_CBfor the netfilter fastpath.
netfilter: add early ingress hook for IPv4
netfilter: add early ingress support for IPv6
netfilter: add ESP support for early ingressinclude/linux/netdev_features.h | 4 +- include/linux/netdevice.h | 6 +- include/linux/netfilter.h | 6 + include/linux/netfilter_ingress.h | 1 + include/linux/skbuff.h | 2 + include/net/netfilter/early_ingress.h | 24 +++ include/net/netfilter/nf_flow_table.h | 4 + include/uapi/linux/netfilter.h | 1 + net/core/dev.c | 50 ++++- net/ipv4/af_inet.c | 1 + net/ipv4/netfilter/Makefile | 1 + net/ipv4/netfilter/early_ingress.c | 327 +++++++++++++++++++++++++++++ net/ipv4/netfilter/nf_flow_table_ipv4.c | 12 ++ net/ipv6/ip6_offload.c | 1 + net/ipv6/netfilter/Makefile | 1 + net/ipv6/netfilter/early_ingress.c | 315 ++++++++++++++++++++++++++++ net/ipv6/netfilter/nf_flow_table_ipv6.c | 1 + net/netfilter/Kconfig | 8 + net/netfilter/Makefile | 1 + net/netfilter/core.c | 35 +++- net/netfilter/early_ingress.c | 361 ++++++++++++++++++++++++++++++++ net/netfilter/nf_flow_table_inet.c | 1 + net/netfilter/nf_flow_table_ip.c | 72 +++++++ net/netfilter/nf_tables_api.c | 120 ++++++----- net/netfilter/nft_chain_filter.c | 6 +- net/netfilter/nft_flow_offload.c | 13 +- net/xfrm/xfrm_output.c | 4 + 27 files changed, 1297 insertions(+), 81 deletions(-) create mode 100644 include/net/netfilter/early_ingress.h create mode 100644 net/ipv4/netfilter/early_ingress.c create mode 100644 net/ipv6/netfilter/early_ingress.c create mode 100644 net/netfilter/early_ingress.c--
2.11.0
David Miller
maintainerFrom: Tom Herbert <[email protected]>
Date: Thu, 14 Jun 2018 13:52:03 -0700
Quoted 7 lines
IIRC, there was a similar proposal a while back that want to bundle packets of the same flow together (without doing GRO) so that they could be processed by various functions by looking at just one representative packet in the group. The concept had some promise, but in the end it created quite a bit of complexity since at some point the packet bundle needed to be undone to go back to processing the individual packets.
You're probably talking about Edward Cree's SKB list stuff, and as per his presenation at netconf 2 weeks ago he plans to revitalize it given how Spectre et al. gives cause to reevaluate all bulking techniques.
Steffen Klassert
maintainerQuoted 11 lines · David Miller
From: Tom Herbert <[email protected]>
Date: Thu, 14 Jun 2018 13:52:03 -0700Quoted 7 lines
IIRC, there was a similar proposal a while back that want to bundle packets of the same flow together (without doing GRO) so that they could be processed by various functions by looking at just one representative packet in the group. The concept had some promise, but in the end it created quite a bit of complexity since at some point the packet bundle needed to be undone to go back to processing the individual packets.
Quoted 4 lines
You're probably talking about Edward Cree's SKB list stuff, and as per his presenation at netconf 2 weeks ago he plans to revitalize it given how Spectre et al. gives cause to reevaluate all bulking techniques.
Are there patches for the proposal Edward did a while ago, or was it just a concept?
Maybe we can somehow put things together, I just need some batching method that works for IPsec and UDP. It does not need to be exactly the one we proposing here.
Quoted 7 lines · Steffen Klassert
Quoted 4 lines · David Miller
You're probably talking about Edward Cree's SKB list stuff, and as per his presenation at netconf 2 weeks ago he plans to revitalize it given how Spectre et al. gives cause to reevaluate all bulking techniques.
Are there patches for the proposal Edward did a while ago, or was it just a concept?
Old patches are at http://lists.openwall.net/netdev/2016/04/19/89
(note that the absolute numbers I give in the cover letter are wrong; I quoted them as Mpps but they're actually Mbps which is 8x higher). I hope to have a new series ready shortly after net-next reopens.
-Ed
Quoted 11 lines · David Miller
From: Tom Herbert <[email protected]>
Date: Thu, 14 Jun 2018 13:52:03 -0700Quoted 7 lines
IIRC, there was a similar proposal a while back that want to bundle packets of the same flow together (without doing GRO) so that they could be processed by various functions by looking at just one representative packet in the group. The concept had some promise, but in the end it created quite a bit of complexity since at some point the packet bundle needed to be undone to go back to processing the individual packets.
Quoted 4 lines
You're probably talking about Edward Cree's SKB list stuff, and as per his presenation at netconf 2 weeks ago he plans to revitalize it given how Spectre et al. gives cause to reevaluate all bulking techniques.nearly
The use case for that will be an interesting question. GSO/GRO solves the problem for TCP and this extends to nearly all cases where TCP is in an encapsulated packet. Super efficient forwarding can be done in XDP/BPF (without needing overhead of GSO/GRO). That pretty much leaves UDP as non-encapsulation end protocol, which I guess these days pretty much means QUIC :-) I am still interested to see if we can implement GSO/GRO for QUIC (via a generic GSO/GRO BPF function so we don't hardcode any QUIC protocol or other application protocols in kernel).
Tom
Steffen Klassert
maintainerQuoted 25 lines · Tom Herbert
Quoted 15 lines · Pablo Neira Ayuso
Hi,
This patchset proposes a new fast forwarding path infrastructure that combines the GRO/GSO and the flowtable infrastructures. The idea is to add a hook at the GRO layer that is invoked before the standard GRO protocol offloads. This allows us to build custom packet chains that we can quickly pass in one go to the neighbour layer to define fast forwarding path for flows.
For each packet that gets into the GRO layer, we first check if there is an entry in the flowtable, if so, the packet is placed in a list until the GRO infrastructure decides to send the batch from
gro_completeto the neighbour layer. The first packet in the list takes the route from the flowtable entry, so we avoid reiterative routing lookups.Quoted 8 lines
In case no entry is found in the flowtable, the packet is passed up to the classic GRO offload handlers. Thus, this packet follows the standard forwarding path. Note that the initial packets of the flow always go through the standard IPv4/IPv6 netfilter forward hook, that is used to configure what flows are placed in the flowtable. Therefore, only a few (initial) packets follow the standard forwarding path while most of the follow up packets take this new fast forwarding path.
Quoted 7 lines
IIRC, there was a similar proposal a while back that want to bundle packets of the same flow together (without doing GRO) so that they could be processed by various functions by looking at just one representative packet in the group. The concept had some promise, but in the end it created quite a bit of complexity since at some point the packet bundle needed to be undone to go back to processing the individual packets.
With the way we chain the packets it is not too complicated to undo this chaining (nft_skb_segment in patch 5 implements this). After that, this looks like a chain of usual segments, so we trigger xmit_more with every packet chain.