Skip to contentSkip to conversation

netfilter: flowtable bulking

RFC PATCH In review Pablo Neira Ayuso 4 participants 16 messages Mar 17 – Mar 20

Subsystems (3)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover netfilter: flowtable bulking

Hi,

Back in 2018 [1], a new fast forwarding combining the flowtable and GRO/GSO was proposed, however, "GRO is specialized to optimize the non-forwarding case", so it was considered "counter-intuitive to base a fast forwarding path on top of it".

Then, Steffen Klassert proposed the idea of adding a new engine for the flowtable that operates on the skb list that is provided after the NAPI cycle. The idea is to process this skb list to create bulks grouped by the ethertype, output device, next hop and tos/dscp. Then, add a specialized xmit path that can deal with these skb bulks. Note that GRO needs to be disabled so this new forwarding engine obtains the list of skbs that resulted from the NAPI cycle.

Before grouping skbs in bulks, there is a flowtable lookup to check if this flow is already in the flowtable, otherwise, the packet follows slow path. In case the flowtable lookup returns an entry, then this packet follows fast path: the ttl is decremented, the corresponding NAT mangling on the packet and layer 2/3 tunnel encapsulation (layer 2:
vlan/pppoe, layer 3: ipip) are performed.

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 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 counter
        }

}

The example above sets up 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.

Note that tcpdump only shows the packets in the tx path, since this new early_ingress hook happens before the ingress tap.

The patch series contains 8 patches:

- #1 and #2 adds the basic RX flowtable bulking infrastructure for IPv4 and IPv6.
- #3 adds the early_ingress netfilter hook.
- #4 adds a helper function to prepare for the netfilter chain for the early_ingress hook.
- #5 adds the early_ingress filter chain.
- #6 and #7 add helper functions to reuse TX path codebase.
- #8 adds the custom TX path for listified skbs and updates the flowtable bulking to use it.

= Benchmark numbers =

Using the following testbed with 4 hosts with this topology:

| sunset |-----| west |====| east |----| sunrise |

And this hardware:

* Supermicro H13SSW Motherboard
* AMD EPYC 9135 16-Core Processor (a.k.a. Bergamo, or Zen 5)
* NIC: Mellanox MT28800 ConnectX-5 Ex (100Gbps NIc)
* NIC: Broadcom BCM57508 NetXtreme-E (only on sunrise, 100Gbps NIc)

With 128 byte packets:

* From ~2 Mpps (baseline) to ~4 Mpps with 1 flow.
* From ~10.6 Mpps (baseline) to ~15.7 Mpps with 10 flows.

Antony Antony collected performance numbers and made a report describing this the benchmarking[2]. This report includes numbers from the IPsec support which is not included in this series.

Comments welcome, thanks.

Pablo Neira Ayuso (8):
netfilter: flowtable: Add basic bulking infrastructure for early ingress hook
netfilter: flowtable: Add IPv6 bulking infrastructure for early ingress hook
netfilter: nf_tables: add flowtable early_ingress support
netfilter: nf_tables: add nft_set_pktinfo_ingress()
netfilter: nf_tables: add early ingress chain
net: add dev_dst_drop() helper function
net: add dev_noqueue_xmit_list() helper function
net: add dev_queue_xmit_list() and use it

 include/linux/netdevice.h             |   2 +
 include/net/netfilter/nf_flow_table.h |  13 +-
 net/core/dev.c                        | 297 ++++++++++++++++----
 net/netfilter/nf_flow_table_inet.c    |  81 ++++++
 net/netfilter/nf_flow_table_ip.c      | 384 ++++++++++++++++++++++++++
 net/netfilter/nf_tables_api.c         |  12 +-
 net/netfilter/nft_chain_filter.c      | 164 +++++++++--
 7 files changed, 872 insertions(+), 81 deletions(-)
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

RFC PATCH 1/8 netfilter: flowtable: Add basic bulking infrastructure for early ingress hook

Add support for registering an early_ingress hook for the flowtable to deal with the skb list. Split initial this list in bulks according to ethertype, output device, next hop and tos.

Then, send each skb bulk through neighbour layer. The xmit path is not yet listified, ie. the bulk is splitted in individual skbuffs that are sent to xmit path, one by one, at this stage.

This only implements the flowtable RX bulking. The TX side comes as a follow up patch in this series.

---
 include/net/netfilter/nf_flow_table.h |  11 +-
 net/netfilter/nf_flow_table_inet.c    |  79 ++++++++++
 net/netfilter/nf_flow_table_ip.c      | 209 ++++++++++++++++++++++++++
 3 files changed, 298 insertions(+), 1 deletion(-)
include/net/netfilter/nf_flow_table.h +10 -1
index b09c11c048d5..ee98da9edc1b 100644
@@ -18,6 +18,13 @@ struct nf_flow_rule;
 struct flow_offload;
 enum flow_offload_tuple_dir;
 
+struct nft_bulk_cb {
+	struct sk_buff *last;
+	struct flow_offload_tuple_rhash *tuplehash;
+};
+
+#define NFT_BULK_CB(skb) ((struct nft_bulk_cb *)(skb)->cb)
+
 struct nf_flow_key {
 	struct flow_dissector_key_meta			meta;
 	struct flow_dissector_key_control		control;
@@ -65,6 +72,7 @@ struct nf_flowtable_type {
 	void				(*get)(struct nf_flowtable *ft);
 	void				(*put)(struct nf_flowtable *ft);
 	nf_hookfn			*hook;
+	nf_hookfn			*hook_list;
 	struct module			*owner;
 };
 
@@ -77,7 +85,6 @@ struct nf_flowtable {
 	unsigned int			flags;		/* readonly in datapath */
 	int				priority;	/* control path (padding hole) */
 	struct rhashtable		rhashtable;	/* datapath, read-mostly members come first */
-
 	struct list_head		list;		/* slowpath parts */
 	const struct nf_flowtable_type	*type;
 	struct delayed_work		gc_work;
@@ -339,6 +346,8 @@ 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);
+void __nf_flow_offload_ip_hook_list(void *priv, struct list_head *head,
+				    const struct nf_hook_state *state);
 
 #if (IS_BUILTIN(CONFIG_NF_FLOW_TABLE) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) || \
     (IS_MODULE(CONFIG_NF_FLOW_TABLE) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
net/netfilter/nf_flow_table_inet.c +79 -0

103 lines not on this page · raw message

net/netfilter/nf_flow_table_ip.c +209 -0

215 lines not on this page · raw message

Signature · 1 line
2.47.3
author maintainer
#2 lore raw

RFC PATCH 2/8 netfilter: flowtable: Add IPv6 bulking infrastructure for early ingress hook

In reply to Pablo Neira Ayuso

Extend bulking infrastructure to support for IPv6. Split skb list in bulks according to ethertype, output device and next hop. Then, send each bulk through neighbour layer.

This only implements the flowtable RX bulking. The TX side comes as a follow up patch in this series.

---
 include/net/netfilter/nf_flow_table.h |   2 +
 net/netfilter/nf_flow_table_inet.c    |   2 +
 net/netfilter/nf_flow_table_ip.c      | 173 ++++++++++++++++++++++++++
 3 files changed, 177 insertions(+)
include/net/netfilter/nf_flow_table.h +2 -0
index ee98da9edc1b..3d41c739f634 100644
@@ -348,6 +348,8 @@ unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
 				       const struct nf_hook_state *state);
 void __nf_flow_offload_ip_hook_list(void *priv, struct list_head *head,
 				    const struct nf_hook_state *state);
+void __nf_flow_offload_ipv6_hook_list(void *priv, struct list_head *head,
+				      const struct nf_hook_state *state);
 
 #if (IS_BUILTIN(CONFIG_NF_FLOW_TABLE) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) || \
     (IS_MODULE(CONFIG_NF_FLOW_TABLE) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
net/netfilter/nf_flow_table_inet.c +2 -0
index d0e7860c9d08..6efcb26c4523 100644
@@ -84,6 +84,8 @@ __nf_flow_offload_hook_list(void *priv, struct sk_buff *unused,
 
 	if (flags & (1 << NFPROTO_IPV4) && !list_empty(&skb_ipv4_list))
 		__nf_flow_offload_ip_hook_list(priv, &skb_ipv4_list, state);
+	if (flags & (1 << NFPROTO_IPV6) && !list_empty(&skb_ipv6_list))
+		__nf_flow_offload_ipv6_hook_list(priv, &skb_ipv6_list, state);
 
 	list_splice_tail(&skb_ipv4_list, skb_list);
 	list_splice_tail(&skb_ipv6_list, skb_list);
net/netfilter/nf_flow_table_ip.c +173 -0

176 lines not on this page · raw message

Signature · 1 line
2.47.3
author maintainer
#3 lore raw

RFC PATCH 3/8 netfilter: nf_tables: add flowtable early_ingress support

In reply to Pablo Neira Ayuso

Update control plane to allow to create a flowtable in the early_ingress hook.

---
 net/netfilter/nf_tables_api.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +10 -2
index 1ed034a47bd0..66fadf4c6e3e 100644
@@ -8969,7 +8969,8 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,
 		}
 
 		hooknum = ntohl(nla_get_be32(tb[NFTA_FLOWTABLE_HOOK_NUM]));
-		if (hooknum != NF_NETDEV_INGRESS)
+		if (hooknum != NF_NETDEV_INGRESS &&
+		    hooknum != NF_NETDEV_EARLY_INGRESS)
 			return -EOPNOTSUPP;
 
 		priority = ntohl(nla_get_be32(tb[NFTA_FLOWTABLE_HOOK_PRIORITY]));
@@ -9008,7 +9009,14 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,
 			ops->hooknum		= flowtable_hook->num;
 			ops->priority		= flowtable_hook->priority;
 			ops->priv		= &flowtable->data;
-			ops->hook		= flowtable->data.type->hook;
+			switch (ops->hooknum) {
+			case NF_NETDEV_INGRESS:
+				ops->hook	= flowtable->data.type->hook;
+				break;
+			case NF_NETDEV_EARLY_INGRESS:
+				ops->hook	= flowtable->data.type->hook_list;
+				break;
+			}
 			ops->hook_ops_type	= NF_HOOK_OP_NFT_FT;
 		}
 	}
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

RFC PATCH 4/8 netfilter: nf_tables: add nft_set_pktinfo_ingress()

In reply to Pablo Neira Ayuso

Add helper function to prepare for early ingress filtering support.

No functional changes are intended, this is a preparation patch.

---
 net/netfilter/nft_chain_filter.c | 48 ++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 15 deletions(-)
net/netfilter/nft_chain_filter.c +33 -15
index b16185e9a6dd..47a612bdd03e 100644
@@ -161,32 +161,50 @@ static unsigned int nft_do_chain_inet(void *priv, struct sk_buff *skb,
 	return nft_do_chain(&pkt, priv);
 }
 
