tun: don't steer a flow to a queue index that no longer exists
Subsystems (3)
PATCH 1/1 tun: don't steer a flow to a queue index that no longer exists
A multi-queue tun device keeps a flow table that maps each flow to the index of the queue it last used, so that packets sent back to the flow go to the same queue. When a queue is removed, the last queue moves into its index. An entry that still holds the last queue's old index then holds an index that no longer exists. Packets of that flow are sent to queue 0 with a "selects TX queue" warning, until the flow sends again or its entry expires after a few seconds.
Commit 4cc0a3f89707 ("tun: delete the flow entries of the moved queue on detach") deletes those entries when the queue is removed. As the Sashiko review linked below points out, a send running at the same moment can still write the old index back right after the delete.
Rather than taking a lock on every send to close that window, check the index when an entry is used. If the entry holds an index that no longer exists, choose the queue by hash, as is done for a flow with no entry. The index is read only once, since a concurrent send can change it.
The race has not been seen in practice. The fix was tested in a guest with stale entries left in place. Flows that all went to queue 0 with the warning are now spread over the remaining queues.
--- drivers/net/tun.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/tun.c +6 -4
@@ -471,13 +471,15 @@ static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb) txq =__skb_get_hash_symmetric (skb); e =tun_flow_find (&tun->flows[tun_hashfn (txq)], txq);if (e) { +u32 queue_index =READ_ONCE (e->queue_index); +tun_flow_save_rps_rxhash (e, txq); - txq = e->queue_index; - }else { - txq =reciprocal_scale (txq, numqueues); +/* A racing update can leave the old index of a moved queue */ +if (likely (queue_index < numqueues)) +return queue_index; } -return txq; +return reciprocal_scale (txq, numqueues); }static u16 tun_ebpf_select_queue (struct tun_struct *tun,struct sk_buff *skb)
Signature · 1 line
2.53.0
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Sat, 14 Nov 2026 21:06:17 +0530 you wrote:
A multi-queue tun device keeps a flow table that maps each flow to the index of the queue it last used, so that packets sent back to the flow go to the same queue. When a queue is removed, the last queue moves into its index. An entry that still holds the last queue's old index then holds an index that no longer exists. Packets of that flow are sent to queue 0 with a "selects TX queue" warning, until the flow sends again or its entry expires after a few seconds.
[...]
Here is the summary with links:
- [net-next] tun: don't steer a flow to a queue index that no longer exists
https://git.kernel.org/netdev/net-next/c/9068e05d35f3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html