On RADV every guest no-copy buffer and heap is a dma-buf import of its own
(the shared mapping's pointer is refused), and RADV lists every import in
every submission: the 780M's vkQueueSubmit cost ~0.45 us per live import
(the consumer's Super Resolution: ~1,010 imports, p50 531 us a submit).
The lever agreed with the consumer: a source answers pieces of files it
shares, and the runtime imports each file once.
- DmaBufChunk is { file: Arc<OwnedFd>, offset, length } (was { fd, length }).
A chunk at offset 0 whose Arc the runtime alone holds (Arc::try_unwrap) is
a dma-buf of its own, imported exactly as before; any other is a piece of
a shared file (dma_buf.rs Piece).
- DmaBufRequest gains `alignment` (the host page, a plain dma-buf buffer's
memory alignment, asked once, or the granule where the request may split)
and `shared_files` (false for an image's dedicated import, a guest RAM's
chunk and its probe, and a list of runs: those take a dma-buf of its own
at offset 0, as before). A misaligned piece, or one past its file, is
misuse (Invalid, Problem::DmaBuf).
- Each device generation keeps DmaBufFiles: the address of the file's Arc
(never the inode) -> Weak<DmaBufFile>, one import of the whole dma-buf,
dedicated to nothing, made with no lock held and entered under a leaf
lock (a racer's import freed). Each buffer's DmaBufPages holds one Arc
per piece; the last holder takes it out of the map under the lock
(Arc::into_inner) and frees it through its own device handle.
- A plain buffer binds at its piece's offset (Placement::dma_buf takes the
offset), a sparse one each piece at its memory offset.
- Residency keeps pieces: a dup of an own descriptor (counted against the
fd budget, as before), an Arc clone of a shared file (no descriptor).
- import_dma_buf borrows the descriptor (it always handed the driver a
dup).
- WorkCounts: dma_buf_pieces_joined, dma_buf_shared_imports_live (new);
dma_buf_imports counts imports made (own chunks and first pieces).
Tests: tests/dma_buf_pieces.rs (Piece classification, the map's holds, no device);
tests/dma_buf_shared_files.rs (device: four buffers over one file -> one import, three joined,
bytes and fills in their pieces, freed with the last; the negative control of own files; two pieces
of one file in a sparse buffer at their offsets; release and import again; a misaligned piece
refused). Example shared_files: the 780M submit-cost A/B (own files, 8 a file, 1000 a file).
Docs: dma_buf.rs module, with_dma_buf (a shared-file import is never dedicated: where a device
needs that, the buffer is a copy, the source not asked again), HostRam::with_dma_buf, HOWTO,
runtime README; api_signatures.tsv; REFUSALS regenerated (unchanged).
Public API change (runtime): DmaBufChunk { file: Arc<OwnedFd>, offset, length } (+Clone), was
{ fd, length }; today's behaviour is `file: Arc::new(fd), offset: 0` with no clone kept.
DmaBufRequest gains `alignment` and `shared_files`. No Degradation kind.
Verified (dmagroup, msi): m3-max-29050 at 51e7f6b569: tests 72/72 on lavapipe (--cfg m2v_cpu_icd;
Mesa 26.2.4 takes the no-pointer dma-buf route with /dev/udmabuf), clippy -p runtime -p validation
--all-features --all-targets -D warnings plain 0 and m2v_cpu_icd 0, example builds (release). Seen:
4 buffers over one file -> imports 1, joined 3, shared live +1; own files -> imports 4, joined 0;
sparse reverse-order pieces -> one import, bytes in order; misaligned (2048 vs 4096) -> Invalid
DmaBuf, nothing imported. The 780M submit-cost A/B runs after landing.