# KVM-QEMU and Virtualbox - concurrent use of svm not possible

## ipic

I have been using Virtualbox for several years now. I would like to move to KVM/QEMU. I am new to this, so apologies if this is a dumb topic or has been covered before.

There is a very old internet article about KVM and Virtualbox not co-existing due to kernel module clashes. However, in articles that talk about migrating Virtualbox to KVM there are also articles that say that the two can co-exist. Ideally I would like to convert one of my VMs at a time (I have four on the same machine), so this would be useful.

I followed the Gentoo wiki article https://wiki.gentoo.org/wiki/QEMU

I installed app-emulation/virt-manager, added my user to groups kvm, quem and libvirt, edited /etc/libvirt/libvirtd.conf as suggested, and started up /etc/init.d/libvirtd

In dmesg I then saw:

```
[26598.924684] kvm: enabling virtualization on CPU0 failed

[26598.924689] kvm: enabling virtualization on CPU1 failed

[26598.924697] kvm: enabling virtualization on CPU2 failed

[26598.924707] kvm: enabling virtualization on CPU3 failed
```

.. repeated several times.

When I entered the "new VM" dialogue in virt-manager, it informed me that KVM was not active (and thus the new VM performance would be impacted).

From what I little I know to look for, I can see the following:

```

ian2 ~ # ls -lh /dev/kvm 

crw-rw-rw-+ 1 root kvm 10, 232 Feb 12 09:04 /dev/kvm

ian2 ~ # lsmod | grep kvm

kvm_amd               102400  0

ccp                    77824  1 kvm_amd

ian2 ~ # 
```

The kernel (gentoo-sources-5.5.3) is configured thus:

```
ian2 ~ # zcat /proc/config.gz | grep KVM

CONFIG_KVM_GUEST=y

# CONFIG_KVM_DEBUG_FS is not set

CONFIG_HAVE_KVM=y

CONFIG_HAVE_KVM_IRQCHIP=y

CONFIG_HAVE_KVM_IRQFD=y

CONFIG_HAVE_KVM_IRQ_ROUTING=y

CONFIG_HAVE_KVM_EVENTFD=y

CONFIG_KVM_MMIO=y

CONFIG_KVM_ASYNC_PF=y

CONFIG_HAVE_KVM_MSI=y

CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT=y

CONFIG_KVM_VFIO=y

CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT=y

CONFIG_KVM_COMPAT=y

CONFIG_HAVE_KVM_IRQ_BYPASS=y

CONFIG_HAVE_KVM_NO_POLL=y

CONFIG_KVM=y

CONFIG_KVM_INTEL=m

CONFIG_KVM_AMD=m

CONFIG_KVM_AMD_SEV=y

CONFIG_PTP_1588_CLOCK_KVM=m

ian2 ~ # 
```

For the running Virtualbox VMs the following modules are loaded:

```
ian2 ~ # lsmod | grep vbox

vboxnetadp             28672  0

vboxnetflt             32768  2

vboxdrv               430080  6 vboxnetadp,vboxnetflt

ian2 ~ # 
```

My question is whether it is possible to run the two (KVM-QEMU and Virtualbox) together, and have both using the AMD svm capabilities?

If so, can someone give some hints for what to look for that I have done wrong?

Many thanks.Last edited by ipic on Wed Feb 12, 2020 9:11 pm; edited 1 time in total

----------

## dimko

I have been ironic, but i did run ESXI inside of KVM.

And to be less ironic, unload drivers from virtual box, try kvm again. If works  - then incompatible. If not, you have not dug deep enough. You have not made your kvm workable.

try "qemu-system-x86_64 -enable-kvm", if window pops up under Xorg, and fails to load - you are on right path. Probably your install is viable and CPU assisted virtualisation works.

----------

## NeddySeagoon

ipic,

Works for me with both installed.

I have not run them both concurrently but I have both installed.

I use KVM/QEMU for something I want to keep around and Virtualbox for VMs that I intend to throw away, except they are mostly still around too. :)

----------

## ipic

 *dimko wrote:*   

> 
> 
> try "qemu-system-x86_64 -enable-kvm", if window pops up under Xorg, and fails to load - you are on right path. Probably your install is viable and CPU assisted virtualisation works.

 

Thanks for that pointer. When I ran it with the vbox modules loaded I got this:

```
ipic@ian2 ~ $ qemu-system-x86_64 -enable-kvm

ioctl(KVM_CREATE_VM) failed: 16 Device or resource busy

qemu-system-x86_64: failed to initialize KVM: Device or resource busy
```

Which gives a pretty big hint what is going on  :Smile: 

So stopped all the vbox VMs, unloaded the modules, and tried again.

This time "qemu-system-x86_64 -enable-kvm" popped up a VM window, which tried its best to find something to load and stopped with "no boot media".

I thus think on my system it's conclusive, the two cannot use KVM at the same time.

I did run qemu while the vbox VMs were running, and it works, but it is so, so slow. Not really usable.

Thanks for the help guys - this is a steep learning curve  :Smile: 

----------

## Zucca

This would explain why I cannot setup a vbox VM via virt-manager when I alrady have qemu/kvm VMs running...

----------

## Hu

If I recall correctly, when kvm was much younger, the incompatibility was more severe.  I seem to recall claims that the hardware tracking of virtualization state had no inherent locking, and trying to run both kvm and virtualbox at the same time would cause a fatal exception on the host.  That has long since been improved, to produce the situation shown here.  You can't use them in parallel, but you can't break your system by trying to use them in parallel.

----------

## Zucca

A quick chat on IRC with a guy who's managing remote vms by using virt-manager confirmed that it's technically impossible to run the two simultaneously.

I guess it would need a kernel level modification/patch to be able to share the resource with more than two kvm hypervisors.

Someone else with more such low level knowledge can correct me if I'm wrong.  :Question: 

----------

## Hu

That sounds right.  The hardware cannot handle being shared, so you need the two software components that want to use the hardware to cooperatively share the hardware, such as by having one ask the other to relinquish it.  I could also see an argument that this is solving the wrong problem, and that the right solution is to get all the userspace frontends to standardize on a single kernel module that operates the virtualization hardware, so that no hand-off is needed because the hardware is always managed by KVM, regardless of whether you use Qemu or VirtualBox for the user process portion.

----------

