hvf: abort() on HV_BAD_ARGUMENT when a guest RAM region is smaller than the host page size (regression in 11.0.0)

Host environment

  • Operating system: macOS 27.0 (build 26A428)
  • OS/kernel version: Darwin 27.0.0, xnu-13432.1.9~1/RELEASE_ARM64_T8103
  • Architecture: ARM (Apple Silicon, M1; 16 KiB host page size)
  • QEMU flavor: qemu-system-aarch64
  • QEMU version: 11.1.1 (Homebrew)
  • QEMU command line:
    qemu-system-aarch64 -machine virt,accel=hvf -cpu host -m 1024 -nographic \
      -chardev socket,id=chrtpm,path=/tmp/swtpm.sock \
      -tpmdev emulator,id=tpm0,chardev=chrtpm \
      -device tpm-tis-device,tpmdev=tpm0

Emulated/Virtualized environment

  • Operating system: n/a — QEMU aborts during device realize, before any guest code runs
  • OS/kernel version: n/a (originally hit while running a Windows 11 guest under Lima)
  • Architecture: ARM (aarch64)

Description of problem

With accel=hvf on an Apple Silicon host, attaching an emulated TPM makes QEMU abort immediately:

qemu-system-aarch64: -device tpm-tis-device,tpmdev=tpm0: Error: ret = HV_BAD_ARGUMENT (0xfae94003, at ../accel/hvf/hvf-all.c:123)

The offending region is tpm-ppi, a 0x400-byte RAM-device region created alongside the TIS MMIO window. Under TCG, info mtree -f shows:

0c000000-0c004fff (prio 0, i/o ): tpm-tis-mmio
0c005000-0c0053ff (prio 0, ramd): tpm-ppi

Because tpm-ppi is RAM, hvf_set_phys_mem() does not take the early return used for MMIO. The alignment check then sets add = false (0x400 is not a multiple of the 16 KiB host page), and the !add path calls hv_vm_unmap() on a range that was never mapped and whose size is not a whole number of pages. HVF rejects it and assert_hvf_ok() aborts.

This is a regression from d1f4ba9d ("accel/hvf: Simplify hvf_set_phys_mem"), first released in 11.0.0. Previously the !add path was a bare return, and the removed mac_slots table recorded whether a range had ever been mapped. v10.1.0 is unaffected; v11.0.0, v11.1.x and current master all carry the unconditional unmap.

Workaround: -device tpm-tis-device,tpmdev=tpm0,ppi=off, which avoids creating the sub-page region.

Lima enables tpm-tis-device by default for Windows 11 guests, so every Lima Windows 11 instance on Apple Silicon fails to start on QEMU >= 11.0.

Steps to reproduce

  1. On an Apple Silicon Mac, start a TPM backend: swtpm socket --tpmstate dir=/tmp/swtpmstate --ctrl type=unixio,path=/tmp/swtpm.sock --tpm2 --terminate (swtpm 0.10.2 here; any version works).
  2. Run the QEMU command line given above.
  3. QEMU aborts instantly with HV_BAD_ARGUMENT. Removing the three TPM arguments, or adding ppi=off to the -device, makes it boot to the UEFI shell normally.

Assisted-by: Claude Opus 5