Cloudmin passthrough CPU information to VM

your-cpu-does-not-support-avx-or-avx2
I have Rocket Chat in VM hosted in Cloudmin that relies on qemu. When I tried to update Rocket Chat to the latest version I got the following error:
Your cpu does not support avx or avx2 instructions, which is required to run mongo 5.x, shipped with the next version of this snap.

I logged in to the virtual machine and ran:

to get CPU details:

or to just get the list of flags:

So VM has “generic” CPU with some default set of CPU flags among which “avx” or “avx2” flag are absent.

The VM possesses much less flags than its parent. The question is, if the cpu flags are beneficial, why arent they enabled for virtual machines?

The answer is simple: compatibility. By default, KVM sets the cpu mode to custom with generic model— to ensure that a persistent guest sees the same hardware no matter what host the guest is booted on. For that, many flags would be removed because that model doesn’t support them. Sometimes, however, the flags are truly necessary.

CPU flags or CPU features are attributes of CPU, denoted which features it supports. The features can be simple as calculating floating point unit, hyperthreading technology, or ability to extend physical memory to 64-bit address…

Examples of notable CPU flags can be:

ht: Hyper-Threading — improves parallelism of computations
lm: Long mode — supports 64-bit architecture
vmx: Virtual Machine Extention — which must be enable for software virtualization services (KVM, VMWare, VirtualBox…) to work
fpu: Floating Point Unit — supports floating point operations
aes-ni (or simply aes): Advanced Encryption Standard new instructions — improves the speed of encryption / decryption operations using AES
pae: Physical Address Extension — ability to use more than 4G memory for 32bit CPU
avx: Advanced Vector Extensions — allows a (quite drastic) speed up in certain floating point operations.

In my hypervisor host I have AMD EPYC 7302P 16-Core Processor installed that supports avx and avx2 flags so the question I got is to how to let VM know about capabilities of real processor.

There is no menu in Cloudmin’s settings that allow you to change CPU mode for VMs so I had to dig deeper and find out how Cloudmin runs virtual machines.

Cloudmin leverages QEMU virtualization systems to run VMs and QEMU has options to configure CPU model for virtual machine:

QEMU Syntax for configuring CPU models in virtual machine

The examples below illustrate the approach to configuring the various CPU models / features in QEMU and libvirt.

QEMU command line
Host passthrough:

Host passthrough with feature customization:

Named CPU models:

Named CPU models with feature customization:

The full list of supported options:

And now I had to find where this options can be specified.

There are two ways to configure CPU models with QEMU / KVM:
1. Host passthrough

This passes the host CPU model features, model, stepping, exactly to the guest. Note
that KVM may filter out some host CPU model features if they cannot be supported with
virtualization. Live migration is unsafe when this mode is used as libvirt / QEMU
cannot guarantee a stable CPU is exposed to the guest across hosts. This is the
recommended CPU to use, provided live migration is not required.

2. Named model

QEMU comes with a number of predefined named CPU models, that typically refer to
specific generations of hardware released by Intel and AMD. These allow the guest VMs
to have a degree of isolation from the host CPU, allowing greater flexibility in live
migrating between hosts with differing hardware.

In Cloudmin management script that run virtual machines are located in /etc/init.d and named cloudmin-kvm

There Cloudmin uses qemu-kvm to run VMs:

I noticed, that qemu-kvm  has wider CPU options available:

And EPYC is what I needed.

Make a backup of this file in a safe place and open it in a text editor.

Next, find the needed virtual machine and add -cpu flag with a proper parameter.

In my case I used Named model of configuration as Host passthrough is available in KVM mode only:

after smp I added -cpu EPYC directive and saved the file.

Now go to Cloudmin menu, choose your VM, shutdown it, and after a while start it.

Log in to the VM and check CPU now:

And now VM has EPYC CPU on board with needed avx and avx2 flags:

qemu-pass-cpu-info-to-vm

And Rocket Chat’s update to the latest version ran without any issue.

Good luck!

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com