Files
reims-vgpu/docs
vintoware d0547561a0 🐛 Make the Shared pool host memory where KVM maps no cached GPU memory
On an M1 Pro under Fedora Asahi Remix 45, once Honeykrisp met the runtime's
floor, QEMU exited as the guest's driver took the Shared pool: Linux's KVM on
arm64 takes a cacheable VM_PFNMAP mapping as a memory slot only where the CPU
has stage-2 forced write-back and CACHE_DIC, every host mapping of a
Honeykrisp allocation is VM_PFNMAP, and KVM_SET_USER_MEMORY_REGION2 refused
the pool's first piece with EINVAL (#174).

For the host: RvgGraphicsDeviceConfig's sixth version adds pool_host_memory,
0 or 1, any other value refused. A host built before it reads as 0 and keeps
the pool of the GPU's own memory. QEMU sets it under KVM on an arm64 host
whose VM does not answer KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED (vendor/qemu
c9f8890b). Each of the pool's blocks is then a memfd of the library's
(RegionMemory, as the device's region is), which rt imports as a dma-buf
(rt_platform::import_host_block, the no-copy buffers' dma-buf path) and the
device knows as it knows rt's blocks (pool::HostMemoryBlocks, the platform's
host_memory_block_source); pool_add hands QEMU the memfd's mapping, which KVM
maps cached, as it maps the guest's RAM. Host, guest and GPU then reach one
cached memory. A platform that makes no such blocks (macOS, Windows) refuses
the 1, where its pool's blocks would be the GPU's; the guest's Private blocks
keep the GPU's memory everywhere.

An uncached memory type of the GPU's would also pass KVM's check, and needs no
import, but the guest would reach the pages cached while the host zeroes each
take through an uncached mapping, a pair of views the architecture does not
keep coherent. The imports' cost on this kernel was measured first: a program
that imported 16 and 32 udmabufs of 16 MiB into Honeykrisp, a GPU fill into
each, then freed them and the device left Shmem as it was (7.3.4-401.asahi,
Mesa 26.2.7), where kernel 6.19 had been reported keeping such imports.

Tests: the C API's field (0 and a size before the field the GPU's memory, 2
refused, 1 taken on Linux and refused elsewhere); HostMemoryBlocks on the M1
Pro (Honeykrisp): a Shared block is imported host memory, zeros, at a GPU
address, known from take to release, Private refused. The C harness gives the
field 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit a8ad00aca33fb895bb4dd5f11cabef677851b32b; vendor/qemu is kept at the
fork's tip here, and moves to the fork's integrated commit, which carries
the fork's PR 19, in a later commit.)
2026-12-02 01:48:00 -08:00
..