ovpn: select physical TX queues from the outer flow
Subsystems (3)
Ralf Lici
reviewercover ovpn: select physical TX queues from the outer flow
Hi,
ovpn keeps the inner socket as skb->sk on encrypted UDP packets, so that write accounting and TCP Small Queues keep working. As a consequence, netdev_pick_tx selects the lower device's TX queue as if the packet still belonged to the inner flow: from that socket's cached queue, from XPS according to the transmitting CPU, or from a recorded RX queue. When several inner flows are sent from different CPUs, one outer OpenVPN flow, which carries a single packet-ID sequence, is spread over several hardware queues, and the resulting reordering can exceed the receiver's replay window.
Patch 1 adds an skb bit which makes netdev_pick_tx select the queue from the packet hash instead, and patch 2 sets it in ovpn after clearing the inner hash, so that the lower device hashes the outer tuple. Patches 3 and 4 let ovpn set that hash directly from the flowi it routes with instead of dissecting every outer packet, which requires restoring __get_hash_from_flowi4.
Patches 1 and 3 change net core code (include/linux/skbuff.h, net/core/dev.c, include/net/flow.h and net/core/flow_dissector.c) and need review from the core networking maintainers when the series is forwarded to netdev. The series also applies cleanly to the current net-next.
With one peer between two directly connected mlx5 ports and four or eight inner TCP flows sent from different CPUs, the outer flow used five to nine TX queues and the receiver rejected 2000 to 4800 packets per 20-second run because of the replay window. With the series, all runs used a single TX queue and no packet was rejected.
Thanks,
Ralf Lici
Mandelbit Srl
---
Ralf Lici (4):
net: allow selecting TX queues from the packet hash
ovpn: select physical TX queues from the outer flow
net: restore __get_hash_from_flowi4
ovpn: hash the outer flow from its flowi
drivers/net/ovpn/io.c | 1 + drivers/net/ovpn/udp.c | 9 +++++++++ include/linux/skbuff.h | 31 +++++++++++++++++++++++++++++++ include/net/flow.h | 1 + net/core/dev.c | 8 ++++++-- net/core/flow_dissector.c | 16 ++++++++++++++++ 6 files changed, 64 insertions(+), 2 deletions(-)
base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
Signature · 8 lines
2.56.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Ralf Lici
reviewerPATCH 1/4 net: allow selecting TX queues from the packet hash
An skb may retain a socket for write accounting even when encapsulation has changed the flow represented by the packet. In that case the socket's cached TX queue and XPS placement describe the inner flow rather than the completed outer packet. This matters when one outer flow multiplexes several inner flows and must stay in order, for example because a replay window protects its sequence.
Add an skb policy bit which makes netdev_pick_tx select within the packet's traffic-class queue range using skb_get_hash. The policy bypasses the owning socket's cached queue, XPS and a recorded RX queue, and is copied with the skb so that it remains effective through stacked devices. The bit takes previously unused space next to tc_depth, so sk_buff does not grow.
--- include/linux/skbuff.h | 18 ++++++++++++++++++ net/core/dev.c | 8 ++++++-- 2 files changed, 24 insertions(+), 2 deletions(-)
include/linux/skbuff.h +18 -0
@@ -833,6 +833,8 @@ enum skb_tstamp_type {* @_nfct: Associated connection, if any (with nfctinfo bits) * @skb_iif: ifindex of device we arrived on * @tc_depth: counter for packet duplication +* @tx_queue_from_hash: select the TX queue from the packet hash rather +* than the owning socket or producer CPU * @tc_index: Traffic control index * @hash: the packet hash * @queue_mapping: Queue mapping for multiqueue devices
@@ -1043,6 +1045,7 @@ struct sk_buff {#endif __u8 unreadable:1; __u8 tc_depth:2; + __u8 tx_queue_from_hash:1;#if defined(CONFIG_NET_SCHED ) || defined(CONFIG_NET_XGRESS )__u16 tc_index;/* traffic control index */ #endif
@@ -5268,6 +5271,21 @@ static inline void skb_copy_queue_mapping(struct sk_buff *to, const struct sk_bu to->queue_mapping = from->queue_mapping; } +static inline void skb_set_tx_queue_from_hash (struct sk_buff *skb) +{ + skb->tx_queue_from_hash =1 ; +} + +static inline void skb_clear_tx_queue_from_hash (struct sk_buff *skb) +{ + skb->tx_queue_from_hash =0 ; +} + +static inline bool skb_tx_queue_from_hash (const struct sk_buff *skb) +{ +return skb->tx_queue_from_hash; +} +static inline void skb_record_rx_queue (struct sk_buff *skb,u16 rx_queue) { skb->queue_mapping = rx_queue +1 ;
net/core/dev.c +6 -2
@@ -3625,7 +3625,7 @@ static u16 skb_tx_hash(const struct net_device *dev, } } -if (skb_rx_queue_recorded (skb)) { +if (!skb_tx_queue_from_hash (skb) &&skb_rx_queue_recorded (skb)) {DEBUG_NET_WARN_ON_ONCE (qcount ==0 ); hash =skb_get_rx_queue (skb);if (hash >= qoffset)
@@ -4925,9 +4925,13 @@ u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb, struct net_device *sb_dev) {struct sock *sk = skb->sk; -int queue_index =sk_tx_queue_get (sk); +int queue_index; sb_dev = sb_dev ? : dev; +if (skb_tx_queue_from_hash (skb)) +return skb_tx_hash (dev, sb_dev, skb); + + queue_index =sk_tx_queue_get (sk);if (queue_index <0 || skb->ooo_okay || queue_index >= dev->real_num_tx_queues) {
Signature · 8 lines
2.56.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Ralf Lici
reviewerPATCH 2/4 ovpn: select physical TX queues from the outer flow
In reply to Ralf Liciovpn retains the inner socket on encrypted UDP skbs so that write accounting and TCP Small Queues remain correct. netdev_pick_tx, however, interprets that socket as the transmitted flow and spreads one outer OpenVPN channel across hardware queues according to the inner socket's cached queue, XPS and the producing CPU. Packets of one packet-ID sequence then race through different queues, and the resulting reordering can exceed the receiver's replay window.
Clear the inner-flow hash and request hash-based queue selection in the UDP output path, so that the lower device hashes the completed outer tuple while skb->sk and its destructor keep describing the inner owner. Clear the policy again after decapsulation.
With one peer between two directly connected mlx5 ports and four or eight inner TCP flows sent from different CPUs, the outer flow used five to nine TX queues and the receiver rejected 2000 to 4800 packets per 20-second run whose packet IDs had fallen behind the replay window. With this change, all of them used a single TX queue and no packet was rejected.
--- drivers/net/ovpn/io.c | 1 + drivers/net/ovpn/udp.c | 5 +++++ 2 files changed, 6 insertions(+)
drivers/net/ovpn/io.c +1 -0
@@ -76,6 +76,7 @@ static void ovpn_netdev_write(struct ovpn_peer *peer, struct sk_buff *skb)/* skb hash for transport packet no longer valid after decapsulation */ skb_clear_hash (skb); +skb_clear_tx_queue_from_hash (skb);/* post-decrypt scrub -- prepare to inject encapsulated packet onto the * interface, based on __skb_tunnel_rx() in dst.h
drivers/net/ovpn/udp.c +5 -0
@@ -467,6 +467,11 @@ void ovpn_udp_send_skb(struct ovpn_peer *peer, struct sock *sk, skb->dev = peer->ovpn->dev; skb->mark = key.mark; +/* select the physical queue from the completed outer flow while +* skb->sk remains the inner socket for write accounting and TSQ +*/ +skb_clear_hash (skb); +skb_set_tx_queue_from_hash (skb);/* no checksum performed at this layer */ skb->ip_summed =CHECKSUM_NONE ;
Signature · 8 lines
2.56.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Ralf Lici
reviewerPATCH 3/4 net: restore __get_hash_from_flowi4
In reply to Ralf Lici__get_hash_from_flowi4 was removed for lack of users in commit de7a0f871fab ("net: Remove unused get_hash_from_flow functions"), while its IPv6 counterpart survived for automatic flow labels. A tunnel which routes its outer packets with a flowi can use these helpers to set the outer flow hash without dissecting the packet, as ovpn will.
Restore the helper and add skb_get_hash_flowi4 next to skb_get_hash_flowi6. Like the IPv6 variant, it leaves basic.n_proto unset, so the hash is stable for a flow but not identical to the one the flow dissector computes from the packet itself.
--- include/linux/skbuff.h | 13 +++++++++++++ include/net/flow.h | 1 + net/core/flow_dissector.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+)
include/linux/skbuff.h +13 -0
@@ -1679,6 +1679,19 @@ static inline __u32 skb_get_hash(struct sk_buff *skb)return skb->hash; } +static inline __u32 skb_get_hash_flowi4 (struct sk_buff *skb, +const struct flowi4 *fl4) +{ +if (!skb->l4_hash && !skb->sw_hash) { +struct flow_keys keys; +__u32 hash =__get_hash_from_flowi4 (fl4, &keys); + +__skb_set_sw_hash (skb, hash,flow_keys_have_l4 (&keys)); + } + +return skb->hash; +} +static inline __u32 skb_get_hash_flowi6 (struct sk_buff *skb,const struct flowi6 *fl6) {if (!skb->l4_hash && !skb->sw_hash) {
include/net/flow.h +1 -0
@@ -194,5 +194,6 @@ static inline struct flowi_common *flowi6_to_flowi_common(struct flowi6 *fl6) }__u32 __get_hash_from_flowi6 (const struct flowi6 *fl6,struct flow_keys *keys); +__u32 __get_hash_from_flowi4 (const struct flowi4 *fl4,struct flow_keys *keys);#endif
net/core/flow_dissector.c +16 -0
@@ -2020,6 +2020,22 @@ __u32 __get_hash_from_flowi6(const struct flowi6 *fl6, struct flow_keys *keys) }EXPORT_SYMBOL (__get_hash_from_flowi6); +__u32 __get_hash_from_flowi4 (const struct flowi4 *fl4,struct flow_keys *keys) +{ +memset (keys,0 ,sizeof (*keys)); + + keys->addrs.v4addrs.src = fl4->saddr; + keys->addrs.v4addrs.dst = fl4->daddr; + keys->control.addr_type =FLOW_DISSECTOR_KEY_IPV4_ADDRS ; + keys->ports.src = fl4->fl4_sport; + keys->ports.dst = fl4->fl4_dport; + keys->keyid.keyid = fl4->fl4_gre_key; + keys->basic.ip_proto = fl4->flowi4_proto; + +return flow_hash_from_keys (keys); +} +EXPORT_SYMBOL (__get_hash_from_flowi4); +static const struct flow_dissector_key flow_keys_dissector_keys[] = { { .key_id =FLOW_DISSECTOR_KEY_CONTROL ,
Signature · 8 lines
2.56.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Ralf Lici
reviewerPATCH 4/4 ovpn: hash the outer flow from its flowi
In reply to Ralf LiciSelecting the physical TX queue from the packet hash makes netdev_pick_tx dissect every outer packet, although ovpn already holds the outer flow in the flowi it routes with. On IPv6, the stack derives the hash from that flowi only when it generates an automatic flow label.
Set the hash from the outer flowi in both output paths, so that queue selection depends neither on dissecting the packet nor on automatic flow labels.
--- drivers/net/ovpn/udp.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ovpn/udp.c +4 -0
@@ -288,6 +288,8 @@ static int ovpn_udp4_output(struct ovpn_peer *peer, struct ovpn_bind *bind,spin_unlock_bh (&peer->lock); transmit: +/* hash the outer flow for queue selection without dissecting it */ +skb_get_hash_flowi4 (skb, &fl);udp_tunnel_xmit_skb (rt, sk, skb, fl.saddr, fl.daddr,0 ,ip4_dst_hoplimit (&rt->dst),0 , fl.fl4_sport, fl.fl4_dport, false, sk->sk_no_check_tx,0 );
@@ -388,6 +390,8 @@ static int ovpn_udp6_output(struct ovpn_peer *peer, struct ovpn_bind *bind,* udp_tunnel_xmit_skb() */ skb->ignore_df =1 ; +/* hash the outer flow for queue selection without dissecting it */ +skb_get_hash_flowi6 (skb, &fl);udp_tunnel6_xmit_skb (dst, sk, skb, skb->dev, &fl.saddr, &fl.daddr,0 ,ip6_dst_hoplimit (dst),0 , fl.fl6_sport, fl.fl6_dport,udp_get_no_check6_tx (sk),0 );
Signature · 8 lines
2.56.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel