virtio-gpu: Add user pointer and HSAKMT support enhancements
Re: [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
In reply to Honglei HuangQuoted 37 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 rendererThis enables more flexible memory management between guest and host for GPU virtualization scenarios.
Signed-off-by Honglei Huang <[email protected]>--- hw/display/virtio-gpu-virgl.c | 21 +++++++++++++++------ hw/display/virtio-gpu.c | 7 ------- include/standard-headers/linux/virtio_gpu.h | 1 + 3 files changed, 16 insertions(+), 13 deletions(-)hw/display/virtio-gpu-virgl.c +2
-6@@ -702,12 +702,21 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, res->base.dmabuf_fd =-1 ;if (cblob.blob_mem !=VIRTIO_GPU_BLOB_MEM_HOST3D ) { - ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), - cmd, &res->base.addrs, - &res->base.iov, &res->base.iov_cnt); -if (!ret) { - cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; -return ; +if (cblob.blob_flags &VIRTIO_GPU_BLOB_FLAG_USE_USERPTR ) { + ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob), cmd, &res->base.addrs,
hw/display/virtio-gpu-virgl.c static void virgl_cmd_resource_create_blob(VirtIOGPU *g, · line 716
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +10
-0+ &res->base.iov, &res->base.iov_cnt); +if (ret !=0 ) { + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + }else { + ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), + cmd, &res->base.addrs, + &res->base.iov, &res->base.iov_cnt); +if (!ret) {
Why does this check !ret instead of ret != 0?
Regards,
Akihiko Odaki
Quoted 36 lines
hw/display/virtio-gpu-virgl.c +3
-0+ cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } } }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;
PATCH 2/3 virtio-gpu: add configurable HSAKMT capset support
In reply to Honglei HuangChanges include:
- Add VIRTIO_GPU_FLAG_HSAKMT_ENABLED flag to virtio_gpu_base_conf_flags
- Add virtio_gpu_hsakmt_enabled() macro for configuration checking
- Add "hsakmt" device property to virtio-gpu-gl device
- Modify virtio_gpu_virgl_get_capsets() to conditionally enable HSAKMT capset based on configuration flag and runtime capability check
The HSAKMT capset is now only enabled when:
1. The "hsakmt=on" device property is set (defaults to false)
2. virgl_renderer_get_cap_set() reports capset_max_size > 0
Usage:
-device virtio-gpu-gl,hsakmt=on
This provides better control over HSAKMT functionality and avoids exposing unsupported capabilities to guests.
--- hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 9 +++++++++ include/hw/virtio/virtio-gpu.h | 3 +++ include/standard-headers/linux/virtio_gpu.h | 1 + 4 files changed, 15 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("hsakmt", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_HSAKMT_ENABLED, false), };static void virtio_gpu_gl_device_unrealize (DeviceState *qdev)
hw/display/virtio-gpu-virgl.c +9 -0
@@ -1227,5 +1227,14 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g) } } +if (virtio_gpu_hsakmt_enabled (g->parent_obj.conf)) { +virgl_renderer_get_cap_set (VIRTIO_GPU_CAPSET_HSAKMT , + &capset_max_ver, + &capset_max_size); +if (capset_max_size) { +virtio_gpu_virgl_add_capset (capset_ids,VIRTIO_GPU_CAPSET_HSAKMT ); + } + } +return capset_ids; }
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_HSAKMT_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_hsakmt_enabled (_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_HSAKMT_ENABLED))struct virtio_gpu_base_conf {uint32_t max_outputs;
include/standard-headers/linux/virtio_gpu.h +1 -0
@@ -313,6 +313,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_HSAKMT 8/* VIRTIO_GPU_CMD_GET_CAPSET_INFO */ struct virtio_gpu_get_capset_info {
Signature · 1 line
2.34.1
PATCH 1/3 virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
In reply to Honglei HuangAdd 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
This enables more flexible memory management between guest and host for GPU virtualization scenarios.
--- hw/display/virtio-gpu-virgl.c | 21 +++++++++++++++------ hw/display/virtio-gpu.c | 7 ------- include/standard-headers/linux/virtio_gpu.h | 1 + 3 files changed, 16 insertions(+), 13 deletions(-)
hw/display/virtio-gpu-virgl.c +15 -6
@@ -702,12 +702,21 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, res->base.dmabuf_fd =-1 ;if (cblob.blob_mem !=VIRTIO_GPU_BLOB_MEM_HOST3D ) { - ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), - cmd, &res->base.addrs, - &res->base.iov, &res->base.iov_cnt); -if (!ret) { - cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; -return ; +if (cblob.blob_flags &VIRTIO_GPU_BLOB_FLAG_USE_USERPTR ) { + ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), cmd, &res->base.addrs, + &res->base.iov, &res->base.iov_cnt); +if (ret !=0 ) { + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + }else { + ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), + cmd, &res->base.addrs, + &res->base.iov, &res->base.iov_cnt); +if (!ret) { + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } } }
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
cover virtio-gpu: Add user pointer and HSAKMT support enhancements
This patch series introduces three key enhancements to virtio-gpu to improve memory management and GPU virtualization capabilities:
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. Configurable HSAKMT capset support: Provides better control over HSAKMT functionality with a new device property "hsakmt=on" to avoid exposing unsupported capabilities to guests.
3. 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.
These patches work together to provide more flexible and efficient memory management between guest and host in GPU virtualization scenarios. The changes are backward compatible and controlled by new device properties.
Usage examples:
-device virtio-gpu-gl,hsakmt=on,userptr=on
The series has been tested with GPU workloads requiring advanced memory management capabilities.
Honglei Huang (3):
virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
virtio-gpu: add configurable HSAKMT capset support
virtio-gpu: Add VIRTIO_GPU_F_RESOURCE_USERPTR feature support
hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 30 ++++++++++++++++----- hw/display/virtio-gpu.c | 9 ++----- include/hw/virtio/virtio-gpu.h | 6 +++++ include/standard-headers/linux/virtio_gpu.h | 4 +++ 6 files changed, 41 insertions(+), 13 deletions(-)
Signature · 1 line
2.34.1
Re: [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
In reply to Akihiko OdakiQuoted 86 lines · Akihiko Odaki
Quoted 51 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 rendererThis enables more flexible memory management between guest and host for GPU virtualization scenarios.
Signed-off-by Honglei Huang <[email protected]>---
hw/display/virtio-gpu-virgl.c | 21 +++++++++++++++------ hw/display/virtio-gpu.c | 7 -------include/standard-headers/linux/virtio_gpu.h| 1 +3 files changed, 16 insertions(+), 13 deletions(-)hw/display/virtio-gpu-virgl.c +3
-6@@ -702,12 +702,21 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, res->base.dmabuf_fd = -1; if (cblob.blob_mem != VIRTIO_GPU_BLOB_MEM_HOST3D) { - ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob), - cmd, &res->base.addrs, - &res->base.iov, &res- >base.iov_cnt); - if (!ret) { - cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC; - return; + if (cblob.blob_flags & VIRTIO_GPU_BLOB_FLAG_USE_USERPTR) { + ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob), cmd, &res->base.addrs, + &res->base.iov, &res-Quoted 1 line
base.iov_cnt);
+ if (ret != 0) {
+cmd->error=VIRTIO_GPU_RESP_ERR_UNSPEC;
+ return;
+ }
+ } else {
+ ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob),
+ cmd,&res->base.addrs, +&res->base.iov, &res-Quoted 2 lines
Quoted 1 line
base.iov_cnt);
+ if (!ret) {
Why does this check !ret instead of ret != 0?
Regards,
Akihiko OdakiQuoted 26 lines
+
cmd->error=VIRTIO_GPU_RESP_ERR_UNSPEC; + return;
+ }
}
}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 +0
-0
Quoted 9 lines
include/standard-headers/linux/virtio_gpu.h struct virtio_gpu_resource_create_blob { · line 411
Quoted 8 lines
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;
Hi Akihiko,
Thank you for the review!
You're absolutely right. I need to maintain a consistent code style. I'll fix this in v2 along with making both check consistent.
Regards,
Honglei
PATCH 3/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
@@ -101,6 +101,7 @@ enum virtio_gpu_base_conf_flags {VIRTIO_GPU_FLAG_VENUS_ENABLED ,VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED ,VIRTIO_GPU_FLAG_HSAKMT_ENABLED , + VIRTIO_GPU_FLAG_RESOURCE_USERPTR_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_hsakmt_enabled (_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_HSAKMT_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
Dear all,
I would like to share some progress that has been made in exploring GPU compute capabilities within virtio-gpu. Work has been undertaken to extend virtio-gpu beyond traditional graphics workloads to support compute applications, and I wanted to update the community on the current status and gather feedback on this effort.
Virtio-gpu has the potential to become a unified solution for both graphics and compute, providing efficient GPU access in virtualized environments. This work aims to enable modern GPU compute stacks like ROCm, allowing AI/ML workloads and scientific computing to run in virtual machines with minimal performance penalty.
The current implementation is functional with essential features enabled and operational. The implementation has been validated with production AI workloads. For ComfyUI image/video generation on AMD W7900, the observed overhead ranges from 0.4% to 8.3% across different tasks. For LLM inference using deepseek-r1-distill-qwen-1.5b, the implementation achieved approximately 86% efficiency with 14% virtualization overhead. For OpenCL, most CTS tests have also been validated, and on certain hardware platforms, full CTS can be fully validated.
As someone approaching this work as a learner, I would greatly appreciate feedback from the community. The current functionality and performance are not bad, there are certainly areas that could benefit from improvement. I am fully committed to addressing any feedback received and working with the community to refine the implementation to meet the expected standards.
Full documentation and testing resources are available at: https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1475
Thank you for your time and consideration. I welcome all feedback, questions, and suggestions.
Best regards,
Honglei Huang
Quoted 38 lines · Honglei Huang
This patch series introduces three key enhancements to virtio-gpu to improve memory management and GPU virtualization capabilities:
1.
VIRTIO_GPU_BLOB_FLAG_USE_USERPTRsupport: Enables user pointer mapping for blob resources, allowing guest applications to use user-allocated memory for GPU resources more efficiently.2. Configurable HSAKMT capset support: Provides better control over HSAKMT functionality with a new device property "hsakmt=on" to avoid exposing unsupported capabilities to guests.
3.
VIRTIO_GPU_F_RESOURCE_USERPTRfeature support: Introduces a new virtio-gpu feature flag with configurable "userptr=on" device property to enable user pointer resources for enhanced memory management.These patches work together to provide more flexible and efficient memory management between guest and host in GPU virtualization scenarios. The changes are backward compatible and controlled by new device properties.
Usage examples:
-device virtio-gpu-gl,hsakmt=on,userptr=onThe series has been tested with GPU workloads requiring advanced memory management capabilities.
Honglei Huang (3):
virtio-gpu: Add support forVIRTIO_GPU_BLOB_FLAG_USE_USERPTRflag
virtio-gpu: add configurable HSAKMT capset support
virtio-gpu: AddVIRTIO_GPU_F_RESOURCE_USERPTRfeature supporthw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 30 ++++++++++++++++----- hw/display/virtio-gpu.c | 9 ++----- include/hw/virtio/virtio-gpu.h | 6 +++++ include/standard-headers/linux/virtio_gpu.h | 4 +++ 6 files changed, 41 insertions(+), 13 deletions(-)
Correction: full documentation and testing resources are available at:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1568
Quoted 59 lines · Honglei Huang
Dear all,
I would like to share some progress that has been made in exploring GPU compute capabilities within virtio-gpu. Work has been undertaken to extend virtio-gpu beyond traditional graphics workloads to support compute applications, and I wanted to update the community on the current status and gather feedback on this effort.
Virtio-gpu has the potential to become a unified solution for both graphics and compute, providing efficient GPU access in virtualized environments. This work aims to enable modern GPU compute stacks like ROCm, allowing AI/ML workloads and scientific computing to run in virtual machines with minimal performance penalty.
The current implementation is functional with essential features enabled and operational. The implementation has been validated with production AI workloads. For ComfyUI image/video generation on AMD W7900, the observed overhead ranges from 0.4% to 8.3% across different tasks. For LLM inference using deepseek-r1-distill-qwen-1.5b, the implementation achieved approximately 86% efficiency with 14% virtualization overhead. For OpenCL, most CTS tests have also been validated, and on certain hardware platforms, full CTS can be fully validated.
As someone approaching this work as a learner, I would greatly appreciate feedback from the community. The current functionality and performance are not bad, there are certainly areas that could benefit from improvement. I am fully committed to addressing any feedback received and working with the community to refine the implementation to meet the expected standards.
Full documentation and testing resources are available at: https:// gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1475
Thank you for your time and consideration. I welcome all feedback, questions, and suggestions.
Best regards,
Honglei HuangQuoted 38 lines · Honglei Huang
This patch series introduces three key enhancements to virtio-gpu to improve memory management and GPU virtualization capabilities:
1.
VIRTIO_GPU_BLOB_FLAG_USE_USERPTRsupport: Enables user pointer mapping for blob resources, allowing guest applications to use user-allocated memory for GPU resources more efficiently.2. Configurable HSAKMT capset support: Provides better control over HSAKMT functionality with a new device property "hsakmt=on" to avoid exposing unsupported capabilities to guests.
3.
VIRTIO_GPU_F_RESOURCE_USERPTRfeature support: Introduces a new virtio-gpu feature flag with configurable "userptr=on" device property to enable user pointer resources for enhanced memory management.These patches work together to provide more flexible and efficient memory management between guest and host in GPU virtualization scenarios. The changes are backward compatible and controlled by new device properties.
Usage examples:
-device virtio-gpu-gl,hsakmt=on,userptr=onThe series has been tested with GPU workloads requiring advanced memory management capabilities.
Honglei Huang (3):
virtio-gpu: Add support forVIRTIO_GPU_BLOB_FLAG_USE_USERPTRflag
virtio-gpu: add configurable HSAKMT capset support
virtio-gpu: AddVIRTIO_GPU_F_RESOURCE_USERPTRfeature supporthw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 30 ++++++++++++++++----- hw/display/virtio-gpu.c | 9 ++----- include/hw/virtio/virtio-gpu.h | 6 +++++
include/standard-headers/linux/virtio_gpu.h| 4 +++6 files changed, 41 insertions(+), 13 deletions(-)