Skip to content

virtio-gpu venus: fix blob mapping on macOS/HVF and Linux/KVM - #91

Open
maxandrews wants to merge 1 commit into
superradcompany:krunfrom
maxandrews:feat/gpu-venus-mapping-fixes
Open

virtio-gpu venus: fix blob mapping on macOS/HVF and Linux/KVM#91
maxandrews wants to merge 1 commit into
superradcompany:krunfrom
maxandrews:feat/gpu-venus-mapping-fixes

Conversation

@maxandrews

@maxandrews maxandrews commented Jul 21, 2026

Copy link
Copy Markdown

Companion to superradcompany/microsandbox#291 (the --gpu flag PR lands there separately, as discussed). Two mapping fixes plus feature wiring, each found by live debugging Venus inference in microsandbox microVMs:

1. macOS/HVF: round blob map/unmap sizes to the host page (16K on Apple Silicon).
hv_vm_map requires host-page-aligned sizes, but venus blob sizes are guest-page (4K) granular — every ring mapping failed (mapped=false) and surfaced as guest vkCreateInstance → ERROR_OUT_OF_HOST_MEMORY with all debug channels silent. Upstream containers/libkrun carries the identical unrounded hv_vm_map; krunkit guests presumably boot 16K-page kernels and never hit it, so this may be worth forwarding upstream too.

2. Linux/KVM: rebind virgl_resource_map2 to upstream's virgl_renderer_resource_map_fixed.
The existing binding targets a crosvm-lineage API that upstream virglrenderer never adopted; the upstream equivalent (>= 1.1x) is resource_map_fixed(res, addr) — size/prot derive from the resource, and its opaque-handle path covers Venus blobs. Also: nothing previously enabled rutabaga_gfx/virgl_resource_map2 from the devices feature of the same name, so the Linux opaque-blob path always returned Unsupported — rings (SHM) still mapped, so enumeration worked while the first mappable device blob died as vk*Create*: ErrorOutOfHostMemory. The feature now propagates, with an msb_krun passthrough for Linux consumers. Deliberately not enabled from the gpu feature: the macOS (krunkit-fork) virglrenderer doesn't export map_fixed, and the extern would fail the macOS link.

Verified end-to-end (guest mesa venus → virglrenderer → host driver, inside microsandbox microVMs):

  • Apple M4 Pro (macOS/HVF, MoltenVK): vulkaninfo enumerates Virtio-GPU Venus (Apple M4 Pro); llama.cpp ggml-vulkan generates tokens fully offloaded.
  • NVIDIA T4G (Linux/KVM aarch64, AWS g5g.metal, virglrenderer 1.11 render-server): Qwen2.5-7B Q4_K_M fully offloaded — pp512 647.85 t/s, tg128 29.18 t/s (native-class for a T4-family part).

Host-setup note that cost us a day and may be worth documenting wherever you land GPU docs: NVIDIA hides VK_EXT_external_memory_dma_buf (which venus needs for mappable memory) unless nvidia_drm is loaded with KMS modesetting and the process can open /dev/dri/renderD* (render group).

Understood that you have internal work in flight and may reshape this freely — happy to rebase or split further.

macOS/HVF: hv_vm_map requires host-page-aligned (16K on Apple Silicon)
sizes, but venus blob sizes are guest-page (4K) granular — every ring
mapping failed (mapped=false) and surfaced as vkCreateInstance
ERROR_OUT_OF_HOST_MEMORY with all debug channels silent. Round blob
map/unmap lengths to the host page size. (Upstream containers/libkrun
has the identical unrounded hv_vm_map; krunkit guests presumably run
16K-page kernels and never hit it.)

Linux/KVM: the virgl_resource_map2 feature bound a crosvm-lineage API
that upstream virglrenderer never adopted; its upstream equivalent is
virgl_renderer_resource_map_fixed (>= 1.1x; size/prot derive from the
resource). Rebind the extern and call. Also wire the feature through:
devices/virgl_resource_map2 now enables rutabaga_gfx/virgl_resource_map2
(previously nothing enabled the rutabaga side, so the Linux opaque-blob
path always returned Unsupported), with an msb_krun passthrough feature
for Linux consumers. Not enabled from the gpu feature because the macOS
krunkit virglrenderer does not export map_fixed.

Verified end-to-end in microsandbox microVMs on both platforms: guest
mesa venus enumerates the host GPU and llama.cpp ggml-vulkan runs fully
offloaded (Apple M4 Pro via MoltenVK; NVIDIA T4G on Linux/KVM at
pp512 648 t/s / tg128 29.2 t/s for a 7B Q4_K_M). Discussion:
superradcompany/microsandbox#291
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant