All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX
@ 2026-11-24 21:19 Val Packett
  2026-11-24 21:19 ` [PATCH v3 1/3] virtio-gpu: document individual blob_flags Val Packett
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Val Packett @ 2026-11-24 21:19 UTC (permalink / raw)
  To: virtio-comment
  Cc: Val Packett, Gurchetan Singh, Sergio Lopez, Parav Pandit,
	dmitry.osipenko, mst, Marek Marczykowski-Górecki,
	Alyssa Ross, Demi Marie Obenour

Hi,

I've been working on actually implementing the "lost" CREATE_GUEST_HANDLE
feature which allows guest-only blobs to be shareable, particularly enabling
PRIME-imported (from udmabuf or passthru dGPUs) buffers to be shared with
the host Wayland compositor when using the cross-domain context type.

This version renames the feature from F_CREATE_GUEST_HANDLE (which was too
host/implementation-centric really) to F_BLOB_GUEST_SHAREABLE, and removes
the new blob creation flag in favor of reusing the existing one,
VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE. While here, I documented all three
existing flags properly, including which kinds of resources they work with.

It seems correct to me to reuse the SHAREABLE flag because the semantics are
the same. Sharing between virtio-gpu contexts *is* what the guest relies on
to instruct the host to effectively share across host processes!

The flag has *not* been used with guest-only blobs when 3d contexts are
present before. The Linux driver did set the SHAREABLE flag in PRIME import
code, but PRIME import was restricted to devices that did *NOT* support
3d contexts at all. In Mesa, the use of SHAREABLE corresponds to "being able
to DMA-BUF export" (non-empty VkExternalMemoryHandleTypeFlags for Venus,
!RADEON_FLAG_NO_INTERPROCESS_SHARING for amdgpu). These are all exactly
the semantics that match the cross-process/dma-buf kind of shareability
on the host side.


Also addressed feedback: now BLOB_GUEST_SHAREABLE depends on BLOB_CTX_ID_FIX
(therefore BLOB_CTX_ID_FIX is introduced first); s/rendering context/context/.

Hopefully third time's the charm :)


v2: https://lore.kernel.org/all/20260903021442.423274-1-val@invisiblethingslab.com/
v1 has been lost to the moderation queue.


Thanks,
~val

---

Val Packett (3):
  virtio-gpu: document individual blob_flags
  virtio-gpu: introduce BLOB_CTX_ID_FIX feature
  virtio-gpu: introduce BLOB_GUEST_SHAREABLE feature

 device-types/gpu/description.tex | 34 +++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

-- 
2.56.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/3] virtio-gpu: document individual blob_flags
  2026-11-24 21:19 [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX Val Packett
@ 2026-11-24 21:19 ` Val Packett
  2026-11-24 21:19 ` [PATCH v3 2/3] virtio-gpu: introduce BLOB_CTX_ID_FIX feature Val Packett
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Val Packett @ 2026-11-24 21:19 UTC (permalink / raw)
  To: virtio-comment
  Cc: Val Packett, Gurchetan Singh, Sergio Lopez, Parav Pandit,
	dmitry.osipenko, mst, Marek Marczykowski-Górecki,
	Alyssa Ross, Demi Marie Obenour

The blob_flags field of virtio_gpu_resource_create_blob has been rather
underdocumented. Describe what each flag actually means and which kinds
of blob resources it is expected to work with.

Signed-off-by: Val Packett <val@invisiblethingslab.com>
---
 device-types/gpu/description.tex | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/device-types/gpu/description.tex b/device-types/gpu/description.tex
index ac3b427725f6..ea6fae4667e1 100644
--- a/device-types/gpu/description.tex
+++ b/device-types/gpu/description.tex
@@ -671,7 +671,22 @@ \subsubsection{Device Operation: controlq}\label{sec:Device Types / GPU Device /
 
 The driver MUST inform the device if the blob resource is used for
 memory access, sharing between driver instances and/or sharing with
-other devices. This is done via the \field{blob_flags} field.
+other devices. This is done via the \field{blob_flags} field:
+
+  \begin{itemize*}
+  \item VIRTIO_GPU_BLOB_FLAG_USE_MAPPABLE indicates that the resource may be
+  memory-mapped with VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB. \field{blob_mem} MUST
+  be VIRTIO_GPU_BLOB_MEM_HOST3D, as MAP_BLOB makes no sense with other kinds
+  of blob resources.
+  \item VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE indicates that the resource may be
+  shared between multiple virtio-gpu contexts. The device MAY only support this
+  flag with certain values of \field{blob_mem}; historically, this has only
+  worked with host-only blobs.
+  \item VIRTIO_GPU_BLOB_FLAG_USE_CROSS_DEVICE indicates that the resource may
+  be shared with other virtio devices via VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID.
+  The device MAY only support this flag with certain values of \field{blob_mem}.
+  Requires VIRTIO_GPU_F_RESOURCE_UUID.
+  \end{itemize*}
 
 If VIRTIO_GPU_F_VIRGL is set, both VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D
 and VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D may be used to update the
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/3] virtio-gpu: introduce BLOB_CTX_ID_FIX feature
  2026-11-24 21:19 [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX Val Packett
  2026-11-24 21:19 ` [PATCH v3 1/3] virtio-gpu: document individual blob_flags Val Packett