-static unsigned int nft_do_chain_inet_ingress(void *priv, struct sk_buff *skb,
-					      const struct nf_hook_state *state)
+static int nft_set_pktinfo_ingress(struct nft_pktinfo *pkt,
+				   struct sk_buff *skb,
+				   struct nf_hook_state *ingress_state)
 {
-	struct nf_hook_state ingress_state = *state;
-	struct nft_pktinfo pkt;
-
 	switch (skb->protocol) {
 	case htons(ETH_P_IP):
 		/* Original hook is NFPROTO_NETDEV and NF_NETDEV_INGRESS. */
-		ingress_state.pf = NFPROTO_IPV4;
-		ingress_state.hook = NF_INET_INGRESS;
-		nft_set_pktinfo(&pkt, skb, &ingress_state);
+		ingress_state->pf = NFPROTO_IPV4;
+		ingress_state->hook = NF_INET_INGRESS;
+		nft_set_pktinfo(pkt, skb, ingress_state);
 
-		if (nft_set_pktinfo_ipv4_ingress(&pkt) < 0)
-			return NF_DROP;
+		if (nft_set_pktinfo_ipv4_ingress(pkt) < 0)
+			return -1;
 		break;
 	case htons(ETH_P_IPV6):
-		ingress_state.pf = NFPROTO_IPV6;
-		ingress_state.hook = NF_INET_INGRESS;
-		nft_set_pktinfo(&pkt, skb, &ingress_state);
+		ingress_state->pf = NFPROTO_IPV6;
+		ingress_state->hook = NF_INET_INGRESS;
+		nft_set_pktinfo(pkt, skb, ingress_state);
 
-		if (nft_set_pktinfo_ipv6_ingress(&pkt) < 0)
-			return NF_DROP;
+		if (nft_set_pktinfo_ipv6_ingress(pkt) < 0)
+			return -1;
 		break;
 	default:
+		return 1;
+	}
+
+	return 0;
+}
+
+static unsigned int nft_do_chain_inet_ingress(void *priv, struct sk_buff *skb,
+					      const struct nf_hook_state *state)
+{
+	struct nf_hook_state ingress_state = *state;
+	struct nft_pktinfo pkt;
+	int ret;
+
+	ret = nft_set_pktinfo_ingress(&pkt, skb, &ingress_state);
+	switch (ret) {
+	case -1:
+		return NF_DROP;
+	case 1:
 		return NF_ACCEPT;
+	default:
+		break;
 	}
 
 	return nft_do_chain(&pkt, priv);
Signature · 1 line
2.47.3
author maintainer
#5 lore raw

RFC PATCH 5/8 netfilter: nf_tables: add early ingress chain

In reply to Pablo Neira Ayuso

Add a new filter chain to filter out packets from the early_ingress hook.

This is the second user of this new hook, after the flowtable.

---
 net/netfilter/nft_chain_filter.c | 116 ++++++++++++++++++++++++++++++-
 1 file changed, 114 insertions(+), 2 deletions(-)
net/netfilter/nft_chain_filter.c +114 -2
index 47a612bdd03e..3467f7b7bd38 100644
@@ -210,17 +210,75 @@ static unsigned int nft_do_chain_inet_ingress(void *priv, struct sk_buff *skb,
 	return nft_do_chain(&pkt, priv);
 }
 
+static unsigned int
+nft_do_chain_inet_early_ingress(void *priv, struct sk_buff *unused,
+				const struct nf_hook_state *state)
+{
+	struct nf_hook_state ingress_state = *state;
+	struct sk_buff *skb, *nskb;
+	struct nft_pktinfo pkt;
+	LIST_HEAD(accept_list);
+	int ret;
+
+	list_for_each_entry_safe(skb, nskb, state->skb_list, list) {
+		skb_list_del_init(skb);
+
+		skb_reset_network_header(skb);
+		if (!skb_transport_header_was_set(skb))
+			skb_reset_transport_header(skb);
+		skb_reset_mac_len(skb);
+
+		ret = nft_set_pktinfo_ingress(&pkt, skb, &ingress_state);
+		switch (ret) {
+		case 1:
+			list_add_tail(&skb->list, &accept_list);
+			continue;
+		case 0:
+			break;
+		case -1:
+			kfree_skb(skb);
+			continue;
+		default:
+			break;
+		}
+
+		ret = nft_do_chain(&pkt, priv);
+		switch (ret) {
+		case NF_ACCEPT:
+			list_add_tail(&skb->list, &accept_list);
+			break;
+		default:
+			WARN_ON_ONCE(1);
+			fallthrough;
+		case NF_DROP:
+			kfree_skb(skb);
+			break;
+		}
+	}
+
+	WARN_ON_ONCE(!list_empty(state->skb_list));
+
+	list_splice(&accept_list, state->skb_list);
+
+	if (list_empty(state->skb_list))
+		return NF_STOLEN;
+
+	return NF_ACCEPT;
+}
+
 static const struct nft_chain_type nft_chain_filter_inet = {
 	.name		= "filter",
 	.type		= NFT_CHAIN_T_DEFAULT,
 	.family		= NFPROTO_INET,
-	.hook_mask	= (1 << NF_INET_INGRESS) |
+	.hook_mask	= (1 << NF_INET_EARLY_INGRESS) |
+			  (1 << NF_INET_INGRESS) |
 			  (1 << NF_INET_LOCAL_IN) |
 			  (1 << NF_INET_LOCAL_OUT) |
 			  (1 << NF_INET_FORWARD) |
 			  (1 << NF_INET_PRE_ROUTING) |
 			  (1 << NF_INET_POST_ROUTING),
 	.hooks		= {
+		[NF_INET_EARLY_INGRESS]	= nft_do_chain_inet_early_ingress,
 		[NF_INET_INGRESS]	= nft_do_chain_inet_ingress,
 		[NF_INET_LOCAL_IN]	= nft_do_chain_inet,
 		[NF_INET_LOCAL_OUT]	= nft_do_chain_inet,
@@ -324,15 +382,69 @@ static unsigned int nft_do_chain_netdev(void *priv, struct sk_buff *skb,
 	return nft_do_chain(&pkt, priv);
 }
 
+static unsigned int
+nft_do_chain_netdev_early_ingress(void *priv, struct sk_buff *unused,
+				  const struct nf_hook_state *state)
+{
+	struct nf_hook_state ingress_state = *state;
+	struct sk_buff *skb, *nskb;
+	struct nft_pktinfo pkt;
+	LIST_HEAD(accept_list);
+	int ret;
+
+	list_for_each_entry_safe(skb, nskb, state->skb_list, list) {
+		skb_list_del_init(skb);
+
+		skb_reset_network_header(skb);
+		if (!skb_transport_header_was_set(skb))
+			skb_reset_transport_header(skb);
+		skb_reset_mac_len(skb);
+
+		ret = nft_set_pktinfo_ingress(&pkt, skb, &ingress_state);
+		switch (ret) {
+		case 1:
+		case -1:
+			nft_set_pktinfo(&pkt, skb, &ingress_state);
+			break;
+		default:
+			break;
+		}
+
+		ret = nft_do_chain(&pkt, priv);
+		switch (ret) {
+		case NF_ACCEPT:
+			list_add_tail(&skb->list, &accept_list);
+			break;
+		default:
+			WARN_ON_ONCE(1);
+			fallthrough;
+		case NF_DROP:
+			kfree_skb(skb);
+			break;
+		}
+	}
+
+	WARN_ON_ONCE(!list_empty(state->skb_list));
+
+	list_splice(&accept_list, state->skb_list);
+
+	if (list_empty(state->skb_list))
+		return NF_STOLEN;
+
+	return NF_ACCEPT;
+}
+
 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) |
-			  (1 << NF_NETDEV_EGRESS),
+			  (1 << NF_NETDEV_EGRESS) |
+			  (1 << NF_NETDEV_EARLY_INGRESS),
 	.hooks		= {
 		[NF_NETDEV_INGRESS]	= nft_do_chain_netdev,
 		[NF_NETDEV_EGRESS]	= nft_do_chain_netdev,
+		[NF_NETDEV_EARLY_INGRESS] = nft_do_chain_netdev_early_ingress,
 	},
 };
 
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

RFC PATCH 6/8 net: add dev_dst_drop() helper function

In reply to Pablo Neira Ayuso

Prepare to reuse this function from listified tx path.

No functional changes are intended, this is a preparation patch.

---
 net/core/dev.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
net/core/dev.c +12 -7
index 476ee88440a6..5c339416ae5d 100644
@@ -4719,6 +4719,17 @@ struct netdev_queue *netdev_core_pick_tx(struct net_device *dev,
 	return netdev_get_tx_queue(dev, queue_index);
 }
 
+/* If device/qdisc don't need skb->dst, release it right now while
+ * its hot in this cpu cache.
+ */
+static inline void dev_dst_drop(const struct net_device *dev, struct sk_buff *skb)
+{
+	if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
+		skb_dst_drop(skb);
+	else
+		skb_dst_force(skb);
+}
+
 /**
  * __dev_queue_xmit() - transmit a buffer
  * @skb:	buffer to transmit
@@ -4784,13 +4795,7 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
 			txq = netdev_tx_queue_mapping(dev, skb);
 	}
 #endif
-	/* If device/qdisc don't need skb->dst, release it right now while
-	 * its hot in this cpu cache.
-	 */
-	if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
-		skb_dst_drop(skb);
-	else
-		skb_dst_force(skb);
+	dev_dst_drop(dev, skb);
 
 	if (!txq)
 		txq = netdev_core_pick_tx(dev, skb, sb_dev);
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

RFC PATCH 7/8 net: add dev_noqueue_xmit_list() helper function

In reply to Pablo Neira Ayuso

This new helper function wraps the device has no queue case. This function can be reused from listified skb in the tx path since the device has no queue path already supports for skb list.

***This replaces validate_xmit_skb() by validate_xmit_skb_list()*** in this new helper function.

An alternative to this patch to reuse a smaller fraction of code can be to wrap this common code instead in a function:

+ HARD_TX_LOCK(dev, txq, cpu);
+
+ if (!netif_xmit_stopped(txq)) {

+                               dev_xmit_recursion_inc();
+                               skb = dev_hard_start_xmit(skb, dev, txq, &rc);
+                               dev_xmit_recursion_dec();
+                               if (dev_xmit_complete(rc)) {

+ HARD_TX_UNLOCK(dev, txq);
+ goto out;
+ }
+ }
+ HARD_TX_UNLOCK(dev, txq);

Note: This comment was in the original patch from Steffen:

       /* FIXME: For each skb!!! */
       dev_core_stats_tx_dropped_inc(dev);
       kfree_skb_list(skb);

This currently reports only one packet drop through stats.

---
 net/core/dev.c | 121 +++++++++++++++++++++++++++----------------------
 1 file changed, 67 insertions(+), 54 deletions(-)
net/core/dev.c +67 -54
index 5c339416ae5d..8f5bef5a715c 100644
@@ -4730,6 +4730,68 @@ static inline void dev_dst_drop(const struct net_device *dev, struct sk_buff *sk
 		skb_dst_force(skb);
 }
 
+/* The device has no queue. Common case for software devices:
+ * loopback, all the sorts of tunnels...
+ *
+ * Really, it is unlikely that netif_tx_lock protection is necessary
+ * here.  (f.e. loopback and IP tunnels are clean ignoring statistics
+ * counters.)
+ * However, it is possible, that they rely on protection
+ * made by us here.
+ *
+ * Check this and shot the lock. It is not prone from deadlocks.
+ * Either shot noqueue qdisc, it is even simpler 8)
+ */
+static inline int dev_noqueue_xmit_list(struct sk_buff *skb,
+					struct net_device *dev,
+					struct netdev_queue *txq)
+{
+	bool again = false;
+	int rc = -ENOMEM;
+
+	if (dev->flags & IFF_UP) {
+		int cpu = smp_processor_id(); /* ok because BHs are off */
+
+		/* Other cpus might concurrently change txq->xmit_lock_owner
+		 * to -1 or to their cpu id, but not to our id.
+		 */
+		if (READ_ONCE(txq->xmit_lock_owner) != cpu) {
+			if (dev_xmit_recursion())
+				goto recursion_alert;
+
+			skb = validate_xmit_skb_list(skb, dev, &again);
+			if (!skb)
+				goto out;
+
+			HARD_TX_LOCK(dev, txq, cpu);
+
+			if (!netif_xmit_stopped(txq)) {
+				dev_xmit_recursion_inc();
+				skb = dev_hard_start_xmit(skb, dev, txq, &rc);
+				dev_xmit_recursion_dec();
+				if (dev_xmit_complete(rc)) {
+					HARD_TX_UNLOCK(dev, txq);
+					goto out;
+				}
+			}
+			HARD_TX_UNLOCK(dev, txq);
+			net_crit_ratelimited("Virtual device %s asks to queue packet!\n",
+					     dev->name);
+		} else {
+			/* Recursion is detected! It is possible,
+			 * unfortunately
+			 */
+recursion_alert:
+			net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
+					     dev->name);
+		}
+	}
+
+	rc = -ENETDOWN;
+out:
+	return rc;
+}
+
 /**
  * __dev_queue_xmit() - transmit a buffer
  * @skb:	buffer to transmit
@@ -4757,7 +4819,6 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
 	struct netdev_queue *txq = NULL;
 	struct Qdisc *q;
 	int rc = -ENOMEM;
-	bool again = false;
 
 	skb_reset_mac_header(skb);
 	skb_assert_len(skb);
@@ -4808,61 +4869,13 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
 		goto out;
 	}
 
-	/* The device has no queue. Common case for software devices:
-	 * loopback, all the sorts of tunnels...
-
-	 * Really, it is unlikely that netif_tx_lock protection is necessary
-	 * here.  (f.e. loopback and IP tunnels are clean ignoring statistics
-	 * counters.)
-	 * However, it is possible, that they rely on protection
-	 * made by us here.
-
-	 * Check this and shot the lock. It is not prone from deadlocks.
-	 *Either shot noqueue qdisc, it is even simpler 8)
-	 */
-	if (dev->flags & IFF_UP) {
-		int cpu = smp_processor_id(); /* ok because BHs are off */
-
-		/* Other cpus might concurrently change txq->xmit_lock_owner
-		 * to -1 or to their cpu id, but not to our id.
-		 */
-		if (READ_ONCE(txq->xmit_lock_owner) != cpu) {
-			if (dev_xmit_recursion())
-				goto recursion_alert;
-
-			skb = validate_xmit_skb(skb, dev, &again);
-			if (!skb)
-				goto out;
-
-			HARD_TX_LOCK(dev, txq, cpu);
-
-			if (!netif_xmit_stopped(txq)) {
-				dev_xmit_recursion_inc();
-				skb = dev_hard_start_xmit(skb, dev, txq, &rc);
-				dev_xmit_recursion_dec();
-				if (dev_xmit_complete(rc)) {
-					HARD_TX_UNLOCK(dev, txq);
-					goto out;
-				}
-			}
-			HARD_TX_UNLOCK(dev, txq);
-			net_crit_ratelimited("Virtual device %s asks to queue packet!\n",
-					     dev->name);
-		} else {
-			/* Recursion is detected! It is possible,
-			 * unfortunately
-			 */
-recursion_alert:
-			net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
-					     dev->name);
-		}
-	}
-
-	rc = -ENETDOWN;
+	rc = dev_noqueue_xmit_list(skb, dev, txq);
 	rcu_read_unlock_bh();
 
-	dev_core_stats_tx_dropped_inc(dev);
-	kfree_skb_list(skb);
+	if (rc < 0) {
+		dev_core_stats_tx_dropped_inc(dev);
+		kfree_skb_list(skb);
+	}
 	return rc;
 out:
 	rcu_read_unlock_bh();
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

RFC PATCH 8/8 net: add dev_queue_xmit_list() and use it

In reply to Pablo Neira Ayuso

Add listified skb tx path and use it to implement the flowtable TX datapath. Use the dev_dst_drop() and dev_noqueue_xmit_list() helper functions to build dev_queue_xmit_list().

100dfa74cad9 ("net: dev_queue_xmit() llist adoption") requires to reverse the skb list and then splice this list to the the last pending skbuff for transmission.

A few notes:

- I removed:

       if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_SCHED_TSTAMP))
               return -1;

Only possible if skb->sk is set on, if my assumption is not correct, this can be checked from flowtable path.

Reducing the size of dev_queue_xmit_list() is convenient, to focus only on speeding up what it can be really speed up, so let's return -1 if either:

- qdisc is not empty

OR

- qdisc is not work-conserving (no TCQ_F_CAN_BYPASS is set on)

Then, the flowtable falls back to call dev_queue_xmit() for each single skbuff.

---
 include/linux/netdevice.h        |   2 +
 net/core/dev.c                   | 157 +++++++++++++++++++++++++++++++
 net/netfilter/nf_flow_table_ip.c |  18 ++--
 3 files changed, 169 insertions(+), 8 deletions(-)
