Copy a no-copy buffer's pages the kernel cannot pin where the process maps them readable

Cause: a copied host buffer (the caller's gate refused the import, or the admitted import
failed) read its first bytes only through the kernel: `process_vm_readv` of our own pid on
Linux. That read pins each page, and no page of a VM_PFNMAP or VM_IO mapping can be pinned, so
on a dma-buf's mapping (udmabuf's on Linux 7.2) it fails although the pages are mapped
readable. `CopiedBuffers::add` then answered `NotCopied::Unreadable`, and the buffer, heap or
rebind was refused as not importable (`Unsupported { HostMemory, NotRepresentable }`): the copy
never worked for dma-buf mappings, which is where a consumer's gate refuses imports on NVIDIA
at the kernel's default vm.max_map_count.

Fix: where the kernel's read fails, the copy asks the process's mappings whether every page of
the range is mapped with read permission and, if so, reads it with plain loads, the access the
copy's comparisons already make at every commit and completion (`copied::read_caller`). The
mapping check generalizes the import's write check: `PROCMAP_QUERY` tests
`PROCMAP_QUERY_VMA_READABLE` as it tested `..._WRITABLE`, and before Linux 6.11 the
/proc/self/maps lines' `r` as their `w` (`host_memory::Access`, `queried_permitted`,
`permitted`, `mapped_readable`). Pages not mapped, or mapped without read permission, are still
refused. All three users of `add` (buffers, heaps' own buffers, rebinds) take it. Off Linux
nothing changes (no mapping is asked; macOS's mach_vm_read path as before). RUNTIME_VERSION
1696 -> 1697 (renumbered at landing). Docs: API.md's copied-host-pages entry, HOWTO's copied
host buffers, the runtime README, and FAST-PATHS' known gap with the measured cost.

Evidence (verified):
- msi (Linux 7.2.8, RTX 5080): tests::copied + tests::host_memory 21/21; the udmabuf test
  printed "the kernel cannot read this udmabuf mapping: copied with plain loads".
  Under the GPU lock on NVIDIA: tests::copied_device + tests::copied 15/15, among them the new
  copied_buffer_is_made_over_a_dma_buf_mapping_the_gate_refuses (gate refusal -> copy made,
  announced, CPU writes copied in and a fill merged back over the udmabuf pages).
- Negative control on msi: with the fallback disabled the two new copied tests and the new
  device test FAIL (the device test at the buffer's refusal); restored, PASS.
- macOS (M3 Max, MoltenVK, under maclock): copied, copied_device, host_memory 25/25; plus
  degradation, catalogue and fast_paths 45/45.
- clippy -D warnings clean: macOS plain and --cfg m2v_gpu; Linux (msi) plain and
  --cfg m2v_gpu, runtime crate, all targets, all features. rustdoc -D warnings clean (runtime).
- Cost, release, msi: one add of a 64 MiB udmabuf range 15 ms (the failing kernel read 6 us,
  the mapping query 22 us); each comparison of a 64 MiB copy 22-41 ms on the CPU; on NVIDIA a
  live 64 MiB copy makes each empty command buffer's commit and wait 45-68 ms (0.2 ms without).
- Not run: the Mac's Linux container exposes no /dev/udmabuf.

RUNTIME_VERSION 1698 at landing.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 1612481fb3, then 95852120a3 (the re-pin).
This commit is contained in:
Anees Iqbal committed 2026-10-29 15:43:54 +02:00
1 parent 63859d8cc1
commit f4394b8712
11 files changed
+528 -89

No files matched your search

+5 -2
View File
@@ -2507,8 +2507,11 @@ bound.
the device's own, which no import maps (a heap's textures shadows of its bytes):
the caller's gate (`HostMemory::with_import_gate`) refused the pages' import, or the import the
device and the gate admitted failed (out of memory, or another Vulkan error, such as a driver out
of the mappings the host kernel allows). Pages the process cannot read are never copied: the
buffer is refused, as their import is. A copy whose own allocation fails refuses the call
of the mappings the host kernel allows). The copy reads the pages through the kernel, and
where the kernel cannot (on Linux it pins each page, which a dma-buf's mapping does not allow),
with plain loads where the process maps every page readable. Pages not mapped, or mapped
without read permission, are never copied: the buffer is refused, as their import is. A copy
whose own allocation fails refuses the call
(`OutOfMemory`). A heap's rebind and memory whose GPU writes Metal's private option bit 24 drops
are never copied. Counted: `WorkCounts::copied_host_buffers_made`, of them
`copied_host_buffers_refused` and `copied_host_buffers_degraded` (and `copied_heaps_made`,