shithub: wiki.9front.org

Download patch

ref: 5b6e1a5f2f44adeec0fff0395a6e20bfac9f254f
parent: 65ca8f63fb13225f88ef9ebe31ac32b5e5464b35
author: kws <kws@cirno>
date: Sun Aug 20 10:56:13 EDT 2023

qemu-arm64: add guide

--- /dev/null
+++ b/qemu-arm64.md
@@ -1,0 +1,49 @@
+QEMU arm64
+==========
+
+The existing arm64 kernels for the RPi and IMX.8 are unsuitable for use
+in hardware-accelerated VMs because they rely on specific CPU features (such as 64K page sizes and physical timers) which are not available on all hypervisors (such as Apple's Hypervisor.framework). Additionally, they do not support QEMU-emulated hardware such as the ECAM-based PCIe bus nor VirtIO drivers.
+
+Thankfully, there is a community kernel which provides all the modifications available to run fully hardware-accelerated VMs via KVM (Linux) or Hypervisor.framework (macOS) through QEMU.
+
+## Kernel Build and Installation Image
+
+Clone and build the kernel:
+
+	cd /sys/src/9/
+	git/clone git://shithub.us/kws/qemu
+	cd qemu
+	mk
+
+Then, on a host machine, download the MNT Reform image which is suitable as a base system (available in the Downloads section).
+
+## Install
+
+Create a plan9.ini which describes the QEMU configuration (this is required because the kernel does not parse device trees for memory and CPU topology), e.g. for 4 CPUs and 4GB of RAM:
+
+	console=0
+	*ncpu=4
+	*maxmem=0x140000000
+
+Create an installation disk:
+
+	qemu-img create -f qcow2 9front.qcow2 64G
+
+Perform an install e.g. for macOS Hypervisor.framework:
+
+	qemu-system-aarch64 -M virt-2.12,accel=hvf,gic-version=3 \
+		-cpu host -smp 4 -m 4G \
+		-device loader,file=9qemu,addr=0x40200000,force-raw=on,cpu-num=0 \
+		-device loader,file=plan9.ini,addr=0x40100000,force-raw=on \
+		-drive file=9front.reform.img,format=raw,if=none,id=reform \
+		-drive file=9front.qcow2,if=none,id=disk \
+		-device virtio-blk-pci-non-transitional,drive=reform \
+		-device virtio-blk-pci-non-transitional,drive=disk \
+		-serial stdio
+
+Explanation:
+
+* `virt-2.12` is required because newer virt versions place ECAM is high memory which is a headache
+* `gic-version=3` is required as the kernel assumes GICv3 but QEMU defaults to GICv2
+* The `-device loader` lines place the kernel and configuration in specific regions of memory so we can avoid the use of a bootloader altogether which results in instantaneous boot times
+* VirtIO devices require the `non-transistional` flag, otherwise they use the old version of the emulated device which has a broken configuration layout