[PATCH v7 2/4] drm/virtgpu api: add blob userptr resource

From: Honglei Huang

Date: Thu Sep 17 2026 - 22:25:55 EST


Add DRM ioctl flags and a userptr address field so userspace can
request a blob backed by an existing process mapping.

UAPI changes:
- Add guest-only VIRTGPU_BLOB_FLAG_USE_USERPTR and
VIRTGPU_BLOB_FLAG_USERPTR_RDONLY flags
- Add a userptr field to drm_virtgpu_resource_create_blob

These flags select guest pin behavior in the ioctl. They are not
part of the virtio CREATE_BLOB wire ABI, so mask them out in
virtio_gpu_cmd_resource_create_blob().

Signed-off-by: Honglei Huang <honghuan@xxxxxxx>
---
drivers/gpu/drm/virtio/virtgpu_vq.c | 6 +++++-
include/uapi/drm/virtgpu_drm.h | 9 +++++++++
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
index c02c03c10d..6830673309 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -1494,7 +1494,11 @@ virtio_gpu_cmd_resource_create_blob(struct virtio_gpu_device *vgdev,
cmd_p->hdr.ctx_id = cpu_to_le32(params->ctx_id);
cmd_p->resource_id = cpu_to_le32(bo->hw_res_handle);
cmd_p->blob_mem = cpu_to_le32(params->blob_mem);
- cmd_p->blob_flags = cpu_to_le32(params->blob_flags);
+ /* Guest-only flags stay off the wire. */
+ cmd_p->blob_flags = cpu_to_le32(params->blob_flags &
+ (VIRTIO_GPU_BLOB_FLAG_USE_MAPPABLE |
+ VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE |
+ VIRTIO_GPU_BLOB_FLAG_USE_CROSS_DEVICE));
cmd_p->blob_id = cpu_to_le64(params->blob_id);
cmd_p->size = cpu_to_le64(params->size);
cmd_p->nr_entries = cpu_to_le32(nents);
diff --git a/include/uapi/drm/virtgpu_drm.h b/include/uapi/drm/virtgpu_drm.h
index 95587e12ae..62c4b8f19b 100644
--- a/include/uapi/drm/virtgpu_drm.h
+++ b/include/uapi/drm/virtgpu_drm.h
@@ -186,6 +186,9 @@ struct drm_virtgpu_resource_create_blob {
#define VIRTGPU_BLOB_FLAG_USE_MAPPABLE 0x0001
#define VIRTGPU_BLOB_FLAG_USE_SHAREABLE 0x0002
#define VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE 0x0004
+/* Guest-only flags */
+#define VIRTGPU_BLOB_FLAG_USE_USERPTR 0x0008
+#define VIRTGPU_BLOB_FLAG_USERPTR_RDONLY 0x0010
/* zero is invalid blob_mem */
__u32 blob_mem;
__u32 blob_flags;
@@ -205,6 +208,12 @@ struct drm_virtgpu_resource_create_blob {
#define DRM_VIRTGPU_BLOB_FLAG_HINT_DEFER_MAPPING 0x0001
__u32 blob_hints;
__u32 pad2;
+
+ /*
+ * userptr: guest userspace memory address for VIRTGPU_BLOB_FLAG_USE_USERPTR.
+ * Must be 0 if VIRTGPU_BLOB_FLAG_USE_USERPTR is not set.
+ */
+ __u64 userptr;
};

#define VIRTGPU_CONTEXT_PARAM_CAPSET_ID 0x0001
--
2.34.1