include/linux/netdevice.h +2 -0
index c0174aa1037f..34747e9b85d2 100644
@@ -3401,6 +3401,8 @@ static inline int dev_direct_xmit(struct sk_buff *skb, u16 queue_id)
 	return ret;
 }
 
+int dev_queue_xmit_list(struct sk_buff *skb);
+
 int register_netdevice(struct net_device *dev);
 void unregister_netdevice_queue(struct net_device *dev, struct list_head *head);
 void unregister_netdevice_many(struct list_head *head);
net/core/dev.c +157 -0

163 lines not on this page · raw message

net/netfilter/nf_flow_table_ip.c +10 -8
index 98b5d5e022c8..3d2d02be0f0d 100644
@@ -863,14 +863,16 @@ static void nf_flow_neigh_xmit_list(struct sk_buff *skb, struct net_device *outd
 		iter = iter->next;
 	}
 
-	iter = skb;
-	while (iter) {
-		struct sk_buff *next;
-
-		next = iter->next;
-		iter->next = NULL;
-		dev_queue_xmit(iter);
-		iter = next;
+	if (dev_queue_xmit_list(skb) == -1) {
+		iter = skb;
+		while (iter) {
+			struct sk_buff *next;
+
+			next = iter->next;
+			iter->next = NULL;
+			dev_queue_xmit(iter);
+			iter = next;
+		}
 	}
 }
 
