Cannot run KVM on the VIM4

I am trying to run KVM on the VIM4 SBC. i’ve tried both the stock ubuntu server image provided on oowow and building my own custom ubuntu server with virtualization and kvm support by enabling them in menuconfig and saving it in fenix, but running kvm-ok on the resulting images always says /dev/kvm is not present and modprobe won’t let me load it. Is there any way to run KVM on these SBCs?

Edit:

I fixed it by adding the following lines to /build/linux/arch/arm64/configs/defconfig

CONFIG_VIRTUALIZATION=y
CONFIG_KVM=y
CONFIG_KVM_MMIO=y
CONFIG_KVM_ARM_HOST=y

Hi! What about experience with KVM?
Were you able to start virtual machines?
How about control through libvirt and Virt-Manager?
What OS did you run?
Have you tried running Windows 10/11?

I was trying to run Android Cuttlefish on CrosVM, so kind of a niche use case. KVM works with the kernel config I wrote above, however VGICv2 is broken for guests. To fix that I had to modify the amlogic dtb, I used this kernel patch to guide me through the process of getting the VGICv2 working in KVM, I can upstream on the Amlogic linux kernel repo if it would be useful. This would make KVM enabled Fenix builds to work out of the box, I just haven’t bothered yet. In the end I managed to get two virtualised android phones running, sadly no GPU acceleration so I have to use swiftshader for now.

The default configuration used for VIM4 is arch/arm64/configs/kvims_defconfig.

Could you please share the patch?

The default desktop image is GPU hardware accelerated, but for KVM I’m not sure whether need other extra configuration.

This is the patch to fix VGICv2 compatibility

diff --git a/arch/arm64/boot/dts/amlogic/mesont7.dtsi b/arch/arm64/boot/dts/amlogic/mesont7.dtsi
index 3a0241e86ba3..8ec9d06111e1 100644
--- a/arch/arm64/boot/dts/amlogic/mesont7.dtsi
+++ b/arch/arm64/boot/dts/amlogic/mesont7.dtsi
@@ -288,7 +288,9 @@
                #address-cells = <0>;
                interrupt-controller;
                reg = <0x0 0xfff01000 0 0x1000>,
-                     <0x0 0xfff02000 0 0x0100>;
+                     <0x0 0xfff02000 0 0x2000>,
+                     <0x0 0xfff04000 0 0x2000>,
+                     <0x0 0xfff06000 0 0x2000>;
                interrupts = <GIC_PPI 9 0xf04>;
        };

Any way to get GPU acceleration on a custom ubuntu server build? I can’t get virglrenderer to work. I’ll keep debugging it on my own once I have the time but tips are always appreciated. Thanks :slight_smile:

I’m not familiar with KVM, could you share the instructions/information you tested on your side?

The current issue with GPU acceleration is that I’m trying to use virglrenderer, which requires OpenGL. Running glxinfo errors out due to not having a display, I’m sure there’s a public solution for this tho, OpenCL works perfectly so I assume GPU drivers are present and just getting an X server up should fix it. To test if the KVM patch worked correctly checking dmesg is the way. In a KVM build without the updated dts grepping dmesg for KVM will result in

[    0.467520] kvm [1]: IPA Size Limit: 40 bits

After the DTS patch:

[    0.467520] kvm [1]: IPA Size Limit: 40 bits
[    0.467930] kvm [1]: vgic interrupt IRQ9
[    0.468116] kvm [1]: Hyp mode initialized successfully

I haven’t tried it with anything except CrosVM and a custom fork of it, but it should enable virtualization for anything that uses KVM, like qemu/libvirt. Some extra defconfigs might be required to get everything working but that’s easier to debug. Btw Fenix is amazing to debug things like these, thanks for making it all OSS and easy to use

Starting an Xvfb display before trying to use OpenGL fixed it, sorry for the bother but I’m just not used to working with gpu related things. For anyone else having the same problem run this:

Xvfb :5 -screen 0 800x600x24 &
export DISPLAY=:5
glxinfo

The GPU only supports OpenGL ES not support OpenGL.