xdp-project / xdp-tutorial

XDP tutorial
2.44k stars 577 forks source link

AF_XDP with bond interface #362

Closed glazychev-art closed 1 year ago

glazychev-art commented 1 year ago

Description

Hi, I'm trying to use af_xdp with bond host interface, but it seems it doesn't work.

Judging by the kernel repository, XDP support was added some time ago.

Steps to reproduce

advanced03-AF_XDP example was taken as a basis. I changed testenv.sh setup function to create bond interface like this (git apply 0001-Change-host-veth-to-bond.txt):

...
    set_sysctls $NS
    ip link add bond0 type bond mode 802.3ad
    ip addr add dev bond0 "${OUTSIDE_IP6}/${IP6_PREFIX_SIZE}"
    ip link set bond0 up
    ethtool -K "$NS" rxvlan off txvlan off
    ip link set "$NS" master bond0
    ip link set dev "$NS" up
    INSIDE_MAC=$(iface_macaddr veth0 "$NS")
    ip neigh add "$INSIDE_IP6" lladdr "$INSIDE_MAC" dev bond0 nud permanent
...

Run:

$ eval $(../testenv/testenv.sh alias)
$ t setup --name veth-adv03
$ t ping
$ sudo ./af_xdp_user -d bond0 

Additional info

According to my observations, data transfer bond0(xdp) ----> veth0(ns:veth-adv03) works fine. The problem occurs on receiving data on the bond0 interface. I guess there is a problem with different RX queues for bond0 (master) - where we attached the xdp program, and veth-adv03 (slave) - where the data actually comes.

Context

# ethtool -S veth-adv03
NIC statistics:
     peer_ifindex: 2
     rx_queue_0_xdp_packets: 13
     rx_queue_0_xdp_bytes: 1352
     rx_queue_0_drops: 13
     rx_queue_0_xdp_redirect: 0
     rx_queue_0_xdp_drops: 0
     rx_queue_0_xdp_tx: 0
     rx_queue_0_xdp_tx_errors: 0
     tx_queue_0_xdp_xmit: 0
     tx_queue_0_xdp_xmit_errors: 0

# uname -r
5.15.0-71-generic

Does anyone have any ideas how to solve this problem?

Thanks in advance

tohojo commented 1 year ago

Artem Glazychev @.***> writes:

Does anyone have any ideas how to solve this problem?

Just install the XDP program on both component interfaces of the bond. That's what the bonding driver does anyway (it just passed through the load action). And since for AF_XDP you have to bind to a particular RXQ, this won't work at all with the bonding driver.

In general, the bonding driver XDP support is weird and hard to reason about, so I'd suggest just avoiding it...

glazychev-art commented 1 year ago

@tohojo Thanks for the answer!

If I understand correctly, the problem is somewhere here? https://github.com/torvalds/linux/tree/v5.15/drivers/net/bonding

What do you think, is it possible to fix it?

tohojo commented 1 year ago

Artem Glazychev @.***> writes:

@tohojo Thanks for the answer!

If I understand correctly, the problem is somewhere here? https://github.com/torvalds/linux/tree/v5.15/drivers/net/bonding

What do you think, is it possible to fix it?

Probably not, it's by design...

joamaki commented 1 year ago

The XDP bonding support was added solely for being able to be able to transparently load XDP BPF programs onto a bonding device without special handling in user-space. AF_XDP support for bonding is likely not feasible.

glazychev-art commented 1 year ago

Thanks for the info!