Signature · 1 line
2.47.3
author maintainer
#9 lore raw
In reply to Pablo Neira Ayuso

Missing links:

[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://linux-ipsec.org/2025-linux-kernel-flowtable-bulk-forwarding-and-xfrm-pcpu-forwarding-testing-results.html

Quoted 106 lines · Pablo Neira Ayuso

Hi,

Back in 2018 [1], a new fast forwarding combining the flowtable and GRO/GSO was proposed, however, "GRO is specialized to optimize the non-forwarding case", so it was considered "counter-intuitive to base a fast forwarding path on top of it".

Then, Steffen Klassert proposed the idea of adding a new engine for the flowtable that operates on the skb list that is provided after the NAPI cycle. The idea is to process this skb list to create bulks grouped by the ethertype, output device, next hop and tos/dscp. Then, add a specialized xmit path that can deal with these skb bulks. Note that GRO needs to be disabled so this new forwarding engine obtains the list of skbs that resulted from the NAPI cycle.

Before grouping skbs in bulks, there is a flowtable lookup to check if this flow is already in the flowtable, otherwise, the packet follows slow path. In case the flowtable lookup returns an entry, then this packet follows fast path: the ttl is decremented, the corresponding NAT mangling on the packet and layer 2/3 tunnel encapsulation (layer 2:
vlan/pppoe, layer 3: ipip) are performed.

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 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 counter
        }

}

The example above sets up 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.

Note that tcpdump only shows the packets in the tx path, since this new early_ingress hook happens before the ingress tap.

The patch series contains 8 patches:

- #1 and #2 adds the basic RX flowtable bulking infrastructure for IPv4 and IPv6.
- #3 adds the early_ingress netfilter hook.
- #4 adds a helper function to prepare for the netfilter chain for the early_ingress hook.
- #5 adds the early_ingress filter chain.
- #6 and #7 add helper functions to reuse TX path codebase.
- #8 adds the custom TX path for listified skbs and updates the flowtable bulking to use it.

= Benchmark numbers =

Using the following testbed with 4 hosts with this topology:

| sunset |-----| west |====| east |----| sunrise |

And this hardware:

* Supermicro H13SSW Motherboard
* AMD EPYC 9135 16-Core Processor (a.k.a. Bergamo, or Zen 5)
* NIC: Mellanox MT28800 ConnectX-5 Ex (100Gbps NIc)
* NIC: Broadcom BCM57508 NetXtreme-E (only on sunrise, 100Gbps NIc)

With 128 byte packets:

* From ~2 Mpps (baseline) to ~4 Mpps with 1 flow.
* From ~10.6 Mpps (baseline) to ~15.7 Mpps with 10 flows.

Antony Antony collected performance numbers and made a report describing this the benchmarking[2]. This report includes numbers from the IPsec support which is not included in this series.

Comments welcome, thanks.

Pablo Neira Ayuso (8):
netfilter: flowtable: Add basic bulking infrastructure for early ingress hook
netfilter: flowtable: Add IPv6 bulking infrastructure for early ingress hook
netfilter: nf_tables: add flowtable early_ingress support
netfilter: nf_tables: add nft_set_pktinfo_ingress()
netfilter: nf_tables: add early ingress chain
net: add dev_dst_drop() helper function
net: add dev_noqueue_xmit_list() helper function
net: add dev_queue_xmit_list() and use it

 include/linux/netdevice.h             |   2 +
 include/net/netfilter/nf_flow_table.h |  13 +-
 net/core/dev.c                        | 297 ++++++++++++++++----
 net/netfilter/nf_flow_table_inet.c    |  81 ++++++
 net/netfilter/nf_flow_table_ip.c      | 384 ++++++++++++++++++++++++++
 net/netfilter/nf_tables_api.c         |  12 +-
 net/netfilter/nft_chain_filter.c      | 164 +++++++++--
 7 files changed, 872 insertions(+), 81 deletions(-)
Signature · 1 line
2.47.3
#10 lore raw
In reply to Pablo Neira Ayuso

Hi Pablo,

Quoted 7 lines · Pablo Neira Ayuso

Hi,

Back in 2018 [1], a new fast forwarding combining the flowtable and GRO/GSO was proposed, however, "GRO is specialized to optimize the non-forwarding case", so it was considered "counter-intuitive to base a fast forwarding path on top of it".

Quoted 7 lines

Then, Steffen Klassert proposed the idea of adding a new engine for the flowtable that operates on the skb list that is provided after the NAPI cycle. The idea is to process this skb list to create bulks grouped by the ethertype, output device, next hop and tos/dscp. Then, add a specialized xmit path that can deal with these skb bulks. Note that GRO needs to be disabled so this new forwarding engine obtains the list of skbs that resulted from the NAPI cycle.

+Cc: Felix Fietkau

How does this compare to fraglist GRO with the original flowtable?

#11 lore raw
Quoted 18 lines · Qingfang Deng

Hi Pablo,

Quoted 7 lines · Pablo Neira Ayuso

Hi,

Back in 2018 [1], a new fast forwarding combining the flowtable and GRO/GSO was proposed, however, "GRO is specialized to optimize the non-forwarding case", so it was considered "counter-intuitive to base a fast forwarding path on top of it".

Quoted 7 lines

Then, Steffen Klassert proposed the idea of adding a new engine for the flowtable that operates on the skb list that is provided after the NAPI cycle. The idea is to process this skb list to create bulks grouped by the ethertype, output device, next hop and tos/dscp. Then, add a specialized xmit path that can deal with these skb bulks. Note that GRO needs to be disabled so this new forwarding engine obtains the list of skbs that resulted from the NAPI cycle.

Quoted 3 lines

+Cc: Felix Fietkau

How does this compare to fraglist GRO with the original flowtable?

GRO can only aggregate packets of the same L4 flow. This can aggregate all packets the are treated the same by the forwarding path. Packets need to have the same output device and next hop, but can be from different L3 and L4 flows.

Packet forwarders usually receive many different flows. GRO might not even kick in if there are not at least two packets from the same flow on a napi cycle.

#12 lore raw
Quoted 23 lines · Steffen Klassert
Quoted 18 lines · Qingfang Deng

Hi Pablo,

Quoted 7 lines · Pablo Neira Ayuso

Hi,

Back in 2018 [1], a new fast forwarding combining the flowtable and GRO/GSO was proposed, however, "GRO is specialized to optimize the non-forwarding case", so it was considered "counter-intuitive to base a fast forwarding path on top of it".

Quoted 7 lines

Then, Steffen Klassert proposed the idea of adding a new engine for the flowtable that operates on the skb list that is provided after the NAPI cycle. The idea is to process this skb list to create bulks grouped by the ethertype, output device, next hop and tos/dscp. Then, add a specialized xmit path that can deal with these skb bulks. Note that GRO needs to be disabled so this new forwarding engine obtains the list of skbs that resulted from the NAPI cycle.

Quoted 3 lines

+Cc: Felix Fietkau

How does this compare to fraglist GRO with the original flowtable?

Quoted 8 lines

GRO can only aggregate packets of the same L4 flow. This can aggregate all packets the are treated the same by the forwarding path. Packets need to have the same output device and next hop, but can be from different L3 and L4 flows.

Packet forwarders usually receive many different flows. GRO might not even kick in if there are not at least two packets from the same flow on a napi cycle.

Interesting approach! Do you think it might be possible to combine this with GRO by bulking together GRO-combined frames from different flows?

I think it would be unfortunate if you have to choose between decent forwarding throughput and decent local rx throughput.

- Felix

#13 lore raw
Quoted 29 lines · Felix Fietkau
Quoted 28 lines · Steffen Klassert
Quoted 18 lines · Qingfang Deng

Hi Pablo,

Quoted 2 lines · Pablo Neira Ayuso

Hi,

Quoted 1 line

Back in 2018 [1], a new fast forwarding combining the flowtable

and

Quoted 4 lines

GRO/GSO was proposed, however, "GRO is specialized to optimize the non-forwarding case", so it was considered "counter-intuitive to base a fast forwarding path on top of it".

Quoted 1 line

Then, Steffen Klassert proposed the idea of adding a new engine

for the

Quoted 6 lines

flowtable that operates on the skb list that is provided after the NAPI cycle. The idea is to process this skb list to create bulks grouped by the ethertype, output device, next hop and tos/dscp. Then, add a specialized xmit path that can deal with these skb bulks. Note that GRO needs to be disabled so this new forwarding engine obtains the list of skbs that resulted from the NAPI cycle.

Quoted 3 lines

+Cc: Felix Fietkau

