Chapter 23 · Part X
macOS guests, the high road: Virtualization.framework
Course progress: chapter 23 is 24 of the 26 chapters written so far (numbering starts at 00)
Warm-up: three questions from earlier chapters
Answer each one in your head or on paper before you open its answer. They change on each visit.
From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
The eight bytes at offset
0x10of an Image header are00 00 2a 02 00 00 00 00, andtext_offsetis 0. Where does the kernel's memory start and end in our plan?Show answer
The field is
image_size, little-endian:0x022a0000. The kernel starts at the 2 MiB-aligned base0x4020_0000plustext_offset0, so it owns0x4020_0000..0x424a_0000(start plusimage_size, end exclusive).From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
That kernel ends at
0x424a_0000. Where does our plan put a 9 MB initramfs, and which part of that choice comes from the boot protocol and which from us?Show answer
At
0x4260_0000, the end rounded up to the next 2 MiB boundary. The protocol only requires that it lie outside the kernel'simage_sizespan and, with the kernel, inside one 1 GiB-aligned window of at most 32 GiB; the 2 MiB rounding is our choice, to keep the numbers readable.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
A
--kernelfile begins with the bytes4d 5aand haszimgat offset 4. What is it, what does our VMM do with it, and what do you run instead?Show answer
An EFI zboot wrapper: a compressed kernel packaged as a UEFI program (the
MZis the PE/COFF signature). The VMM refuses it with "EFI zboot image" and exit code 2 before creating a VM;cargo xtask unzboot(run byscripts/fetch.sh linux) unwraps it on the host into the raw Image.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
An Image's
flagsfield is6. Does our loader accept it?Show answer
No. Bit 0 is 0 (little-endian, fine), but bits 1 and 2 read
0b11= 3, "64 KiB pages", which Apple Silicon does not implement. The loader refuses it with a named error rather than let the kernel die in early boot with no output.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
A header claims
image_size = 0xFFFF_FFFF_FFFF_FFFF. Why doesload + image_size <= ram_endnot catch it, and what does?Show answer
With wrapping arithmetic the sum overflows to a small number (here
0x401F_FFFF), which passes the comparison; in a Rust debug build+panics instead.load.checked_add(image_size)returnsNoneon overflow, and the range check (RamRange::contains) treats that as "outside RAM", so the plan fails with exit code 2.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
An ELF program header of type
PT_LOADsaysp_filesz = 0x100andp_memsz = 0x80. What does the loader do?Show answer
Refuse the file. A segment cannot hold more file bytes than memory:
p_filesz <= p_memszmust hold, and the difference is the zero-filled tail (the BSS). Copyingp_fileszbytes into ap_memszslot would write past the segment.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
List the register values our vCPU starts a Linux kernel with, and the one system-register setting that goes with them.
Show answer
PC = the kernel's first byte (
0x4020_0000),x0= the device tree's address (0x4000_0000),x1,x2andx3= 0,CPSR=0x3c5(EL1h with D, A, I and F masked). The MMU is off:SCTLR_EL1.M(and the cache-enable bits C and I) cleared.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
macvmm run --dry-run ...printed a full boot plan and exited 0 from a binary that lacks the hypervisor entitlement. What does that prove, and why is it worth designing for?Show answer
That planning makes no Hypervisor.framework call: without the entitlement,
hv_vm_createwould have failed withHV_DENIED. Keeping placement a pure computation means every overlap and bound can be printed, unit-tested and property-tested on any machine, and is checked before a VM exists.From chapter 10: The Device Tree: the VMM's promise to the guest
A node's parent says
#address-cells = <2>and#size-cells = <1>. The node'sregdescribes two ranges. How many bytes long is theregproperty?Show answer
Each range is 2 + 1 = 3 cells, and a cell is 4 bytes, so one range is 12 bytes and two ranges are 24. The counts come from the parent, not from the node itself.
From chapter 10: The Device Tree: the VMM's promise to the guest
The first eight bytes of a blob are
d0 0d fe ed 00 00 04 f7. What is it, and how big is it?Show answer
A flattened device tree:
0xd00dfeedis its magic number. The next big-endian 32-bit word istotalsize,0x4f7= 1271 bytes. Read little-endian, the same bytes would give0xf7040000, which is why the byte order matters.From chapter 10: The Device Tree: the VMM's promise to the guest
Why can an arm64 kernel not find the PL011 by reading every address in the first 4 GiB and looking for a UART?
Show answer
Nothing on that bus answers "who is here?", and an address with no device behind it does not return a polite "nothing" either: on real hardware it can fault or hang, and in our VMM it is an unhandled access that stops the guest (exit code 3 by default). Even the PrimeCell ID registers help only once you know where the device is. So somebody has to tell the kernel: the DTB.
From chapter 10: The Device Tree: the VMM's promise to the guest
Two nodes each have a
compatibleproperty. How many times does the wordcompatibleappear in the blob, and where?Show answer
Once, in the strings block: property names are stored there once and referred to by offset (
nameoff). The values ("arm,pl011","arm,pl031") are not names; they sit in the structure block after eachFDT_PROPtoken.From chapter 10: The Device Tree: the VMM's promise to the guest
Your writer opens
/cpus, openscpu@0, closes it, and then adds#size-cellsto/cpus. What should happen, and why?Show answer
An error. The format requires every property of a node to come before its first child node, because a reader walks the token stream once and attaches each property to the node it is in. The reference writer refuses it as
PropAfterChildinstead of writing a tree a kernel would misread.From chapter 10: The Device Tree: the VMM's promise to the guest
A guest's first instruction runs with
x0 = 0x40000000. What does an arm64 kernel expect to find there, and what two rules does the address obey?Show answer
The device tree blob: Linux's boot protocol says
x0holds its physical address. It must be 8-byte aligned and the blob at most 2 MiB long, in RAM. Our VMM puts it at the start of RAM.From chapter 10: The Device Tree: the VMM's promise to the guest
You add a node
pl031@9050000to the DTB but no device to the bus. Linux boots. With the default unhandled-access policy, what doesmacvmmprint, and why at that address?Show answer
unhandled MMIO read at 0x9050fe0, then exit code 3. The AMBA bus code reads a PrimeCell's ID registers, at offsets0xFE0to0xFFC, before it picks a driver, so the first access to the phantom device is the ID read. With--unhandled-mmio logthe reads return zero and the device is left unbound ("deferred probe pending").From chapter 10: The Device Tree: the VMM's promise to the guest
A node says
compatible = "arm,pl011", "arm,primecell". Why two strings, and in which order are they tried?Show answer
Most specific first. A kernel looks for a driver that knows
arm,pl011; the second string says what family the device belongs to (an Arm PrimeCell, with ID registers), which a more general driver or bus can use.From chapter 10: The Device Tree: the VMM's promise to the guest
/cpussays#address-cells = <1>and#size-cells = <0>. How long iscpu@0'sreg, and what does it hold?Show answer
4 bytes: one address cell and no size. It holds the CPU's identity (its MPIDR affinity, here 0), which is why the node is called
cpu@0.From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
Your doctor prints
hv_vm_create: HV_BUSY (0xfae94002). What is the most likely cause in your own code?Show answer
A VM already exists in this process: Hypervisor.framework allows one per process. Usually an earlier
Vmis still alive, or was dropped withoutDropcallinghv_vm_destroy.From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
hv_vm_createreturns0xfae94009, a code yourHvErrordoes not list. What shouldHvError::from_codereturn, and why not a generic "unknown error"?Show answer
HvError::Unknown(0xfae94009). The exact value is the evidence a bug report needs, and a newer macOS may add codes;Displaystill prints it in full.From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
A freshly built
macvmm, run without the signing runner, getsHV_DENIED (0xfae94007). Is that a link problem? What fixes it?Show answer
No: the program linked and started; the kernel refused at the call because the signature has no
com.apple.security.hypervisor. Run it throughcargo run(the runner signs a copy first) or sign it withscripts/sign.sh.From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
A guest stores a byte to
0x0900_0000, where nothing is mapped. Which layer decides that this access leaves the guest, and which decides what it means?Show answer
The macOS kernel's EL2 part decides it stops the guest and forwards it (a VM exit); our VMM, an ordinary EL0 process, decides what it means, by playing the device at that address.
From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
Inside an
unsafeblock you index a slice out of bounds. What happens, and what does that tell you aboutunsafe?Show answer
It still panics: bounds checks on safe indexing stay on, as do type and borrow checks.
unsafeonly allows a few extra operations (such as calling an FFI function); the invariants those operations need become yours.From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
The header declares
hv_return_t hv_vm_get_max_vcpu_count(uint32_t *max_vcpu_count);. What is the Rust parameter type, and who owns the memory it points to?Show answer
*mut u32. It is an out-pointer: the caller owns a live, writableu32(for example a local variable) and passes its address; the function writes the answer there and returns only an error code.From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
Why does
hv_vm_destroytake no argument at all?Show answer
There is no handle to pass: the VM belongs to the whole process, and there can be only one, so "destroy the VM" is unambiguous.
From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
At which exception level does
macvmmitself run, and at which does the guest kernel run?Show answer
macvmmruns at EL0, like any app. The guest kernel runs natively at EL1. The level above both, EL2, belongs to part of the macOS kernel.From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI
A guest reads the clock counter with
mrs x0, CNTVCT_EL0a million times. How many of those reads reach our VMM?Show answer
None: the hardware virtualizes the counter, so the read completes inside the guest without any exit.
Concepts you'll need
Chapters before this one: chapter 14, Booting Linux to a shell.
- Core, taught here: Virtualization.framework (VZ) as a machine Apple defines and you configure;
VZLinuxBootLoader; where a VZ guest runs (an XPC service with private entitlements); the two entitlements compared; for macOS guests, restore images, the Mac platform identity,VZMacOSBootLoaderand Apple-specific devices; the inventory of what a low-level VMM must provide. - Core, from earlier: a guest as a host process, and paravirtual devices (chapter 00); VZ's place in the macOS stack and the hypervisor entitlement (chapter 01); exception levels (chapter 02); the memory map (chapter 05); memory-mapped I/O, MMIO (chapter 07); the PL011,
ttyAMA0and the output filter (chapter 09); the device tree (chapter 10); the Generic Interrupt Controller, GIC (chapter 12); the loader and test initramfs (chapter 13); booting Linux to a shell (chapter 14). - Primers (read first):
codesign-entitlements, including its optional sections on restricted entitlements and the hardened runtime. - Primers (review):
tty-termios(escape sequences, and its section on why bytes from a guest are dangerous);linux-boot-sequence(kernel modules);uefi(only the name, for one table row). - Pointers: Apple's Virtualization documentation and software development kit (SDK) headers; Apple's licence for macOS virtual machines (cited, not interpreted); Swift; PCI Express; XPC services.
- Forward definitions: virtio and its virtio-mmio transport (chapter 15), and virtio-console with its Linux name
hvc0, and virtio-rng (chapter 17); virtio-blk, virtio's disk (chapter 18); AVPBooter, Apple's boot ROM for virtual Macs, and ParavirtualizedGraphics (chapter 24). Each is defined where it first appears.
In chapter 14 your virtual machine monitor (VMM) booted Alpine's kernel with the command line console=ttyAMA0 earlycon=pl011,0x09000000 macvmm.test=boot, and the test initramfs printed macvmm-initramfs: ready. Now give the same kernel file, the same initramfs file and that command line minus its earlycon= word to a different VMM: the one Apple ships inside macOS, Virtualization.framework. The earlycon= word goes because it names an address on our machine, the PL011 at 0x0900_0000, which means nothing on a machine whose map you have not seen. Same Mac, same CPU, the same files. What appears on your terminal?
Predict The kernel and the initramfs are byte for byte what your VMM booted in chapter 14, and the command line is console=ttyAMA0 macvmm.test=boot, chapter 14's without the early console. Under Virtualization.framework, will you see (a) the same boot log ending in macvmm-initramfs: ready, (b) a kernel panic, or (c) something else? If you think the command line needs a change, which change, and why?
Write your answer under ## Predict in your journal now, before you read on. The section "Same kernel, another machine" runs it.
Every row of the problem ledger is closed (this chapter needs only chapter 14's), so this chapter sits beyond it. It makes explicit what the ledger left implicit: a machine is its whole contract of devices and firmware, and a kernel that boots on one meets a different contract on the next. Plan about 3 hours at your Mac. There is no Rust to write: you read and run a small tool, and write two short documents.
Objectives: by the end you can
- Explain, with an example from your own runs, what Virtualization.framework (VZ) supplies that Hypervisor.framework (HVF) does not: a complete machine with Apple's memory map, devices and boot loader, and, for macOS guests, restore images, the Mac platform identity,
VZMacOSBootLoaderand paravirtual graphics. - Build and run the provided Swift tool
tools/vz-mac/, signed with exactlycom.apple.security.virtualization; boot our Linux test initramfs under VZ, and predict, then explain from the output, which console it prints on. - Compare the two programs' entitlements with
codesign, find withpswhich process runs a VZ guest, and state whose code a hostile guest attacks in each case. - Inventory what a low-level VMM must provide to boot macOS, marking each piece documented or undocumented; chapter 24 starts from it.
Before you start. From the repository root, run scripts/learner start 23 to copy this chapter's journal to learner/journal/23.md. You also need Xcode, for the swift command (swift --version should print a version), and the kernel and initramfs from chapter 13 in .cache/macvmm/. If swift complains about the Xcode licence, open Xcode once and accept it there; no sudo is needed.
Configured, not built
Chapter 01 placed two Apple frameworks side by side. With HVF you build the machine, as every Part so far did. With VZ you describe the machine, and Apple builds and runs it: a boot loader, a platform, a CPU count, a memory size and a list of devices.
The tool in this chapter, vz-mac, is a small Swift program, because VZ has no C interface to call from Rust; you read and run it, not write it.
Aside
Swift is Apple's language for its own frameworks; VZ is an Objective-C and Swift interface. If a line puzzles you, see The Swift Programming Language: let is Rust's let, var is let mut, and throws marks a function that can fail, like a Result. Apple's reference for every class below is the Virtualization documentation.
Here is the whole machine definition for a Linux guest, from tools/vz-mac/Sources/vz-mac/LinuxBoot.swift:
/// The whole machine definition for a Linux guest under VZ. Everything else (memory map,/// interrupt controller, device tree, boot protocol, device models) is Apple's.func makeLinuxConfiguration(_ r: LinuxRequest, console: VZSerialPortAttachment) -> VZVirtualMachineConfiguration{ let bootLoader = VZLinuxBootLoader(kernelURL: URL(fileURLWithPath: r.kernel)) bootLoader.initialRamdiskURL = URL(fileURLWithPath: r.initrd) bootLoader.commandLine = r.cmdline // One virtio-console port: the guest's `hvc0`. let serial = VZVirtioConsoleDeviceSerialPortConfiguration() serial.attachment = console let config = VZVirtualMachineConfiguration() config.platform = VZGenericPlatformConfiguration() config.bootLoader = bootLoader config.cpuCount = r.cpus config.memorySize = r.memory config.serialPorts = [serial] config.entropyDevices = [VZVirtioEntropyDeviceConfiguration()] // virtio-rng, as in chapter 17 return config}VZLinuxBootLoader takes a kernel, an initramfs and a command line: chapter 13's loader and boot plan, and chapter 10's device tree, in three lines, because VZ writes its own device tree and places everything itself. VZGenericPlatformConfiguration is Apple's generic 64-bit Arm machine, with its memory map, interrupt controller and timer. The serialPorts line gives one serial port, a VZVirtioConsoleDeviceSerialPortConfiguration; there is no PL011 class to choose instead, and the next section's run shows what that means. The entropyDevices line adds a random-number source.
| Your VMM, and the chapter that built it | The line in VZ's configuration |
|---|---|
| guest RAM and the region table (04, 05) | config.memorySize |
| virtual CPUs (vCPUs), the exit loop, power calls (06 to 08) | config.cpuCount |
| the PL011 (09) | config.serialPorts: a serial port of another kind (next section) |
| the device tree (10) | generated inside VZ, never shown to you |
| the GIC and the timer (11, 12) | inside VZGenericPlatformConfiguration |
| the loader and the boot plan (13) | VZLinuxBootLoader |
Every job on the left still exists under VZ. Apple's code does it, and you cannot read it.
Building and signing the tool
tools/vz-mac/run.sh does for vz-mac what the signing runner does for macvmm: it runs swift build, copies the binary to target/vz-mac/signed/vz-mac, signs the copy ad hoc with tools/vz-mac/vz-mac.entitlements, reads the signature back, and only then runs it. It also signs with the hardened runtime (codesign -o runtime), which among other things makes macOS ignore the DYLD_* environment variables that could inject code into the process.
Build and sign without running anything, sign macvmm in place, then compare the two signatures:
tools/vz-mac/run.sh --print-pathscripts/sign.sh target/debug/macvmmcodesign -d --entitlements - target/vz-mac/signed/vz-maccodesign -d --entitlements - target/debug/macvmmThe first run.sh compiles vz-mac (a minute or so; build lines go to standard error), then, with --print-path, prints where the signed copy is, target/vz-mac/signed/vz-mac under your repository, and runs nothing. The second line matters because cargo run signs a private copy under target/run-bin/, so target/debug/macvmm carries only the linker's signature until you sign it in place.
codesign -d --entitlements - target/vz-mac/signed/vz-mac[Dict] [Key] com.apple.security.virtualization [Value] [Bool] trueExecutable=<repo>/target/vz-mac/signed/vz-maccodesign -d --entitlements - target/debug/macvmm[Dict] [Key] com.apple.security.hypervisor [Value] [Bool] trueExecutable=<repo>/target/debug/macvmmTwo programs, one self-granted entitlement each. com.apple.security.hypervisor lets macvmm create a virtual machine (VM) and run vCPUs itself; com.apple.security.virtualization lets vz-mac ask VZ for a whole machine. In separate programs, a bug in one cannot borrow the other's right.
Same kernel, another machine
Time for your Predict. Run chapter 14's command line, minus the earlycon= word:
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=ttyAMA0 macvmm.test=boot"tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=ttyAMA0 macvmm.test=boot"Building for production...[1 / 1]Build complete! (0.33 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)We checked this on a real Mac: (c). Not one byte on standard output, yet VZ guest state: stopped (guest) and exit 0: the guest powered itself off, and the only code in this initramfs that does so is /init, after it prints macvmm-initramfs: ready. So the kernel booted, /init ran and printed, and nobody heard.
ttyAMA0 is the name Linux gives a PL011, and this machine has no PL011. Its one serial port, the VZVirtioConsoleDeviceSerialPortConfiguration from the configuration, is a virtio-console. Virtio is the standard family of devices designed for virtual machines, which share memory with the VMM instead of trapping on every register (chapter 15 builds its transport), and virtio-console is its serial port; Linux calls the first one hvc0 (chapter 17 adds one to your VMM). The random-number source was virtio-rng, virtio's random-number device (also chapter 17).
When the command line names a console, Linux enables only a console of that name. The virtio-console registered but was never switched on, so /init's bytes went nowhere. Now name the console this machine has:
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=boot"[ 0.044643] hv_vmbus: registering driver hyperv_keyboard[ 0.044843] rtc-pl031 20050000.pl031: registered as rtc0[ 0.044888] rtc-pl031 20050000.pl031: setting system clock to 2026-11-20T09:12:00 UTC (1795165920)[ 0.045042] NET: Registered PF_INET6 protocol family[ 0.046628] Segment Routing with IPv6[ 0.046678] In-situ OAM (IOAM) with IPv6[ 0.050367] registered taskstats version 1[ 0.050510] Loading compiled-in X.509 certificates[ 0.088238] Freeing initrd memory: 9204K[ 0.091070] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: 87fa969a47f3e2a6aa35859eb932a17c95abcd82'[ 0.091832] Demotion targets for Node 0: null[ 0.091959] Key type .fscrypt registered[ 0.091990] Key type fscrypt-provisioning registered[ 0.093376] clk: Disabling unused clocks[ 0.093410] PM: genpd: Disabling unused power domains[ 0.093840] Freeing unused kernel memory: 2048K[ 0.093895] Run /init as init processmacvmm-initramfs: ready 6.18.60-0-virtBuilding for production...Build complete! (0.15 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)The marker line: the same files boot to the end, so the first run did not panic either. Two lines deserve a second look:
rtc-pl031 20050000.pl031. Chapter 14's run saidrtc-pl031 9010000.pl031: the same real-time clock (RTC) design, at another address. Same kernel, different machine.- The first line: 44 milliseconds in, not
0.000000. Chapter 14 had an early boot console,earlycon, printing from the kernel's first line; this machine has none.
So when did hvc0 start printing? Ask the guest, in the test initramfs's shell case, which stops at a / # prompt:
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=shell"At the prompt, type dmesg | grep -i -e console -e virtio, then poweroff -f:
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=shell"[ 0.068223] hv_vmbus: registering driver hyperv_keyboard[ 0.069149] rtc-pl031 20050000.pl031: registered as rtc0[ 0.069204] rtc-pl031 20050000.pl031: setting system clock to 2026-11-20T10:15:33 UTC (1795169733)[ 0.069551] NET: Registered PF_INET6 protocol family[ 0.070095] Segment Routing with IPv6[ 0.070276] In-situ OAM (IOAM) with IPv6[ 0.074155] registered taskstats version 1[ 0.075462] Loading compiled-in X.509 certificates[ 0.127501] Freeing initrd memory: 9204K[ 0.131197] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: 87fa969a47f3e2a6aa35859eb932a17c95abcd82'[ 0.134628] Demotion targets for Node 0: null[ 0.135149] Key type .fscrypt registered[ 0.135360] Key type fscrypt-provisioning registered[ 0.137531] clk: Disabling unused clocks[ 0.137739] PM: genpd: Disabling unused power domains[ 0.138056] Freeing unused kernel memory: 2048K[ 0.138446] Run /init as init processmacvmm-initramfs: ready 6.18.60-0-virt/ # ^[[6ndmesg | grep -i -e console -e virtio[ 0.000000] Kernel command line: console=hvc0 macvmm.test=shell[ 0.003404] Console: colour dummy device 80x25[ 0.058483] virtio-pci 0000:00:05.0: enabling device (0000 -> 0002)[ 0.061198] virtio-pci 0000:00:06.0: enabling device (0000 -> 0002)[ 0.067685] printk: legacy console [hvc0] enabled/ # poweroff -fBuilding for production...Build complete! (0.20 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)(Times vary a little from run to run.) The kernel enabled hvc0 only after finding the virtio devices. The earlier lines are still in the log buffer, since dmesg reads them back, but hvc0 did not replay them. ttyAMA0 did: in the macvmm shell run in the next section, with no early console, printk: console [ttyAMA0] enabled comes about 4 milliseconds in, yet the log on your terminal starts at 0.000000. We have not checked why hvc0 skipped it.
The misconception this retires is "the same PL011". The kernel is identical; the machine is not, and the command line is part of their contract.
From the repository root, this chapter's cargo run lines run the reference VMM. To use yours, run them inside learner/ with ../.cache/macvmm/. Two options, --console and --serial none, arrive in chapter 17; if you came straight from chapter 14, use the reference.
Try it
Run the mirror image on a VMM of ours: macvmm with console=hvc0 and no --console option (the option that adds a virtio-console), so it has no virtio-console. Predict before you look.
cargo run -q -p macvmm -- run --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --mem 512M --cmdline "console=hvc0 macvmm.test=boot" --timeout 30Silence again, exit 0, for the same reason in reverse. Now add a virtio-console on standard output with --console stdio. Only one of --serial (where the PL011's output goes, chapter 09) and --console may own standard output, and --serial takes it by default, so send the PL011 nowhere with --serial none:
cargo run -q -p macvmm -- run --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --mem 512M --serial none --console stdio --cmdline "console=hvc0 macvmm.test=boot" --timeout 30Still silent, and this time the device is there. In Alpine's kernel the virtio-mmio transport, the code that finds virtio devices at fixed addresses as our VMM places them (chapter 15), is a loadable module (scripts/initramfs/init notes this; the linux-boot-sequence primer explains modules). The boot case never loads it, so no driver finds the console. Under VZ the console sits on a different bus, PCI Express (next section), whose driver is built in.
One more variant, for the spec hunt at the end: a VZ boot whose command line names no console at all.
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "macvmm.test=boot"Building for production...[1 / 3]Build complete! (3.43 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)Silent again, exit 0. The spec hunt asks which console Linux picks when you name none.
Looking inside Apple's machine
VZ never shows its device tree, but the guest can describe what it found. Boot the shell case again under VZ, and then under a VMM of ours:
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=shell"cargo run -q -p macvmm -- run --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --mem 512M --cmdline "console=ttyAMA0 macvmm.test=shell" --timeout 300At each / # prompt, type the same lines. The for loop prints every Peripheral Component Interconnect (PCI) device the kernel found, with its vendor and device IDs:
cat /proc/consolesdmesg | head -n 3cat /proc/iomemfor d in /sys/bus/pci/devices/*; do echo $d $(cat $d/vendor $d/device); donepoweroff -fLeave with poweroff -f. Ctrl-C also works under vz-mac, which then exits 130; under macvmm, Ctrl-C goes to the guest, and Ctrl-A then x quits (chapter 09). The captures piped these lines in; if macvmm stops with exit 5 while you type, its --timeout ran out, so raise it. First VZ:
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=shell"[ 0.049452] hv_vmbus: registering driver hyperv_keyboard[ 0.049612] rtc-pl031 20050000.pl031: registered as rtc0[ 0.049646] rtc-pl031 20050000.pl031: setting system clock to 2026-11-20T09:12:36 UTC (1795165956)[ 0.049813] NET: Registered PF_INET6 protocol family[ 0.051186] Segment Routing with IPv6[ 0.051217] In-situ OAM (IOAM) with IPv6[ 0.053410] registered taskstats version 1[ 0.053486] Loading compiled-in X.509 certificates[ 0.094109] Freeing initrd memory: 9204K[ 0.097203] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: 87fa969a47f3e2a6aa35859eb932a17c95abcd82'[ 0.097987] Demotion targets for Node 0: null[ 0.098251] Key type .fscrypt registered[ 0.098284] Key type fscrypt-provisioning registered[ 0.099973] clk: Disabling unused clocks[ 0.100005] PM: genpd: Disabling unused power domains[ 0.100201] Freeing unused kernel memory: 2048K[ 0.100266] Run /init as init processmacvmm-initramfs: ready 6.18.60-0-virt/ # ^[[6ncat /proc/consoleshvc0 -W- (EC p ) 229:0/ # dmesg | head -n 3[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x610f0000][ 0.000000] Linux version 6.18.60-0-virt (buildozer@build-3-24-aarch64) (cc (Alpine 15.2.0) 15.2.0, GNU ld (GNU Binutils) 2.45.1) #1-Alpine SMP PREEMPT_DYNAMIC 2026-11-01 07:26:31[ 0.000000] efi: UEFI not found./ # cat /proc/iomem10000000-1000ffff : GICD10010000-1004ffff : GICR20050000-20050fff : pl031 20050000-20050fff : rtc-pl03120060000-20060fff : pl06140000000-4fffffff : PCI ECAM50000000-6ffdffff : pci 50000000-5000007f : 0000:00:05.0 50000080-500000bf : 0000:00:06.070000000-8fffffff : System RAM 70000000-7157ffff : Kernel code 71580000-7177ffff : reserved 71780000-7229ffff : Kernel data 722a0000-72b9dfff : reserved 72c00000-72c00fff : reserved 8f2f7000-8fbfffff : reserved 8fc27000-8fc27fff : reserved 8fc28000-8fca7fff : reserved 8fca8000-8fcf0fff : reserved 8fcf1000-8fd03fff : reserved 8fd04000-8fd06fff : reserved 8fd07000-8fffffff : reserved100000000-4ffffffff : pci 100000000-10000ffff : 0000:00:05.0 100000000-10000ffff : virtio-pci-modern 100010000-100017fff : 0000:00:06.0 100010000-100017fff : virtio-pci-modern/ # for d in /sys/bus/pci/devices/*; do echo $d $(cat $d/vendor $d/device); done/sys/bus/pci/devices/0000:00:00.0 0x106b 0x1a05/sys/bus/pci/devices/0000:00:05.0 0x1af4 0x1043/sys/bus/pci/devices/0000:00:06.0 0x1af4 0x1044/ # poweroff -fBuilding for production...Build complete! (0.17 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)Then your VMM:
cargo run -q -p macvmm -- run --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --mem 512M --cmdline "console=ttyAMA0 macvmm.test=shell" --timeout 300[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x610f0000][ 0.000000] Linux version 6.18.60-0-virt (buildozer@build-3-24-aarch64) (cc (Alpine 15.2.0) 15.2.0, GNU ld (GNU Binutils) 2.45.1) #1-Alpine SMP PREEMPT_DYNAMIC 2026-11-01 07:26:31[ 0.000000] random: crng init done[ 0.000000] Machine model: macvmm-virt[ 0.000000] efi: UEFI not found.[ 0.000000] OF: reserved mem: Reserved memory: No reserved-memory node in the DT[ 0.000000] NUMA: Faking a node at [mem 0x0000000040000000-0x000000005fffffff][ 0.000000] NODE_DATA(0) allocated [mem 0x5fd03780-0x5fd05c3f][ 0.000000] Zone ranges:[ 0.000000] DMA [mem 0x0000000040000000-0x000000005fffffff][ 0.000000] DMA32 empty[ 0.000000] Normal empty[ 0.000000] Movable zone start for each node[ 0.000000] Early memory node ranges[ 0.000000] node 0: [mem 0x0000000040000000-0x000000005fffffff][ 0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x000000005fffffff][ 0.000000] psci: probing for conduit method from DT.[ 0.000000] psci: PSCIv1.1 detected in firmware.[ 0.000000] psci: Using standard PSCI v0.2 function IDs[ 0.000000] psci: Trusted OS migration not required[ 0.000000] psci: SMC Calling Convention v1.1[ 0.000000] percpu: Embedded 34 pages/cpu s99608 r8192 d31464 u139264[ 0.000000] Detected PIPT I-cache on CPU0[ 0.000000] CPU features: detected: Address authentication (IMP DEF algorithm)[ 0.000000] CPU features: detected: GICv3 CPU interface[ 0.000000] CPU features: detected: Spectre-v4[ 0.000000] CPU features: detected: Spectre-BHB[ 0.000000] alternatives: applying boot alternatives[ 0.000000] Kernel command line: console=ttyAMA0 macvmm.test=shell[ 0.000000] printk: log buffer data + meta data: 131072 + 458752 = 589824 bytes[ 0.000000] Dentry cache hash table entries: 65536 (order: 7, 524288 bytes, linear)[ 0.000000] Inode-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)[ 0.000000] software IO TLB: SWIOTLB bounce buffer size adjusted to 0MB[ 0.000000] software IO TLB: area num 1.[ 0.000000] software IO TLB: mapped [mem 0x000000005f380000-0x000000005f400000] (0MB)[ 0.000000] Fallback order for Node 0: 0 [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 131072[ 0.000000] Policy zone: DMA[ 0.000000] mem auto-init: stack:all(zero), heap alloc:on, heap free:off[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1[ 0.000000] Dynamic Preempt: none[ 0.000000] rcu: Preemptible hierarchical RCU implementation.[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=4096 to nr_cpu_ids=1.[ 0.000000] Trampoline variant of Tasks RCU enabled.[ 0.000000] Tracing variant of Tasks RCU enabled.[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 100 jiffies.[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1[ 0.000000] RCU Tasks: Setting shift to 0 and lim to 1 rcu_task_cb_adjust=1 rcu_task_cpu_ids=1.[ 0.000000] RCU Tasks Trace: Setting shift to 0 and lim to 1 rcu_task_cb_adjust=1 rcu_task_cpu_ids=1.[ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0[ 0.000000] GICv3: 988 SPIs implemented[ 0.000000] GICv3: 0 Extended SPIs implemented[ 0.000000] Root IRQ handler: gic_handle_irq[ 0.000000] GICv3: GICv3 features: 16 PPIs, RSS[ 0.000000] GICv3: GICD_CTLR.DS=1, SCR_EL3.FIQ=0[ 0.000000] GICv3: CPU0: found redistributor 0 region 0:0x00000000080a0000[ 0.000000] rcu: srcu_init: Setting srcu_struct sizes based on contention.[ 0.000000] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns[ 0.000000] arch_timer: cp15 timer running at 24.00MHz (virt).[ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns[ 0.000000] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 4398046511097ns[ 0.000201] kfence: initialized - using 2097152 bytes for 255 objects at 0x(____ptrval____)-0x(____ptrval____)[ 0.000247] Console: colour dummy device 80x25[ 0.000266] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=24000)[ 0.000267] pid_max: default: 32768 minimum: 301[ 0.000288] LSM: initializing lsm=lockdown,capability,landlock,yama[ 0.000353] landlock: Up and running.[ 0.000353] Yama: becoming mindful.[ 0.000384] Mount-cache hash table entries: 1024 (order: 1, 8192 bytes, linear)[ 0.000385] Mountpoint-cache hash table entries: 1024 (order: 1, 8192 bytes, linear)[ 0.000826] rcu: Hierarchical SRCU implementation.[ 0.000827] rcu: Max phase no-delay instances is 400.[ 0.001311] EFI services will not be available.[ 0.001330] smp: Bringing up secondary CPUs ...[ 0.001333] smp: Brought up 1 node, 1 CPU[ 0.001334] SMP: Total of 1 processors activated.[ 0.001334] CPU: All CPU(s) started at EL1[ 0.001341] CPU features: detected: Branch Target Identification[ 0.001344] CPU features: detected: ARMv8.4 Translation Table Level[ 0.001344] CPU features: detected: Data cache clean to the PoU not required for I/D coherence[ 0.001345] CPU features: detected: Common not Private translations[ 0.001345] CPU features: detected: CRC32 instructions[ 0.001345] CPU features: detected: Data independent timing control (DIT)[ 0.001345] CPU features: detected: E0PD[ 0.001346] CPU features: detected: Enhanced Privileged Access Never[ 0.001346] CPU features: detected: Generic authentication (IMP DEF algorithm)[ 0.001347] CPU features: detected: RCpc load-acquire (LDAPR)[ 0.001348] CPU features: detected: LSE atomic instructions[ 0.001348] CPU features: detected: Privileged Access Never[ 0.001348] CPU features: detected: RAS Extension Support[ 0.001349] CPU features: detected: Speculation barrier (SB)[ 0.001349] CPU features: detected: TLB range maintenance instructions[ 0.001350] CPU features: detected: Scalable Matrix Extension[ 0.001350] CPU features: detected: SME2[ 0.001391] alternatives: applying system-wide alternatives[ 0.002309] SME: minimum available vector length 64 bytes per vector[ 0.002310] SME: maximum available vector length 64 bytes per vector[ 0.002310] SME: default vector length 64 bytes per vector[ 0.002351] Memory: 464096K/524288K available (13312K kernel code, 1994K rwdata, 8460K rodata, 2048K init, 9282K bss, 57716K reserved, 0K cma-reserved)[ 0.002452] devtmpfs: initialized[ 0.002662] posixtimers hash table entries: 512 (order: 1, 8192 bytes, linear)[ 0.002667] futex hash table entries: 256 (16384 bytes on 1 NUMA nodes, total 16 KiB, linear).[ 0.002677] 23904 pages in range for non-PLT usage[ 0.002677] 515424 pages in range for PLT usage[ 0.002698] pinctrl core: initialized pinctrl subsystem[ 0.002748] DMI not present or invalid.[ 0.003815] NET: Registered PF_NETLINK/PF_ROUTE protocol family[ 0.003889] DMA: preallocated 128 KiB GFP_KERNEL pool for atomic allocations[ 0.003911] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA pool for atomic allocations[ 0.003933] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations[ 0.003967] audit: initializing netlink subsys (disabled)[ 0.004042] thermal_sys: Registered thermal governor 'step_wise'[ 0.004048] audit: type=2000 audit(0.003:1): state=initialized audit_enabled=0 res=1[ 0.004050] cpuidle: using governor ladder[ 0.004052] cpuidle: using governor menu[ 0.004062] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.[ 0.004065] ASID allocator initialised with 65536 entries[ 0.004081] Serial: AMBA PL011 UART driver[ 0.004236] 9000000.pl011: ttyAMA0 at MMIO 0x9000000 (irq = 13, base_baud = 0) is a PL011 rev1[ 0.004262] printk: console [ttyAMA0] enabled[ 0.049311] HugeTLB: registered 1.00 GiB page size, pre-allocated 0 pages[ 0.049313] HugeTLB: 0 KiB vmemmap can be freed for a 1.00 GiB page[ 0.049313] HugeTLB: registered 32.0 MiB page size, pre-allocated 0 pages[ 0.049314] HugeTLB: 0 KiB vmemmap can be freed for a 32.0 MiB page[ 0.049314] HugeTLB: registered 2.00 MiB page size, pre-allocated 0 pages[ 0.049314] HugeTLB: 0 KiB vmemmap can be freed for a 2.00 MiB page[ 0.049315] HugeTLB: registered 64.0 KiB page size, pre-allocated 0 pages[ 0.049315] HugeTLB: 0 KiB vmemmap can be freed for a 64.0 KiB page[ 0.049505] ACPI: Interpreter disabled.[ 0.049512] iommu: Default domain type: Translated[ 0.049513] iommu: DMA domain TLB invalidation policy: lazy mode[ 0.052048] clocksource: Switched to clocksource arch_sys_counter[ 0.059241] VFS: Disk quotas dquot_6.6.0[ 0.059248] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)[ 0.059577] pnp: PnP ACPI: disabled[ 0.060904] NET: Registered PF_INET protocol family[ 0.060928] IP idents hash table entries: 8192 (order: 4, 65536 bytes, linear)[ 0.066377] tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 4096 bytes, linear)[ 0.066383] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)[ 0.066387] TCP established hash table entries: 4096 (order: 3, 32768 bytes, linear)[ 0.066392] TCP bind hash table entries: 4096 (order: 5, 131072 bytes, linear)[ 0.066397] TCP: Hash tables configured (established 4096 bind 4096)[ 0.066423] MPTCP token hash table entries: 512 (order: 2, 12288 bytes, linear)[ 0.066429] UDP hash table entries: 256 (order: 2, 16384 bytes, linear)[ 0.066431] UDP-Lite hash table entries: 256 (order: 2, 16384 bytes, linear)[ 0.066448] NET: Registered PF_UNIX/PF_LOCAL protocol family[ 0.066454] NET: Registered PF_XDP protocol family[ 0.066458] PCI: CLS 0 bytes, default 64[ 0.066540] Unpacking initramfs...[ 0.071248] kvm [1]: HYP mode not available[ 0.071413] Initialise system trusted keyrings[ 0.072305] workingset: timestamp_bits=44 max_order=17 bucket_order=0[ 0.079794] Key type asymmetric registered[ 0.079797] Asymmetric key parser 'x509' registered[ 0.079834] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 248)[ 0.089781] io scheduler mq-deadline registered[ 0.089785] io scheduler kyber registered[ 0.089799] io scheduler bfq registered[ 0.090135] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled[ 0.090578] hv_vmbus: registering driver hyperv_keyboard[ 0.090712] rtc-pl031 9010000.pl031: registered as rtc0[ 0.090719] rtc-pl031 9010000.pl031: setting system clock to 2026-11-20T10:15:44 UTC (1795169744)[ 0.090806] NET: Registered PF_INET6 protocol family[ 0.093832] Segment Routing with IPv6[ 0.093836] In-situ OAM (IOAM) with IPv6[ 0.096136] registered taskstats version 1[ 0.096203] Loading compiled-in X.509 certificates[ 0.153029] Freeing initrd memory: 9204K[ 0.156597] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: 87fa969a47f3e2a6aa35859eb932a17c95abcd82'[ 0.158655] Demotion targets for Node 0: null[ 0.158696] Key type .fscrypt registered[ 0.158696] Key type fscrypt-provisioning registered[ 0.161146] clk: Disabling unused clocks[ 0.161150] PM: genpd: Disabling unused power domains[ 0.161381] Freeing unused kernel memory: 2048K[ 0.161398] Run /init as init processmacvmm-initramfs: ready 6.18.60-0-virt/ # cat /proc/consolesttyAMA0 -W- (EC Np a) 204:64/ # dmesg | head -n 3[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x610f0000][ 0.000000] Linux version 6.18.60-0-virt (buildozer@build-3-24-aarch64) (cc (Alpine 15.2.0) 15.2.0, GNU ld (GNU Binutils) 2.45.1) #1-Alpine SMP PREEMPT_DYNAMIC 2026-11-01 07:26:31[ 0.000000] random: crng init done/ # cat /proc/iomem08000000-0800ffff : GICD080a0000-080bffff : GICR09000000-09000fff : pl011@9000000 09000000-09000fff : 9000000.pl011 pl011@900000009010000-09010fff : pl031@9010000 09010000-09010fff : rtc-pl03140000000-5fffffff : System RAM 40000000-40000fff : reserved 40200000-4177ffff : Kernel code 41780000-4197ffff : reserved 41980000-4249ffff : Kernel data 42600000-42efdfff : reserved 5f337000-5fbfffff : reserved 5fc0b000-5fccbfff : reserved 5fccc000-5fcf2fff : reserved 5fcf3000-5fd05fff : reserved 5fd06000-5fd07fff : reserved 5fd08000-5fffffff : reserved/ # for d in /sys/bus/pci/devices/*; do echo $d $(cat $d/vendor $d/device); donecat: can't open '/sys/bus/pci/devices/*/vendor': No such file or directorycat: can't open '/sys/bus/pci/devices/*/device': No such file or directory/sys/bus/pci/devices/*/ # poweroff -f[ 4.553231] reboot: Power downWhere our VMM puts devices at fixed addresses, VZ puts its virtio devices on PCI Express (PCIe), the bus ordinary computers use for expansion cards. The operating system finds each device by reading its vendor and device IDs from a configuration space (Linux PCI documentation); the PCI ECAM range in VZ's /proc/iomem is that space, laid out by the Enhanced Configuration Access Mechanism (ECAM).
Under VZ the loop printed three devices. Vendor 0x106b is Apple: the host bridge, the device that connects the CPU to the PCI bus. Vendor 0x1af4 is the ID the virtio specification assigns to virtio devices (it is Red Hat's), and a modern virtio device's ID is 0x1040 plus its virtio type: 0x1043 is type 3, the console, and 0x1044 is type 4, the virtio-rng. Under our VMM the pattern matched no file, so cat complained about the literal *.
Put side by side:
| our VMM | VZ's generic platform | |
|---|---|---|
console (/proc/consoles) | ttyAMA0, the PL011 | hvc0, a virtio-console |
| interrupt controller | GICD, the GIC's distributor, at 0x0800_0000 | GICD at 0x1000_0000 |
| RAM | from 0x4000_0000 | from 0x7000_0000 |
| RTC | PL031 at 0x0901_0000 | PL031 at 0x2005_0000 |
| other devices | none on a bus | a PCI host bridge, two virtio devices on PCI, and a PL061 (a general-purpose input/output controller) |
| firmware | none, the VMM enters the kernel | none: efi: UEFI not found. |
| CPU ID in the first log line | 0x610f0000 | 0x610f0000 |
The kernel copes because, as chapter 10 showed, it reads the machine from the device tree each VMM hands it. UEFI is the Unified Extensible Firmware Interface, the standard firmware the uefi primer describes; neither machine runs one here.
The last row is the interesting sameness. It is the main ID register (MIDR), which names the CPU's maker and model.
A guest does not read the chip's own MIDR: HVF's header hv_vcpu_types.h lists HV_SYS_REG_MIDR_EL1 among the registers a VMM may set, and macvmm never sets it, so 0x610f0000 is HVF's default. The Arm Architecture Reference Manual's description of MIDR_EL1 gives the fields: bits [31:24] are the implementer, [23:20] the variant, [19:16] the architecture (0xF), [15:4] the part number and [3:0] the revision. So 0x610f0000 is implementer 0x61 (Apple) with part number 0, while Apple's real cores carry non-zero part numbers (Linux's arch/arm64/include/asm/cputype.h lists them).
Seeing HVF's default under VZ hints that VZ runs on HVF too; only a hint, since VZ could choose the same value. The next section has stronger evidence.
Who runs the guest?
Under macvmm, the guest's vCPUs are threads of your own process (chapter 00). Look for vz-mac's guest the same way: start the shell boot again and, while it waits at its prompt, run this in a second terminal:
ps -axo pid,ppid,comm | grep -i -e virtualization -e vz-macYour process IDs will differ:
ps -axo pid,ppid,comm | grep -i -e virtualization -e vz-mac77330 77328 target/vz-mac/signed/vz-mac77333 1 /System/Library/Frameworks/Virtualization.framework/Versions/A/XPCServices/com.apple.Virtualization.VirtualMachine.xpc/Contents/MacOS/com.apple.Virtualization.VirtualMachineTwo processes: vz-mac, and Apple's com.apple.Virtualization.VirtualMachine, whose parent is process 1, launchd, which starts macOS services. Other VM apps add one each; yours goes away when vz-mac stops.
It is an XPC service: a helper program macOS starts on an app's behalf and talks to by messages (XPC documentation). vz-mac sent it a configuration; the service builds the machine, runs the vCPUs and emulates the devices. vz-mac never sees a VM exit, and VZ has no interface that would show one. What may that service do? Read its signature:
codesign -d --entitlements - /System/Library/Frameworks/Virtualization.framework/Versions/A/XPCServices/com.apple.Virtualization.VirtualMachine.xpc | grep -F '[Key]' [Key] adi-client [Key] com.apple.ane.iokit-user-access [Key] com.apple.aned.private.adapterWeight.allow [Key] com.apple.aned.private.allow [Key] com.apple.developer.kernel.increased-memory-limit [Key] com.apple.private.AppleVirtualPlatformIdentity [Key] com.apple.private.FairPlayIOKitUserClient.Virtual.access [Key] com.apple.private.PCIPassthrough.access [Key] com.apple.private.amber.client [Key] com.apple.private.ane.mappingMutableWeightsBuffer.allow [Key] com.apple.private.ane.privileged-vm-client [Key] com.apple.private.apfs.no-padding [Key] com.apple.private.biometrickit.allow-match [Key] com.apple.private.debug-usb.access [Key] com.apple.private.fpsd.client [Key] com.apple.private.ggdsw.GPUProcessProtectedContent [Key] com.apple.private.hypervisor [Key] com.apple.private.proreshw [Key] com.apple.private.security.message-filter [Key] com.apple.private.system-keychain [Key] com.apple.private.tcc.check-allow-on-responsible-process [Key] com.apple.private.vfs.open-by-id [Key] com.apple.private.virtualization [Key] com.apple.private.virtualization.linux-gpu-support [Key] com.apple.private.virtualization.plugin-loader [Key] com.apple.private.xpc.domain-extension [Key] com.apple.security.hardened-process [Key] com.apple.security.hardened-process.checked-allocations [Key] com.apple.security.hardened-process.no-guard-objects [Key] com.apple.security.hypervisor [Key] com.apple.security.private.Virtualization.VzDevicesMonitor.register [Key] com.apple.usb.hostcontrollerinterface [Key] com.apple.vm.networking [Key] keychain-access-groups [Key] lskdd-clientAbout three dozen keys on our Mac (macOS 27.2.1); your list may differ. Among them is com.apple.security.hypervisor, the one macvmm holds: the service may use Hypervisor.framework, and with the CPU ID above that is good evidence it does. Many others are com.apple.private.* keys, including com.apple.private.hypervisor. These are restricted entitlements: macOS honours them only in code Apple has vouched for, never in an ad-hoc signature (the primer shows macOS killing such a program at launch).
In chapter 02's exception levels: guest kernels run at EL1; macvmm, vz-mac and Apple's service at EL0; the macOS kernel's hypervisor part at EL2. A guest reaches its devices by memory-mapped I/O (MMIO, chapter 07), loads and stores that trap to the VMM, and by virtio traffic in shared memory. Who parses what the guest sends:
guest kernel, EL1 (untrusted) guest kernel, EL1 (untrusted) | sends MMIO and | sends virtio traffic | virtio traffic | over PCI; writes console bytes - - | - - - - - - trust boundary - - -| - - - - - - - - - - - - - - - - - - v v macvmm, EL0, our process VirtualMachine service, EL0 vz-mac, EL0, parses guest traffic: Apple's process <-- our process devices, exit loop parses guest traffic: sends a also holds: devices, exit loop configuration device tree, loader also holds: (XPC) | device tree, loader | | console bytes ------------> filters them, | | prints them | runs vCPUs | runs vCPUs v v [ macOS kernel, EL2 part (chapter 02): one kernel under both columns ]The machine moved out of your process. Notice who now parses the guest's device traffic, and the one stream that still reaches vz-mac.
Security
Under macvmm, a hostile guest attacks our device code, in a process with one entitlement; you can read, test and patch every line. Under VZ, it attacks Apple's device code, in a process with about three dozen entitlements, many restricted; Apple audits and patches it, and you can do neither. A trade, not a ranking.
vz-mac's own surface: the console
vz-mac copies the guest's console bytes to your terminal, and some escape sequences make a terminal answer: ESC [ 6 n asks for the cursor position, and the terminal types its reply into its own input. vz-mac forwards what you type to the guest, so while it runs the reply goes to the guest; after it exits, your shell reads it (the tty-termios primer has worse examples). The VZ shell capture shows the guest's shell sending that query, which reached your terminal as the harmless text ^[[6n. (macvmm's default filter from chapter 09 drops queries silently, so its capture shows nothing there.) This filter, like chapter 09's in its strict mode, did that:
private mutating func feedByte(_ b: UInt8, into out: inout [UInt8]) { if expected != 0 { if b & 0xC0 == 0x80 { pending.append(b) if pending.count == expected { completeSequence(into: &out) } return } // A lead or ASCII byte cut the sequence short: replace it, then handle `b` afresh. out += Self.replacement pending.removeAll(keepingCapacity: true) expected = 0 } switch b { case 0x20...0x7E, 0x0A, 0x0D, 0x09, 0x08: out.append(b) case 0x00...0x1F: out += [UInt8(ascii: "^"), b + 0x40] // ESC -> ^[, BEL -> ^G, NUL -> ^@ case 0x7F: out += Array("^?".utf8) case 0x80...0x9F: out += Array(String(format: "\\x%02x", b).utf8) // raw 8-bit C1, e.g. CSI 0x9b case 0xC2...0xDF: start(b, length: 2) case 0xE0...0xEF: start(b, length: 3) case 0xF0...0xF4: start(b, length: 4) default: // 0xA0...0xBF stray continuation, 0xC0, 0xC1, 0xF5...0xFF never valid out += Self.replacement }}Three parts carry the defence for single bytes:
case 0x00...0x1F: every control byte but newline, carriage return, tab and backspace prints in caret notation,^then the byte plus0x40. ESC (0x1b) becomes^[, so no escape sequence can start.case 0x80...0x9F: these are the 8-bit C1 controls. Some terminals treat0x9balone as the start of a sequence (CSI, the Control Sequence Introducer, the same asESC [), so a raw one is printed as the text\x9b.- The
expected != 0branch: bytes0xC2to0xF4start a multi-byte UTF-8 character, continued by bytes0x80to0xBF. A character cut short becomes the replacement character, U+FFFD. A continuation byte with no lead takes the arms below:0x80to0x9Fprint as\x.., and0xA0to0xBFfall todefault, U+FFFD.
A complete character is checked again, since a C1 control can be spelled in UTF-8: C2 9B is U+009B, CSI again.
private mutating func completeSequence(into out: inout [UInt8]) { var cp: UInt32 switch expected { case 2: cp = UInt32(pending[0] & 0x1F) case 3: cp = UInt32(pending[0] & 0x0F) default: cp = UInt32(pending[0] & 0x07) } for c in pending.dropFirst() { cp = (cp << 6) | UInt32(c & 0x3F) } let minimum: UInt32 = expected == 2 ? 0x80 : (expected == 3 ? 0x800 : 0x1_0000) if cp < minimum || cp > 0x10_FFFF || (0xD800...0xDFFF).contains(cp) { out += Self.replacement // overlong, out of range, or a surrogate } else if (0x80...0x9F).contains(cp) { out += Array(String(format: "\\u{%x}", cp).utf8) // UTF-8-encoded C1 } else { out += pending } pending.removeAll(keepingCapacity: true) expected = 0}An overlong form (more bytes than the character needs), a value past U+10FFFF or a surrogate becomes U+FFFD; U+0080 to U+009F print as \u{..}; anything else passes unchanged.
Good place to stop. Sitting B needs your Mac and about 1.5 hours (more if you install macOS).
The high road to macOS
Why use VZ at all? For Linux, mostly you would not; your own VMM shows you everything. For a macOS guest, VZ is the only supported way. A macOS virtual machine starts from a restore image, Apple's installation file for macOS (ending in .ipsw), a VZMacOSRestoreImage to VZ; VZMacOSInstaller installs it onto a disk image. Ask VZ which restore image this Mac supports; it asks Apple's servers but downloads nothing:
tools/vz-mac/run.sh install --bundle .cache/macvmm/macos-vm --latest --dry-runtools/vz-mac/run.sh install --bundle .cache/macvmm/macos-vm --latest --dry-runBuilding for production...Build complete! (0.15 sec)vz-mac: latest supported restore image: macOS 27.2.1 build "26B131" at "https://updates.cdn-apple.com/2026FallFCS/c202a724-db7e-4d56-917b-110aa0226507/UniversalMac_27.2.1_26B131_Restore.ipsw"vz-mac: requirements: at least 2 CPUs and 4096 MiBvz-mac: dry run: nothing downloaded, no bundle createdA macOS guest also has an identity. vz-mac keeps it in a bundle, a directory holding the disk image, the auxiliary storage, the hardware model and the machine identifier, and builds the platform from the last three:
func makeMacConfiguration( hardwareModel: VZMacHardwareModel, machineIdentifier: VZMacMachineIdentifier, auxiliaryStorage: VZMacAuxiliaryStorage, disk: URL, cpus: Int, memory: UInt64) throws(VZMacError) -> VZVirtualMachineConfiguration { let platform = VZMacPlatformConfiguration() platform.hardwareModel = hardwareModel platform.machineIdentifier = machineIdentifier platform.auxiliaryStorage = auxiliaryStorage let config = VZVirtualMachineConfiguration() config.platform = platform config.bootLoader = VZMacOSBootLoader() config.cpuCount = cpus config.memorySize = memory- The hardware model: an opaque value naming the kind of virtual Mac the restore image was installed for.
- The machine identifier: an opaque value that gives this one VM its identity.
- The auxiliary storage: a file holding data the boot loader and the guest need, such as boot settings, laid out by the installer.
The SDK that ships with Xcode keeps VZ's headers in $(xcrun --show-sdk-path)/System/Library/Frameworks/Virtualization.framework/Headers/. There, VZMacPlatformConfiguration.h says that when a VM is loaded again, all three "must be restored to their original values". And VZMacOSBootLoader takes no kernel at all: it runs AVPBooter, Apple's boot ROM for virtual Macs, which loads and checks macOS's own boot files from the disk (chapter 24 runs it under your VMM). The devices complete the machine:
// The main disk must be the first storage device (VZVirtualMachineConfiguration.h). let attachment: VZDiskImageStorageDeviceAttachment do { attachment = try VZDiskImageStorageDeviceAttachment(url: disk, readOnly: false) } catch { throw .failure("cannot attach \(debugQuoted(disk.path)): \(describe(error))") } config.storageDevices = [VZVirtioBlockDeviceConfiguration(attachment: attachment)] // Apple-specific devices: ParavirtualizedGraphics, a Mac keyboard and trackpad. They are // what a low-level VMM would have to reimplement (docs/macos/inventory.md). No network // device by default: the tool needs none, and NAT would add a surface for no lesson. let graphics = VZMacGraphicsDeviceConfiguration() graphics.displays = [ VZMacGraphicsDisplayConfiguration(widthInPixels: 1920, heightInPixels: 1200, pixelsPerInch: 80) ] config.graphicsDevices = [graphics] config.keyboards = [VZMacKeyboardConfiguration()] config.pointingDevices = [VZMacTrackpadConfiguration()] config.entropyDevices = [VZVirtioEntropyDeviceConfiguration()] return config}The disk is a standard virtio-blk device, virtio's disk (chapter 18). The display, keyboard and trackpad are VZMac* classes: Apple-specific. The display is paravirtual graphics, a device designed for VMs. Its host half is ParavirtualizedGraphics, a public macOS framework, but the protocol the guest speaks to it is not documented (chapter 24).
Installing is optional, and big. Ask Apple's server how big the restore image above is, without downloading it (-I sends a HEAD request, which returns only the headers):
curl -sSI https://updates.cdn-apple.com/2026FallFCS/c202a724-db7e-4d56-917b-110aa0226507/UniversalMac_27.2.1_26B131_Restore.ipsw | grep -i '^content-length'Use the URL your dry run printed; it changes with each release.
curl -sSI https://updates.cdn-apple.com/2026FallFCS/c202a724-db7e-4d56-917b-110aa0226507/UniversalMac_27.2.1_26B131_Restore.ipsw | grep -i '^content-length'Content-Length: 25595954706About 26 GB. The disk image can grow to 64 GB, and the tool's README expects 20 to 40 minutes. If you have the space and time:
tools/vz-mac/run.sh install --bundle .cache/macvmm/macos-vm --latesttools/vz-mac/run.sh boot --bundle .cache/macvmm/macos-vm --seconds 60The tool is written to print VZ guest state: running and, after the virtual power button, VZ guest state: stopped (requested). We did not install macOS, so there is no capture of a macOS boot here. running proves only that VZ started the machine: the reference's docs/macos/status.md records it even for a bundle with no macOS installed.
Aside
Apple's software licence agreement for macOS addresses macOS in virtual machines; the reference's docs/research/macos-guest.md cites section 2B(iii). Read the version for your macOS at apple.com/legal/sla; this course links it and does not interpret it. VZ enforces a limit of its own: its header VZError.h defines VZErrorVirtualMachineLimitExceeded, for when starting a VM "would exceed the system's limit on the number of simultaneously running virtual machines".
Breaking it on purpose
Deliberate breakage 1: run vz-mac without its entitlement. Copy the signed tool to a scratch directory and re-sign the copy with the hardened runtime and no entitlement (-i keeps the identifier vz-mac; with no entitlements file, the copy carries none):
mkdir -p target/scratchcp target/vz-mac/signed/vz-mac target/scratch/codesign -s - -f -o runtime -i vz-mac target/scratch/vz-mactarget/scratch/vz-mac linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=boot"Chapter 01's macvmm got HV_DENIED from hv_vm_create. Predict: does VZ fail at the same moment, earlier, or later?
target/scratch/vz-mac linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=boot"vz-mac: configuration rejected by Virtualization.framework: "Invalid virtual machine configuration. The process doesn’t have the “com.apple.security.virtualization” entitlement. [VZErrorDomain 2]"Earlier, and by name. vz-mac calls the configuration's validate() before starting the machine, and VZ refused there; vz-mac exits 1. What you saw: a clean, named refusal at run time. The misconception it exposes: "Apple's service holds all the rights, so my program needs none"; the framework checks your signature before it asks the service for anything. The tool that finds it: the error text and codesign -d --entitlements -.
A weekend's work?
A common thought: "VZ is a wrapper around Hypervisor.framework; we could rewrite it in a weekend." Your runs say otherwise. Here are the device classes VZ offers, from the SDK headers:
ls "$(xcrun --show-sdk-path)/System/Library/Frameworks/Virtualization.framework/Headers" | grep -E 'Device(Specific)?Configuration|Keyboard|Trackpad|Pointing'VZAudioDeviceConfiguration.hVZConsoleDeviceConfiguration.hVZCustomVirtioDeviceConfiguration.hVZCustomVirtioDeviceConfigurationDelegate.hVZDirectorySharingDeviceConfiguration.hVZEntropyDeviceConfiguration.hVZGraphicsDeviceConfiguration.hVZKeyboardConfiguration.hVZMacGraphicsDeviceConfiguration.hVZMacKeyboardConfiguration.hVZMacTrackpadConfiguration.hVZMemoryBalloonDeviceConfiguration.hVZNetworkDeviceConfiguration.hVZNVMExpressControllerDeviceConfiguration.hVZPointingDeviceConfiguration.hVZSocketDeviceConfiguration.hVZStorageDeviceConfiguration.hVZUSBDeviceConfiguration.hVZUSBKeyboardConfiguration.hVZUSBMassStorageDeviceConfiguration.hVZUSBPassthroughDeviceConfiguration.hVZUSBScreenCoordinatePointingDeviceConfiguration.hVZVirtioBlockDeviceConfiguration.hVZVirtioConsoleDeviceConfiguration.hVZVirtioDeviceSpecificConfiguration.hVZVirtioEntropyDeviceConfiguration.hVZVirtioFileSystemDeviceConfiguration.hVZVirtioGraphicsDeviceConfiguration.hVZVirtioNetworkDeviceConfiguration.hVZVirtioSocketDeviceConfiguration.hVZVirtioSoundDeviceConfiguration.hVZVirtioTraditionalMemoryBalloonDeviceConfiguration.hThey fall into three groups:
- Standard virtio: the
VZVirtio*classes, documented in a public specification. - Other public standards: the Universal Serial Bus (USB) keyboard, pointing device and mass storage (
VZUSB*), and the NVM Express (NVMe) disk controller; anyone can read their specifications. - Apple-specific: the
VZMac*graphics, keyboard and trackpad, and the Mac platform identity behind them.
"Apple implemented it" and "Apple defined it" are different questions; only the second leaves a low-level VMM with no specification. Under the configuration sits a whole machine, generated privately: a memory map, PCIe, a GIC, a device tree, and for macOS a boot ROM, an identity tied to Apple's installer and an undocumented graphics protocol. The misconception, corrected: VZ supplies a complete machine, firmware and devices, much of it undocumented.
Production note
Low-level macOS guests do exist: QEMU's vmapple machine boots macOS on Hypervisor.framework by loading Apple's boot ROM from the host's Virtualization.framework and reimplementing Apple's devices from observation. Chapter 24 follows that road, as an investigation, not a promise.
Your turn
- Run
tools/vz-mac/test.shuntil it ends inVZ TESTS OK; the checkpoint below shows its five steps. - In your journal, write a comparison table of VZ and your VMM in your own words, six rows at least: who defines the devices, the console, the memory map, who runs the exit loop, the entitlement, what a hostile guest attacks.
- Write your inventory in a file of your own, such as
learner/docs/macos/inventory.md: one row per piece a low-level VMM must provide to boot macOS, with the VZ class or file that supplies it today, what you would build, and "documented" or "undocumented". Start from this chapter's three (the Mac platform identity, the boot ROM, the graphics device), add what the headers showed, then compare with the reference'sdocs/macos/inventory.md.
Checkpoint
Back at the repository root, run:
Checkpoint
Needs a MacRun this from the repository root:
scripts/checkpoint.sh 23You should see, as the last line:
CHECKPOINT 23 PASSThe checkpoint runs vz-mac's acceptance test, tools/vz-mac/test.sh, then checks that every journal heading has an answer:
scripts/checkpoint.sh 23[INFO] contract tests none for this chapter[PASS] runs on your Mac vz-acceptance: 10/10 serial markers, exit 0 in 8.55s[INFO] journal not checked (not a learner tree)CHECKPOINT 23 PASSThe test's five steps, as the checkpoint ran them:
tools/vz-mac/test.sh== 1. swift test (host-only)Test run with 72 tests in 16 suites passed after 0.131 seconds.PASS swift_test== 2. vz_entitlements_exactbinary: <repo>/target/vz-mac/signed/vz-macentitlement: com.apple.security.virtualizationCodeDirectory v=20500 size=935 flags=0x10002(adhoc,runtime) hashes=19+7 location=embeddedPASS vz_entitlements_exact== 3. vz_breaks_without_entitlementvz-mac: configuration rejected by Virtualization.framework: "Invalid virtual machine configuration. The process doesn’t have the “com.apple.security.virtualization” entitlement. [VZErrorDomain 2]"PASS vz_breaks_without_entitlement (exit 1)== 4. vz_linux_dry_runvz-mac: configuration valid: linux, 2 vCPUs, 512 MiB, console hvc0PASS vz_linux_dry_run== 5. vz_linux_bootmacvmm-initramfs: ready 6.18.60-0-virt\rVZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)PASS vz_linux_boot (exit 0, 0s)VZ TESTS OKBuilding for production...Build complete! (0.15 sec)Step 1 is 72 host-only tests (argument parsing, hostile inputs); step 2 checks vz-mac's signature and macvmm's entitlements file; steps 3 and 5 repeat this chapter's runs (no entitlement, the Linux boot); step 4 validates the Linux configuration without booting (--dry-run).
What now works:
- you can run a VZ guest from the same kernel and initramfs as your VMM, and say why its console is
hvc0; - you can show, with
psandcodesign, that a VZ guest runs in Apple's service, which holds restricted entitlements you cannot get; - you have a comparison table and an inventory of what a macOS guest needs.
No Rust changed; chapter 24 starts from the reference at the end of chapter 23.
What's next
Chapter 24 takes the low road: a VMM of ours loads Apple's boot ROM in place from the host's Virtualization.framework, runs it on a second board, and records every access to a device it lacks. Your inventory is its map; its honest answer may be "not yet".
Open question
From your inventory, which three pieces will be hardest for a low-level VMM to provide, and is each one hard because it is complex or because it is undocumented?
Spec hunt
- The SDK header
VZMacPlatformConfiguration.h, the discussion above the class: what must be restored when a saved VM is loaded again, and what should differ between two VMs created from the same configuration? - The virtio 1.2 specification, section 4.1.2 "PCI Device Discovery", with the device ID table in chapter 5: why is the console
0x1043, and what PCI device ID would a virtio-blk disk have? - Linux
Documentation/admin-guide/serial-console.rst: what does the kernel use as its console when the command line names none? Our VZ run with noconsole=word was silent, not printed onhvc0; which console registered first (look for theConsole:line incourse/captures/23-macvmm-shell.txt, a log with no early console), and why did it win?