[libvirt] How to enable vhost for virtIO NIC?

Hi gurus on the list, I'm trying to bring up a Linux with virtio vhost backend. My system is running on kernel 2.6.34-rc7, libvirt 0.8.0. Two questions regarding to vhost: 1) XML format for vhost I didn't find any documents on libvirt.org description the XML or QMU argument format for vhost. According to http://www.linux-kvm.org/page/VhostNet#vhost-net_driver_projects, I tried *domxml-from-native* to convert following qemu argument to XML qemu-system-x86_64 -m 1G disk-c.qcow2 \ -net nic,model=virtio,netdev=foo \ -netdev tap,id=foo,ifname=msttap0,script=/home/mst/ifup,downscript=no,vhost=on But the output clearly ignore the network. <domain type='qemu'> <name>unnamed</name> <uuid>9cc877c1-7ac2-463d-3d3f-fa8f8918fe23</uuid> <memory>1048576</memory> <currentMemory>1048576</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64'>hvm</type> </os> <features> <acpi/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>qemu-system-x86_64</emulator> <input type='mouse' bus='ps2'/> <graphics type='sdl'/> <video> <model type='cirrus' vram='9216' heads='1'/> </video> </devices> </domain> What's the problem here? 2) Virtio driver. It's said that vhost require guest kernel version > 2.6.31 because vhost requires MSI-X. How about frontend of virtio driver? Say I'm running a Windows 2008 (with MSI-X support) + virtio NIC, is it necessary to upgrade frontend driver too? Regards, HUANG, Zhiteng

On 05/19/2010 01:49 AM, Huang, Zhiteng wrote:
Hi gurus on the list,
I'm trying to bring up a Linux with virtio vhost backend. My system is running on kernel 2.6.34-rc7, libvirt 0.8.0.
Two questions regarding to vhost:
1) XML format for vhost I didn't find any documents on libvirt.org description the XML or QMU argument format for vhost.
If you're using virtio networking, and vhost-net support is available on your system, libvirt will automatically alter the qemu commandline arguments to take advantage of it. libvirt checks for two things: 1) it runs "qemu-kvm --help" and looks for ",vhost=" in the output (demonstrating that this build of qemu supports vhost) 2) it attempts to open "/dev/vhost-net" in rw mode (demonstrating that the kernel support is there, either built into the kernel or loaded as a module). You can verify libvirt has enabled vhost by looking at the generated commandline in /var/log/libvirt/qemu/<domain>.log for "vhost=on,vhostfd=<some number>"
According to http://www.linux-kvm.org/page/VhostNet#vhost-net_driver_projects, I tried *domxml-from-native* to convert following qemu argument to XML
qemu-system-x86_64 -m 1G disk-c.qcow2 \ -net nic,model=virtio,netdev=foo \ -netdev tap,id=foo,ifname=msttap0,script=/home/mst/ifup,downscript=no,vhost=on
But the output clearly ignore the network. <domain type='qemu'> <name>unnamed</name> <uuid>9cc877c1-7ac2-463d-3d3f-fa8f8918fe23</uuid> <memory>1048576</memory> <currentMemory>1048576</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64'>hvm</type> </os> <features> <acpi/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>qemu-system-x86_64</emulator> <input type='mouse' bus='ps2'/> <graphics type='sdl'/> <video> <model type='cirrus' vram='9216' heads='1'/> </video> </devices> </domain>
What's the problem here?
I haven't used domxml-from-native, so I can't help you there.
2) Virtio driver. It's said that vhost require guest kernel version> 2.6.31 because vhost requires MSI-X. How about frontend of virtio driver? Say I'm running a Windows 2008 (with MSI-X support) + virtio NIC, is it necessary to upgrade frontend driver too?
a vhost virtio NIC appears to the guest driver identically to a user-space virtio NIC, so the same guest-side driver should work fine. (Actually, the vhost NIC doesn't (yet) support shared buffers that the user-space NIC does, but the guest's driver can deal with that)