How does this compare to fraglist GRO with the original flowtable?

GRO can only aggregate packets of the same L4 flow. This can aggregate all packets the are treated the same by the forwarding path. Packets need to have the same output device and next hop, but can be from different L3 and L4 flows.

Quoted 6 lines
Quoted 3 lines

Packet forwarders usually receive many different flows. GRO might not even kick in if there are not at least two packets from the same flow on a napi cycle.

Interesting approach! Do you think it might be possible to combine this with GRO by bulking together GRO-combined frames from different flows?

This depends on how the GRO packets are crafted. If the packets built just by adding skb page frags, then yes. If the fraglist pointer is used to chain packets, then no (our approach uses the fraglist pointer as well). So combining these would require some changes to the GRO layer.

Quoted 2 lines

I think it would be unfortunate if you have to choose between decent forwarding throughput and decent local rx throughput.

Would be nice if we could tune for both cases, but sometimes it needs a decision for which use case it should be tuned.

#14 lore raw
Quoted 34 lines · Steffen Klassert
Quoted 33 lines · Felix Fietkau
Quoted 31 lines · Steffen Klassert
Quoted 18 lines · Qingfang Deng

Hi Pablo,

Quoted 2 lines · Pablo Neira Ayuso

Hi,

Quoted 1 line

Back in 2018 [1], a new fast forwarding combining the flowtable

and

Quoted 4 lines

GRO/GSO was proposed, however, "GRO is specialized to optimize the non-forwarding case", so it was considered "counter-intuitive to base a fast forwarding path on top of it".

Quoted 1 line

Then, Steffen Klassert proposed the idea of adding a new engine

for the

Quoted 6 lines

flowtable that operates on the skb list that is provided after the NAPI cycle. The idea is to process this skb list to create bulks grouped by the ethertype, output device, next hop and tos/dscp. Then, add a specialized xmit path that can deal with these skb bulks. Note that GRO needs to be disabled so this new forwarding engine obtains the list of skbs that resulted from the NAPI cycle.

Quoted 3 lines

+Cc: Felix Fietkau

How does this compare to fraglist GRO with the original flowtable?

GRO can only aggregate packets of the same L4 flow. This can aggregate all packets the are treated the same by the forwarding path. Packets need to have the same output device and next hop, but can be from different L3 and L4 flows.

Packet forwarders usually receive many different flows. GRO might not even kick in if there are not at least two packets from the same flow on a napi cycle.

Quoted 8 lines
Quoted 2 lines

Interesting approach! Do you think it might be possible to combine this with GRO by bulking together GRO-combined frames from different flows?

This depends on how the GRO packets are crafted. If the packets built just by adding skb page frags, then yes. If the fraglist pointer is used to chain packets, then no (our approach uses the fraglist pointer as well). So combining these would require some changes to the GRO layer.

On OpenWrt we use fraglist GRO by default for both TCP and UDP.
Maybe the bulking code could take fraglist GRO packets and simply convert them to its internal form of bulking batches. That way the GRO layer doesn't have to be changed, and it shouldn't add too much complexity to the bulking code either.

- Felix

#15 lore raw
Quoted 40 lines · Felix Fietkau
Quoted 30 lines · Steffen Klassert
Quoted 29 lines · Felix Fietkau
Quoted 11 lines · Steffen Klassert
Quoted 10 lines · Qingfang Deng

Hi Pablo,

Quoted 3 lines
Quoted 1 line · Pablo Neira Ayuso

Hi,

Quoted 1 line

Back in 2018 [1], a new fast forwarding combining the flowtable

and

Quoted 4 lines

GRO/GSO was proposed, however, "GRO is specialized to optimize the non-forwarding case", so it was considered "counter-intuitive to base a fast forwarding path on top of it".

Quoted 1 line

Then, Steffen Klassert proposed the idea of adding a new engine

for the

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

flowtable that operates on the skb list that is provided after the NAPI cycle. The idea is to process this skb list to create bulks grouped by the ethertype, output device, next hop and tos/dscp. Then, add a specialized xmit path that can deal with these skb bulks. Note that GRO needs to be disabled so this new forwarding engine obtains the list of skbs that resulted from the NAPI cycle.

Quoted 2 lines

+Cc: Felix Fietkau
How does this compare to fraglist GRO with the original

flowtable?

Quoted 7 lines
Quoted 1 line

GRO can only aggregate packets of the same L4 flow. This can

aggregate all packets the are treated the same by the forwarding path. Packets need to have the same output device and next hop, but can be from different L3 and L4 flows.

Quoted 1 line

Packet forwarders usually receive many different flows.

GRO might not even kick in if there are not at least two packets from the same flow on a napi cycle.

Quoted 8 lines
Quoted 2 lines

Interesting approach! Do you think it might be possible to combine this with GRO by bulking together GRO-combined frames from different flows?

This depends on how the GRO packets are crafted. If the packets built just by adding skb page frags, then yes. If the fraglist pointer is used to chain packets, then no (our approach uses the fraglist pointer as well). So combining these would require some changes to the GRO layer.

Quoted 3 lines

On OpenWrt we use fraglist GRO by default for both TCP and UDP. Maybe the bulking code could take fraglist GRO packets and simply convert them to its internal form of bulking batches.

This is possible, but would run the bulking logic two times in the forwarding path.

The problem is the standard GRO. This also use the fraglist pointer if MAX_SKB_FRAGS is reached. Converting this back is complicated. That would not be a forwarding fastpath anymore.