Problems in compiling Android with PKVM

Which system do you use? Android, Ubuntu, OOWOW or others?

Android

Which version of system do you use? Please provide the version of the system here:

khadas-edge2-android14

Please describe your issue below:

I tried to build the Android with PKVM support, but failed in vm creation.

Post a console log of your issue below:

I changed these configurations:

BOARD_AVB_ENABLE ?= true # device/khadas/common/BoardConfig.mk
BOARD_ROCKCHIP_PKVM ?= true # device/khadas/common/BoardConfig.mk
BOARD_KERNEL_CMDLINE += kvm-arm.mode=protected # device/khadas/common/modules/make_boot.mk

Enable Android properties:

kedge2:/ # setprop ro.boot.hypervisor.protected_vm.supported true
kedge2:/ # getprop ro.boot.hypervisor.protected_vm.supported
true
kedge2:/ # setprop ro.boot.hypervisor.vm.supported true
kedge2:/ # getprop ro.boot.hypervisor.vm.supported
true

Failed in creating a vm (`microdroid` is a simple os):

kedge2:/ # /apex/com.android.virt/bin/vm run-microdroid
found path /apex/com.android.virt/app/EmptyPayloadApp@UQ1A.240205.004.B1/EmptyPayloadApp.apk
creating work dir /data/local/tmp/microdroid/1X8wZrlqq1rogHFqD
apk.idsig path: /data/local/tmp/microdroid/1X8wZrlqq1rogHFqD/apk.idsig
instance.img path: /data/local/tmp/microdroid/1X8wZrlqq1rogHFqD/instance.img
Error: Failed to create VM

Caused by:
    Status(-8, EX_SERVICE_SPECIFIC): '-1: Too many attempts to create VM context failed.'

I locate this error in /packages/modules/Virtualization/virtualizationmanager/src/aidl.rs

Does anyone know how to solve this error?

I also enabled KVM in the kernel’s configuration. This ensures /dev/kvm is registered in the kernel:

$ cat .config | grep KVM
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_HAVE_KVM_MSI=y
CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT=y
CONFIG_KVM_VFIO=y
CONFIG_HAVE_KVM_ARCH_TLB_FLUSH_ALL=y
CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT=y
CONFIG_HAVE_KVM_IRQ_BYPASS=y
CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE=y
CONFIG_KVM_XFER_TO_GUEST_WORK=y
CONFIG_KVM=y
CONFIG_PKVM_MODULE_PATH=""
CONFIG_PTP_1588_CLOCK_KVM=y

Should I follow this post to enable PKVM in the bootloader?

@qianfei11

Hi, we haven’t tested this feature on Edge2 yet. We will check this feature and provide feedback.

@qianfei11,

Sorry, we have also confirmed with Rockchip. RK3588 does not support PKVM. It supports KVM, but requires a system with Android 15 or above to support it.