@ 2026-11-24 21:19 ` Val Packett
  2026-11-24 21:19 ` [PATCH v3 3/3] virtio-gpu: introduce BLOB_GUEST_SHAREABLE feature Val Packett
  2026-11-24 22:44 ` [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX Demi Marie Obenour
  3 siblings, 0 replies; 5+ messages in thread
From: Val Packett @ 2026-11-24 21:19 UTC (permalink / raw)
  To: virtio-comment
  Cc: Val Packett, Gurchetan Singh, Sergio Lopez, Parav Pandit,
	dmitry.osipenko, mst, Marek Marczykowski-Górecki,
	Alyssa Ross, Demi Marie Obenour

virtio-gpu device backends typically use ctx_id to route commands to
different modules that implement distinct context types, e.g.
virglrenderer vs. cross-domain. Each module may require the blob
resources intented to use with it to be allocated through it as well.

Currently, this happens for host-only and default blobs which are
allocated from a context-specific local blob_id (e.g. an image
requirements blob in cross-domain). For guest-only resources however,
existing software (both the Linux kernel and the rutabaga-gfx library
used by device backends to implement virtio-gpu) allocates those with
ctx_id == 0, which might be a different "default" context type from the
one the resource is intended to be used with, e.g. when both
virglrenderer and cross-domain are present, the socket buffers used by
cross-domain were processed by virglrenderer which happens to work
but does not actually make sense.

Additionally we would like to support PRIME imported resources (udmabufs
or dGPU passthrough dma-bufs) being passed over cross-domain with the
CREATE_GUEST_HANDLE feature which, due to kernel constraints, must also
perform the creation of a guest-only blob resource with ctx_id but
without blob_id.

Unfortunately changing this without breaking backwards compatibility
requires a flag to negotiate the use of the "fixed" convention. Otherwise
new guest kernel + old rutabaga would result in the command failing due
to old rutabaga not expecting guest resources to be allocated w/ ctx_id.

Signed-off-by: Val Packett <val@invisiblethingslab.com>
---
 device-types/gpu/description.tex | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/device-types/gpu/description.tex b/device-types/gpu/description.tex
index ea6fae4667e1..63e600bd04e8 100644
--- a/device-types/gpu/description.tex
+++ b/device-types/gpu/description.tex
@@ -39,6 +39,9 @@ \subsection{Feature bits}\label{sec:Device Types / GPU Device / Feature bits}
   synchronization timelines supported.  Requires VIRTIO_GPU_F_VIRGL.
 \item[VIRTIO_GPU_F_BLOB_ALIGNMENT (5)] configuration field
   \field{blob_alignment} is valid. Requires VIRTIO_GPU_F_RESOURCE_BLOB.
+\item[VIRTIO_GPU_F_BLOB_CTX_ID_FIX (6)] it is always safe to pass the
+  current context ID to VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB,
+  including for guest-only blobs.
 \end{description}
 
 \subsection{Device configuration layout}\label{sec:Device Types / GPU Device / Device configuration layout}
@@ -669,6 +672,12 @@ \subsubsection{Device Operation: controlq}\label{sec:Device Types / GPU Device /
 identified by the \field{blob_id}. The actual allocation is done via
 VIRTIO_GPU_CMD_SUBMIT_3D.
 
+If VIRTIO_GPU_F_BLOB_CTX_ID_FIX has been negotiated, the \field{ctx_id} of
+the \field{hdr} MUST always be filled in with the ID of the default context
+associated with the current handle, if one exists. Otherwise, it MUST only
+be filled when the \field{blob_id} has been filled to create a resource
+from a context local object.
+
 The driver MUST inform the device if the blob resource is used for
 memory access, sharing between driver instances and/or sharing with
 other devices. This is done via the \field{blob_flags} field:
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/3] virtio-gpu: introduce BLOB_GUEST_SHAREABLE feature
  2026-11-24 21:19 [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX Val Packett
  2026-11-24 21:19 ` [PATCH v3 1/3] virtio-gpu: document individual blob_flags Val Packett
  2026-11-24 21:19 ` [PATCH v3 2/3] virtio-gpu: introduce BLOB_CTX_ID_FIX feature Val Packett
@ 2026-11-24 21:19 ` Val Packett
  2026-11-24 22:44 ` [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX Demi Marie Obenour
  3 siblings, 0 replies; 5+ messages in thread
From: Val Packett @ 2026-11-24 21:19 UTC (permalink / raw)
  To: virtio-comment
  Cc: Val Packett, Gurchetan Singh, Sergio Lopez, Parav Pandit,
	dmitry.osipenko, mst, Marek Marczykowski-Górecki,
	Alyssa Ross, Demi Marie Obenour

So far, desktop integration over VIRTIO_GPU_CAPSET_CROSS_DOMAIN has
relied on host-only blob resources, which are always backed by a
shareable object on the host side (such as a memfd or a DMA-BUF).

However, to access such resources the guest needs to use the
VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB command which is currently only
available when a VIRTIO_GPU_SHM_ID_HOST_VISIBLE shared memory region
exists, which is not possible in all environments (e.g. under Xen).

Also, this necessarily introduces copying for software-rendered client
buffers. The Wayland protocol makes clients responsible for allocating
their SHM buffer pools, which are ordinary guest kernel shared temporary
file objects (memfds). The only way to bridge those and host-only buffers
is a copy on every content update.

Host-only resources with the HOST_VISIBLE region were picked as the
default solution because it's easy to implement with KVM. However with
the introduction of the udmabuf driver, it also became possible to create
shareable handles (namely DMA-BUFs) for specific subranges of various
memfd objects (which can be the backing objects for a KVM guest's RAM).
And on the Xen side, gntdev-dmabuf provides a similar operation for
Xen grant references. With these capabilities, it should be possible
to use guest-only blob resources as well.

The udmabuf driver can also be used in the guest to complete the Wayland
SHM zero-copy fast path. A memfd allocated by an ordinary client,
completely unaware of virtualization, can be turned into a DMA-BUF (as
long as some conditions hold) which can be imported into the virtio-gpu
device. With the new feature VIRTIO_GPU_F_BLOB_GUEST_SHAREABLE, it is
possible to use the VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE flag (previously
only available for host-only resources) to indicate to the host that the
resource should be shareable between contexts (therefore, importable
into the cross-domain context). In practice that would imply that the
provided memory range entries would be used to construct a corresponding
DMA-BUF on the host side, which the cross-domain context would send over
to the host Wayland compositor.

Such resources can also be used for scanout, e.g. when a guest
compositor wants to directly scan out a full-screen
software-rendered application.

Signed-off-by: Val Packett <val@invisiblethingslab.com>
---
 device-types/gpu/description.tex | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/device-types/gpu/description.tex b/device-types/gpu/description.tex
index 63e600bd04e8..9c1ccd854f6a 100644
--- a/device-types/gpu/description.tex
+++ b/device-types/gpu/description.tex
@@ -41,7 +41,10 @@ \subsection{Feature bits}\label{sec:Device Types / GPU Device / Feature bits}
   \field{blob_alignment} is valid. Requires VIRTIO_GPU_F_RESOURCE_BLOB.
 \item[VIRTIO_GPU_F_BLOB_CTX_ID_FIX (6)] it is always safe to pass the
   current context ID to VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB,
-  including for guest-only blobs.
+  including for guest-only blobs. Requires VIRTIO_GPU_F_RESOURCE_BLOB.
+\item[VIRTIO_GPU_F_BLOB_GUEST_SHAREABLE (7)] guest-only blob resources
+  may be created with the VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE flag.
+  Requires VIRTIO_GPU_F_BLOB_CTX_ID_FIX.
 \end{description}
 
 \subsection{Device configuration layout}\label{sec:Device Types / GPU Device / Device configuration layout}
@@ -672,6 +675,10 @@ \subsubsection{Device Operation: controlq}\label{sec:Device Types / GPU Device /
 identified by the \field{blob_id}. The actual allocation is done via
 VIRTIO_GPU_CMD_SUBMIT_3D.
 
+If VIRTIO_GPU_F_BLOB_GUEST_SHAREABLE has been negotiated, guest-only
+(VIRTIO_GPU_BLOB_MEM_GUEST) resources MAY also be created from the
+context local object identified by the \field{blob_id}.
+
 If VIRTIO_GPU_F_BLOB_CTX_ID_FIX has been negotiated, the \field{ctx_id} of
 the \field{hdr} MUST always be filled in with the ID of the default context
 associated with the current handle, if one exists. Otherwise, it MUST only
@@ -690,7 +697,8 @@ \subsubsection{Device Operation: controlq}\label{sec:Device Types / GPU Device /
   \item VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE indicates that the resource may be
   shared between multiple virtio-gpu contexts. The device MAY only support this
   flag with certain values of \field{blob_mem}; historically, this has only
-  worked with host-only blobs.
+  worked with host-only blobs. If VIRTIO_GPU_F_BLOB_GUEST_SHAREABLE has been
+  negotiated, this flag MUST be supported with guest-only blobs as well.
   \item VIRTIO_GPU_BLOB_FLAG_USE_CROSS_DEVICE indicates that the resource may
   be shared with other virtio devices via VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID.
   The device MAY only support this flag with certain values of \field{blob_mem}.
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX
  2026-11-24 21:19 [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX Val Packett
                   ` (2 preceding siblings ...)
  2026-11-24 21:19 ` [PATCH v3 3/3] virtio-gpu: introduce BLOB_GUEST_SHAREABLE feature Val Packett
@ 2026-11-24 22:44 ` Demi Marie Obenour
  3 siblings, 0 replies; 5+ messages in thread
From: Demi Marie Obenour @ 2026-11-24 22:44 UTC (permalink / raw)
  To: Val Packett, virtio-comment
  Cc: Gurchetan Singh, Sergio Lopez, Parav Pandit, dmitry.osipenko, mst,
	Marek Marczykowski-Górecki, Alyssa Ross


[-- Attachment #1.1: Type: text/plain, Size: 2359 bytes --]

On 11/24/26 4:19 PM, Val Packett wrote:
> Hi,
> 
> I've been working on actually implementing the "lost" CREATE_GUEST_HANDLE
> feature which allows guest-only blobs to be shareable, particularly enabling
> PRIME-imported (from udmabuf or passthru dGPUs) buffers to be shared with
> the host Wayland compositor when using the cross-domain context type.
> 
> This version renames the feature from F_CREATE_GUEST_HANDLE (which was too
> host/implementation-centric really) to F_BLOB_GUEST_SHAREABLE, and removes
> the new blob creation flag in favor of reusing the existing one,
> VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE. While here, I documented all three
> existing flags properly, including which kinds of resources they work with.
> 
> It seems correct to me to reuse the SHAREABLE flag because the semantics are
> the same. Sharing between virtio-gpu contexts *is* what the guest relies on
> to instruct the host to effectively share across host processes!
> 
> The flag has *not* been used with guest-only blobs when 3d contexts are
> present before. The Linux driver did set the SHAREABLE flag in PRIME import
> code, but PRIME import was restricted to devices that did *NOT* support
> 3d contexts at all. In Mesa, the use of SHAREABLE corresponds to "being able
> to DMA-BUF export" (non-empty VkExternalMemoryHandleTypeFlags for Venus,
> !RADEON_FLAG_NO_INTERPROCESS_SHARING for amdgpu). These are all exactly
> the semantics that match the cross-process/dma-buf kind of shareability
> on the host side.
> 
> 
> Also addressed feedback: now BLOB_GUEST_SHAREABLE depends on BLOB_CTX_ID_FIX
> (therefore BLOB_CTX_ID_FIX is introduced first); s/rendering context/context/.
> 
> Hopefully third time's the charm :)
> 
> 
> v2: https://lore.kernel.org/all/20260903021442.423274-1-val@invisiblethingslab.com/
> v1 has been lost to the moderation queue.
> 
> 
> Thanks,
> ~val
> 
> ---
> 
> Val Packett (3):
>   virtio-gpu: document individual blob_flags
>   virtio-gpu: introduce BLOB_CTX_ID_FIX feature
>   virtio-gpu: introduce BLOB_GUEST_SHAREABLE feature
> 
>  device-types/gpu/description.tex | 34 +++++++++++++++++++++++++++++++-
>  1 file changed, 33 insertions(+), 1 deletion(-)

Looks good from what I can tell, though I'm not too familiar with this.
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-24 22:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 21:19 [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX Val Packett
2026-11-24 21:19 ` [PATCH v3 1/3] virtio-gpu: document individual blob_flags Val Packett
2026-11-24 21:19 ` [PATCH v3 2/3] virtio-gpu: introduce BLOB_CTX_ID_FIX feature Val Packett
2026-11-24 21:19 ` [PATCH v3 3/3] virtio-gpu: introduce BLOB_GUEST_SHAREABLE feature Val Packett
2026-11-24 22:44 ` [PATCH v3 0/3] virtio-gpu: add F_BLOB_GUEST_SHAREABLE (ex CREATE_GUEST_HANDLE) and F_BLOB_CTX_ID_FIX Demi Marie Obenour

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.