Skip to content

virtio_gpu: add F_CREATE_GUEST_HANDLE and F_BLOB_CTX_ID_FIX

Val Packett virtio-comment 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest2 patches 3 repliesIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2virtio-gpu: support requesting host handles for guest-only blob resourcesdevice-types/gpu/description.tex+13 -30 replies
2/2virtio-gpu: add flag to negotiate always passing ctx_id to RESOURCE_CREATE_BLOBdevice-types/gpu/description.tex+9 -03 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] virtio_gpu: add F_CREATE_GUEST_HANDLE and F_BLOB_CTX_ID_FIX

Hi,

I've been working on actually implementing the "lost" CREATE_GUEST_HANDLE feature, previously half-implemented and removed in crosvm
(https://crrev.com/c/8064741), which allows the guest to tell the device backend to create a shareable handle to a guest-only memory blob (using facilities like udmabuf or gntdev-dmabuf) which can be e.g. sent over to the Wayland compositor when using the cross-domain capset.

This allows for cross-domain Wayland passthrough to:

1) have a zero-copy fast path for wl_shm (software rendered buffers) thanks to udmabuf being able to wrap memfds from regular clients;
2) share buffers coming from a passed-through dGPU;
3) have an alternative way to share memory when host-only buffers cannot be mapped due to lack of a host_visible virtio SHM region, which might not be available in some setups (e.g. on Xen).

I have a working implementation with the zero-copy fast path:

Backend: https://github.com/magma-gpu/rutabaga_gfx/pull/81
+ https://github.com/libkrun/libkrun/pull/822
Guest: https://codeberg.org/drakulix/wl-cross-domain-proxy/pulls/24
Kernel: want to link here when posting to lkml :) temporarily:
https://github.com/valpackett/linux-qclaptops/commits/guest-handle
Demo video: https://social.treehouse.systems/@valpackett/117149550756102167

This requires adding two new virtio-gpu feature flags:

Obviously the original CREATE_GUEST_HANDLE itself; but during implementation it was discovered that we need to change the CREATE_BLOB cmd handling in a backwards-incompatible way, to ensure that code changes on both sides are an clean-up rather than a pile-up of odd spaghetti conditionals.

If you're wondering why the explicit indication from the guest must be used rather than the backend "lazily" creating the handles based on usage:
it is better for the guest userspace to explicitly know which ways of sharing memory are supported, so that one can be auto-negotiated. (discussed in https://github.com/magma-gpu/rutabaga_gfx/issues/66)

v2: added F_BLOB_CTX_ID_FIX
v1 has been lost to the moderation queue, but if it gets approved:
https://lore.kernel.org/all/[email protected]/

Thanks,
~val

---

Val Packett (2):
virtio-gpu: support requesting host handles for guest-only blob
resources
virtio-gpu: add flag to negotiate always passing ctx_id to
RESOURCE_CREATE_BLOB

 device-types/gpu/description.tex | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
Signature · 1 line
2.55.0