简体   繁体   English

无法使用自定义(桥接)tap 设备在 QEMU VM 中加载 XDP 程序

[英]Failed to load XDP program inside a QEMU VM with custom (bridged) tap device

I'm recently trying to load XDP program inside a QEMU VM (with virtio-net-pci as NIC driver, and tap device as the backend).我最近尝试在 QEMU VM 中加载 XDP 程序(使用virtio-net-pci作为 NIC 驱动程序,并使用设备作为后端)。 It seems that by doing so my NIC is required to features vCPU*2 of queues, which can be done by declaring it at QEMU startup command ( ... -netdev tap,queues=<N>... ).这样做似乎需要我的 NIC 具有队列的 vCPU*2 功能,这可以通过在 QEMU 启动命令 ( ... -netdev tap,queues=<N>... ) 中声明它来完成。 If I didn't declare the NIC with enough amount of the queues and trying to load the XDP program, I get the following kernel message and error:如果我没有用足够数量的队列声明 NIC 并尝试加载 XDP 程序,我会收到以下 kernel 消息和错误:

[    8.663795] virtio_net virtio0 eth0: request 2 queues but max is 1
RTNETLINK answers: Cannot allocate memory

This is totally not a problem so far, though idk why this is required (I've successfully load the same XDP program on my host machine, which has only single queue).到目前为止,这完全不是问题,尽管我知道为什么需要这样做(我已经成功地在我的主机上加载了相同的 XDP 程序,它只有一个队列)。

But my goal is have QEMU to use my custom tap device, which has connected to a bridge on the host.但我的目标是让 QEMU 使用我的自定义分接设备,该设备已连接到主机上的网桥。 Instead of letting QEMU to create a new one for me.而不是让 QEMU 为我创建一个新的。

In order to use the custom tap device, I start the VM with following command:为了使用自定义 Tap 设备,我使用以下命令启动 VM:

sudo qemu-system-x86_64 -hda output/images/node_rootfs.ext2  -enable-kvm -echr 2 --nographic \
 -netdev tap,script=no,downscript=no,id=xcxc,ifname=tap0,queues=4 -device virtio-net-pci,netdev=xcxc,mq=on \
 -cpu host \
 -smp 2 \
 -m 512 \
 -kernel output/images/bzImage -append "root=/dev/sda rw nokaslr"

where tap0 is the so called custom tap device.其中tap0是所谓的自定义抽头设备。

The above QEMU command won't start the VM, and the error message is:上面的 QEMU 命令不会启动 VM,错误信息是:

qemu-system-x86_64: could not configure /dev/net/tun (tap0): Invalid argument

By removing the option ifname=tap0 or queues=4 , it boots properly.通过删除选项ifname=tap0queues=4 ,它可以正确启动。

It seems that it's telling me I can't declare a NIC with multi-queue and a bridged tap device at the same time.似乎它告诉我我不能同时声明具有多队列和桥接抽头设备的 NIC。 But what is awkward is that I need the XDP program executing on the bridged tap device.但尴尬的是我需要在桥接分接头设备上执行 XDP 程序。

Does anyone have idea why a bridged tap device can't live with multi-queue enabled NIC?有谁知道为什么桥接分接头设备不能与启用多队列的 NIC 一起使用?

PS kernel version: 5.4.33 QEMU version: 4.2.0 (Debian 1:4.2-3ubuntu6.2) PS kernel 版本: 5.4.33 QEMU 版本: 4.2.0 (Debian 1:4.2-3ubuntu6.2)

Thank you for reading my question!感谢您阅读我的问题!

Turns out QEMU doesn't allow specifying ifname in the option directly.原来 QEMU 不允许直接在选项中指定ifname Instead, this should be done with the script (option script=/path/to/script and downscript=/path/to/script ).相反,这应该使用脚本来完成(选项script=/path/to/scriptdownscript=/path/to/script )。

IOW, the tap device should be configured within the script, instead of creating one manually and pass it with option ifname . IOW,应在脚本中配置 tap 设备,而不是手动创建一个并使用选项ifname传递它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM