A no-copy buffer over memory its process maps read-only cannot lie over its
own pages today: the kext refuses the pages block, and the host would lay a
buffer over it that takes the GPU's writes. So the bundle syncs a slab copy
of it at every commit that uses it. macOS 12's WindowServer wraps clients'
Core Animation backing stores, mapped read-only into it (8-30 MB each), that
way, and spent 14.1 s of a 451 s walk syncing them (appwalk14, 12.7.6 on the
Iris Xe). This makes the device and the kext ready to keep them in place; the
bundle takes the route in the next commit.
What changes on the wire:
- A new feature bit, RGFX_FEATURE_READ_ONLY_PAGES (bit 45, FEATURES_HI bit
13), offered wherever PAGES_BUFFERS is, and taken by the kext.
- A new SURFACE_PAGES flag, RGFX_SURFACE_PAGES_READ_ONLY (1 << 5), meaningful
with RGFX_SURFACE_PAGES_PRIVATE alone (else INVALID_ARGUMENT): the pages
block holds pages its process maps read-only.
- BUFFER_OVER_PAGES needs no new field: its options already carry
MTLResourceOptions bit 24 to the host, which hands it to the runtime as
memory whose GPU writes it drops (accuracy-ledger.md,
read-only-pages-written).
The host keeps every object over a read-only block from writing its pages: a
BUFFER_OVER_PAGES without bit 24, a HEAP_OVER_PAGES, an ICB_SLOTS_IN_PAGES
and a MANAGED_BUFFER_CREATE or MANAGED_TEXTURE_CREATE whose CPU copy lies over
one are refused, each logged as the guest error it is. The block's view stays
the writable mapping of guest RAM.
Where the kext took the bit, PagesBlock makes a block of read-only memory too:
it wires the pages with kIODirectionOut, which asks the VM system only for
read access, completes them for that direction at the unwire, and marks the
block read-only (rgfxPagesWiring). Without the bit it refuses read-only
memory as before.
Why a feature bit, though reims-ctl ships the host and the x86 set together:
the mark is where the host holds the line, not a hint. A process can post any
message on its rings, so a forged BUFFER_OVER_PAGES without bit 24 over a
read-only block would let the GPU write pages the process maps read-only, a
file's page cache among them. A host older than the mark ignores it, so the
kext makes such a block only where the host took the bit. The arm64e set also
reaches VMs through Ambrosia's config bundle, apart from the host. Old guest
sets never ask, and change nothing; a new set on an older host gets no block
and keeps its copy.
The header is regenerated, and the option ROM's record takes the header's
new hash (the ROM's bytes are unchanged); both guest sets are rebuilt with
the bundle's change, in the 📦 commit after it. Tests: the
header test, the peer and offer tests, a decoder test of what a read-only
block admits and refuses
(a_read_only_pages_block_holds_only_buffers_that_drop_their_writes), and the
kext's features and pages-block tests.