Closed rohityadavcloud closed 1 year ago
On further debugging, I found it wasn't able to start and use KVM:
From libvirtd logs:
2023-07-24 08:43:41.734+0000: 7121: debug : virCommandRunAsync:2607 : About to run LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /usr/bin/qemu-system-aarch64 -S -no-user-config -nodefaults -nographic -machine none,accel=kvm:tcg -qmp unix:/var/lib/libvirt/qemu/qmp-HIZ771/qmp.monitor,server=on,wait=off -pidfile /var/lib/libvirt/qemu/qmp-HIZ771/qmp.pid -daemonize
2023-07-24 08:43:41.735+0000: 7121: debug : virCommandRunAsync:2609 : Command result 0, with PID 16324
2023-07-24 08:43:41.753+0000: 7121: debug : virCommandRun:2453 : Result exit status 0, stdout: '' stderr: '2023-07-24 08:43:41.735+0000: 16324: debug : virExecCommon:462 : Setting child uid:gid to 64055:109 with caps 2
2023-07-24 08:43:41.735+0000: 16324: debug : virSetUIDGIDWithCaps:1122 : Added 'dac_override' to child capabilities' set
ioctl(KVM_CREATE_VM) failed: 22 Invalid argument
qemu-system-aarch64: failed to initialize kvm: Invalid argument
qemu-system-aarch64: falling back to tcg
I even upgraded to Ubuntu server 23.04 with qemu 8.x, still same issue. However, I found if I run qemu directly on shell it seems to be starting, with:
/usr/bin/qemu-system-aarch64 -accel kvm -M virt -cpu host -m 2G -smp 2 -bios /usr/share/AAVMF/AAVMF_CODE.fd -drive if=none,file=/export/primary/disk,id=hd0 -vnc :1 -monitor stdio
It appears much of this could be to do with libvirtd, and not necessarily the kernel.
Thanks for the research! I have just read the backlog in #asahi and saw that you got some good support there. Fwiw I use lxd VMs on 23.04 on my m2 air and those work just fine, so a bug in libvirt doesn't seem unlikely.
It might be a combination of some parameters or something libvirtd/qemu isn't able to check properly. Yes, I asked a few questions and the asahi community is really helpful (logs https://oftc.irclog.whitequark.org/asahi/2023-07-24). I was able to strace the libvirtd parameter, and it appears libvirtd on M1 mac mini fails to get KVM to use as accelerator; the same libvirtd behaves differently on a Raspberry Pi4. I scp'd the qemu-system-aarch64 binaries from RPi4 but still same issue. I tried the qemu args option in the domain xml, but libvirt seems to be ignoring those. I'll revisit this again in future. (would like to keep the ticket open for couple of days more if I'm near a solution I'll share and close it).
Using qemu (tcg) works, but KVM acceleration would be preferable.
I did some digging on the upstream bug tracker and https://gitlab.com/libvirt/libvirt/-/issues/365 sounds like a similar issue.
Ha I found the same just few mins ago, came here to close it. You're right @tobhe it's an upstream/libvirtd issue. Closing on the linked issue - https://gitlab.com/libvirt/libvirt/-/issues/365
So it turns out this was actually a qemu bug caused by kvm using -M none
. It was fixed in https://lists.nongnu.org/archive/html/qemu-devel/2023-07/msg05127.html. I will see if we can backport the fix into the Ubuntu package.
Ah great- thanks @tobhe that would be awesome! It was Hector Martin who did further investigation and filed the issue https://gitlab.com/libvirt/libvirt/-/issues/365#note_1501797497 but glad to see it's been already fixed.
Thought to update/share that CloudStack + libvirt + KVM is working fine with latest Ubuntu Asahi on Mac mini M2 pro:
https://twitter.com/RohitYadavCloud/status/1747993477147664410
I'm trying to see if my M1 Mac Mini with Ubuntu Asahi (Ubuntu 22.04 server) can run VMs with KVM. Defining the domain [1] with kvm domain type is throwing error:
This however, works, if I change the domain type to 'qemu' and change the CPU mode to a host model such as cortex-a57 etc. but the VM is slow as qemu emulates the CPU and KVM can't be used.
I upgraded the linux kernel from 5.19 to 6.3 (ubuntu-asahi pkg) but still the same issue. I repeated the same on a Raspberry Pi 4 (4GB model) arm64 host with Ubuntu 22.04 but Linux kernel 5.15.0-1033-raspi and this is working as expected (I tried both terminal and creating/checking with cockpit-machines). Any hints, pointers, tips cc @tobhe ? Thanks.
Additional detail about the system:
[1] Domain vm.xml example: