virtio-gpu: Add user pointer and ROCm support enhancements
v4 cover virtio-gpu: Add user pointer and ROCm support enhancements
This patch series introduces enhancements to virtio-gpu to improve memory management and GPU virtualization capabilities for ROCm workloads.
The series includes:
1. VIRTIO_GPU_BLOB_FLAG_USE_USERPTR support: Enables user pointer mapping for blob resources, allowing guest applications to use user-allocated memory for GPU resources more efficiently.
2. VIRTIO_GPU_F_RESOURCE_USERPTR feature support: Introduces a new virtio-gpu feature flag with configurable "userptr=on" device property to enable user pointer resources for enhanced memory management.
3. ROCm capability support: Adds native support for AMD's ROCm (Radeon Open Compute) platform through a new "rocm=on" device property and VIRTIO_GPU_CAPSET_ROCM capability. This enables GPU compute workloads using the ROCm stack through virtio-gpu.
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
These patches work together to provide more flexible and efficient memory management between guest and host in GPU virtualization scenarios, with enhanced support for AMD ROCm compute workloads. The changes are backward compatible and controlled by new device properties.
Usage examples:
-device virtio-gpu-gl,rocm=on,userptr=on
The series has been tested with ROCm GPU compute workloads requiring advanced memory management capabilities.
TODO:
- Unify and simplify the handling path for userptr resources. This improvement requires coordinated changes across multiple components (virglrenderer and virtio-gpu driver), and will be implemented once the approach is finalized with other component maintainers.
Related patches in other components:
- Linux kernel virtio-gpu support:
https://lore.kernel.org/lkml/[email protected]/
- Virglrenderer support:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1568
- ROCm Runtime support (merged):
https://github.com/ROCm/ROCR-Runtime/commit/48d3719dba6ca91f597a8179d8b341387ce155e8
Honglei Huang (3):
virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
virtio-gpu: Add VIRTIO_GPU_F_RESOURCE_USERPTR feature support
virtio-gpu: Add ROCm capability support
hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 12 ++++++++++++ hw/display/virtio-gpu.c | 9 ++------- include/hw/virtio/virtio-gpu.h | 6 ++++++ include/standard-headers/linux/virtio_gpu.h | 4 ++++ 6 files changed, 29 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
RFC PATCH v4 1/3 virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
Add support for the USE_USERPTR blob flag in virtio-gpu to enable user pointer mapping for blob resources. This allows guest applications to use user-allocated memory for GPU resources more efficiently.
Changes include:
- Add VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag definition
- Enhance blob resource creation to handle userptr flag properly
- Remove arbitrary nr_entries limit (16384) in mapping creation
- Add conditional handling for userptr vs regular blob mapping
- Support guest_blob_mapped parameter for virgl renderer
- Fix value check issue in virtio-gpu
This enables more flexible memory management between guest and host for GPU virtualization scenarios.
--- hw/display/virtio-gpu.c | 7 ------- include/standard-headers/linux/virtio_gpu.h | 1 + 2 files changed, 1 insertion(+), 7 deletions(-)
hw/display/virtio-gpu.c +0 -7
@@ -808,13 +808,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_malloc (esize); s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,
include/standard-headers/linux/virtio_gpu.h +1 -0
@@ -405,6 +405,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_USERPTR 0x0008/* zero is invalid blob mem */ uint32_t blob_mem;uint32_t blob_flags;
Signature · 1 line
2.34.1
Re: [PATCH RFC v4 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
Quoted 12 lines · Honglei Huang
Add support for the
USE_USERPTRblob flag in virtio-gpu to enable user pointer mapping for blob resources. This allows guest applications to use user-allocated memory for GPU resources more efficiently.Changes include:
- AddVIRTIO_GPU_BLOB_FLAG_USE_USERPTRflag definition
- Enhance blob resource creation to handle userptr flag properly
- Remove arbitrarynr_entrieslimit (16384) in mapping creation
- Add conditional handling for userptr vs regular blob mapping
- Supportguest_blob_mappedparameter for virgl renderer
- Fix value check issue in virtio-gpu
Quoted 8 lines
This enables more flexible memory management between guest and host for GPU virtualization scenarios.
Signed-off-by Honglei Huang <[email protected]>--- hw/display/virtio-gpu.c | 7 ------- include/standard-headers/linux/virtio_gpu.h | 1 + 2 files changed, 1 insertion(+), 7 deletions(-)
Please split out any updates to the imported Linux headers into a separate patch to be replaced by a headers sync (I thought checkpatch would warn about that?)
Re: [PATCH RFC v4 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
Quoted 23 lines · Cornelia Huck
Quoted 12 lines · Honglei Huang
Add support for the
USE_USERPTRblob flag in virtio-gpu to enable user pointer mapping for blob resources. This allows guest applications to use user-allocated memory for GPU resources more efficiently.Changes include:
- AddVIRTIO_GPU_BLOB_FLAG_USE_USERPTRflag definition
- Enhance blob resource creation to handle userptr flag properly
- Remove arbitrarynr_entrieslimit (16384) in mapping creation
- Add conditional handling for userptr vs regular blob mapping
- Supportguest_blob_mappedparameter for virgl renderer
- Fix value check issue in virtio-gpuQuoted 8 lines
This enables more flexible memory management between guest and host for GPU virtualization scenarios.
Signed-off-by Honglei Huang <[email protected]>--- hw/display/virtio-gpu.c | 7 ------- include/standard-headers/linux/virtio_gpu.h | 1 + 2 files changed, 1 insertion(+), 7 deletions(-)
Quoted 4 lines
Please split out any updates to the imported Linux headers into a separate patch to be replaced by a headers sync (I thought checkpatch would warn about that?)
Understood, will split the Linux headrs changes into a separate commit in next version. Really thanks for the reminding.
Regards,
Honglei
RFC PATCH v4 2/3 virtio-gpu: Add VIRTIO_GPU_F_RESOURCE_USERPTR feature support
In reply to Honglei HuangThis patch introduces support for the VIRTIO_GPU_F_RESOURCE_USERPTR feature in virtio-gpu implementation:
- Add VIRTIO_GPU_F_RESOURCE_USERPTR feature flag definition
- Implement resource_userptr property as a configurable option
- Add VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED configuration flag
- Enable feature negotiation when resource_userptr is enabled
Usage:
-device virtio-gpu-gl,userptr=on
This feature allows virtio-gpu to support user pointer resources, enhancing memory management capabilities for GPU virtualization scenarios.
--- hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu.c | 2 ++ include/hw/virtio/virtio-gpu.h | 3 +++ include/standard-headers/linux/virtio_gpu.h | 2 ++ 4 files changed, 10 insertions(+)
hw/display/virtio-gpu-base.c +3 -0
@@ -264,6 +264,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,if (virtio_gpu_resource_uuid_enabled (g->conf)) { features |= (1 <<VIRTIO_GPU_F_RESOURCE_UUID ); } +if (virtio_gpu_resource_userptr_enabled (g->conf)) { + features |= (1 <<VIRTIO_GPU_F_RESOURCE_USERPTR ); + }return features; }
hw/display/virtio-gpu.c +2 -0
@@ -1685,6 +1685,8 @@ static const Property virtio_gpu_properties[] = { 256 * MiB),DEFINE_PROP_BIT ("blob" , VirtIOGPU, parent_obj.conf.flags,VIRTIO_GPU_FLAG_BLOB_ENABLED , false), +DEFINE_PROP_BIT ("userptr" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED , false),DEFINE_PROP_SIZE ("hostmem" , VirtIOGPU, parent_obj.conf.hostmem,0 ), DEFINE_PROP_UINT8("x-scanout-vmstate-version", VirtIOGPU, scanout_vmstate_version, 2), };
include/hw/virtio/virtio-gpu.h +3 -0
@@ -100,6 +100,7 @@ enum virtio_gpu_base_conf_flags {VIRTIO_GPU_FLAG_RUTABAGA_ENABLED ,VIRTIO_GPU_FLAG_VENUS_ENABLED ,VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED , + VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED, };#define virtio_gpu_virgl_enabled (_cfg) \
@@ -122,6 +123,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.hostmem > 0)#define virtio_gpu_venus_enabled (_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED)) +#define virtio_gpu_resource_userptr_enabled (_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED))struct virtio_gpu_base_conf {uint32_t max_outputs;
include/standard-headers/linux/virtio_gpu.h +2 -0
@@ -65,6 +65,8 @@*/ #define VIRTIO_GPU_F_CONTEXT_INIT 4 +#define VIRTIO_GPU_F_RESOURCE_USERPTR 5 +enum virtio_gpu_ctrl_type {VIRTIO_GPU_UNDEFINED =0 ,
Signature · 1 line
2.34.1
RFC PATCH v4 3/3 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
- Register VIRTIO_GPU_CAPSET_ROCM (capset 8) capability
- 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 | 12 ++++++++++++ include/hw/virtio/virtio-gpu.h | 3 +++ include/standard-headers/linux/virtio_gpu.h | 1 + 4 files changed, 18 insertions(+)
hw/display/virtio-gpu-gl.c +2 -0
@@ -159,6 +159,8 @@ static const Property virtio_gpu_gl_properties[] = { VIRTIO_GPU_FLAG_STATS_ENABLED, false), DEFINE_PROP_BIT("venus", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_VENUS_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 +12 -0
@@ -1160,6 +1160,9 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)if (virtio_gpu_venus_enabled (g->parent_obj.conf)) { flags |=VIRGL_RENDERER_VENUS |VIRGL_RENDERER_RENDER_SERVER ; } +if (virtio_gpu_rocm_enabled (g->parent_obj.conf)) { + flags |= (VIRGL_RENDERER_USE_ROCM ); + }#endif ret =virgl_renderer_init (g, flags, &virtio_gpu_3d_cbs);
@@ -1218,5 +1221,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
@@ -101,6 +101,7 @@ enum virtio_gpu_base_conf_flags {VIRTIO_GPU_FLAG_VENUS_ENABLED ,VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED ,VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED , + VIRTIO_GPU_FLAG_ROCM_ENABLED, };#define virtio_gpu_virgl_enabled (_cfg) \
@@ -125,6 +126,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED))#define virtio_gpu_resource_userptr_enabled (_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED)) +#define virtio_gpu_rocm_enabled (_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_ROCM_ENABLED))struct virtio_gpu_base_conf {uint32_t max_outputs;
include/standard-headers/linux/virtio_gpu.h +1 -0
@@ -315,6 +315,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 8/* VIRTIO_GPU_CMD_GET_CAPSET_INFO */ struct virtio_gpu_get_capset_info {
Signature · 1 line
2.34.1