Laine, Thank you for the answer. That really solved my problem. Regards, HUANG, Zhiteng Intel -----Original Message----- From: sendmail [mailto:justsendmailnothingelse@gmail.com] On Behalf Of Laine Stump Sent: Thursday, May 20, 2010 12:23 AM To: libvir-list@redhat.com Cc: Huang, Zhiteng Subject: Re: [libvirt] How to enable vhost for virtIO NIC? On 05/19/2010 01:49 AM, Huang, Zhiteng wrote:
Hi gurus on the list,
I'm trying to bring up a Linux with virtio vhost backend. My system is running on kernel 2.6.34-rc7, libvirt 0.8.0.
Two questions regarding to vhost:
1) XML format for vhost I didn't find any documents on libvirt.org description the XML or QMU argument format for vhost.
If you're using virtio networking, and vhost-net support is available on your system, libvirt will automatically alter the qemu commandline arguments to take advantage of it. libvirt checks for two things: 1) it runs "qemu-kvm --help" and looks for ",vhost=" in the output (demonstrating that this build of qemu supports vhost) 2) it attempts to open "/dev/vhost-net" in rw mode (demonstrating that the kernel support is there, either built into the kernel or loaded as a module). You can verify libvirt has enabled vhost by looking at the generated commandline in /var/log/libvirt/qemu/<domain>.log for "vhost=on,vhostfd=<some number>"
According to http://www.linux-kvm.org/page/VhostNet#vhost-net_driver_projects, I tried *domxml-from-native* to convert following qemu argument to XML
qemu-system-x86_64 -m 1G disk-c.qcow2 \ -net nic,model=virtio,netdev=foo \ -netdev tap,id=foo,ifname=msttap0,script=/home/mst/ifup,downscript=no,vhost=on
But the output clearly ignore the network. <domain type='qemu'> <name>unnamed</name> <uuid>9cc877c1-7ac2-463d-3d3f-fa8f8918fe23</uuid> <memory>1048576</memory> <currentMemory>1048576</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64'>hvm</type> </os> <features> <acpi/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>qemu-system-x86_64</emulator> <input type='mouse' bus='ps2'/> <graphics type='sdl'/> <video> <model type='cirrus' vram='9216' heads='1'/> </video> </devices> </domain>
What's the problem here?
I haven't used domxml-from-native, so I can't help you there.
2) Virtio driver. It's said that vhost require guest kernel version> 2.6.31 because vhost requires MSI-X. How about frontend of virtio driver? Say I'm running a Windows 2008 (with MSI-X support) + virtio NIC, is it necessary to upgrade frontend driver too?
a vhost virtio NIC appears to the guest driver identically to a user-space virtio NIC, so the same guest-side driver should work fine. (Actually, the vhost NIC doesn't (yet) support shared buffers that the user-space NIC does, but the guest's driver can deal with that)

Hi all, On Wed, May 19, 2010 at 18:22, Laine Stump <laine@laine.org> wrote:
On 05/19/2010 01:49 AM, Huang, Zhiteng wrote:
Hi gurus on the list,
I'm trying to bring up a Linux with virtio vhost backend. My system is running on kernel 2.6.34-rc7, libvirt 0.8.0.
Two questions regarding to vhost:
1) XML format for vhost I didn't find any documents on libvirt.org description the XML or QMU argument format for vhost.
If you're using virtio networking, and vhost-net support is available on your system, libvirt will automatically alter the qemu commandline arguments to take advantage of it. libvirt checks for two things:
1) it runs "qemu-kvm --help" and looks for ",vhost=" in the output (demonstrating that this build of qemu supports vhost)
2) it attempts to open "/dev/vhost-net" in rw mode (demonstrating that the kernel support is there, either built into the kernel or loaded as a module).
I just tried this with libvirt 0.8.1, on a 2.6.34 kernel, and it doesn't seem to work for me. Setting a breakpoint on the qemudOpenVhostNet function shows that it returns -1, because QEMUD_CMD_FLAG_NETDEV isn't set. -netdev is disabled on qemu 0.12 Ruben

On 05/20/2010 10:30 AM, Ruben Kerkhof wrote:
Hi all,
On Wed, May 19, 2010 at 18:22, Laine Stump<laine@laine.org> wrote:
On 05/19/2010 01:49 AM, Huang, Zhiteng wrote:
Hi gurus on the list,
I'm trying to bring up a Linux with virtio vhost backend. My system is running on kernel 2.6.34-rc7, libvirt 0.8.0.
Two questions regarding to vhost:
1) XML format for vhost I didn't find any documents on libvirt.org description the XML or QMU argument format for vhost.
If you're using virtio networking, and vhost-net support is available on your system, libvirt will automatically alter the qemu commandline arguments to take advantage of it. libvirt checks for two things:
1) it runs "qemu-kvm --help" and looks for ",vhost=" in the output (demonstrating that this build of qemu supports vhost)
2) it attempts to open "/dev/vhost-net" in rw mode (demonstrating that the kernel support is there, either built into the kernel or loaded as a module).
I just tried this with libvirt 0.8.1, on a 2.6.34 kernel, and it doesn't seem to work for me. Setting a breakpoint on the qemudOpenVhostNet function shows that it returns -1, because QEMUD_CMD_FLAG_NETDEV isn't set.
-netdev is disabled on qemu 0.12
Sigh. Yes, you are correct. I had forgotten that I had locally modify the libvirt source to force the use of the qemu -netdev commandline option (rather than -net). -netdev is required for vhost-net because qemu purposefully ignores vhost= in the -net options (I don't recall the reason behind this, but do remember that it somehow made sense when it was explained). Also, I just noticed that F13 is still serving up libvirt 0.7.7, and the vhost-net patch went in just after that, so it would require at least libvirt 0.8.0. If you don't care about network device hotplug, you can grab the latest sources and enable -netdev - just remove the "#if 0" around the block testing for presence of -netdev in qemudComputeCmdFlags, and appropriately modify the qemu version number it's looking for. If you're not that adventurous, you'll have to play the waiting game. When support is enabled, though, you won't need to do anything with your config; just restart your guests.
participants (3)
-
Huang, Zhiteng
-
Laine Stump
-
Ruben Kerkhof