Compiled qemu from this manual
Try to run this on Apple Silicon with qemu-system-aarch64, but got an error:
Error: internal error: Failed to start QEMU binary /usr/local/bin/qemu-system-aarch64 for probing: qemu-system-aarch64: invalid accelerator kvm Could not allocate dynamic translator buffer
This is the XML:
<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>ubuntu</name>
<uuid>2005CB24-522A-4485-9B9A-E60A61D9F8CF</uuid>
<memory unit='GB'>2</memory>
<cpu mode='custom'>
<model>Westmere</model>
</cpu>
<vcpu>2</vcpu>
<features>
<acpi/>
<apic/>
</features>
<os>
<type arch='aarch64' machine='cortex-a57'>hvf</type>
<bootmenu enable='yes'/>
</os>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/local/bin/qemu-system-aarch64</emulator>
<controller type='usb' model='ehci'/>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/Users/matthias/VM/Ubuntu_20.04-LTS/disk.qcow2'/>
<target dev='vda' bus='virtio'/>
</disk>
<!--disk type='file' device='cdrom'>
<source file='/Users/matthias/VM/Ubuntu_20.04-LTS/ubuntu-20.04.2-live-server-arm64.iso'/>
<target dev='sdb' bus='sata'/>
</disk-->
<console type='pty'>
<target type='serial'/>
</console>
<input type='tablet' bus='usb'/>
<input type='keyboard' bus='usb'/>
<graphics type='vnc' port='5900' listen='127.0.0.1'/>
<video>
<model type='virtio' vram='16384'/>
</video>
</devices>
<seclabel type='none'/>
<qemu:commandline>
<!--qemu:arg value='-machine'/>
<qemu:arg value='type=q35,accel=hvf'/>
<qemu:arg value='-netdev'/>
<qemu:arg value='user,id=n1,hostfwd=tcp::2222-:22'/>
<qemu:arg value='-device'/>
<qemu:arg value='virtio-net-pci,netdev=n1,bus=pcie.0,addr=0x19'/-->
<qemu:arg value='-accel hvf -m 2048 -cpu cortex-a57 -M virt,highmem=off'/>
<qemu:arg value='-drive file=/usr/local/share/qemu/edk2-aarch64-code.fd,if=pflash,format=raw,readonly=on'/>
<qemu:arg value='-drive file=ovmf_vars.fd,if=pflash,format=raw'/>
<qemu:arg value='-serial telnet::4444,server,nowait'/>
<qemu:arg value='-device virtio-blk-device,drive=hd0,serial="dummyserial"'/>
<qemu:arg value='-device virtio-net-device,netdev=net0'/>
<qemu:arg value='-netdev user,id=net0,hostfwd=tcp:127.0.0.1:2222-0.0.0.0:22'/>
<qemu:arg value='-vga none -device ramfb'/>
<qemu:arg value='-device usb-ehci -device usb-kbd -device usb-mouse -usb'/>
<qemu:arg value='-nographic -serial mon:stdio'/>
</qemu:commandline>
</domain>
Thx for any feedback!
QEMU appears to be trying use the KVM accelerator, which obviously does not work on a macos host, so QEMU reports "invalid accelerator kvm". It then tries to fall back to TCG (pure emulation), which also fails, because of a macos bug involving mprotect(), hence "Could not allocate dynamic translator buffer". (Latest upstream QEMU has a workaround for this in commit c118881ee607dcac, but you don't need that since you're only running into it because hvf is not actually being used.)
I think that this is happening because your XML syntax is incorrect and so QEMU is not seeing your attempt to tell it to use hvf. Specifically, each "qemu:arg" tag in the XML must specify one single command line argument word, so if you want to say "-accel hvf" you must write
and so on for all the other options and arguments you want to specify. (You can see that the q35 options you've commented out are all specified in this way, unlike the ones you've added for the virt machine: look at the difference between the -netdev handling there and what you have, for example.)
If you try to pass a longer string in the XML as you have done, then QEMU will see it as a single long commandline argument with embedded spaces, which it will then probably treat as a very odd disk image filename or complain about as invalid.