# libvirt: -enable-kvm missing

## bitozoid

I have just upgraded to qemu 2.0, with the following message from portage:

```
"The /usr/bin/kvm and /usr/bin/qemu-kvm wrappers are no longer"

"installed.  In order to use kvm acceleration, pass the flag"

"-enable-kvm when running your system target."
```

So that I changed in my libvirt xml file

```
-    <emulator>/usr/bin/qemu-kvm</emulator>

+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
```

restarted libvirtd, started my qemu virtual machine, and issued:

```
ps aux | grep qemu
```

However, I can't see the -enable-kvm parameter:

```
qemu     24208 91.3  0.6 4947948 55856 ?       Sl   11:52   0:07 /usr/bin/qemu-system-x86_64 -name 20140205-win7 -S -machine pc-i440fx-1.5,accel=kvm,usb=off -m 4096 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 8143daf4-1183-7943-b58e-78fc38c004bd -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/20140205-win7.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x7 -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4 -drive file=/var/lib/libvirt/images/w7amd64.qcow2,if=none,id=drive-virtio-disk0,format=qcow2,cache=writeback -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x8,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/var/lib/libvirt/images/virtio-win-0.1-74.iso,if=none,id=drive-ide0-1-0,readonly=on,format=raw,cache=none -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev tap,fd=19,id=hostnet0,vhost=on,vhostfd=20 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:f5:69:1c,bus=pci.0,addr=0x6 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -chardev spicevmc,id=charchannel0,name=vdagent -device virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel0,id=channel0,name=com.redhat.spice.0 -spice port=5900,addr=127.0.0.1,disable-ticketing,seamless-migration=on -k es -device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,bus=pci.0,addr=0x2 -device intel-hda,id=sound0,bus=pci.0,addr=0x3 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
```

I assume libvirt detects qemu capabilities. Why is it missing?

----------

## kikko

Hi! 

for what I can see, you have "accel=kvm" enabled in your command line options:

 *Quote:*   

> 
> 
> qemu     24208 91.3  0.6 4947948 55856 ?       Sl   11:52   0:07 /usr/bin/qemu-system-x86_64 -name 20140205-win7 -S -machine pc-i440fx-1.5,accel=kvm,usb=off -m 4096 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 8143daf4-1183-7943-b58e-78fc38c004bd -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/20140205-win7.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x7 -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4 -drive file=/var/lib/libvirt/images/w7amd64.qcow2,if=none,id=drive-virtio-disk0,format=qcow2,cache=writeback -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x8,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/var/lib/libvirt/images/virtio-win-0.1-74.iso,if=none,id=drive-ide0-1-0,readonly=on,format=raw,cache=none -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev tap,fd=19,id=hostnet0,vhost=on,vhostfd=20 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:f5:69:1c,bus=pci.0,addr=0x6 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -chardev spicevmc,id=charchannel0,name=vdagent -device virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel0,id=channel0,name=com.redhat.spice.0 -spice port=5900,addr=127.0.0.1,disable-ticketing,seamless-migration=on -k es -device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,bus=pci.0,addr=0x2 -device intel-hda,id=sound0,bus=pci.0,addr=0x3 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

 

Since you have edited the XML file from libvirtd, this may be the only proof that KVM is enabled

----------

## dmoulding

I'm facing the same situation. The message from emerge says:

 *Quote:*   

> Please update your configs in /etc/libvirt/qemu/ to use the -enable-kvm flag and the right system binary (e.g. qemu-system-x86_64).

 

It's easy to see in the XML where the binary goes (just search for qemu-kvm), but it's not obvious where arguments to the emulator are supposed to go. Neither the libvirt "Domain XML format" documentation nor "man virsh" have provided me with any illumination. Anybody know how to specify emulator command-line arguments in libvirt domain XML?

----------

## dmoulding

More browsing of the libvirt documentation led me here: http://libvirt.org/drvqemu.html#xmlimport

That taught me about the "domxml-from-native" virsh command. So, trying that out... first without the -enable-kvm option:

```
$ virsh domxml-from-native qemu-argv <(echo "/usr/bin/qemu-system-x86_64")

<domain type='qemu'>

  <name>unnamed</name>

  <uuid>0586443e-1960-4227-8c05-f922e3990e96</uuid>

  <memory unit='KiB'>65536</memory>

  <currentMemory unit='KiB'>65536</currentMemory>

  <vcpu placement='static'>1</vcpu>

  <os>

    <type arch='x86_64' machine='pc'>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>/usr/bin/qemu-system-x86_64</emulator>

    <controller type='usb' index='0'/>

    <controller type='pci' index='0' model='pci-root'/>

    <input type='mouse' bus='ps2'/>

    <input type='keyboard' bus='ps2'/>

    <graphics type='sdl'/>

    <video>

      <model type='cirrus' vram='9216' heads='1'/>

    </video>

    <memballoon model='virtio'/>

  </devices>

</domain>

```

Then with the -enable-kvm option:

```
$ virsh domxml-from-native qemu-argv <(echo "/usr/bin/qemu-system-x86_64 -enable-kvm")

<domain type='kvm'>

  <name>unnamed</name>

  <uuid>6a1d3d03-4630-45ce-9732-aad149d31754</uuid>

  <memory unit='KiB'>65536</memory>

  <currentMemory unit='KiB'>65536</currentMemory>

  <vcpu placement='static'>1</vcpu>

  <os>

    <type arch='x86_64' machine='pc'>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>/usr/bin/qemu-system-x86_64</emulator>

    <controller type='usb' index='0'/>

    <controller type='pci' index='0' model='pci-root'/>

    <input type='mouse' bus='ps2'/>

    <input type='keyboard' bus='ps2'/>

    <graphics type='sdl'/>

    <video>

      <model type='cirrus' vram='9216' heads='1'/>

    </video>

    <memballoon model='virtio'/>

  </devices>

</domain>

```

That leads me to believe setting the "type" attribute on the "domain" element is the way to do it, which, incidentally, is what's already in the XML I have.

I also noticed that the "qemu-kvm" wrapper script did *not* use the "-enable-kvm" flag, either. It passed "-machine accel=kvm" only.

----------

## szatox

The easiest test ever:

 *Quote:*   

> $ lsmod | grep kvm
> 
> kvm_amd                42845  0 
> 
> kvm                   218141  1 kvm_amd
> ...

 

Second one is with a single VM running

----------

## bitozoid

It looks like the code reads the 'qemu -help' and sets capabilities.

```
cat libvirt-1.2.3/src/qemu/qemu_capabilities.c

...

    if (strstr(help, "-enable-kvm"))

        virQEMUCapsSet(qemuCaps, QEMU_CAPS_ENABLE_KVM);

...

    cmd = virQEMUCapsProbeCommand(qemuCaps->binary, NULL, runUid, runGid);

    virCommandAddArgList(cmd, "-help", NULL);

...
```

Then, from the capabilities it adds the argument to the command line:

```
$ cat libvirt-1.2.3/src/qemu/qemu_command.c

...

        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM)) {

            enableKVM = true;

...

    if (enableKVM)

        virCommandAddArg(cmd, "-enable-kvm");

...
```

So something is missing. I wonder whether some gentoo specific patch is needed.

libvirt-1.2.3/src/qemu/qemu_capabilities.c

```
 714     /* qemu-kvm/kvm binaries can only be used if

 715      *  - host & guest arches match

 716      * Or

 717      *  - hostarch is x86_64 and guest arch is i686

 718      * The latter simply needs "-cpu qemu32"

 719      */

 720     if (virQEMUCapsIsValidForKVM(hostarch, guestarch)) {

 721         const char *const kvmbins[] = { "/usr/libexec/qemu-kvm", /* RHEL */

 722                                         "qemu-kvm", /* Fedora */

 723                                         "kvm" }; /* Upstream .spec */

 724 
```

----------

## PeeJay

I only added the qemu-system-x86_64 part and libvirt seems to be automagicly using kvm as the hypervisor.

----------

