net: mana: Clamp the recorded RX queue in mana_select_queue()
PATCH 1/1 net: mana: Clamp the recorded RX queue in mana_select_queue()
mana_select_queue() falls back to the RX queue recorded in the skb when the socket-cached TX queue is unusable:
txq = sk_tx_queue_get(skb->sk);
if (txq < 0 || skb->ooo_okay || txq >= ndev->real_num_tx_queues) {
if (skb_rx_queue_recorded(skb))
txq = skb_get_rx_queue(skb);
else
txq = mana_get_tx_queue(ndev, skb, txq);
}
return txq;The bounds check only decides whether the socket-cached value has to be recomputed; it does not validate the value that is returned. The recorded RX queue belongs to whichever device the skb was received on, so when a packet is forwarded from an interface with more queues than the MANA port has, an out of range index is returned and netdev_core_pick_tx() complains:
enPX selects TX queue 43, but real number of TX queues is 32 enPX selects TX queue 42, but real number of TX queues is 32 enPX selects TX queue 33, but real number of TX queues is 32
netdev_cap_txqueue() then forces every one of those packets onto TX queue 0, so besides the log spam all affected flows collapse onto a single queue.
This is easy to hit on Azure when container traffic is forwarded out of a MANA VF: veth sizes its queues with num_possible_cpus(), while mana sizes them with num_online_cpus(). On a guest with more possible than online CPUs the veth devices end up with more queues than the VF, and the index chosen on the veth survives into the VF transmit path.
Wrap the recorded queue into range, the same thing the generic path does in skb_tx_hash() and that mlx5e_txq_to_ch_ix() does for mlx5e. A single subtraction is not enough: the recorded index can be an arbitrary multiple of real_num_tx_queues, so use a modulo and keep it off the fast path with an unlikely() check. Read real_num_tx_queues once while at it, so that all three tests agree on one value even if the queue count is changed concurrently. The other two sources are already bounded: the socket-cached index is range checked above, and mana_get_tx_queue() returns an indirection table entry, which is always below apc->num_queues.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +12 -4
@@ -684,18 +684,26 @@ static int mana_get_tx_queue(struct net_device *ndev, struct sk_buff *skb,static u16 mana_select_queue (struct net_device *ndev,struct sk_buff *skb,struct net_device *sb_dev) { +int num_txq =READ_ONCE (ndev->real_num_tx_queues);int txq; -if (ndev->real_num_tx_queues ==1 ) +if (num_txq ==1 )return 0 ; txq =sk_tx_queue_get (skb->sk); -if (txq <0 || skb->ooo_okay || txq >= ndev->real_num_tx_queues) { -if (skb_rx_queue_recorded (skb)) +if (txq <0 || skb->ooo_okay || txq >= num_txq) { +if (skb_rx_queue_recorded (skb)) { +/* The queue was recorded by another device, which may +* have many more queues than this port, so wrap it +* into range like skb_tx_hash() does. +*/ txq =skb_get_rx_queue (skb); -else +if (unlikely (txq >= num_txq)) + txq %= num_txq; + }else { txq =mana_get_tx_queue (ndev, skb, txq); + } }return txq;
Signature · 1 line
2.55.0