Commit Graph
13 Commits
Author SHA1 Message Date
Anees Iqbal 99bfd0583f 🐛 Build the library on Linux without the vulkan feature
On Linux the Vulkan platform is the library's only one, yet reims-vgpu and
reims-vgpu-c refused to build without their `vulkan` features (a
compile_error!), and the code behind it did not compile either: a
default-feature Linux build of the package failed. A crate that does not
build in a feature setting is a failure, so the platform is now unconditional
on Linux.

- reims-vgpu's new build script sets `cfg(vulkan_platform)` on Linux, and on
  macOS with the `vulkan` feature, declared for check-cfg. Every
  `feature = "vulkan"` gate in the crate is that cfg; the gates of "macOS or
  the feature", true on every target the library builds for, are gone.
- The Vulkan platform's dependencies are not optional on Linux; on macOS they
  stay the feature's, optional, so the Mac's default build is as before.
- reims-vgpu-c makes every handle on VulkanPlatform on Linux whatever its
  features; the compile_error!s go.

Behaviour is unchanged on both OSes: on macOS every cfg answers as the
feature did, and on Linux as the builds with the feature did. The docs and
comments that said Linux needs the feature say it no longer does.
2026-11-07 06:54:33 -08:00
Anees Iqbal c4ae86719e 🐛 Refuse a panic in a guest op instead of ending QEMU
A Rust panic in the graphics lane's code, a bug that guest input can reach,
ended QEMU: the panic hook aborted before anything unwound, and a refusal
scope would have re-raised the unwind anyway (ledger R099g). The lane's rule
is that no guest input ends QEMU (docs/graphics-kext/design.md, "Guest input
the host refuses").

Inside a refusal scope the hook now writes its line and lets the panic
unwind, and the scope answers it as a Refusal of DeathId::Panic, logged at
ERROR as the bug it is: the op is refused as for a death there. Outside every
scope (the paravirt device, the host's calls) a panic aborts as before.
Under the test capture a panic still fails its test, passing every scope, so
the decoder's fuzz and every test's assertion in scoped work still fail.

What the guest and the host see changes: an op whose decode panics is
refused (its create unanswered, its command buffer failed, a completion
handler's work ended alone) where QEMU ended before.
2026-11-05 21:59:35 -08:00
Anees Iqbal 422eab5b82 🐎 Run an isolated task's exec job and reply on the FIFO thread
Each exec (op 55 or 67) of an isolated task waited for four woken threads in
turn: the connection queue's worker delivered the message, the service queue's
worker ran the job, the link queue's worker ran the reply, and the FIFO thread
woke on it. On the M3 Max, in a macOS 26 guest's Finder drag at 120 Hz, those
hand-offs were 0.41 ms of the FIFO thread's 1.41 ms of execs a frame on the
Metal platform, and 0.48 to 0.9 ms a frame on the Vulkan one; a trace on an
Iris Xe put them at about 0.15 ms an exec, 6 ms a frame.

The FIFO thread now delivers the exec itself (ServiceLink::send_here): it takes
the connection queue's turn and then the service queue's, with
SerialQueue::sync, and the service runs the job there, as the task's code. The
reply, made on that thread, runs there too when the link's queue is idle with
nothing queued: its turn on that queue (SerialQueue::hold_if_idle, a held turn
that waits for nothing and wakes no one) is taken under the state lock, under
which every hand-over to the queue happens, so it keeps its place in the order
of the service's messages and replies, and runs outside the task's code, as on
the queue's worker. When the link's queue is busy, its worker runs the reply
as before.
What the delivery holds with no holder goes when it returns
(rt::held::LastResortScope), as the queues' workers release theirs.

Messages still reach the service in send order, jobs run in arrival order, and
replies run in the order the service made them. A death in the job unwinds to
the delivery's TaskLife::run and ends only the task, whose FIFO sees status 4.
The FIFO thread waited for the reply before as well: what changes is which
library thread runs the job and the reply, which the contract leaves free. The
FIFO thread's stack grows from 512 to 576 KiB: a queue worker's 512 KiB for the
job, and room for its own frames.

It is always on, with no switch. A cold-cache macOS 26 boot on the Vulkan
platform once stalled before its menu bar with it on; cold boots showed the
same stall with it off (a pipeline compile into empty caches held an exec past
the guest's own 10 s check), and warm boots were clean either way.

The tests of the queues' workers that the delivery now skips take its path,
and the reply's worker path is tested through a busy link queue. A drop-order
test's scripted service blocked in its exec handler until the test thread
opened a gate; its GPU completion now comes from a thread of its own, as a
Metal completion handler's does.
2026-10-28 22:55:25 +02:00
Anees Iqbal 094a50318a 🆕 Draw the guest's cursor where the guest moves it on its own
Issue #135: with the mouse passed through to the guest (QEMU's usb-host), the
window drew the guest's glyph at the host's pointer, which never moves, while
the guest's cursor moved elsewhere.

At each cursor doorbell the window now reads the guest's cursor position
through its sink, via the display's core, which the callback's block holds.
A change of position with no pointer event of the window's in the second
before means something else moves the cursor: a passed-through mouse, or the
guest placing its own. The window then draws the guest's cursor into its
image at that position, and the host's cursor is invisible over the image.
The window's next pointer event gives the cursor back to the host's pointer.
A doorbell that moves nothing (a show, a hide, a glyph change) changes
nothing. The lead is timed on the platform's clock. There is no option: the
window decides from what the guest does.

The glyph is a second draw in the display's own render pass, after the
frame's and before its endEncoding (DisplayCore::encode_current_frame_with
and an OverlayDraw), so the target is stored once, with no pass that loads it
again. The host's encode_current_frame is unchanged and draws no overlay.
- The draw uses the display's own quad buffers over a viewport that is the
  glyph's rectangle, clipped to the image by a scissor.
- The pipeline is the display's overlay pipeline, kept in its cache and made
  of its functions (DisplayPipelineCache::overlay_for). Colour attachment 0
  blends premultiplied (RenderPipelineDesc::blend_over, on Metal and Vulkan).
- The glyph's texture holds it premultiplied, so a scaled glyph's filtered
  edges keep their colour.
- The runtime hands a viewport to Vulkan as it is, so a glyph whose viewport
  would reach past the least bounds Vulkan sets every device ([-8192, 8191],
  4096 wide) is not drawn: only one at the far edge of a window over 8000
  pixels across.

Nothing the guest reads moves for it: the pass makes no buffer, and on the
Vulkan platform the glyph's texture is the platform's own
(VulkanDevice::new_own_texture: no resource ID, no range of Metal's space).
The pipeline and the texture are made before the display encodes the frame,
outside the time a guest's present waits on. The position is read without
dying while the guest display is paused (DisplayCore::guest_cursor_position).

Tests: the lead and the doorbell's read; the placement, the clip and the
viewport bounds; the overlay draw's place in the display's pass; pixels
on Metal and on the Vulkan platform through SinkDisplay::encode, at 1:1,
scaled, letterboxed and clipped; the own texture's ID and address; the
blending pipeline value on both platforms. features.md gains the entry, with
a manual walk owed.
2026-10-26 20:51:10 +02:00
Anees Iqbal 28aecd0f04 🎨 Move the development scripts to scripts/internal
scripts/ mixed the one script a person installing reims-ctl runs,
install-ctl.sh, with eight that only developing the project runs: the worktree
and build environment, the GPU locks, the VM boot and tour drivers, the window
walk and the IOSurface qtest. Those move to scripts/internal, so scripts/ holds
what users run. run_vmapple.sh, walk_window_macos.sh and vm_drive.py find the
repository from their own path, one level deeper now; every reference in the
docs, the Makefile, the video crates' tools and the code's comments follows.
2026-10-26 14:08:39 +02:00
Anees Iqbal 24683a8a5a ✅ Hold the GPU-faulting and busy-kernel tests to intent
Tests that pass alone failed under the check's load:
- client_direction's GPU-faulting test failed 9 to 14 others of each
  check on the M3 Max; it runs first and alone;
- the Vulkan crate's paging and unmap tests held work in flight with busy
  kernels sized for the M3 Max, too short on an RTX 5080 Laptop GPU; each
  holds as long as it means, through gpu::spin;
- Metal's compute answers are made in a child the test restarts when the
  compiler service crashes;
- a released ICB's ID may come back once the handlers ran, timed by the
  crate's clock.

docs say what a busy kernel holds and what it cannot, and tie a compiler
crash's client to its binary.

Source: 3ff3ef405 f278b85aa 88b524c90 92ffe0067 38bd30f60 084cad5ae c442c1d44
        294a44dcf
2026-10-26 12:24:31 +02:00
Anees Iqbal 3547942461 🐛 Fix Metal's deallocator callouts, resolver throws and no-draw pass
- A no-copy buffer's and a descriptor's deallocators ran core's closures on
  Metal's threads unmarked, so a panic unwound into Metal's frames; each
  now marks its thread for the call.
- A death inside an isolated task's function resolver unwound through
  Metal's deserializer frames. The context catches it in
  functionWithFunctionRef: and carries it across them, and a raise Metal
  answered past lands in the send's hold.
- A dead isolated task's IOSurface references leak, as its other handles
  do, and REIMS_VGPU_TRACE writes a timed trace on Metal too.
- The macOS 27.0.1 hang workaround made its no-draw pipeline at every pass
  over a mutable rate map. A pass is now marked, a draw of at least one
  whole triangle (3 vertices, an instance or more) removes the mark, and
  endEncoding makes the pipeline only for a pass still marked.

For the guest: an ICB-capable pipeline's uniqueIdentifier is Metal's own
until the first pass over a mutable map that ends with no such draw, where
it moved from the first pass over a mutable map, drawing or not. The
rate-map suite cases pass unchanged, so no expected file changes.

Source: f27786809 affb99292 24b5acbfe 165cad0bc e8409d961 c2eec45a8 9b0dfdb79
        8b2cd7ebb 79e3df85c
2026-10-26 12:24:31 +02:00
Anees Iqbal 4097f5ee52 🐛 Fix core's 2^64 allocations, raced stores and IOSurface lookups
- The root task's allocator rounded sizes and block ends with wrapping
  arithmetic, so a request near 2^64 could take a block it never held. Such
  a request now fails and changes nothing; no guest or host reaches it
  today, as every root-task mapping is at most 2^32 bytes.
- Two FIFOs of one in-process task binding a resource's guest pages at once
  could each make a transfer buffer, and the second store released the
  first. Apple's framework keeps the overwritten buffer (read in macOS
  27.0.1's ParavirtualizedGraphics), and now every kind keeps it too.
- The IOSurface device lookup that the mapper service and the video and
  scaler devices make on their own threads retained the device, so a host's
  last release during a lookup left the teardown to the lookup's thread. The
  lookup now never retains the device.
- A test pins the hang of an EFI display ending a display as Apple's
  framework's own, and three docs say what the code does.

For the host, under those races alone: it gets no unmap of the overwritten
transfer buffer, the GPU VAs placed after it are numbered after it, and its
last release of an IOSurface device always runs the teardown on its own
thread.

Source: 26e0df468 e3babe69d c855160f3 18f681533 31a47a52b befc42c4a 15790979b
        9c62ee575 022e74743
2026-10-26 12:24:31 +02:00
Anees Iqbal 30c7cd604b 🆕 Capture the pointer with the keyboard, held over the image
A click into the image captured only the keyboard: the host's pointer could
still leave the window for the bars, the title bar or another app, where a
click meant for the guest's edge landed on the host instead. Capture now takes
the pointer too, and never one without the other: while captured, the host's
pointer is held over the image, and ⌃⌥⌘ (Ctrl+Alt+Super on Linux), Release
Input, losing focus or closing frees both.

On AppKit's window the hold is NSWindow's mouseConfinementRect, the property
SDL3 confines its macOS windows with, which AppKit leaves out of its headers;
a window that does not answer it leaves the pointer free and logs one line.
On SDL's windows it is SDL's mouse rect, rounded out to whole points so the
image's last row and column stay in reach, which SDL keeps with the
compositor's pointer constraints on Wayland, XFixes barriers on X11 and the
same property on macOS; where SDL has no mouse rect, its mouse grab holds the
pointer in the whole window. In native full screen an image that reaches the
screen's top or bottom edge takes the pointer there, where macOS slides its
own menu bar or Dock in.

features.md, README.md, docs/api.md, docs/architecture.md and the module docs
say so. The macOS walk releases capture wherever a step needs the pointer off
the image, captures before Finder takes focus in C4, and walks the hold at
each edge and corner (C2), at the window's edge (C2e), across Mission Control
(C2m), in full screen (C2f) and after a mode change (M4), which only a
person's own mouse shows: a warped pointer, or one moved by events posted at
the HID tap, is not held.
2026-10-19 02:47:57 +03:00
Anees Iqbal afdb76f844 🆕 Give every x86-64 VM the IOSurface device over PCI
An x86-64 macOS guest running Apple's arm64 GPU driver, ported, needs the
IOSurface host device vmapple has as apple-gfx-mmio's second region: the
driver's start waits for its mapper's service, and every texture over an
IOSurface is a mapper texture. reims-ctl now gives every x86-64 VM on
reims-vgpu that device, with no opt-in, and Apple's own x86-64 driver keeps
running as before.

For the guest:
- apple-gfx-iosurface-pci (106b:eeef, ours) sits at 00:06.0 next to the GPU
  at 00:04.0: its registers in BAR 0 at 0x1000, 8-byte accesses passed
  whole, one MSI vector per completed command. A reset returns its
  registers to 0, ring size aside.
- 0x1028 offers the second, 0x400-byte descriptor form only where its table
  holds all 8192 mapping ids (16 KiB pages); on x86-64's 4 KiB pages it
  reads 0, and the guest's mapper takes the first form, which fills them.
- On apple-gfx-pci, a task other than task 0 runs isolated only if the
  IOSurface device has a descriptor table when the guest defines it, and
  device info offers argument buffers (key 33 bit 0x20, key 42) only while
  it has one. Apple's x86-64 driver, stock (binary version 6) or patched by
  reims-util (245), never programs the IOSurface device and makes ref
  textures whose backing is in task 0, which an isolated task does not
  serve (testing.md 6.20); its tasks stay in process and its device info
  is as without isolation. The ported driver's mapper programs the device
  before its GPU driver starts, and its tasks run isolated, which its info
  replies need. apple-gfx-mmio still isolates every task.

For the host:
- apple-gfx-pci has no option for this: adding apple-gfx-iosurface-pci is
  the only switch, and a VM without it runs as before. Its gpu link is
  optional, the machine's only apple-gfx-pci when unset. vendor/qemu moves
  to bd95509a.
- RvgDeviceConfig gains process_isolation_follows_guest at its end (64
  bytes; a host that passes 56 reads it false), and the Rust API's
  DeviceConfig the same field; apple-gfx-pci always sets it with
  use_iosurface_mapper and process_isolation. Each task made under it logs
  whether it runs isolated or in process, and device info logs each change
  of its argument-buffer answer.
- reims-ctl's q35-x86_64 profile adds
  apple-gfx-iosurface-pci,id=iosfc,gpu=gfx,addr=0x6; vmware-svga and
  vmapple VMs are unchanged. reims-ctl and QEMU from this commit go
  together, as its installer installs them.
- On Linux, the detach heap's temporary and a writable alias with zeros
  past its pages come from a range of a file of the library's own, so the
  Vulkan platform can alias and import them; QEMU no longer ends at an
  x86-64 guest's first such heap. macOS is unchanged.
- The first command given to a task whose service has died writes one
  warning naming the task.
- scripts/qtest_iosurface_pci.py checks the device under qtest (27 checks).

Checked: cargo xtask check and the suite on the M3 Max; reims-ctl's install
and a cold boot on um780; stock, reims-util and ported-driver guests booted
on gem10 and ms01 with the isolation rule, Apple's driver's tasks in
process at about 62 fps, the port's isolated.
2026-10-17 06:43:31 +03:00
Anees Iqbal 39d6ca78ef 🆕 Make new x86-64 VMs from reims-util's macOS downloads
A new x86-64 VM needed an OpenCore image and an installer made by hand with
OSX-KVM or ULTMOS. reims-ctl now runs reims-util for both: pick a macOS
version (n in the interface, create --macos on the command line) and it
downloads the installer from Apple, makes the VM's OpenCore image with OVMF
and a Mac identity of its own, and makes the disk.

- create --macos VERSION downloads Apple's recovery image (about 1 GB), or
  with --offline an installer of one release (13 to 20 GB). Installers are
  kept in the data directory's installers for the next VM, one reims-util at
  a time writes there, and a stopped download continues. The download comes
  before the VM's directory, so stopping it leaves no VM half made, and
  reims-util ends with reims-ctl on Linux. What create is given (a disk, an
  installer, an OpenCore image and the OVMF beside it, reims-util itself) is
  checked before the download and the disk's copy, and the VM list is read
  again before the VM joins it, so VMs made or deleted during a download
  stay as they are.
- --opencore is optional: without it reims-util makes the image, with the
  VM's MAC as its ROM, and an iMacPro1,1 for macOS 10.13 and 10.14. An image
  of the user's brings OVMF_CODE.fd and OVMF_VARS.fd beside it, as
  reims-util writes them.
- The interface's form asks where macOS comes from, the version first; with
  no name, the VM takes the version's, skipping names a VM or a leftover
  directory has. A VM with an installer says in its details, and create
  prints, how to install macOS from it; one made from a disk is reminded to
  set Metal's error mode.
- A new disk needs an installer or a download: a VM of an empty disk and no
  installer is refused.
- Every installer attaches as a read-only disk (snapshot=on), a DMG
  converted to a raw image in the VM's directory, so the CD drive is gone: a
  change of installer applies at the next start. vm.toml's installer_kind
  is no longer written, and is ignored where an older vm.toml has it. A
  missing installer says how to eject it.
- reims-ctl __record-install, which scripts/install-ctl.sh runs last,
  installs reims-util at the commit reims_util.rs pins, so the update that
  brings this reims-ctl installs it too, though it runs the script it
  started with. doctor checks for it in place of the system's OVMF, and the
  install no longer adds the ovmf or edk2-ovmf package.
- vm.max_map_count: a new VM's default of up to 16 GiB needs about 1.13
  million mappings, more than the 1048576 suggested (CachyOS's stock
  value). The README, the install script, doctor and the start warning
  suggest 2097152, which covers 30 GiB, and check against what the VM, the
  largest VM or a new one's default needs.
- Updating from the interface while a create runs says the restart stops
  it, as quitting does.

Dropped, as reims-util's images leave nothing for them to cover:
- create --from-script and the interface's launch-script import, which read
  OSX-KVM's and ULTMOS's QEMU scripts. A VM made from one keeps working; its
  vm.toml names its own copies.
- The search for OVMF beside a user's OpenCore image in those projects'
  layouts, QEMU's edk2 build and the distributions' packages, and
  --firmware-code and --firmware-vars.
- create --disk-mode overlay: copy, a reflink where the file system can, or
  in-place covers an existing disk. A VM made with an overlay keeps working.
- --cpu-model and --cpu-flags on create and set, and the edit form's CPU
  fields: new VMs take Skylake-Client-noTSX-IBRS. vm.toml keeps cpu_model
  and cpu_flags, so an older VM keeps its model; docs/qemu.md says how to
  change it there.
- --installer's --iso and --cdrom aliases.

README, the help and the docs no longer point at OSX-KVM or ULTMOS. README
step 3 describes reims-util's OpenCore picker (5 seconds, which an arrow key
stops, measured on homelab-ms01), and architecture.md 11.4 counts its image
among those that keep AvoidRuntimeDefrag on.
2026-10-12 19:37:12 +03:00
Anees Iqbal a811de7fd0 🐛 Show installers and recovery the EFI framebuffer in BAR 2
macOS installers and recovery images ship no AppleParavirtGPU, so the only
driver that binds the device is IOGraphics' IONDRVFramebuffer, which takes
the EFI boot framebuffer over only when it lies inside one of the device's
memory BARs. The option ROM gave the Graphics Output Protocol its
framebuffer in guest RAM, and the device had one register BAR, so the
installer's WindowServer found no usable display, aborted and started
again and again, the screen frozen on the Apple logo's progress bar.

vendor/qemu's 1a72df98 gives apple-gfx-pci a BAR 2: a 64 MiB window (the
efi-framebuffer-bar property, on by default) holding one alias of the
machine's RAM. After a guest write to 0x1210, QEMU reads the start back
from the library and shows the run of RAM there, up to 64 MiB and never
past what the guest sees of that RAM (so not SMRAM); only the next 0x1210
write and a reset change it.

The option ROM, after it writes the framebuffer's start and length (0x1210,
0x1214), asks PCI I/O for BAR 2's attributes: a memory BAR at least as long
as the buffer, below 4 GiB and with no address translation. It then writes
a pattern and its complement into the buffer's first and last dwords and
reads each back through BAR 2, restoring the dwords. When all four read
back, the GOP's FrameBufferBase is BAR 2's address; otherwise it is the
buffer's own, as before. The buffer stays runtime services data in RAM:
Blt draws into it, the registers name it, and the device presents it, so
the library, its C API, the suite and the pins are unchanged. Those pages
stay the framebuffer's only while the loader keeps boot.efi from moving
runtime data, as OpenCore's AvoidRuntimeDefrag does; the ROM's comment and
architecture.md 11.4 say so.

What the guest sees: one more memory BAR on apple-gfx-pci, which shows the
EFI framebuffer from the ROM's 0x1210 write until the next one or a reset,
and a GOP framebuffer at that BAR's address, which boot.efi hands the
kernel; on a device without BAR 2, the RAM address as before. The ROM's
size is unchanged (5,632 bytes); its bytes change.

docs/qemu.md and docs/architecture.md 11.4 describe BAR 2 and the ROM's
probe, and what the boots measured on the RTX 5080 Laptop GPU host: the
macOS 26.6.2 BaseSystem reaches its Recovery UI (kernel framebuffer at BAR
2, WindowServer started once), and the installed macOS 26 guest reaches
its desktop with BAR 2 on and off, its late draws to the boot framebuffer
landing in RAM.
2026-10-12 00:48:55 +03:00
Anees Iqbal 98fe2a3bd5 🆕 Replace the tree with libreims_vgpu and its C API
This repository now holds libreims_vgpu, a Rust library that is the host
side of the paravirtualized GPU macOS guests drive, in place of Apple's
ParavirtualizedGraphics.framework: the library and its C API
(reims_vgpu.h), the PCI device's option ROM, QEMU's apple-gfx on that API
(vendor/qemu), the behaviour-lock suite that drives the C API as QEMU
does, and reims-ctl, the VM manager users run. README.md says what it is
and how it is laid out, and AGENTS.md how to change it.

Every file of the earlier tree is replaced. vendor/qemu moves to the
steelbrain/reims-vgpu branch of the same public repository.
2026-10-11 20:27:17 +03:00