* [PATCH 0/3] virtio-gpu: Add user pointer and HSAKMT support enhancements
@ 2025-11-12 7:54 Honglei Huang
2025-11-12 7:54 ` [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag Honglei Huang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Honglei Huang @ 2025-11-12 7:54 UTC (permalink / raw)
To: alex.bennee, dmitry.osipenko, Ray.Huang
Cc: odaki, mst, cohuck, pbonzini, qemu-devel, 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_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(-)
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
2025-11-12 7:54 [PATCH 0/3] virtio-gpu: Add user pointer and HSAKMT support enhancements Honglei Huang
@ 2025-11-12 7:54 ` Honglei Huang
2025-11-12 8:44 ` Akihiko Odaki
2025-11-12 7:54 ` [PATCH 2/3] virtio-gpu: add configurable HSAKMT capset support Honglei Huang
2025-11-12 7:54 ` [PATCH 3/3] virtio-gpu: Add VIRTIO_GPU_F_RESOURCE_USERPTR feature support Honglei Huang
2 siblings, 1 reply; 6+ messages in thread
From: Honglei Huang @ 2025-11-12 7:54 UTC (permalink / raw)
To: alex.bennee, dmitry.osipenko, Ray.Huang
Cc: odaki, mst, cohuck, pbonzini, qemu-devel, Honglei Huang
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
This enables more flexible memory management between guest and host
for GPU virtualization scenarios.
Signed-off-by: Honglei Huang <honghuan@amd.com>
---
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(-)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 07f6355ad6..9da64bf16f 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -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;
+ }
}
}
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 43e88a4daf..956dc811fa 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -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,
diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h
index 00cd3f04af..b85e781a2d 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] virtio-gpu: add configurable HSAKMT capset support
2025-11-12 7:54 [PATCH 0/3] virtio-gpu: Add user pointer and HSAKMT support enhancements Honglei Huang
2025-11-12 7:54 ` [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag Honglei Huang
@ 2025-11-12 7:54 ` Honglei Huang
2025-11-12 7:54 ` [PATCH 3/3] virtio-gpu: Add VIRTIO_GPU_F_RESOURCE_USERPTR feature support Honglei Huang
2 siblings, 0 replies; 6+ messages in thread
From: Honglei Huang @ 2025-11-12 7:54 UTC (permalink / raw)
To: alex.bennee, dmitry.osipenko, Ray.Huang
Cc: odaki, mst, cohuck, pbonzini, qemu-devel, Honglei Huang
Changes 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.
Signed-off-by: Honglei Huang <honghuan@amd.com>
---
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(+)
diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index c06a078fb3..4ed2f53e4e 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -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)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 9da64bf16f..7162c4bfee 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -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;
}
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 58e0f91fda..c820247db8 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -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;
diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h
index b85e781a2d..6c54cb745f 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -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 {
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] virtio-gpu: Add VIRTIO_GPU_F_RESOURCE_USERPTR feature support
2025-11-12 7:54 [PATCH 0/3] virtio-gpu: Add user pointer and HSAKMT support enhancements Honglei Huang
2025-11-12 7:54 ` [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag Honglei Huang
2025-11-12 7:54 ` [PATCH 2/3] virtio-gpu: add configurable HSAKMT capset support Honglei Huang
@ 2025-11-12 7:54 ` Honglei Huang
2 siblings, 0 replies; 6+ messages in thread
From: Honglei Huang @ 2025-11-12 7:54 UTC (permalink / raw)
To: alex.bennee, dmitry.osipenko, Ray.Huang
Cc: odaki, mst, cohuck, pbonzini, qemu-devel, Honglei Huang
This 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.
Signed-off-by: Honglei Huang <honghuan@amd.com>
---
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(+)
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index 7269477a1c..f013a4ece6 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -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;
}
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 956dc811fa..5f1dc80060 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -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),
};
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index c820247db8..ff68f3c451 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -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;
diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h
index 6c54cb745f..321477598e 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -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,
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
2025-11-12 7:54 ` [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag Honglei Huang
@ 2025-11-12 8:44 ` Akihiko Odaki
2025-11-12 10:54 ` Honglei1.Huang@amd.com
0 siblings, 1 reply; 6+ messages in thread
From: Akihiko Odaki @ 2025-11-12 8:44 UTC (permalink / raw)
To: Honglei Huang, alex.bennee, dmitry.osipenko, Ray.Huang
Cc: mst, cohuck, pbonzini, qemu-devel
On 2025/11/12 16:54, Honglei Huang wrote:
> 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
>
> This enables more flexible memory management between guest and host
> for GPU virtualization scenarios.
>
> Signed-off-by: Honglei Huang <honghuan@amd.com>
> ---
> 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(-)
>
> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> index 07f6355ad6..9da64bf16f 100644
> --- a/hw/display/virtio-gpu-virgl.c
> +++ b/hw/display/virtio-gpu-virgl.c
> @@ -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) {
Why does this check !ret instead of ret != 0?
Regards,
Akihiko Odaki
> + cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
> + return;
> + }
> }
> }
>
> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> index 43e88a4daf..956dc811fa 100644
> --- a/hw/display/virtio-gpu.c
> +++ b/hw/display/virtio-gpu.c
> @@ -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,
> diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h
> index 00cd3f04af..b85e781a2d 100644
> --- a/include/standard-headers/linux/virtio_gpu.h
> +++ b/include/standard-headers/linux/virtio_gpu.h
> @@ -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;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag
2025-11-12 8:44 ` Akihiko Odaki
@ 2025-11-12 10:54 ` Honglei1.Huang@amd.com
0 siblings, 0 replies; 6+ messages in thread
From: Honglei1.Huang@amd.com @ 2025-11-12 10:54 UTC (permalink / raw)
To: Akihiko Odaki
Cc: mst, cohuck, pbonzini, qemu-devel, Ray.Huang, dmitry.osipenko,
alex.bennee
On 2025/11/12 16:44, Akihiko Odaki wrote:
> On 2025/11/12 16:54, Honglei Huang wrote:
>> 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
>>
>> This enables more flexible memory management between guest and host
>> for GPU virtualization scenarios.
>>
>> Signed-off-by: Honglei Huang <honghuan@amd.com>
>> ---
>> 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(-)
>>
>> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-
>> virgl.c
>> index 07f6355ad6..9da64bf16f 100644
>> --- a/hw/display/virtio-gpu-virgl.c
>> +++ b/hw/display/virtio-gpu-virgl.c
>> @@ -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) {
>
> Why does this check !ret instead of ret != 0?
>
> Regards,
> Akihiko Odaki
>
>> + cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
>> + return;
>> + }
>> }
>> }
>> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
>> index 43e88a4daf..956dc811fa 100644
>> --- a/hw/display/virtio-gpu.c
>> +++ b/hw/display/virtio-gpu.c
>> @@ -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,
>> diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/
>> standard-headers/linux/virtio_gpu.h
>> index 00cd3f04af..b85e781a2d 100644
>> --- a/include/standard-headers/linux/virtio_gpu.h
>> +++ b/include/standard-headers/linux/virtio_gpu.h
>> @@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-11-12 14:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 7:54 [PATCH 0/3] virtio-gpu: Add user pointer and HSAKMT support enhancements Honglei Huang
2025-11-12 7:54 ` [PATCH 1/3] virtio-gpu: Add support for VIRTIO_GPU_BLOB_FLAG_USE_USERPTR flag Honglei Huang
2025-11-12 8:44 ` Akihiko Odaki
2025-11-12 10:54 ` Honglei1.Huang@amd.com
2025-11-12 7:54 ` [PATCH 2/3] virtio-gpu: add configurable HSAKMT capset support Honglei Huang
2025-11-12 7:54 ` [PATCH 3/3] virtio-gpu: Add VIRTIO_GPU_F_RESOURCE_USERPTR feature support Honglei Huang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).