virtio-gpu: Add userptr support and ROCm capability
v7 cover virtio-gpu: Add userptr support and ROCm capability
This patch series introduces enhancements to virtio-gpu to improve memory management and GPU virtualization capabilities for ROCm (Radeon Open Compute) workloads.
Usage example:
-device virtio-gpu-gl,rocm=on
The series includes:
1. Add ROCm capset ID 10 to the imported Linux headers.
2. Enable ROCm native contexts through the "rocm=on" device property.
3. Remove the only qemu side 16384 entry limit for blob backing entries.
4. Add VIRTIO_GPU_F_BLOB_READONLY and VIRTIO_GPU_BLOB_FLAG_USE_READONLY to the imported Linux headers.
5. Advertise readonly blob support for ROCm devices with blobs enabled.
See overall detail in virglrenderer pr [1].
Changes in v7:
- Replace the obsolete USE_USERPTR=0x8 / USERPTR_RDONLY=0x10 header definitions with negotiated BLOB_READONLY feature bit 6 and USE_READONLY=0x8.
- Use ROCm capset ID 10 rather than 8.
- Add readonly advertisement for the paired ROCm blob backend.
Changes in v6:
- Changed to RFC status
- Removed VIRTIO_GPU_F_RESOURCE_USERPTR feature flag from patch 1
- Added VIRTIO_GPU_BLOB_FLAG_USERPTR_RDONLY flag to patch 1
Changes in v5:
- Split userptr header updates into dedicated patch (patch 1/4)
- Extracted nr_entries limit removal into standalone commit (patch 2/4)
- Split ROCm header updates into dedicated patch (patch 3/4)
- Removed VIRTIO_GPU_F_RESOURCE_USERPTR feature detection
- Keep ROCm capability support with "rocm=on" device property (patch 4/4)
- Change corresponding commit messages, change corresponding cover letter content
- Remove RFC label
Changes in v4:
- Change this series to RFC
- Renamed HSAKMT-related functionality to ROCm for better clarity and alignment with the ROCm ecosystem terminology
- Changed device property from "hsakmt=on" to "rocm=on"
- Changed flag from VIRTIO_GPU_FLAG_HSAKMT_ENABLED to VIRTIO_GPU_FLAG_ROCM_ENABLED
- Changed renderer flag from VIRGL_RENDER_USE_HSAKMT to VIRGL_RENDERER_USE_ROCM
- Updated capset handling to use VIRTIO_GPU_CAPSET_ROCM (8) instead of VIRTIO_GPU_CAPSET_HSAKMT (8)
- Removed the error handling fix from patch 1 (virtio-gpu-virgl.c) into another thread
Changes in v3:
- Renamed HSAKMT-related functionality to ROCm for better clarity and alignment with the ROCm ecosystem terminology
- Changed device property from "hsakmt=on" to "rocm=on"
- Changed flag from VIRTIO_GPU_FLAG_HSAKMT_ENABLED to VIRTIO_GPU_FLAG_ROCM_ENABLED
- Changed renderer flag from VIRGL_RENDER_USE_HSAKMT to VIRGL_RENDERER_USE_ROCM
- Updated capset handling to use VIRTIO_GPU_CAPSET_ROCM (8) instead of VIRTIO_GPU_CAPSET_HSAKMT (8)
- Removed the error handling fix from patch 1 (virtio-gpu-virgl.c) into another thread
Changes in v2:
- Fixed error handling bug in virtio-gpu-virgl.c where the return value check was inverted (changed from "if (!ret)" to "if (ret != 0)")
- Added VIRGL_RENDER_USE_HSAKMT flag initialization in virtio_gpu_virgl_init() when HSAKMT support is enabled
- Simplified blob resource creation logic by removing complex conditional branching for userptr vs regular blob handling
- Updated commit messages to reflect bug fixes and improvements
- Added references to related patches in Linux kernel, virglrenderer, and ROCm Runtime components for complete feature implementation tracking
[1]: https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1708
Honglei Huang (5):
virtio-gpu: Update Linux headers to add ROCm capability set
virtio-gpu: Add ROCm capability support
virtio-gpu: remove the artificial IOV mapping limit
virtio-gpu: add readonly blob definitions to Linux headers
virtio-gpu: advertise readonly blobs for ROCm
hw/display/virtio-gpu-base.c | 4 ++++ hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 20 ++++++++++++++++++++ hw/display/virtio-gpu.c | 7 ------- include/hw/virtio/virtio-gpu.h | 6 ++++++ include/standard-headers/linux/virtio_gpu.h | 3 +++ 6 files changed, 35 insertions(+), 7 deletions(-)
base-commit: 73294d096cc591e122fde9e63db4739de6d84f2b
Signature · 1 line
2.34.1
RFC PATCH v7 1/5 virtio-gpu: Update Linux headers to add ROCm capability set
Add VIRTIO_GPU_CAPSET_ROCM to the imported virtio_gpu.h so the device can advertise the ROCm capability set to the guest.
--- include/standard-headers/linux/virtio_gpu.h | 1 + 1 file changed, 1 insertion(+)
include/standard-headers/linux/virtio_gpu.h +1 -0
@@ -321,6 +321,7 @@ struct virtio_gpu_cmd_submit {#define VIRTIO_GPU_CAPSET_VENUS 4#define VIRTIO_GPU_CAPSET_CROSS_DOMAIN 5#define VIRTIO_GPU_CAPSET_DRM 6 +#define VIRTIO_GPU_CAPSET_ROCM 10/* VIRTIO_GPU_CMD_GET_CAPSET_INFO */ struct virtio_gpu_get_capset_info {
Signature · 1 line
2.34.1
RFC PATCH v7 2/5 virtio-gpu: Add ROCm capability support
In reply to Honglei HuangAdd support for ROCm (Radeon Open Compute) capability in virtio-gpu. This enables GPU compute workloads using AMD's ROCm platform through the virtio-gpu interface.
Changes include:
- Add "rocm" property to virtio-gpu-gl device
- Define VIRTIO_GPU_FLAG_ROCM_ENABLED flag
- Enable VIRGL_RENDERER_USE_ROCM flag when ROCm is enabled
- Add virtio_gpu_rocm_enabled() helper macro
This allows guests to detect and utilize ROCm capabilities through the virtio-gpu device when the feature is enabled.
--- hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 17 +++++++++++++++++ include/hw/virtio/virtio-gpu.h | 3 +++ 3 files changed, 22 insertions(+)
hw/display/virtio-gpu-gl.c +2 -0
@@ -170,6 +170,8 @@ static const Property virtio_gpu_gl_properties[] = { VIRTIO_GPU_FLAG_VENUS_ENABLED, false), DEFINE_PROP_BIT("drm_native_context", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_DRM_ENABLED, false), + DEFINE_PROP_BIT("rocm", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_ROCM_ENABLED, false), };static void virtio_gpu_gl_device_unrealize (DeviceState *qdev)
hw/display/virtio-gpu-virgl.c +17 -0
@@ -1514,6 +1514,14 @@ static int virtio_gpu_virgl_init(VirtIOGPU *g) return -EINVAL; } } +if (virtio_gpu_rocm_enabled (g->parent_obj.conf)) { +#ifdef VIRGL_RENDERER_USE_ROCM + flags |=VIRGL_RENDERER_USE_ROCM ; +#else +error_report ("rocm requires a ROCm-enabled virglrenderer" ); +return -EINVAL ; +#endif + }#endif ret =virgl_renderer_init (g, flags, &virtio_gpu_3d_cbs);
@@ -1615,5 +1623,14 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g) } } +if (virtio_gpu_rocm_enabled (g->parent_obj.conf)) { +virgl_renderer_get_cap_set (VIRTIO_GPU_CAPSET_ROCM , + &capset_max_ver, + &capset_max_size); +if (capset_max_size) { +virtio_gpu_virgl_add_capset (capset_ids,VIRTIO_GPU_CAPSET_ROCM ); + } + } +return capset_ids; }
include/hw/virtio/virtio-gpu.h +3 -0
@@ -112,6 +112,7 @@ enum virtio_gpu_base_conf_flags {VIRTIO_GPU_FLAG_VENUS_ENABLED ,VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED ,VIRTIO_GPU_FLAG_DRM_ENABLED , + VIRTIO_GPU_FLAG_ROCM_ENABLED, };#define virtio_gpu_virgl_enabled (_cfg) \
@@ -136,6 +137,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED))#define virtio_gpu_drm_enabled (_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DRM_ENABLED)) +#define virtio_gpu_rocm_enabled (_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_ROCM_ENABLED))struct virtio_gpu_base_conf {uint32_t max_outputs;
Signature · 1 line
2.34.1
RFC PATCH v7 3/5 virtio-gpu: remove the artificial IOV mapping limit
In reply to Honglei HuangUserptr-backed blobs can require a very large number of virtio_gpu_mem_entry elements when their pages are not contiguous. The guest virtio-gpu frontend forwards that entry count and does not impose the 16384-entry cap previously enforced by virtio_gpu_create_mapping_iov().
Drop that QEMU-only limit so these larger userptr iovecs can be mapped. Keep the existing allocation, copy-size, and DMA mapping checks.
--- hw/display/virtio-gpu.c | 7 ------- 1 file changed, 7 deletions(-)
hw/display/virtio-gpu.c +0 -7
@@ -990,13 +990,6 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,size_t esize, s;int e, v; -if (nr_entries >16384 ) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: nr_entries is too big (%d > 16384)\n" , - __func__, nr_entries); -return -1 ; - } - esize =sizeof (*ents) * nr_entries; ents =g_try_malloc (esize);if (!ents && esize) {
Signature · 1 line
2.34.1
RFC PATCH v7 4/5 virtio-gpu: add readonly blob definitions to Linux headers
In reply to Honglei HuangAdd VIRTIO_GPU_F_BLOB_READONLY and VIRTIO_GPU_BLOB_FLAG_USE_READONLY to the imported virtio-gpu header.
Mirror the kernel UAPI definitions needed by readonly blob support. This is a targeted header update, not a full Linux header resync.
--- include/standard-headers/linux/virtio_gpu.h | 2 ++ 1 file changed, 2 insertions(+)
include/standard-headers/linux/virtio_gpu.h +2 -0
@@ -72,6 +72,7 @@* must be aligned to that value. */ #define VIRTIO_GPU_F_BLOB_ALIGNMENT 5 +#define VIRTIO_GPU_F_BLOB_READONLY 6enum virtio_gpu_ctrl_type {VIRTIO_GPU_UNDEFINED =0 ,
@@ -415,6 +416,7 @@ struct virtio_gpu_resource_create_blob {#define VIRTIO_GPU_BLOB_FLAG_USE_MAPPABLE 0x0001#define VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE 0x0002#define VIRTIO_GPU_BLOB_FLAG_USE_CROSS_DEVICE 0x0004 +#define VIRTIO_GPU_BLOB_FLAG_USE_READONLY 0x0008/* zero is invalid blob mem */ uint32_t blob_mem;uint32_t blob_flags;
Signature · 1 line
2.34.1
RFC PATCH v7 5/5 virtio-gpu: advertise readonly blobs for ROCm
In reply to Honglei HuangMark readonly blobs available when the ROCm capset is present, and advertise the feature only for ROCm devices with blob support enabled. Treat readonly registration support as part of the paired ROCm backend.
--- hw/display/virtio-gpu-base.c | 4 ++++ hw/display/virtio-gpu-virgl.c | 3 +++ include/hw/virtio/virtio-gpu.h | 3 +++ 3 files changed, 10 insertions(+)
hw/display/virtio-gpu-base.c +4 -0
@@ -269,6 +269,10 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, }if (virtio_gpu_blob_enabled (g->conf)) { features |= (1 <<VIRTIO_GPU_F_RESOURCE_BLOB ); +if (virtio_gpu_rocm_enabled (g->conf) && +virtio_gpu_blob_readonly_enabled (g->conf)) { + features |= (1 <<VIRTIO_GPU_F_BLOB_READONLY ); + } }if (virtio_gpu_context_init_enabled (g->conf)) { features |= (1 <<VIRTIO_GPU_F_CONTEXT_INIT );
hw/display/virtio-gpu-virgl.c +3 -0
@@ -1593,6 +1593,7 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g)uint32_t capset_max_ver, capset_max_size;GArray *capset_ids; + g->parent_obj.conf.flags &= ~(1 <<VIRTIO_GPU_FLAG_BLOB_READONLY_ENABLED ); capset_ids =g_array_new (false, false,sizeof (uint32_t ));/* VIRGL is always supported. */
@@ -1629,6 +1630,8 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g) &capset_max_size);if (capset_max_size) {virtio_gpu_virgl_add_capset (capset_ids,VIRTIO_GPU_CAPSET_ROCM ); + g->parent_obj.conf.flags |= +1 <<VIRTIO_GPU_FLAG_BLOB_READONLY_ENABLED ; } }
include/hw/virtio/virtio-gpu.h +3 -0
@@ -113,6 +113,7 @@ enum virtio_gpu_base_conf_flags {VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED ,VIRTIO_GPU_FLAG_DRM_ENABLED ,VIRTIO_GPU_FLAG_ROCM_ENABLED , + VIRTIO_GPU_FLAG_BLOB_READONLY_ENABLED, };#define virtio_gpu_virgl_enabled (_cfg) \
@@ -139,6 +140,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DRM_ENABLED))#define virtio_gpu_rocm_enabled (_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_ROCM_ENABLED)) +#define virtio_gpu_blob_readonly_enabled (_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_READONLY_ENABLED))struct virtio_gpu_base_conf {uint32_t max_outputs;
Signature · 1 line
2.34.1