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. Signed-off-by: Ralf Lici <[email protected]> --- include/linux/skbuff.h | 18 ++++++++++++++++++ net/core/dev.c | 8 ++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 1d6832878930..aaa33d44b01c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -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; diff --git a/net/core/dev.c b/net/core/dev.c index a230ecce9327..e150d5e92712 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -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) { -- 2.56.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
