Commit Graph
1014 Commits
Author SHA1 Message Date
Anees Iqbal 2f67f20468 📝 Record the dropped POOL_BLOCK answer in the lessons [ci skip]
A boot found it: the kext's event handler routed answers from a list of its
own, POOL_BLOCK was not in it, and POOL_TAKE's waiter, asleep uninterruptibly
with no deadline, hung WindowServer for good with no fatal line on the host.
Say how to spot the next one.
2026-11-19 00:00:12 -08:00
Anees Iqbal 648d627bfa 📝 Describe the Shared pool and its slabs [ci skip]
design.md gains "The Shared pool", which the wire, the host and the kext
cite: the range and who gets it, a take and its wait with no deadline, the
heap over a block, a give and a close, what moves to the pool and what stays
in the region, and why no empty slab of the pool is kept. The slab section
says the pool comes first where the device has one.
2026-11-19 00:00:12 -08:00
Anees Iqbal b2cbf70558 🆕 Map the Shared pool's blocks into the x86-64 kext's processes
The x86-64 kext takes the device's POOL where offered, and sets its own Pool
bit (1 << 15) where it did. A process takes a block through selector 16
(PoolTake): the kext posts its context's POOL_TAKE, maps the block the host
answers with into the process write-back, and lists it. It gives the block
back through selector 17 (PoolGive): the kext unmaps it, then posts the
POOL_GIVE. At the client's close the kext unmaps every block it lists before
the CONTEXT_CLOSE, which gives them all back. HEAP_OVER_POOL joins the
context ring's commands a process submits itself.

The take waits for the host's answer with no deadline, THREAD_UNINT like
the kext's other asks of the host: the host answers each take of an open
context, and the close waits for its takes in flight, so the kext never
gives up on a take whose answer then comes late. Where the host stops
answering, each taking thread waits, holding one of the 32 lifecycle
waiters, until it does.

The arm64e kext takes no POOL and sets no Pool bit: selectors 16 and 17
answer kIOReturnUnsupported there, and its processes keep the region's
blocks and the kext's chunked pages. Selectors 16 and 17 are numbers the
sandbox lets a web content process call.
2026-11-19 00:00:12 -08:00
Anees Iqbal 245e28e1e8 📝 Give the WHPX populate's times at memory priority 5 [ci skip]
The times recorded came from a job at potluck's memory priority 4, which
Windows trims and a user's QEMU does not run at (docs/lessons.md). A run at
5 populated 256, 548 and 1024 MiB in 40, 71 and 119 ms, where the run at 4
took 37, 86 and 151 ms.
2026-11-18 22:08:45 -08:00
Anees Iqbal 74dcaf7723 📝 Record the pool populate's BQL holds and walks [ci skip]
The walks on the 3090 and the 780M measured what the populate costs and
saves: a removal's BQL hold back under 0.8 ms with its slot delete on the
library's thread, adds as before at the median with a 3-of-72 tail of single
slot creates, and no workload slower beyond the walks' spread.
2026-11-18 22:08:45 -08:00
Anees Iqbal 20ddeba97f 🐎 Move vendor/qemu to the removed piece's slot delete off the BQL
The populate maps a whole pool piece, so KVM's delete of a removed piece's
slot zaps all of it: 3.0-8.3 ms for a 256 MiB piece on the 780M and 3090
hosts, under the BQL, where a removal held it 0.8-1.4 ms p50 before the
populate. QEMU's 7ad9c809 deletes the slots on the library's thread before
the removal is queued (kvm_unmap_before_del), as WHPX unmaps a removed
piece there, so the removal's transaction finds no slot.
2026-11-18 22:08:45 -08:00
Anees Iqbal 6f733d6e78 🆕 Pre-fault the guest's Shared pool pieces in QEMU
QEMU's reims-graphics-pci now fills the second-level tables of each pool
piece once its add is answered, on a thread of its own in 2 MiB slices, so
the guest's first touch of a piece takes no fault where it took one a 4 KiB
page: 140,289 for 548 MiB, 184 ms on um870's 3090 and 262 ms on um790's
780M under KVM, and 1.3 s on the Windows mini under WHPX. Under KVM the
call is KVM_PRE_FAULT_MEMORY on a vCPU of the thread's that never runs,
which keeps KVM's master clock on across guest reboots and is never waited
for under the BQL; under WHPX it is WHvAdviseGpaRange's populate.

vendor/qemu moves to b561d79c (dd0e0d4a..b561d79c on 0590cfde), and
docs/qemu.md says what the populate does.
2026-11-18 22:08:45 -08:00
Anees Iqbal c6ab041d68 🆕 Record a no-copy buffer's escape in the replay stream
metal2vulkan's replay player must stop, typed, where the GPU may reach a
no-copy buffer through an address in memory alone. The guest says so with
BUFFER_ESCAPED, but the note ended in the decoder: no stream carried it, and
only the stats file's counted totals showed it.

The decoder's first note for each buffer now also records it, where the
process records (REIMS_VGPU_RECORD): an m2v.bufferEscaped call on the
buffer's stream id, [kind], the note's RGFX_BUFFER_ESCAPED_* act (0
gpuAddress, 1 argument encoder, 2 resource id, 3 residency set), of the whole
buffer. It is queued on the decoder's thread at the note, so it lies after
the m2v.write records of each commit made before the note and before those of
each commit made after it. A later note, a note for a refused create and a
bad reference write none. Each record is counted by its selector in the stats
file, and the recorder_fix "buffer-escaped" names the change.

Nothing changes for the guest or the C API's host. With REIMS_VGPU_RECORD
unset the note costs one more relaxed load (recorder::on).
2026-11-18 22:08:45 -08:00
Anees Iqbal bce35ba434 📝 Say when the scanout's zeros are written and what they cost [ci skip]
The pass that zeroes the scanout's room for a new owner runs only when a new
WindowServer process opens the server connection, never at boot or on the
same WindowServer's reopen. It zeroes the display's whole share, so the host
backs all of it from the first replacement on. The paragraph now says so, with
the measured stores on KVM (103 ms) and WHP (802 ms).
2026-11-18 22:07:13 -08:00
Anees Iqbal 02c8dcdf49 📝 Record WHPX first touch and the memory-priority trap [ci skip]
Measured on the UHD 630 Windows host, a guest page under WHPX costs about
20 us the first time the guest touches it, guest RAM and the device's
region alike, and a page the host already backs about 1.5 us. qemu.md now
holds those costs, the region's use at the desktop, and the largest
first-touch burst between two presents, so later sizing reads them there.

The same runs found that potluck's Windows jobs start at memory priority 4,
and that Windows trims a priority-4 QEMU's working set with tens of GB free:
703,604 RAM and 9,637 region pages in one walk, each costing 19 to 32 us to
fault back, and none at priority 5, which a user's shell gives. lessons.md
records the trap and how to spot it, since a timing taken in such a job pays
faults a user's VM does not.
2026-11-18 21:59:53 -08:00
Anees Iqbal 3c6f085a75 🐎 Keep the kernel's mappings for new blocks' zeros
The kext zeroed each span of a new block through a kernel mapping it made for
that span and took down after it. Over a boot to the desktop and a probe's 905
new bodies (rzboot2, a macOS 26.7.2 guest on a 780M host), making and taking
down those mappings took 402.5 ms of the zeroing's 433.3 ms, and they were its
longest waits at boot: 114 ms for one staging chunk, 19 ms for one surface
header.

The kext now maps the blocks' range into the kernel once for each cache mode at
its start, write-back from the region and write-combined from the region's
write-combined descriptor. It keeps both mappings for the kernel's life, as it
keeps the doorbells' mapping, and writes a new block's zeros through them, so a
block's zeros cost only their stores. The kept mappings hold the kernel's
address space and page tables only, and none of the host's memory: no page of
the region is touched until it is zeroed or used. On a Windows host (WHP) the
kext's zeros are the first touch of a region page that was never touched
before. Where the kernel will not make a kept mapping, each span is mapped
alone, as before. The kext logs each kept mapping's size and how long it took
to make, once at its start.
2026-11-18 20:55:11 -08:00
Anees Iqbal 712a08e435 🐛 Zero the scanout's room before a new owner can map it
The scanout's room holds the display's pixels, and the region keeps them past
the process that wrote them. A task that opened the framebuffer's server
connection after another (the next WindowServer, after a crash or a logout)
was handed the room through the VRAM range, a surface lock or the scanout
grant with the last owner's last frame still in it.

The framebuffer now zeroes the display's room when a task that is not its
last owner opens the server connection, through a write-back mapping, the mode
the windows and the locks map the scanout in. The task owns nothing until the
zeros are in, and every other task's hold of the scanout is taken back first.
A room the kernel will not map for the zeros fails the open. The last owner
opening again keeps its bytes, and the first owner finds the boot screen,
which no process wrote and which the first present clears, as before.

What the guest sees: the screen shows black, not the old owner's last frame,
from the new owner's open until its first present. The pass is one zeroing of
the display's room, up to 128 MiB, per new owner, logged with its mapping and
store time.

scanout_owner_test checks that a new owner's first read of the room is zero
and that it owns nothing before, and that the last owner's open again keeps
its bytes.
2026-11-18 20:48:32 -08:00
Anees Iqbal 82a8d1b00d 🐛 Zero each new region block before a process's window maps it
A region block's offset goes to any process once the device answers its
release or its holder's close, and the region keeps its bytes across the
device's reset and the guest's reboot. A new block held whatever its last
holder left: another app's command buffers' bodies, its shader library's
staging chunks, its buffers, or a surface copy of its window's pixels.

The kext now writes zeros over every span a window maps of a new block
before the window maps it, each through a kernel mapping of the cache mode
the window maps it with (write-combined from the region's write-combined
descriptor, write-back from its own), and allocBlock maps from the same
spans, so what is zeroed is what is mapped (RgfxBlockZero.hpp). A surface's
new block is zeroed over the part its holders map: the whole copy for a copy
block, the header for one in place. A span the kernel will not map fails the
grant. A block held again (a shared or revived surface block) and a pages
block, never in a window, are left.

The kext logs what the zeroing took by kind (bodies, split, write-back,
surface copies, surface headers), and offers it as feature bit 1 << 14
ZeroedBlocks, after which the bundle takes the region's slabs as clean
rather than zero them again. block_zero_test checks the spans and the
cross-process cases natively; guest/bundle/tools/block_zero_probe.c checks
them in a guest, a block filled by one process and read by the next.
2026-11-18 20:48:32 -08:00
Anees Iqbal 3eab605b32 🆕 Count the commits of a process holding an escaped read-only copy
On Linux and Windows, a no-copy buffer over pages the process maps read-only
lies over a copy of those pages. Once such a buffer's identity has escaped,
the GPU may read the copy through memory after the guest's CPU has changed
the pages, with no binding naming the buffer. This commit records how often
that situation arises, and pins the runtime behaviour that keeps it correct.
The behaviour is unchanged: the decoder adds nothing to any command buffer.

Metal requires an encoder to make resident (useResource:usage:) any buffer a
function reaches through memory, and that names the buffer as a use. At the
commit, the runtime copies in every copy that a command buffer's uses name,
and every copy where its work may reach memory that no use names
(metal2vulkan's command_buffer/mod.rs:4747-4772 at the pinned commit, which
picks the copies at 4754-4766). A reach of a buffer that no encoder made
resident is undefined in Metal, and on the runtime it reads zero
(residency.rs).

What the decoder adds is bookkeeping:
- each process's count of its live escaped copies (Context::escaped_copies),
  which a copy joins at its first note and leaves when it is dropped;
- escaped-copy-commits, which counts each command buffer begun by a process
  that holds one, in the degradation counts line and the recorder's stats.
The first such command buffer is logged at info.

on_vulkan_an_escaped_copy_reached_by_its_address_reads_the_cpus_writes pins
today's runtime. A kernel reaches the escaped copy only through an address it
loads, with the encoder having made the copy resident. It reads the pages' old
bytes, then their new ones after the CPU's write.
2026-11-18 19:52:35 -08:00
Anees Iqbal 8447199fee 🆕 Note a no-copy buffer's identity the first time it escapes
The host reads a no-copy buffer's bytes in place. The guest's Metal can hand
that buffer's identity to the app, or write it where the GPU reads, with no
message naming the buffer, and from then on the GPU may reach the buffer
through memory alone. The host had no way to know which buffers that happened
to. This commit adds a note for it, so the host can tell them apart.

The note is RGFX_CMD_BUFFER_ESCAPED (0x23b), RgfxBufferEscaped of 32 bytes:
the buffer's object id and the act, one of GPU_ADDRESS, ARGUMENT_ENCODER,
RESOURCE_ID and RESIDENCY_SET. The device offers it as
RGFX_FEATURE_BUFFER_ESCAPED (bit 56), and both kexts carry it. The submit gate
takes it in a batch, like a Managed range's write: unwaited, a fixed size,
naming no block and making no object.

The bundle marks each covered buffer as it is made (_rgfxEscape, set by
rgfxOwesEscapeNote) where the host took the feature. The first of these acts
in the buffer's life posts the note, before the act returns:
- a read of the buffer's gpuAddress;
- an argument encoder's setBuffer(s) of it, or setTexture(s) of a texture or
  view over it;
- a read of such a texture's or view's gpuResourceID;
- the buffer, or such a texture, joining a residency set.
Every later act is one relaxed load.

Wire order holds the note ahead of any command buffer that could use the
identity. The note goes on ring 0, posted or held in the serialiser to go
before the next commit's messages, and the device carries out a command buffer
only after every ring-0 message its process posted before it. Across threads,
the act's slow path posts the note under the buffer's lock and then clears the
mark with a release store. Every commit takes an acquire fence before it posts,
so a commit after an act that found the mark clear posts after the note.

The covered buffers are the app's no-copy buffers over its own pages
(BUFFER_OVER_PAGES, writable or read-only, bit 24) and over bytes already in
a block of the process (BUFFER_OVER_HOST_MEMORY). Managed buffers, heaps over
pages, IOSurface shadows and buffers placed in a slab's heap
(BUFFER_AT_OFFSET) are not covered.

A slab buffer made with an address of its own is covered too: a Shared buffer
past 2 MiB over a slab of the process's own pages, a device buffer, or a
no-copy buffer's shadow (RgfxSlabSource::Made's ownsAddress). It reaches the
host as the same BUFFER_OVER_PAGES or BUFFER_OVER_HOST_MEMORY message as an
app's no-copy buffer, and the host takes every such message alike. Leaving
slab buffers out would leave the host unable to read the mark as "this
buffer's identity never left".

The host marks the buffer's entry escaped, once for its life, and a later
note changes nothing. A note for an object that is not such a buffer is a bad
reference. A note for an object whose create the host refused is dropped, as
any naming of one is. Escapes are counted in the degradation counts line and
in the recorder's stats (`counted <code> <n>` lines), with no new stream
records:
- buffer-escaped-gpu-address, -argument-encoder, -resource-id and
  -residency-set, by the act that noted the escape;
- buffer-escaped-read-only-pages, the escaped buffers over a copy of their
  pages;
- no-copy-buffers, every no-copy buffer made, of which the escapes are a
  share.
Each act's first escape is also logged at info.

This changes nothing the guest observes. No one waits for the note, it has no
reply, and the mark changes no answer, object, address or command. Both
prebuilt sets and the option ROM's record are rebuilt from these sources. The
ROM's bytes do not change: its record changes only by the wire header's hash.
2026-11-18 19:52:34 -08:00
Anees Iqbal 9c01dcd1be 📝 Record arm64 guests' TCG boot with the pool past RAM [ci skip]
A cold boot of macOS 26.6.2 under TCG on a Linux host's Radeon 780M passed
check-boot with no fatal line, with the device's pool grown over QMP at the
desktop: under TCG vmapple answers the same 1012 GiB room to 2^40, the max
CPU's 52-bit PARange stopping at 40. The measured block also names the
rebased commits its measurements ran as, since 66e66267 and 818dd28e6 are
no longer on the branch.
2026-11-18 19:15:08 -08:00
Anees Iqbal 8601e15c58 📝 Record arm64 guests' pool room, boot and IPA cost under HVF [ci skip]
Measured on the M3 Max on 11-18: HVF's default and largest IPA sizes, the
room vmapple answered paused and the range the library took of it, a macOS
27.0.1 boot that passed check-boot with the pool grown mid-boot, and the
stage-2 cost of a 40-bit IPA against 36 bits, none measurable. The M2's
largest size is read from a public thread; the M1's and M4's are not known.
2026-11-18 19:15:08 -08:00
Anees Iqbal 5273e0eeb9 🆕 Give arm64 guests' device the Shared pool's room past RAM
QEMU gave the library a pool range only on a PC machine, and an arm64
guest's device on vmapple had none. vmapple now answers the room past its
RAM, from the end of RAM rounded up to 1 GiB to the end of the guest's
physical addresses (the CPU's PARange, at most 40 bits), as read-only
machine properties, and reims-graphics-pci gives the library that room
where no PC host bridge answers one, reserving nothing where the machine
has no fw_cfg. Ambrosia lists RAM alone, so the guest places nothing
there; it is told of no piece yet. x86-64 guests' pool is unchanged.
2026-11-18 19:15:08 -08:00
Anees Iqbal 48293e5f80 🆕 Give arm64 guests 40 bits of guest physical address under HVF
vendor/qemu's vmapple had no get_physical_address_range, so HVF made the
VM with its default IPA size, 36 bits, and the guest's
ID_AA64MMFR0_EL1.PARange read 36 (HVF clamps it to the VM's size). The
machine now asks for 40 bits, the most macOS's kernel maps (its TCR_EL1.IPS
is 40 bits, read from xnu's source), or for the host's most where that is
fewer, so an arm64 guest on the M3 Max reads PARange 40 and the device has
room past RAM for the Shared pool, which the next commit gives it. KVM and
TCG are unchanged.
2026-11-18 19:15:08 -08:00
Anees Iqbal a39e43e99f 🐛 Cap the pool's room at the end of the host's physical addresses
QEMU offered the library the pool's room up to three quarters of the
guest's physical address space only. A guest may have more physical
address bits than its host (QEMU allows it with a warning; the Windows
mini's Coffee Lake has 39 against the guest's default 40), and a piece
placed past the host's width makes KVM refuse its slot (x86 KVM's
memslot check, read from code); WHPX gets the same cap. Under KVM and
WHPX the room now ends at the host's width too, read from CPUID
0x80000008: the device file builds for every target, where
target/i386's host_cpu_phys_bits is not linked.

What changed for the host: where the host's addresses end before three
quarters of the guest's, so does the room. Measured with the device
realized paused and the 64-bit window pushed so the room starts 4 GiB
below the host's end, the range the library took ends there: at
0x1000000000000 under KVM on a 48-bit Ryzen with phys-bits=52
(m3-max-49283), and at 0x8000000000 under WHPX on the mini
(m3-max-49316); under TCG it runs past both. On the mini's default q35
machine the room is now 487424 MiB, its 39 bits' end less the window's;
the range, the UHD 630's 31 GiB of heaps, is as it was.
2026-11-18 18:42:35 -08:00
Anees Iqbal f4692c7179 🐛 Take a pool piece out of the guest before its block goes back
The pool gave an empty piece's block back to its source and left the
guest's mapping to the source's unmap hook (BlockMappings::unmap), which
the source called before it freed the block, on the pool's thread or its
own. The metal2vulkan runtime deletes that hook, so the pool keeps the
promise itself: it gives a block back only once no thread of the device
holds it and the host has said its piece is out of the guest's address
space, and its close gives every block back only after every hold has
ended. The source may then free any block it gets back at once.
HostBlocks loses its mappings field, and Pool::new takes the source
itself.

What changed for the host: pool_remove comes on the device's pool thread
as the pool gives a block back (an empty piece past RELEASE_DELAY), never
on the source's thread; and a block the source hands out again is placed
and gets a new pool_add, where it used to keep its piece and mapping.
QEMU's x-pool-grow boot (8 asks of 256 MiB) now shows 8 adds and 7
removals (m3-max-49284), where it showed 5 removals before
(m3-max-49031). The release waits for the device's own holds before it
frees the blocks. The guest sees nothing new.

The tests that held "a block taken again keeps its piece" now hold that
it is mapped anew. New tests hold that a piece goes back only once the
host removed it and its hold ended, that one given back before the
host's add answered still waits for its remove, that ready blocks past
two are freed with no word to the host, and that the release gives a
held piece's block back only once the hold ends and asks the host
nothing. All ten fail on the code before this commit. QEMU's comment now
says pool_remove comes on the pool thread.
2026-11-18 18:42:29 -08:00
Anees Iqbal 191daab32a 🐛 Send a render pipeline's tessellation state and call stack depths
A guest's render pipeline drew its patches with Metal's default tessellation
state, whatever its descriptor set: power-of-two partitions, a maximum factor
of 16, no factor scale, constant factors per patch and clockwise output. The
bundle never sent the seven tessellation fields, so the device never saw them.
For the same reason the device never saw maxVertexCallStackDepth or
maxFragmentCallStackDepth, and created every pipeline with a depth of 1.

The bundle now reads each of these properties and sends it. Each tessellation
field travels as Metal's raw value, and tessellationFactorScaleEnabled as a new
flag, RGFX_RENDER_PIPELINE_TESSELLATION_FACTOR_SCALE (bit 8). The depths are
read only where the descriptor answers their selectors (macOS 12 and later);
older guests send 1.

The decoder passes every value through FullRenderPipelineDesc to the runtime's
RenderPipelineDescriptor. A state equal to Metal's defaults becomes the
runtime's `None`, so a pipeline that sets nothing is created exactly as
before. A raw value the runtime has no enumerator for dies at the send, as
every other enumerated field does. The recorder's tag-13 map carries the
values as three keys after privateState: `tessellation`,
`maxVertexCallStackDepth` and `maxFragmentCallStackDepth`.

Guests now see patches tessellated with the partition mode, maximum factor,
factor scale, step function, winding and control point index type that their
pipeline sets. They also see pipelines created with the call stack depths
they asked for.

The tessellation fields and the call stack depths share this commit because
they share one wire record. RgfxRenderPipelineCreate grows from 464 to 496
bytes, with eight u32s appended at offset 464, and both prebuilt sets and the
option ROM's record are rebuilt from these sources. The ROM's bytes do not
change.
2026-11-18 18:12:19 -08:00
Anees Iqbal 785552765f 📝 Record the pool's range and room a 780M boot logged [ci skip]
The boot that checked the sum of the heaps as the pool's range logged the
range, the room QEMU gave and the heaps' total; the room, 725 GiB on
reims-ctl's machine, is far above any lab GPU's sum, so none is clamped.
2026-11-18 17:54:51 -08:00
Anees Iqbal 16ad40298e 🆕 Size the guest's Shared pool's range from all the GPU's heaps
The guest's Shared pool's range of guest physical addresses, which QEMU
reserves and gives the firmware as etc/reserved-memory-end, is now the sum of
the host GPU's memory heaps, every heap, rounded up to 2 MiB and at most the
room the host gives, where it was the heap of the GPU's host-visible,
host-coherent and host-cached memory type alone. A heap's size is how the
driver accounts for memory, not the most it allocates: on a 780M, RADV puts
that type on a 5.52 GiB heap beside an 11.05 GiB device-local one over the same
system memory, so the guest's pool stopped at about 5.5 GiB, while the runtime
takes Shared blocks until the driver refuses one. A guest on a 780M now gets
about 16.6 GiB of pool addresses, on an RTX 3090 about 46 to 47 GiB, on an
RX 7900 XTX about 38.6 GiB; on an Iris Xe, with one heap, 23.24 GiB as before.

GpuDevice::shared_heap_size becomes memory_heaps_total, which sums the heaps
of VkPhysicalDeviceMemoryProperties and needs no buffer to ask which types a
buffer can use. A GPU that answers no heap still gives no pool. The library's
pool line now also logs the room the host gave, so a boot's log shows whether
the room clamps the range. QEMU's code is unchanged: vendor/qemu moves to a
commit that rewords its comments.
2026-11-18 17:54:51 -08:00
Anees Iqbal c3b1330a41 🐎 Cut QEMU's cost of a pool piece's add and removal
With N of the guest's 16 MiB pool pieces in, one add cost QEMU 21 ms of BQL
under KVM at N = 2,000 (13.5 ms under HVF, 43 ms under WHPX), most of it
work that walked every RAM block or flat range: a probe device doing the
add's calls, paused, measured each part. vendor/qemu moves to six cuts, each
its own commit with its measurement:
- set a piece unmergeable inside its add's transaction, so an add commits
  once, not twice;
- place a RAM block in one pass over the blocks sorted by offset, not by
  comparing each block with every other;
- carry out a run of queued asks of one kind in one transaction, answering
  each add once its run has committed;
- render a flat view with a gap at the last insert and a binary search,
  not by moving every later range, with the same views (20,162 compared);
- put a RAM block in the list by its run of one size, with the list's order
  unchanged (4,398 compared);
- find a pool piece by binary search over the pieces sorted by address.

After them one ask at N = 2,000 costs 745 / 779 us (add / removal) under
KVM, 584 / 565 us under HVF and 376 / 370 us under WHPX, and a run of 8
119 / 121, 81 / 70 and 63 / 47 us an ask. What the guest observes does not
change: its pieces, their addresses and the order of the device's answers
are as before. Between free gaps of one size a new RAM block now takes the
lowest offset, an offset of this process's own that no guest sees.

docs/qemu.md gives the before and after per host, with the job ids; what
one ask costs at the 131 pieces a recorded session reached, set beside what
the runtime's own 16 MiB block costs on each host; the rule that a piece
the runtime holds for reuse keeps its region, with what a removal and
re-add would cost; and HVF's costs with many blocks resident and the counts
it maps without a refusal.
2026-11-18 17:54:04 -08:00
Anees Iqbal e74f40cc65 🆕 Name the display library's hash in each recording's stats file
A recording makes the device's own display library with
newLibraryWithSource:options:error: and no arguments, so a stream does not hold
its bytes. metal2vulkan's players now make it from a copy of the committed
shaders.metallib kept beside each stream (NAME.display.metallib), and asked that
each stream's stats file name that library by its hash, so a play can say which
display library it ran. The stats file now writes a display_library line after
recorder_commit: the SHA-256 of the bytes the device loads, in the hex the blobs
directory names libraries by, and their length.
2026-11-18 17:54:04 -08:00
Anees Iqbal b3e2511aa7 📝 Record the Shared heaps that size the pool's range on the lab's GPUs [ci skip]
What the range comes to on each GPU, read with vulkaninfo the way the library
picks the heap, so a range in a trace can be checked against its GPU.
2026-11-18 16:52:13 -08:00
Anees Iqbal 706353df2c 🆕 Size the guest's Shared pool's range from the GPU's Shared heap
The pool's range was a fixed 64 GiB of guest physical addresses, whatever the
host GPU: more than a GPU whose Shared heap is 24 GiB can ever fill, and less
than one whose heap is larger. The range now follows the heap the pool's
blocks come from: metal2vulkan-rt's Shared memory type, the first type with
HOST_VISIBLE, HOST_COHERENT and HOST_CACHED that a buffer of the device's
usage can use, on the GPU device the library opens. The bound is the heap's
size, not VK_EXT_memory_budget's budget: the range is address space held for
the VM's life, while a budget is momentary, moved by other processes, and on
Intel's Windows driver answered past its heap's size; RAM is bounded at each
block's take.

The config's pool range is now the room the host can give. The create opens
the GPU device, takes the heap rounded up to 2 MiB of that room (warning once
where the room is smaller, and giving no pool where no type is host-cached),
and rvg_graphics_device_pool_range answers what it took. The range is read
after the create rather than asked of the library before it, which would open
the GPU device twice or keep one alive without a device. QEMU offers the room
from pci-hole64-end to three quarters of the guest's physical addresses, then
reserves the range the library took, rounded up to 1 GiB, in
etc/reserved-memory-end, still at realize before the firmware runs. The
x-pool-size property goes; 0 and 0 still mean no pool in the C API.

What the guest sees changes: the firmware's reserved-memory-end, and so where
OVMF may put its 64-bit PCI window, follows the host GPU's Shared heap instead
of a fixed 64 GiB.
2026-11-18 16:52:12 -08:00
Anees Iqbal 09205507d3 📝 Say where reims-ctl starts arm64 VMs, and under what [ci skip]
README.md, docs/qemu.md's "arm64 guests" and reims-restore's design say that
reims-ctl restores an arm64 VM from an IPSW and starts it on vmapple with
Ambrosia: under HVF on an arm64 Mac, KVM on arm64 Linux and TCG on x86-64
Linux, and that install-ctl.sh builds the qemu-system-aarch64 it runs there.
2026-11-18 15:58:03 -08:00
Anees Iqbal 776156792b 📝 Record what HVF's map and unmap of a block cost a running VM [ci skip]
metal2vulkan's runtime cutover maps the host-visible blocks it gives the
device into the guest one block at a time, as WHPX does today. The M3's
measurement of that form under HVF (11-18, Hypervisor.framework alone) found
the map cheap at any size, the unmap about 70 ns a touched page, no vCPU
stall and no refault of other mappings, and a first touch of about 1.2 us a
16 KiB page. docs/qemu.md holds the VM measurements.
2026-11-18 15:37:12 -08:00
Anees Iqbal 7efe324717 🆕 Count the buffers made over read-only guest pages, and their KiB
At the runtime's cutover every host makes a no-copy buffer over pages the
guest maps read-only over a copy of them, the Mac included, where today it
imports them in place. To know what that copy costs a guest, the decoder now
counts each such buffer it makes, once a boot, in the degradation counts'
line: `read-only-pages-buffers` (how many were made) and `read-only-pages-kib`
(their bytes' sum in KiB, rounded up).

A BUFFER_OVER_PAGES over a block the kext marks RGFX_SURFACE_PAGES_READ_ONLY
is the only such object: the bundle sends read-only Shared memory there with
bit 24, and a heap, an indirect command buffer's slots or a Managed object's
CPU copy over the block is refused. The count is taken there, in the decoder
every host shares, so it means the same on Linux, Windows and macOS.

The counts' line is where they go: docs/conventions.md lists every kind
counted since the process began there, not degradations alone (the rings'
`vblank-dropped` and `*-post-waited` among them), and says no count goes
elsewhere. On macOS the buffers are no degradation; on Linux and Windows the
runtime also counts their copies, with failed imports, under its own code.

answer.rs gains count_kind_by, which adds an amount to a kind's count.
Diagnostics only: no ring message, value or answer the guest sees changes.
2026-11-18 15:19:15 -08:00
Anees Iqbal aa28476e9d 📝 Name Windows beside Linux and macOS in the window and OS docs [ci skip]
The swapchain, the window's presenter, the display's sink and the window
system's extensions present on Windows too, through SDL's Win32 surface
(os/windows.rs's WINDOW_SURFACE_EXTENSIONS), but their docs said "either OS"
or named Linux and macOS alone. rust-toolchain.toml still named the Metal
platform, deleted on 11-07. caps.rs's table gave a host's naming of its
device by Metal's registry ID (open_device, a handshake) as the reason for
the stand-in; no host names its device so now, and the reason that holds is
that Metal's core count and driver sizes for that GPU are found by that ID.
Comments and docs only.
2026-11-18 14:56:42 -08:00
Anees Iqbal 5d38c7e825 📝 Say the library's hosts are Linux, Windows and macOS [ci skip]
The owner's word (Telegram 1924, relayed by metal2vulkan): the hosts are
Linux, Windows and macOS, and on macOS the library runs on Vulkan, not Metal.
README and the crates' and docs' notes said VMs run on Linux and that the Mac
build was for development and tests. They now say x86-64 guests run on Linux
and Windows hosts and arm64 guests on Apple silicon Macs, and that the Vulkan
platform runs natively on Linux and Windows and over MoltenVK on macOS.
rust-toolchain.toml names Windows' target as shipping too, and a reims-ctl
test's note says the test, not the installer, is Linux-only. AGENTS.md waits
for the owner's own word.
2026-11-18 14:28:11 -08:00
Anees Iqbal cb7f52c9a6 🆕 Name the recorder's build in each recording's stats file
metal2vulkan's stream table reads which recorder made a recording off its
files. The stats file now starts with recorder_commit, the commit the library
was built from, and a recorder_fix line for each change to what a stream holds
since format version 2, in landing order (recorder::FIXES, which each such
change extends in its own commit). cargo xtask dist stamps the commit for its
Cargo steps in RVG_BUILD_COMMIT (git rev-parse HEAD, -dirty where a tracked
file differs); other builds write unknown. Cargo and kache key the Vulkan
crate on the variable, so a dist at another commit compiles it again. The
stream itself and the device's behaviour are unchanged.
2026-11-18 13:56:40 -08:00
Anees Iqbal 6245436399 🆕 Put the platform's GPU times on the device's clock in one place
metal2vulkan's new runtime counts its GPU times on CLOCK_MONOTONIC on Linux
(its ruling of 2026-11-18: lavapipe calibrates no CLOCK_MONOTONIC_RAW domain),
while the device's clock, which the guest's kext maps the device's times by, is
CLOCK_MONOTONIC_RAW. At the cutover every GPU time the platform answers has to
be moved onto the device's clock before the guest sees it.

reims-vgpu-graphics's clock::runtime does that by a paired read (the
platform's clock, the device's, the platform's again; the least bracket of
three), fresh at each conversion, and names the platform's clock in one
constant, PLATFORM. Its one call is the CB_COMPLETE record's GPU start and end
in the decoder: the only platform GPU time that reaches the guest. One pair
moves both, so the run's length, which is what the guest reads, stays exact.

The runtime the library runs today counts the device's clock on Linux and
Windows, so PLATFORM is Domain::Device and the times pass unchanged: no value
the guest sees changes. The cutover sets it to Domain::Monotonic on Linux;
should the new runtime count CLOCK_MONOTONIC_RAW there, the module goes.
2026-11-18 01:00:46 -08:00
Anees Iqbal 285f0bdd69 🆕 Carry a no-copy Managed buffer's create-time bytes on two copies
On a device that keeps two copies of a Managed buffer (hasUnifiedMemory NO),
a no-copy Managed buffer's GPU copy takes the pages' bytes at its create, but
from zeroFrom on, and only didModifyRange: changes it afterwards. The stream
carried a no-copy buffer's bytes only as the writes before its first use, so a
player could not rebuild what the GPU copy held when the guest's CPU writes
since the create were never flushed to it.

Such a buffer's create record now carries the bytes the create copied, read
while the call holds them, a blob where long, as a copied buffer's contents
are: newBufferWithDescriptor:'s contents (the bytes before zeroFrom, nil where
that is 0) and newBufferWithBytesNoCopy:length:options:deallocator:'s first
argument (all of them). Shared and Private no-copy buffers, and any on a device
that keeps one copy, are recorded as before, and the writes before first use
are unchanged.
2026-11-18 00:45:55 -08:00
Anees Iqbal 0ba37884af 🆕 Record each device's identity at each segment's start
A player makes a stream's resources in the forms the recording device made
them, and the device's answers decide some of those forms: a Managed buffer is
one copy where the GPU shares the CPU's memory and two where it does not. The
stream named neither, so a player on another GPU could only guess them.

The recorder now writes an m2v.deviceIdentity call record on each device,
answering its name (the one the guest's device info gives) and
hasUnifiedMemory, right after the record that made the device, and again as the
first records of each later segment, one per device then live, so a segment
read on its own names them too. The format stays version 2: a reader that does
not use the record skips it, and its keys are answers.
2026-11-18 00:45:55 -08:00
Anees Iqbal 5544fb6672 📝 Record when the 5300M takes a Managed texture's bytes [ci skip]
oracle_storage mtexcap on the AMD Radeon Pro 5300M: a replaceRegion: made after
the commit is seen, whole or partial, until the command buffer is submitted (a
wait on an unsignalled shared event holds it unscheduled until the signal), and
not once the GPU has started it: the bytes are taken at the submission, as a
Managed buffer's. The Intel UHD Graphics 630, one copy, sees every replace.
2026-11-18 00:43:58 -08:00
Anees Iqbal 35b6935c8b 📝 Record when the 5300M takes a Managed buffer's bytes [ci skip]
metal2vulkan's planner is ruling on when the new runtime takes a Managed
buffer's CPU bytes on a discrete GPU. capture's new steps, run at 4 KiB
and 64 MiB on the 5300M and the Intel 630, answer it: the 5300M takes the
bytes at the submission, after the commit returns (a write at once after
the commit is seen whole, one 20 ms after scheduling is not), and a second
didModifyRange: does not reach a command buffer already running. The
Intel 630, one copy, sees every write.

Q2 gets the three steps' rows, the 64 MiB answers of all eight, the job
ids, the 64 MiB run's memory, and the window's timings. The sentence that
said no step writes between the commit and the submission now says step 5
does, and that the 5300M's spin once saw the CPU's flag write.
2026-11-17 23:43:54 -08:00
Anees Iqbal 9fbd2c1390 📝 Record the 2 GiB maxBufferLength and the trap it closes [ci skip]
The oracle table's row for our device now reads 2147483648 (c795bf3d5), and
its relaxation names the cap and why. A lessons entry records the trap: a
size the device answered (12821200896 on the RTX 5080) passed what the
platform's shaders address, and only an access past 4 GiB in a buffer shows
it.
2026-11-17 16:10:29 -08:00
Anees Iqbal 5cfbd942cb 📝 Record that a KVM call in the device file breaks non-KVM QEMUs [ci skip]
reims-graphics-pci.c is built once into every QEMU target, so the pool's
KVM quirk call broke qemu-system-aarch64's link on x86-64 Linux hosts,
and only an aarch64 build saw it. Say how to spot the next one.
2026-11-17 12:36:09 -08:00
Anees Iqbal b27a603cb4 🆕 Record the commands a CPU encodes into indirect command buffers
With REIMS_VGPU_RECORD set, the commands the guest's CPU encodes into an
indirect command buffer never reached the stream: an ICB_WRITE's went through
IndirectRenderCommand::encode and IndirectComputeCommand::encode, which had no
hook, and an ICB_SLOTS slot's call was recorded with its commands as nil (its
iterator prints nothing). The buffer's records live in the runtime, which no
memory write carries, so a replay executed commands it never saw.

Each send of commands to a buffer is now a call record on it,
indirectRenderCommandAtIndex: or indirectComputeCommandAtIndex:, with the
arguments [index, commands] that metal2vulkan's format names (section 8): the
commands in the order the platform carried them out, each a map of one pair,
the command's Metal selector and the list of its arguments read from its fields
(objects as stream ids, sizes and regions as maps). A command sent on its own
is a list of one; a slot's call lists the commands it took, read as it took
them, out of line over one iterator type. No m2v. selector is added.

With the variable unset nothing changes: one relaxed load and a branch, and the
platform's sends keep their shape.
2026-11-17 09:57:46 -08:00
Anees Iqbal 00d59542bc 🆕 Record Private buffers around dispatches of linked kernels
metal2vulkan replays the benchmark's lockstep kernels to check its forms against
Metal, and 28 of them link functions and bind Private buffers, whose bytes no CPU
can read, so no recording held them and those replays could not be checked.

With REIMS_VGPU_RECORD set, each recorded dispatch of a compute pipeline made
with linked functions (outside a block of command predication) now splits its
compute encoder around a blit before and after it, which copies each bound
Private buffer range (from its offset to the buffer's end, 256 MiB a dispatch at
most) into a Shared buffer of the recorder's own. At the command buffer's
completion the recorder writes both byte runs into the blobs directory and an
m2v.privateBytes record per range: receiver the buffer, arguments [the
dispatch's position among the stream's call records, {location, length}, the
before blob, the after blob]. A fresh compute encoder takes the guest's bindings
and residency again, as predication's refresh gives them; a recording process
keeps those bindings in a command buffer that holds no predication. Only these
dispatches: one per dispatch binding a Private buffer would split and copy far
more than the stream costs. stats.txt counts private_ranges, private_bytes and
private_skipped.

With the variable unset nothing changes: the hooks read the recorded call,
which is None there.
2026-11-17 09:24:15 -08:00
Anees Iqbal 4b866b6914 🐛 Fail the command buffer a predicated loop overran in
A loop of command predication that ran past the iterations laid down for
it set a flag in its command buffer's state buffer, and a completed handler
of the platform's own read the flag and ended the process. That handler ran
on the runtime's thread outside every refusal scope, so a guest whose loop
ran on, or anything that wrote the flag, ended QEMU. The state buffer is host
data the GPU writes, and after the runtime's cutover every byte on the device
is guest-writable.

The flags are now read where the runtime's own failures are read, once the
command buffer completed with none: by each completed and completion-seen
handler's read, and by status, error and waitUntilCompleted. An overrun is a
failure that is none of Metal's, dying where it is read, as the others do.
What the guest sees: inside the graphics lane's refusal scope, which every
guest command buffer's handlers carry, the read is refused and the command
buffer completes with status Error and an internal error (RGFX_CB_INTERNAL),
after its event signals and in its queue's order, and QEMU goes on. Each
such command buffer is counted once as the degradation
predication-loop-overrun. Outside every scope (the library's own tests) it
still ends the process, now at the first read of the completion.

The death test now dies at the wait, and two tests pin the refused
completion and a loop that ends within its copies.
2026-11-17 09:08:30 -08:00
Anees Iqbal 1b532d111f 🆕 Read every CPU's PAT through the accelerator's user client
The kext sets the guest PAT's entry 2 to write-back on every CPU, and
nothing the guest could run showed whether every CPU holds it. CpuPats,
selector 15 on the 'RGFX' client (the next number every WebKit sandbox
allows), reads each online CPU's PAT on that CPU in an mp_rendezvous_no_intrs
action, into a record sized to the kernel's CPU count (real_ncpus), by CPU
number: a CPU whose number lies past it is counted, never written past the
record or shifted past a mask's width. It answers an administrator's process
alone, as the read stops every CPU for a moment; arm64, with no PAT, answers
kIOReturnUnsupported. The x86-64 kext sets kext feature bit 13, CpuPats.

guest/bundle/tools/pat_probe.c checks every online CPU holds entry 2
write-back and entry 6 write-combining, and times stores and loads over a
write-back block of the region beside process memory, on any kext.
pat_test holds the record's rules; user_client_words_test the number and
the bit; design.md's registry gives both out.
2026-11-17 08:56:29 -08:00
Anees Iqbal ba4f1a31ee 🐎 Set the guest PAT's entry 2 to write-back on every CPU
xnu's x86-64 pmap maps every page it does not manage through PAT entry 2
for any ask but write-combined, and xnu's PAT holds UC- there. So the
device's region, which QEMU backs with host RAM, was uncached wherever the
kext asked for write-back: its rings, the cursor, the device info and every
block the bundle maps write-back. AMD's nested paging and WHP apply the
guest's memory type: through entry 2 the region ran at 78-202 MB/s on AMD
KVM and on WHP, against 43-46 GB/s and 16.5/8.8 GB/s write-back. KVM on an
Intel host ignores it for RAM-backed pages and ran at write-back speed
either way.

ReimsGraphics' start now sets entry 2 to write-back on every online CPU,
before the region's first mapping, in an mp_rendezvous_no_intrs action
with the SDM's sequence for a PAT change, and leaves entry 6 write-combining
as xnu sets it. A priority sleep/wake interest runs it again at each wake,
for a wake from S3, which resets every CPU's PAT; reims-ctl keeps S3 off, and
through its dark wake and a CPU's offline and online the measured guests
kept the rewrite and xnu wrote no PAT, so no CPU-start hook is needed. What
the guest observes: the region's write-back mappings are write-back on AMD
and Windows hosts. Every other user of entry 2 is device registers the host
traps, or RAM a driver asks uncached, which QEMU reads write-back.

The calls are com.apple.kpi.unsupported's (mp_rendezvous_no_intrs) and
IOKit's, which the kext links already. The comments and design.md that
called the region uncached now say under which PAT it is.
2026-11-17 08:56:29 -08:00
Anees Iqbal 3f44b9cbdd 📝 Record the guest's Shared pool's range and its measured adds [ci skip]
docs/qemu.md says where the device reserves the pool's range and why it
adds no e820 entry, how a piece is added and removed under KVM and WHPX,
and what the pool's measurement arm measured on um790's 780M and the Mac
mini 2018, with a UEFI probe of a guest's accesses across a piece's map,
add, unmap and removal under WHPX.
2026-11-17 06:35:09 -08:00
Anees Iqbal 6f3d1ca802 📝 Describe the guest's Shared pool in the architecture and QEMU's head
Architecture 7.3 names the pool's thread and 15.1 says how the pool places,
keeps and gives back its blocks, and the order of its release. QEMU's
device file lists the pool's range among what the device gives the guest,
and its teardown's taking the pieces out.
2026-11-17 06:35:09 -08:00
Anees Iqbal 426724ff52 🆕 Map the guest's Shared pool's blocks into a range the host reserves
metal2vulkan's new runtime allocates the GPU memory the guest's Shared
buffers live in, and the device maps those blocks into the guest (plan D2,
route 1). This is the host side of that pool: the guest's side, and the
wire it reads the range and its pieces from, come with the D2 guest work.

The library: a pool per device (crates/reims-vgpu/src/pool.rs) over the
range the host reserved. Its thread takes Shared blocks from a block source
and asks the host to map each at the lowest free 2 MiB-aligned address
(pool_add); the host says when the guest's address space has it
(rvg_graphics_device_pool_added). The source's unmap hook takes a piece out
of the lookups, waits for every hold on it, asks the host to unmap it
(pool_remove) and returns once the host says it is gone
(rvg_graphics_device_pool_removed); only then may the source free the block.
The pool keeps one empty piece as headroom, asks for a block more when the
guest uses the last empty one, and gives back a piece that stayed empty for
5 s above the lowest empty one. The source's calls and hook have
metal2vulkan-rt's shape (take_block, release_block, BlockMappings::unmap,
BlockInfo); until the device runs on that runtime the source is the
process's own memory (HostBlocks), so only the source changes then.

The C API: RvgGraphicsDeviceConfig and RvgGraphicsCallbacks go to their fifth
version (pool_physical_address and _length; pool_add and pool_remove), with
rvg_graphics_device_pool_added, _pool_removed and _pool_grow (the host's ask
for more pool now, which QEMU's x-pool-grow property drives).

QEMU (vendor/qemu): the device reserves 64 GiB past the RAM and the host
bridge's default 64-bit window, raises etc/reserved-memory-end past it so
OVMF's 64-bit window goes above it, turns KVM's zap-every-slot quirk off, maps
each piece as a RAM region of its own (a pure add) on its main loop, and under
WHPX runs the hypervisor's map outside the BQL. Its teardown takes every piece
out before the release, which frees the blocks before the process exits.

For the guest: the firmware's 64-bit PCI window starts past the reserved
range, 32 GiB or more higher than before; nothing else changes until the
guest's side maps the pool.
2026-11-17 06:35:09 -08:00
Anees Iqbal b8aa508721 📝 Note the system mapper wait of a kext before the platform expert [ci skip]
A probe kext that allocated an IOBufferMemoryDescriptor at its kmod start hung a
macOS 26.7.2 boot in IOMapper::checkForSystemMapper, which only the platform
expert's start releases. Record the trap and how to spot it, for any kext work
that moves a start earlier.
2026-11-17 06:28:21 -08:00