`-M none` breaks on ARM64 platforms with max IPA size < 40
Host environment
- Operating system: Fedora 38 ARM64
- OS/kernel version: Linux yell 6.3.8-400.asahi.fc38.aarch64 #1 SMP PREEMPT_DYNAMIC Tue Jun 20 23:45:34 UTC 2023 aarch64 GNU/Linux
- Architecture: ARM64
- QEMU flavor: qemu-system-aarch64
- QEMU version: qemu-7.2.1-2.fc38
- QEMU command line: qemu-system-aarch64 -M none,accel=kvm
Emulated/Virtualized environment
N/A
Description of problem
QEMU fails to initialize the KVM type properly when -M none
is used. On ARM64, the KVM type sets the IPA size. Without that setting, the kernel defaults to 40 bits. This fails on machines which cannot support that IPA size, such as Apple M1 machines.
This presumably happens because virt_machine_class_init()
in hw/arm/virt.c
never gets called in that case, which means it doesn't initialize mc->kvm_type
to the correct callback to do the IPA check.
Since the max IPA size is a property of the host CPU and must be queried properly for things to work at all, this logic should be invoked unconditionally for all machines, even none
.
This is breaking libvirt on Apple M1/M2 systems, since it uses -M none,accel=kvm
for its KVM test, and when it fails it considers KVM support unavailable. See: libvirt/libvirt#365
Steps to reproduce
On any ARM64 machine:
- strace -e ioctl qemu-system-aarch64 -M none,accel=kvm 2>&1 | grep -C1 CREATE_VM
- strace -e ioctl qemu-system-aarch64 -M virt,accel=kvm 2>&1 | grep -C1 CREATE_VM
Observe that the first command line does not issue a KVM_CAP_ARM_VM_IPA_SIZE
and does not set the machine type argument to KVM_CREATE_VM
, while the second one does. On machines with <40 bit max IPA, the first invocation would fail to initialize KVM.