On Wed, 11 Nov 2026 10:45:36 +0000
Frank Dressler <[email protected]> wrote:
> This fix ensures that the queues of an AF_PACKET vdev do not
> accidentally join an already existing fanout group in the same netns.
> Joining such a group would make each member receive only a fraction of
> the packets.
>
> It sets the PACKET_FANOUT_FLAG_UNIQUEID flag for the first queue which
> asks the kernel to allocate a new, unique fanout group ID, then asks the
> kernel for that queue's fanout configuration which includes this
> generated ID but not the flag anymore (the flag is ephemeral) and then
> uses it for subsequent queues to make them join the same fanout group.
>
> The bug exists since the PMD's introduction in 2014:
>
> # 2014 DPDK:
> $ git show 364e08f2bb:lib/librte_pmd_af_packet/rte_eth_af_packet.c |
> grep getpid
> fanout_arg = (getpid() ^ (*internals)->if_index) & 0xffff;
>
> # v26.07:
> $ git show v26.07:drivers/net/af_packet/rte_eth_af_packet.c |
> grep getpid
> return (getpid() ^ if_index) & 0xffff;
>
> The chance for a collision might look low initially as it requires PIDs
> to be equal mod 65536. But the chance is high for applications running
> in containers having individual pidns but a shared netns, which can be
> the case in a k8s pod, or also with manually started containers, e.g.
> `--network ns:<path>` in Podman. The individual pidns increase the
> chance of different processes having the same PID.
>
> To quickly reproduce the issue, you can start multiple AF_PACKET DPDK
> applications with qpairs greater than 1, prefixing them with
> `unshare --fork -p` to have each one get the same PID as if they were
> executed in a container. Each one then only receives a fraction of
> the traffic.
>
> The used UNIQUEID fanout flag is available since Linux v4.12, while DPDK
> currently requires Linux v5.4 or newer. The change is also compatible
> with RHEL 8.
>
> Fixes: 364e08f2bbc0 ("af_packet: add PMD for AF_PACKET-based virtual devices")
> Cc: [email protected]
>
> Signed-off-by: Frank Dressler <[email protected]>
> ---
Reviewed-by: Stephen Hemminger <[email protected]>
The commit message is way to long though. Will chop it during merge.
You need to tell you AI to be concise. I have started using multiple
prompts to tell it to not repeat.
The kernel review prompt includes /kslop skill which has:
https://github.com/masoncl/review-prompts/blob/main/kernel/slop-indicators.md
AI even flagged that:
Logic is correct. The kernel clears PACKET_FANOUT_FLAG_UNIQUEID from
the stored group flags after allocating the id, and PACKET_FANOUT
getsockopt returns id | type << 16 | flags << 24, which is exactly
the encoding fanout_add() needs for the later queues to pass the
match->flags/type checks and join. DEFRAG, ROLLOVER and
IGNORE_OUTGOING survive the round trip unchanged.
Info
The commit message is longer than it needs to be. The two git show
transcripts repeat what the Fixes: tag already says; dropping them
and the "This fix ensures" opener would leave something like:
The fanout group id was derived from (getpid() ^ ifindex), so
processes in separate pid namespaces sharing a netns (e.g. a k8s
pod) can pick the same id. Their queues then join one fanout group
and each process sees only part of the traffic.
Use PACKET_FANOUT_FLAG_UNIQUEID on the first queue so the kernel
allocates an unused id, then read it back with getsockopt and use
it for the remaining queues.
PACKET_FANOUT_FLAG_UNIQUEID is available since Linux 4.12.
Worth one sentence: this also fixes two af_packet vdevs on the same
interface in one process, which previously shared a group because
pid and ifindex were identical.