Linux-HyperV List
 help / color / mirror / Atom feed
* [PATCH net-next] net: mana: Clamp the recorded RX queue in mana_select_queue()
@ 2026-12-01  4:43 Jon Maxwell
  0 siblings, 0 replies; only message in thread
From: Jon Maxwell @ 2026-12-01  4:43 UTC (permalink / raw)
  To: haiyangz
  Cc: wei.liu, decui, andrew+netdev, davem, edumazet, kuba, pabeni,
	horms, dipayanroy, ernis, longli, gargaditya, hamzamahfooz,
	linux-hyperv, netdev, linux-kernel, jmaxwell37

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.

Fixes: ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")
Signed-off-by: Jon Maxwell <jmaxwell37@gmail.com>
---
 drivers/net/ethernet/microsoft/mana/mana_en.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 95bf153c3e1a..eafba38488e8 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -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;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-01  4:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  4:43 [PATCH net-next] net: mana: Clamp the recorded RX queue in mana_select_queue() Jon Maxwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox