0
Fork 0
mirror of https://github.com/Droid-VM/crosvm.git synced 2026-11-17 06:58:03 +00:00
crosvm/vm_memory
HuJK 86cbededbf pools: media_host and media_guest, the two virtio-media buffer pools
virtio-media's buffers have to live somewhere both sides can reach. On a
protected Gunyah VM guest RAM is lent, so the host cannot touch a buffer the
guest allocated, and the upstream shape for host-owned buffers -- a memfd per
buffer mapped into a 4 GiB PCI shared-memory BAR -- does not fit either: the
64-bit MMIO window holds exactly one such BAR and the GPU already has it
(VPU_DESIGN.md 0.2, 2.3). Both directions therefore want a pool, and the pool
machinery to build one has been in the tree since gfx_host.

So: two more of them. media_host is host-owned and works like gfx_host,
drm2kgsl_host and venus_host -- the device sub-allocates every host-produced
buffer from it (camera frames, decoded frames, encoded bitstreams) and the
guest maps them at the pool base plus the offset QUERYBUF answered with.
media_guest is guest-owned and works like gpu_guest -- the guest driver runs
its own allocator over the range and cuts the buffers it produces out of it
(bitstreams to decode, raw frames to encode), handing the host bare
guest-physical scatter-gather lists. Direction decides ownership: whichever
side produces the data owns the memory (VPU_DESIGN.md 2.1, 2.2).

Both are fully pre-shared, step 0. A growable pool needs runtime grants over a
share device this phone does not load, and a second growable pool would enter
the pool_id ordering hazard between create_fdt's call order and the host's
address rank, so v1 takes neither. media_host comes out of --mem like the other
host pools; media_guest is additive like gpu_guest, because it is the VM's own
memory and was sized deliberately.

The mechanical part is the recipe in logs/vpu_survey/crosvm-pools.md 3, and two
of its twelve steps are the ones that matter: check_host_access ends in a
catch-all that would refuse the host every byte of both pools in a protected
VM, and gunyah's is_pool is a matches! that decides whether a region is
folio-prepared and mlocked at all. Neither is a compile error. Both are now
extended, and create_pool_node's "Adding a pool" comment says so, so the next
pool does not have to rediscover it.

media_host is handed to its consumer as the region itself rather than as
environment variables: MediaPoolHandle::from_guest_memory reads
(fd, fd_offset, host_va, gpa, size) off the one region, so an in-VMM device and
a vhost-user helper cannot disagree about which region is the pool, and a helper
has something it can carry across an exec. The env-var handoff exists because
the renderer is forked before any of this runs; the media device is not
(VPU_DESIGN.md 2.2, 3.1). media_guest gets no host-side handoff at all -- the
guest owns it, and the host meets it as ordinary guest addresses.

The --pre-alloc help text was wrong before this and is now complete:
venus-host-mb and the three test-pool-* keys existed and were documented
nowhere.

Tests cover the two silent sites and the ordering. The vm_memory tests build a
GuestMemory with both pools, set_protected(), and assert the host keeps access
where plain lent RAM loses it -- verified to fail when the new check_host_access
arm is removed. The aarch64 test pins the layout order to
gfx/gpu_guest/drm2kgsl/venus/media_host/media_guest/test, which is guest-
physical order and, for growable pools, pool_id order.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BkN7vYhuc1w9iVuqsHzSn
History 2026-10-28 05:59:58 +08:00
..
src pools: media_host and media_guest, the two virtio-media buffer pools 2026-10-28 05:59:58 +08:00
Android.bp Merge remote-tracking branch 'aosp/upstream-main' into merge 2025-02-25 18:10:03 +00:00
bindgen.sh health-check: enforce blank line after copyright 2022-09-13 22:24:35 +00:00
Cargo.toml crosvm: upgrade zerocopy to 0.8 2025-02-24 11:35:51 -08:00