How to use Ubuntu as a hypervisor?
Note Recommended 14.10 or later
Ubuntu is able to be used as a hypervisor, as an alternative to PowerKVM. Just install in bare metal (NV) it following the steps in Running Ubuntu non-virtualized on POWER8 After the installation you need:
- Install the missing virtualization packages:
# sudo apt-get install qemu-kvm qemu-user qemu-utils cloud-image-utils qemu-system-ppc qemu-slof libvirt-bin numactl
- Add the users that would be able to run virtual machines into the kvm group:
# sudo usermod -a -G kvm <user>
- Disable the SMT:
# sudo ppc64_cpu --smt=off You can disable it on every boot, changing /etc/rc.local, something as:
1 #!/bin/sh -e 2 # 3 # rc.local 4 # 5 # This script is executed at the end of each multiuser runlevel. 6 # Make sure that the script will "exit 0" on success or any other 7 # value on error. 8 # 9 # In order to enable or disable this script just change the execution 10 # bits. 11 # 12 # By default this script does nothing. 13 14 ppc64_cpu --smt=off 15 16 exit 0
- If you kvm_HV module is not loaded automatically, enable KVM module in the kernel (Add a line "kvm_hv" in /etc/modules in order to automatically load it after a reboot).
- If you hit "failed to parse default acl file `/etc/qemu/bridge.conf", you need to edit (or create) file /etc/qemu/bridge.conf and add:
- If you hit "failed to create tun device: Operation not permitted", you need to set the setuid attribute:
# chmod u+s /usr/lib/qemu/qemu-bridge-helper
PCI hot plug of devices that require 64-bit DMA window
Problem: Guest PCI device, which require 64-bit DMA window, hot plug causes guest to throw kernel fault and gets rebooted.
Solution: In order to perform hot plugging of PCI devices that use 64-bit DMA window to a KVM guest, make sure that the guest is started with a XHCI USB device.
For example, XML clause to add to libvirt guest XML is as follows:
<controller type='usb' index='0' model='nec-xhci'> </controller>
If you are using the QEMU interface directly, please add below device option while booting the QEMU instance:
- -device nec-usb-xhci,id=u0
Enable 256 memory slots
In Ubuntu 17.04, when trying to increase the number of memory slots from 32 to 256, only 63 slots were available even though 256 slots was specified in the guest xml.
Machine Type = POWER8
Even though 256 slots are supported in QEMU 2.8, distributed with Ubuntu 17.04, there is an implicit limit coming from the vhost backend, limiting the number of max memory slots that are supported.
The work around is to increase the vhost mem slots by reloading the vhost module in the guest:
[root@localhost ~]# modprobe -r vhost [root@localhost ~]# modprobe vhost max_mem_regions=512 [root@localhost ~]# cat /sys/module/vhost/parameters/max_mem_regions 512
If you are using a old Ubuntu version on a POWER9 hardware guest, you might want to enable p8compat mode, where the guest machine will behave as a POWER8.
In order to do so, you can either configure the the libvirt XML or the qemu.
<cpu mode='host-model' check='partial'> <model fallback='forbid'>power8</model> <topology sockets='1' cores='16' threads='1'/> </cpu>
If you are starting the qemu manually, you can use -machine pseries, max-cpu-compat=power8
Limitation in migrating POWER8 guest from POWER8 host to POWER9 host
POWER8 host (Ubuntu 16.04.4) have older Qemu 2.5 (< Qemu 2.10) that boots the guest in raw mode, where as POWER9 host (Ubuntu 18.04) that have newer Qemu 2.11 which boots the guest in target (with -incoming) in architected mode during migration and cause it to fail with below error,
# virsh migrate <vm_name> qemu+ssh://<target_ip>/system --live --verbose Migration: [ 99 %] error: internal error: qemu unexpectedly closed the monitor: <Timestamp> qemu-system-ppc64: error while loading state for instance 0x0 of device 'cpu' qemu-system-ppc64: load of migration failed: Operation not permitted
To work around this limitation, POWER8 guest have to be booted with explicit compat settings configured in guest xml on a POWER8 host,
<domain> ... <cpu mode='host-model'> <model>power8</model> </cpu> ... </domain>
With this compat setting newer Qemu (since Qemu 2.10) boots the guest in target (with -incoming) using explicit compat mode on POWER9 host for the migration to succeed.
Ubuntu 18.04 and POWER9 CPU hot plug Limitation
Original Ubuntu 18.04 and POWER9 has a limitation on KVM Hot plug CPU which has been fixed by Launchpad https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1759723 starting on linux 4.15.0-24.26.
If for some reason you are using a linux version older than 4.15.0-24.26 and you cannot update to the latest version available in Ubuntu 18.04, it is not recommended to run the CPU with extra CPU to be hotplugged later. This should be fixed soon, but this is a near term limitation.
We basically lose the ability to hotplug/unplug CPUs into virtual machines. Considering that blk-mq enqueue tasks using 'for_each_present_cpu()' (that iterates over CPUs in systems that don't support CPU hotplug - refer to those patches for technical details) we can also have problems if tasks are scheduled to CPUs present but not online.
So I suggest to not run VMs with extra CPUs to be hotplugged later, like:
<vcpu placement='static' current='8'>16</vcpu>
If we want a guest with 16 CPUs it's better to define it beforehand, for instance:
Reference and additional material
For more information about KVM on Power, please check here.