af_xdp: documents incompatibility with 1GB hugepages and high buffers-per-numa.
[vpp.git] / src / plugins / af_xdp / af_xdp_doc.md
1 # AF_XDP Ethernet driver {#af_xdp_doc}
2
3 This driver relies on Linux AF_XDP socket to rx/tx Ethernet packets.
4
5 ## Maturity level
6 Under development: it should work, but has not been thoroughly tested.
7
8 ## Features
9  - copy and zero-copy mode
10  - multiqueue
11  - API
12  - custom eBPF program
13  - polling, interrupt and adaptive mode
14
15 ## Limitations
16 Because of AF_XDP restrictions, the MTU is limited to below PAGE_SIZE
17 (4096-bytes on most systems) minus 256-bytes, and they are additional
18 limitations depending upon specific Linux device drivers.
19 As a rule of thumb, a MTU of 3000-bytes or less should be safe.
20 Furthermore, upon UMEM creation, the kernel allocates a physically-contiguous structure, whose size is proportional to the number of 4KB pages contained in the UMEM. That allocation might fail when the number of buffers allocated by VPP is too high. That number can be controlled with the `buffers { buffers-per-numa }` configuration option.
21 Finally, note that because of this limitation, this plugin is unlikely to be compatible with the use of 1GB hugepages.
22
23 ## Requirements
24 The Linux kernel interface must be up and have enough queues before
25 creating the VPP AF_XDP interface, otherwise Linux will deny creating
26 the AF_XDP socket.
27 The AF_XDP interface will claim NIC RX queue starting from 0, up to the
28 requested number of RX queues (only 1 by default). It means all packets
29 destined to NIC RX queue `[0, num_rx_queues[` will be received by the
30 AF_XDP interface, and only them. Depending on your configuration, there
31 will usually be several RX queues (typically 1 per core) and packets are
32 spread accross queues by RSS. In order to receive consistent traffic,
33 you **must** program the NIC dispatching accordingly. The simplest way
34 to get all the packets is to reconfigure the Linux kernel driver to use
35 only `num_rx_queues` RX queues (ie all NIC queues will be associated
36 with the AF_XDP socket):
37 ```
38 ~# ethtool -L <iface> combined <num_rx_queues>
39 ```
40 Additionally, the VPP AF_XDP interface will use a MAC address generated at
41 creation time instead of the Linux kernel interface MAC. As Linux kernel
42 interface are not in promiscuous mode by default (see below) this will
43 results in a useless configuration where the VPP AF_XDP interface only
44 receives packets destined to the Linux kernel interface MAC just to drop
45 them because the destination MAC does not match VPP AF_XDP interface MAC.
46 If you want to use the Linux interface MAC for the VPP AF_XDP interface,
47 you can change it afterwards in VPP:
48 ```
49 ~# vppctl set int mac address <iface> <mac>
50 ```
51 Finally, if you wish to receive all packets and not only the packets
52 destined to the Linux kernel interface MAC you need to set the Linux
53 kernel interface in promiscuous mode:
54 ```
55 ~# ip link set dev <iface> promisc on
56 ```
57
58 ## Security considerations
59 When creating an AF_XDP interface, it will receive all packets arriving
60 to the NIC RX queue #0. You need to configure the Linux kernel NIC
61 driver properly to ensure that only intented packets will arrive in
62 this queue. There is no way to filter the packets after-the-fact using
63 eg. netfilter or eBPF.
64
65 ## Quickstart
66 1. Setup the Linux kernel interface (enp216s0f0 here) to use 4 queues:
67 ```
68 ~# ethtool -L enp216s0f0 combined 4
69 ```
70 2. Put the Linux kernel interface up and in promiscuous mode:
71 ```
72 ~# ip l set dev enp216s0f0 promisc on up
73 ```
74 3. Create the AF_XDP interface:
75 ```
76 ~# vppctl create int af_xdp host-if enp216s0f0 num-rx-queues 4
77 ```
78 4. Use the interface as usual, eg.:
79 ```
80 ~# vppctl set int ip addr enp216s0f0/0 1.1.1.1/24
81 ~# vppctl set int st enp216s0f0/0 up
82 ~# vppctl ping 1.1.1.100`
83 ```
84
85 ## Custom eBPF XDP program
86 This driver relies on libbpf and as such relies on the `xsks_map` eBPF
87 map.  The default behavior is to use the XDP program already attached
88 to the interface if any, otherwise load the default one.
89 You can request to load a custom XDP program with the `prog` option when
90 creating the interface in VPP:
91 ```
92 ~# vppctl create int af_xdp host-if enp216s0f0 num-rx-queues 4 prog extras/bpf/af_xdp.bpf.o
93 ```
94 In that case it will replace any previously attached program.  A custom
95 XDP program example is provided in `extras/bpf/`.
96
97 ## Performance consideration
98 AF_XDP relies on the Linux kernel NIC driver to rx/tx packets. To reach
99 high-performance (10's MPPS), the Linux kernel NIC driver must support
100 zero-copy mode and its RX path must run on a dedicated core in the NUMA
101 where the NIC is physically connected.