* [PATCH net-next] net: mana: Clamp the recorded RX queue in mana_select_queue()
@ 2026-12-01 4:43 Jon Maxwell
2026-12-04 4:45 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread* Re: [PATCH net-next] net: mana: Clamp the recorded RX queue in mana_select_queue()
2026-12-01 4:43 [PATCH net-next] net: mana: Clamp the recorded RX queue in mana_select_queue() Jon Maxwell
@ 2026-12-04 4:45 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 4:45 UTC (permalink / raw)
To: jmaxwell37
Cc: haiyangz, wei.liu, decui, andrew+netdev, davem, edumazet, kuba,
pabeni, horms, dipayanroy, ernis, longli, gargaditya,
hamzamahfooz, linux-hyperv, netdev, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The commit message says mana_get_tx_queue() is already bounded
because it "returns an indirection table entry, which is always below…
- [Low] The commit message's explanation of the trigger does not match
the current tree.
--
net: mana: Clamp the recorded RX queue in mana_select_queue()
This commit wraps the recorded RX queue returned by mana_select_queue()
into the range of real_num_tx_queues with a modulo. Forwarded skbs that
carry a queue index from a device with more queues then no longer trigger
the netdev_cap_txqueue() warning. It also reads real_num_tx_queues once
with READ_ONCE().
> 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.
[Severity: Low]
Does this description of the trigger match the current tree?
In veth_init_queues(), the real TX queue count defaults to 1 unless
IFLA_NUM_TX_QUEUES is given:
drivers/net/veth.c:veth_init_queues() {
...
if (!tb[IFLA_NUM_TX_QUEUES] && dev->num_tx_queues > 1) {
err = netif_set_real_num_tx_queues(dev, 1);
...
}
num_possible_cpus() only sets num_tx_queues, which is the maximum. With
one real TX queue, queue_mapping stays at 0. veth never calls
skb_record_rx_queue(), so skb_rx_queue_recorded() is false and
mana_select_queue() takes the mana_get_tx_queue() path. A default container
veth would not seem to hit this.
On the mana side, mana_probe_port() sets:
apc->num_queues = min(gc->max_num_queues_vport, MANA_DEF_NUM_QUEUES);
MANA_DEF_NUM_QUEUES is 16, and num_online_cpus() only caps the maximum.
A port with default settings would not show the quoted "real number of TX
queues is 32" either.
The real trigger looks wider than described. Any forwarded skb whose
queue_mapping - 1 is at or above the MANA port's real_num_tx_queues hits
it, whatever the possible and online CPU counts are. Examples are traffic
from a multi-queue ingress NIC, or from a veth created with numtxqueues or
resized with ethtool -L. The code change covers all of these cases.
Could the commit message be updated to describe the actual trigger
conditions?
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
> index 95bf153c3e1a8..eafba38488e8c 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 (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;
[Severity: Medium]
Can mana_get_tx_queue() return an index at or above num_txq here?
The commit message says:
mana_get_tx_queue() returns an indirection table entry, which is
always below apc->num_queues.
That does not seem to hold while the channel count is shrinking. Take an
ethtool -L that reduces the queues from 32 to 16:
mana_set_channels()
apc->num_queues = new_count;
mana_attach()
mana_alloc_queues()
netif_set_real_num_tx_queues(ndev, apc->num_queues); /* now 16 */
...
mana_add_rx_queues() / netif_set_real_num_rx_queues()
...
mana_rss_table_init(apc); /* indir_table rewritten for 16 */
mana_detach() only calls netif_tx_disable() and netif_device_detach(). So
__dev_queue_xmit()->netdev_core_pick_tx()->mana_select_queue() can still
run on other CPUs inside this window. Take a skb with no recorded RX queue
and no usable socket mapping. mana_get_tx_queue() would read the old
table:
txq = apc->indir_table[hash & (apc->indir_table_sz - 1)];
This can return 16..31, and mana_select_queue() returns it without a check.
netdev_cap_txqueue() would then print the same "selects TX queue N, but
real number of TX queues is M" warning and move the packet to queue 0. The
value is also cached with sk_tx_queue_set(). That cache does recover,
because the txq >= num_txq check recomputes it later.
mana_alloc_queues() can also fail between netif_set_real_num_tx_queues()
and mana_rss_table_init(). In that case real_num_tx_queues is not rolled
back, but mana_set_channels() restores apc->num_queues:
apc->num_queues = new_count;
err = mana_attach(ndev);
if (err) {
apc->num_queues = old_count;
indir_table can then keep entries above real_num_tx_queues until the next
successful attach.
The patch reads real_num_tx_queues once to cope with concurrent queue
count changes. Would it make sense to bound the final txq against num_txq
on every path? Another option is to rewrite indir_table before
real_num_tx_queues is lowered.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201044330.3046262-1-jmaxwell37%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 4:45 UTC | newest]
Thread overview: 2+ messages (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
2026-12-04 4:45 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox