Files
metal2vulkan/docs
Anees Iqbal 44eaa09898 Copies of read-only pages drop the GPU's writes; the gate is asked before write permission
The consumer's 4K boot on the RTX 5080 (NVIDIA 615.71.09) died at a buffer rebind onto 12 KiB of
read-only pages (`replaceBackingWithRanges:readOnly:`) with `OutOfMemory(Device)`, its gate having
refused the pages.

Cause: on Linux the runtime asked the pages' write permission before the caller's gate. Read-only
pages with a dma-buf source were sent to the source (by_pointer cleared), and the gate, asked only
for pages imported by pointer, was skipped. NVIDIA 615's import of the source's dma-bufs fails with
VK_ERROR_OUT_OF_DEVICE_MEMORY, and that failure was answered as the call's error, where a failed
pointer import takes the copy. The copy path itself never ran. Reproduced on the 5080: a buffer's
rebind, a heap's rebind and a no-copy buffer over read-only pages under a refusing gate each
answered OutOfMemory(Device). On macOS the gate was asked and the copy made, and the copy's
merge-back then wrote the read-only pages: SIGBUS in all three.

Fix:
- The gate is asked before the write permission, at a no-copy buffer's or heap's making and at a
  rebind. Pages it refuses, and bytes moved in their page, are a copy, their permission unasked;
  only pages imported have it asked.
- An admitted import of the caller's dma-bufs that fails (out of memory, another Vulkan error)
  takes the copy too, as the pointer's import did: the gate's documented contract.
- A copy of pages the process cannot write drops the GPU's writes (copied.rs), as Metal drops them
  for read-only memory (read_only_view.rs). The copy asks the system as it is made
  (`mapped_writable`: PROCMAP_QUERY on Linux, mach_vm_region on macOS). At each completion, every
  byte the GPU changed in the copy takes back the byte the pages and the copy last agreed on, and
  nothing is written to the pages. Later commands of the same batch read the write back; a later
  command buffer reads the pages' bytes. CPU writes through another mapping are copied in at each
  commit as before.
- The copied-host-pages detail says so; read-only-pages-written is not announced over a copy.

Changes beyond the consumer's case: gate-refused pages and moved-bytes copies no longer ask the
kernel for write permission (no host_mappings_queried for them). Read-only pages with no source
under a refusing gate are a copy instead of Unsupported.

WorkCounts::copied_dropped_bytes (new). RUNTIME_VERSION 1703. api_signatures.tsv blessed;
REFUSALS.md regenerated, unchanged. Docs: HOWTO (copied host buffers), API.md (copied-host-pages,
read-only-pages-written), FAST-PATHS (the read-only-memory known gap now excepts copies),
ImportGate, HostMemory::new, new_buffer_with_bytes_no_copy, Buffer::rebind_bytes_no_copy, the two
Degradation declarations, copied.rs module docs.

Tests:
- Device, copied_device:
  - a no-copy buffer, a buffer's rebind and a heap's rebind over read-only pages under a refusing
    gate, the consumer's form: a read-only shared mapping, a dma-buf source on Linux;
  - checked in each: the gate asked once with the pages, the source never called, a copy that
    reads the bytes and a CPU write through the writable mapping;
  - a blit fill completes with the pages unchanged, nothing merged back, copied_dropped_bytes the
    fill's changed bytes, and a later command buffer reading the pages' bytes;
  - Linux: the rebind under an admitting gate whose dma-buf import fails is a degraded copy that
    drops the writes.
- Unit: restore, merge_back of an unwritable copy, mapped_writable (Linux and macOS).
- Negative controls:
  - the three refusing-gate tests on the unfixed runtime: RTX 5080 3/3 fail with
    OutOfMemory(Device) at the call; M3 Max 3/3 die with SIGBUS;
  - the admitted test with only the source-failure copy arm removed: the 5080 fails with
    OutOfMemory(Device).

Verified:
- RTX 5080 Laptop, NVIDIA 615.71.09 (msi; four holds, each under a minute): runtime
  copied_device|rebind|host_ram_device|tests::copied::|can_be_written 52/52 at the final tree. The
  admitted test's copy path ran (its line printed).
- M3 Max, MoltenVK 1.4.2, --cfg m2v_gpu under maclock and memcap: the same filter 49/49 (the
  admitted test is Linux-only).
- Mac: degradation_catalogue, copied and host_memory unit tests with api_surface and
  published_crates 37/37; api_signatures and fast_paths 16/16; clippy --workspace --all-targets
  --all-features, plain and --cfg m2v_gpu, clean; rustdoc -D warnings for the runtime clean.
- msi: clippy -p metal2vulkan-runtime --all-targets --all-features --cfg m2v_gpu clean.
- Not run: the validation suites. The runtime-sources pin is left for landing.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 5012056c31, then 6385d650b9 (the re-pin).
2026-10-29 15:43:55 +02:00
..