Files
reims-vgpu/vm
Anees Iqbal 089280a93f ✨ Guest pages can leave QEMU as a dma-buf instead of a host pointer
Component: shared ABI header (v15 -> v16), `crates/reims-vgpu` HostOps,
`vm/boot-x86.sh`, and the QEMU submodule bump carrying the shim side.

`HostOps::dmabuf_for_pages` turns a run of page-aligned guest GPAs into one
Linux dma-buf fd. This is the mechanism by which the host GPU will read *and
write* guest memory in place, which is the only way to retire the copy on each
side of every guest resource — `write_staging_from_runs` on the way in, and the
deferred-flush rail on the way out.

It is deliberately not `map_pages` with a different return type, and that
distinction is why this is admissible where `VK_EXT_external_memory_host` is
not. That extension imports an arbitrary host virtual address range, which over
guest RAM is unbounded by anything the guest asked for, cannot be revoked once
handed to a driver, and is trusted rather than mediated. A dma-buf is bounded to
the page ranges named at create time, revoked by closing the fd, and referenced
through the kernel. The ban on host-pointer imports stands and nothing here
requests one. Two stale doc comments that still described that deleted rail as
the reason `map_pages_stable` exists are corrected to say what it actually
claims now: a CPU-side pointer lifetime, and nothing about the GPU.

`DmaBufExportError` names one check per code. Eight of them because they are
eight different things to do about it: a missing `/dev/udmabuf` is a permission
fix, `not_memfd` is a boot-argument fix, and `too_fragmented` is a property of
the guest's own allocation that no host change addresses. A ninth,
`UnknownCode`, carries the number rather than swallowing it, so a shim newer
than the staticlib says so instead of being misfiled.

The fd is `OwnedFd` from the moment it crosses the boundary. The shim creates it
and does not retain it, so ownership is unambiguous, and no refusal path reaches
the arm that takes it.

`vm/boot-x86.sh` now backs guest RAM with `memory-backend-memfd,share=on`. A
plain `-m` allocation is an anonymous mapping with no fd and nothing can be
exported from it; `share=on` is required rather than tidy, because a private
mapping is copy-on-write and the GPU's view would diverge from the guest's the
first time either wrote.

Verified: `cargo test -p reims-vgpu --no-default-features --features
backend-vulkan,host-window -- --test-threads=1` — 1298 lib tests pass,
including `the_abi_header_agrees_on_the_dmabuf_codes` (each code exists twice
with nothing else in the toolchain comparing them) and
`every_dmabuf_code_maps_to_its_own_named_check`. Clippy on that arm: 0 errors.
A standalone C probe confirmed this host's NVIDIA ICD imports a udmabuf as
`VkDeviceMemory` and binds a buffer to it, which is what makes the rail worth
building.

Not verified: no live boot. Nothing in the crate calls `dmabuf_for_pages` yet,
so neither the memfd-backed boot line nor the export itself has run against real
guest pages. The Vulkan import side and its first caller land next. The Metal
arm was not built (Apple-only host).
2026-08-04 18:07:58 +03:00
..
2026-07-26 15:24:53 +03:00

vm/ — macOS guests for the reims-vgpu pathways

crates/reims-vgpu runs three backend pathways over two guest rails. Pick the boot script for the guest you are on and the QEMU/reims-vgpu backend for the host GPU path.

Pathway Script Host accel Backend Typical device
x86 macOS / Linux Vulkan vm/boot-x86.sh KVM / OpenCore+OVMF Vulkan via metal2vulkan reims-vgpu-pci
arm64 macOS / macOS Metal vm/boot-arm64.sh HVF / vmapple Metal-direct reims-vgpu-mmio (product) or apple-gfx-mmio (Apple reference A/B)
arm64 macOS / macOS Vulkan vm/boot-arm64.sh HVF / vmapple Vulkan via metal2vulkan through MoltenVK reims-vgpu-mmio
# arm64 macOS guest on Mac host (Metal or Vulkan/MoltenVK backend)
vm/boot-arm64.sh --testing                 # agent boot: GUI + serial-to-file, hard kill, reverts
vm/boot-arm64.sh --interactive             # human boot: GUI, no time limit, reverts
vm/boot-arm64.sh --device reims-vgpu-mmio --testing
vm/boot-arm64.sh --device apple-gfx-mmio --testing   # Apple-paravirt reference (arm only)

# x86 macOS guest on Linux host
vm/boot-x86.sh --testing
vm/boot-x86.sh --device reims-vgpu-pci --testing

Both scripts use a snapshot-revert lifecycle (testing vs interactive classes; testing hard kill). QMP is a per-boot unix socket under the run dir for that pathway (scripts/qmp/qmp.py).

Networking is typically QEMU SLIRP with SSH hostfwd. Guest disks, IPSWs, OpenCore blobs, and runtime clones are gitignored - private and large; never commit them.

Layout (gitignored runtime)

Pathway-specific trees hold provisioned disks, snapshots, and per-boot clones. See the boot and provisioning scripts for where golden images and SSH setup live.

Stop a wedged guest with the pathway's shutdown helper when available (scripts/vmapple-shutdown on arm); otherwise use QMP quit plus a process kill.