12. XDP
●
A high performance, programmable network
data path
●
No specialized hardware
●
No kernel bypass
●
Works with the existing network stack
●
Direct packet write
13. XDP Actions
●
XDP_ABORTED
eBPF program error, treat like DROP
●
XDP_DROP
Drop the packet
●
XDP_PASS
Pass the packet up to the stack
●
XDP_TX
Transmit packet out the same interface
15. XDP Restrictions
●
One packet buffer per 4K page
– Memory waste
– Needs the change of the memory model of the
driver
●
No per-RX-queue XDP instance
●
No transmit on other interface
20. static int virtnet_xdp_set(struct net_device *dev,
struct bpf_prog *prog)
{
...
if (dev->mtu > max_sz) {
netdev_warn(dev, "XDP requires MTU less than %lun",
max_sz);
return -EINVAL;
}
...
if (prog) {
prog = bpf_prog_add(prog, vi->max_queue_pairs - 1);
if (IS_ERR(prog))
return PTR_ERR(prog);
}
...
for (i = 0; i < vi->max_queue_pairs; i++) {
old_prog = rtnl_dereference(vi->rq[i].xdp_prog);
rcu_assign_pointer(vi->rq[i].xdp_prog, prog);
if (old_prog)
bpf_prog_put(old_prog);
}
return 0;
}
21. static struct sk_buff *receive_mergeable(struct net_device *dev,
...
unsigned int len)
{
...
rcu_read_lock();
xdp_prog = rcu_dereference(rq->xdp_prog);
if (xdp_prog) {
...
act = bpf_prog_run_xdp(xdp_prog, &xdp);
switch (act) {
case XDP_PASS:
...
case XDP_TX:
...
default:
...
case XDP_ABORTED:
...
case XDP_DROP:
...
}
}
rcu_read_unlock();
...
head_skb = page_to_skb(vi, rq, page, offset, len, truesize);
22. Test XDP with virtio-net
QEMU
tap0
192.168.100.1
pktgen
Host
virtio-net
192.168.100.2
XDP
23. Setup the host
●
Create the multiqueue tap
# ip tuntap add mode tap multi_queue
user <user_name> name tap0
●
Bring up tap0
# ip addr add 192.168.100.1 dev tap0
# ip link set tap0 up
●
Change the permission of /dev/vhost-net
# chmod 666 /dev/vhost-net
24. Setup the guest
●
Enable multiqueue for virtio-net (for 1 CPU)
-netdev tap,id=hn1,ifname=tap0,script=no,
downscript=no,vhost=on,queues=2
-device virtio-net-pci,netdev=hn1,mq=on,
vectors=6
●
Disable LRO support
-device guest_tso4=off,guest_tso6=off,
guest_ecn=off,guest_ufo=off