virtio-gpu: Add userptr support and ROCm capability enhancements
v5 cover virtio-gpu: Add userptr support and ROCm capability enhancements
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. Linux header updates for userptr support: Synchronizes virtio-gpu headers with upstream kernel changes, adding VIRTIO_GPU_F_RESOURCE_USERPTR feature flag and VIRTIO_GPU_BLOB_FLAG_USE_USERPTR blob flag support. This enables user pointer mapping for blob resources, allowing guest applications to use user-allocated memory for GPU resources more efficiently.
2. Removal of nr_entries limit: Removes the artificial 16384 entry limit in virtio_gpu_create_mapping_iov() to align with kernel driver behavior and support legitimate large scatter-gather operations.
3. Linux header updates for ROCm capability: Synchronizes headers to add VIRTIO_GPU_CAPSET_ROCM capability set definition.
4. ROCm capability support: Adds native support for AMD's ROCm (Radeon Open Compute) platform through a new "rocm=on" device property and capability. This enables GPU compute workloads using the ROCm stack through virtio-gpu.
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 decectiontion
- 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
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 (4):
virtio-gpu: Update Linux headers to add virtio-gpu userptr support
virtio-gpu: Remove nr_entries limit check in create_mapping_iov
virtio-gpu: Update Linux headers to add ROCM capability set
virtio-gpu: Add ROCm capability support
hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 12 ++++++++++++ hw/display/virtio-gpu.c | 7 ------- include/hw/virtio/virtio-gpu.h | 3 +++ include/standard-headers/linux/virtio_gpu.h | 6 ++++++ 5 files changed, 23 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/4 virtio-gpu: Update Linux headers to add virtio-gpu userptr support
Update linux header same with the related linux patches. kernel headers, which introduces:
- VIRTIO_GPU_F_RESOURCE_USERPTR feature flag
- VIRTIO_GPU_BLOB_FLAG_USE_USERPTR blob flag
--- include/standard-headers/linux/virtio_gpu.h | 5 +++++ 1 file changed, 5 insertions(+)
include/standard-headers/linux/virtio_gpu.h +5 -0
@@ -64,6 +64,10 @@* context_init and multiple timelines */ #define VIRTIO_GPU_F_CONTEXT_INIT 4 +/* +* VIRTGPU_BLOB_FLAG_USE_USERPTR +*/ +#define VIRTIO_GPU_F_RESOURCE_USERPTR 5enum virtio_gpu_ctrl_type {VIRTIO_GPU_UNDEFINED =0 ,
@@ -405,6 +409,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
PATCH v5 2/4 virtio-gpu: Remove nr_entries limit check in create_mapping_iov
In reply to Honglei HuangRemove the check that limits nr_entries to 16384 in the virtio_gpu_create_mapping_iov() function. The kernel virtio-gpu driver does not have this limitation, and this artificial limit in QEMU can prevent legitimate large scatter-gather list operations from succeeding.
Remove this check to keep consistent with the kernel virtio-gpu implementation.
--- hw/display/virtio-gpu.c | 7 ------- 1 file changed, 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,
Signature · 1 line
2.34.1
PATCH v5 3/4 virtio-gpu: Update Linux headers to add ROCM capability set
In reply to Honglei HuangUpdate linux header same with the related linux patches. kernel headers, which introduces:
- VIRTIO_GPU_CAPSET_ROCM capability set definition
--- include/standard-headers/linux/virtio_gpu.h | 1 + 1 file changed, 1 insertion(+)
include/standard-headers/linux/virtio_gpu.h +1 -0
@@ -317,6 +317,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
PATCH v5 4/4 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 | 12 ++++++++++++ include/hw/virtio/virtio-gpu.h | 3 +++ 3 files changed, 17 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
@@ -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_ROCM_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_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
Quoted 26 lines · Honglei Huang
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=onThe series includes:
1. Linux header updates for userptr support: Synchronizes virtio-gpu headers with upstream kernel changes, adding
VIRTIO_GPU_F_RESOURCE_USERPTRfeature flag andVIRTIO_GPU_BLOB_FLAG_USE_USERPTRblob flag support. This enables user pointer mapping for blob resources, allowing guest applications to use user-allocated memory for GPU resources more efficiently.2. Removal of
nr_entrieslimit: Removes the artificial 16384 entry limit invirtio_gpu_create_mapping_iov()to align with kernel driver behavior and support legitimate large scatter-gather operations.3. Linux header updates for ROCm capability: Synchronizes headers to add
VIRTIO_GPU_CAPSET_ROCMcapability set definition.4. ROCm capability support: Adds native support for AMD's ROCm (Radeon Open Compute) platform through a new "rocm=on" device property and capability. This enables GPU compute workloads using the ROCm stack through virtio-gpu.
Quoted 8 lines
Changes in v5:
- Split userptr header updates into dedicated patch (patch 1/4)
- Extractednr_entrieslimit removal into standalone commit (patch 2/4)
- Split ROCm header updates into dedicated patch (patch 3/4)
- RemovedVIRTIO_GPU_F_RESOURCE_USERPTRfeature decectiontion
- Keep ROCm capability support with "rocm=on" device property (patch 4/4)
- Change corresponding commit messages, change corresponding cover letter content
- Remove RFC label
It is too early to drop the RFC labell. The following should happen before dropping the RFC label:
- The Linux header change land in some maintainer's tree.
- The Linux headers with scripts/update-linux-headers.sh is updated
using the tree.
- The virglrenderer change lands the upstream.
- A proper virglrenderer feature detection with a version number that is
expected to have the change.
So the QEMU change will land the last. The patches can still be reviewed in the RFC state to ensure that the series will be quickly pulled when ready.
Regards,
Akihiko Odaki
Quoted 60 lines
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 fromVIRTIO_GPU_FLAG_HSAKMT_ENABLEDtoVIRTIO_GPU_FLAG_ROCM_ENABLED
- Changed renderer flag fromVIRGL_RENDER_USE_HSAKMTtoVIRGL_RENDERER_USE_ROCM
- Updated capset handling to useVIRTIO_GPU_CAPSET_ROCM(8) instead ofVIRTIO_GPU_CAPSET_HSAKMT(8)
- Removed the error handling fix from patch 1 (virtio-gpu-virgl.c) into another threadChanges 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 fromVIRTIO_GPU_FLAG_HSAKMT_ENABLEDtoVIRTIO_GPU_FLAG_ROCM_ENABLED
- Changed renderer flag fromVIRGL_RENDER_USE_HSAKMTtoVIRGL_RENDERER_USE_ROCM
- Updated capset handling to useVIRTIO_GPU_CAPSET_ROCM(8) instead ofVIRTIO_GPU_CAPSET_HSAKMT(8)
- Removed the error handling fix from patch 1 (virtio-gpu-virgl.c) into another threadChanges in v2:
- Fixed error handling bug invirtio-gpu-virgl.cwhere the return value check was inverted (changed from "if (!ret)" to "if (ret != 0)")
- AddedVIRGL_RENDER_USE_HSAKMTflag initialization invirtio_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 trackingRelated 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/48d3719dba6ca91f597a8179d8b341387ce155e8Honglei Huang (4):
virtio-gpu: Update Linux headers to add virtio-gpu userptr support
virtio-gpu: Removenr_entrieslimit check increate_mapping_iov
virtio-gpu: Update Linux headers to add ROCM capability set
virtio-gpu: Add ROCm capability supporthw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 12 ++++++++++++ hw/display/virtio-gpu.c | 7 ------- include/hw/virtio/virtio-gpu.h | 3 +++ include/standard-headers/linux/virtio_gpu.h | 6 ++++++ 5 files changed, 23 insertions(+), 7 deletions(-)
Quoted 45 lines · Akihiko Odaki
Quoted 26 lines · Honglei Huang
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=onThe series includes:
1. Linux header updates for userptr support: Synchronizes virtio-gpu headers with upstream kernel changes, adding
VIRTIO_GPU_F_RESOURCE_USERPTRfeature flag andVIRTIO_GPU_BLOB_FLAG_USE_USERPTRblob flag support. This enables user pointer mapping for blob resources, allowing guest applications to use user-allocated memory for GPU resources more efficiently.2. Removal of
nr_entrieslimit: Removes the artificial 16384 entry limit invirtio_gpu_create_mapping_iov()to align with kernel driver behavior and support legitimate large scatter-gather operations.3. Linux header updates for ROCm capability: Synchronizes headers to add
VIRTIO_GPU_CAPSET_ROCMcapability set definition.4. ROCm capability support: Adds native support for AMD's ROCm (Radeon Open Compute) platform through a new "rocm=on" device property and capability. This enables GPU compute workloads using the ROCm stack through virtio-gpu.
Quoted 9 lines
Changes in v5:
- Split userptr header updates into dedicated patch (patch 1/4)
- Extractednr_entrieslimit removal into standalone commit (patch 2/4)
- Split ROCm header updates into dedicated patch (patch 3/4)
- RemovedVIRTIO_GPU_F_RESOURCE_USERPTRfeature decectiontion
- Keep ROCm capability support with "rocm=on" device property (patch 4/4)
- Change corresponding commit messages, change corresponding cover letter content
- Remove RFC labelIt is too early to drop the RFC labell. The following should happen before dropping the RFC label:
- The Linux header change land in some maintainer's tree.
- The Linux headers withscripts/update-linux-headers.shis updated
using the tree.
- The virglrenderer change lands the upstream.
- A proper virglrenderer feature detection with a version number that is
expected to have the change.
Quoted 4 lines
So the QEMU change will land the last. The patches can still be reviewed in the RFC state to ensure that the series will be quickly pulled when ready.
Regards,
Akihiko Odaki
Thanks for the feedback. Totally agreed, will add RFC label in next version.
Regards,
Honglei
Quoted 63 lines
Quoted 62 lines
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 fromVIRTIO_GPU_FLAG_HSAKMT_ENABLEDtoVIRTIO_GPU_FLAG_ROCM_ENABLED
- Changed renderer flag fromVIRGL_RENDER_USE_HSAKMTtoVIRGL_RENDERER_USE_ROCM
- Updated capset handling to useVIRTIO_GPU_CAPSET_ROCM(8) instead ofVIRTIO_GPU_CAPSET_HSAKMT(8)
- Removed the error handling fix from patch 1 (virtio-gpu-virgl.c) into another threadChanges 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 fromVIRTIO_GPU_FLAG_HSAKMT_ENABLEDtoVIRTIO_GPU_FLAG_ROCM_ENABLED
- Changed renderer flag fromVIRGL_RENDER_USE_HSAKMTtoVIRGL_RENDERER_USE_ROCM
- Updated capset handling to useVIRTIO_GPU_CAPSET_ROCM(8) instead ofVIRTIO_GPU_CAPSET_HSAKMT(8)
- Removed the error handling fix from patch 1 (virtio-gpu-virgl.c) into another threadChanges in v2:
- Fixed error handling bug invirtio-gpu-virgl.cwhere the return value check was inverted (changed from "if (!ret)" to "if (ret != 0)")
- AddedVIRGL_RENDER_USE_HSAKMTflag initialization invirtio_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 trackingRelated patches in other components:
- Linux kernel virtio-gpu support:
https://lore.kernel.org/lkml/20251112072910.3716944-1- [email protected]/
- Virglrenderer support:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/ merge_requests/1568
- ROCm Runtime support (merged):
https://github.com/ROCm/ROCR-Runtime/ commit/48d3719dba6ca91f597a8179d8b341387ce155e8Honglei Huang (4):
virtio-gpu: Update Linux headers to add virtio-gpu userptr support
virtio-gpu: Removenr_entrieslimit check increate_mapping_iov
virtio-gpu: Update Linux headers to add ROCM capability set
virtio-gpu: Add ROCm capability supporthw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 12 ++++++++++++ hw/display/virtio-gpu.c | 7 ------- include/hw/virtio/virtio-gpu.h | 3 +++
include/standard-headers/linux/virtio_gpu.h| 6 ++++++5 files changed, 23 insertions(+), 7 deletions(-)