* [RFC PATCH 1/2] vhost-user-gpu: Forward RESOURCE_BLOB and CONTEXT_INIT flags
2024-07-18 12:12 [RFC PATCH 0/2] vhost-user-gpu: Add support for blob resources Matej Hrica
@ 2024-07-18 12:12 ` Matej Hrica
2024-07-18 12:12 ` [RFC PATCH 2/2] vhost-user-gpu: Add shared memory region support Matej Hrica
1 sibling, 0 replies; 3+ messages in thread
From: Matej Hrica @ 2024-07-18 12:12 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, dbassey, aesteve, slp, Matej Hrica
Forward VIRTIO_GPU_F_RESOURCE_BLOB and VIRTIO_GPU_F_CONTEXT_INIT recieved from
a vhost backend to expose it to the guest.
Signed-off-by: Matej Hrica <mhrica@redhat.com>
---
hw/display/vhost-user-gpu.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index 63c64ddde6..0ebc2218b9 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -631,6 +631,12 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)
error_report("EDID requested but the backend doesn't support it.");
g->parent_obj.conf.flags &= ~(1 << VIRTIO_GPU_FLAG_EDID_ENABLED);
}
+ if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_RESOURCE_BLOB)) {
+ g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_BLOB_ENABLED;
+ }
+ if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_CONTEXT_INIT)) {
+ g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED;
+ }
if (!virtio_gpu_base_device_realize(qdev, NULL, NULL, errp)) {
return;
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [RFC PATCH 2/2] vhost-user-gpu: Add shared memory region support
2024-07-18 12:12 [RFC PATCH 0/2] vhost-user-gpu: Add support for blob resources Matej Hrica
2024-07-18 12:12 ` [RFC PATCH 1/2] vhost-user-gpu: Forward RESOURCE_BLOB and CONTEXT_INIT flags Matej Hrica
@ 2024-07-18 12:12 ` Matej Hrica
1 sibling, 0 replies; 3+ messages in thread
From: Matej Hrica @ 2024-07-18 12:12 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, dbassey, aesteve, slp, Matej Hrica
Add a 'hostmem' property to the vhost-user-gpu which enables the shared memory
in the parent object.
The memory region is created by the parent object (virtio-gpu-pci or virtio-vga)
Add a subregion (which spans the whole region) in vhost-user-gpu and register it
in the shmem_list, which enables the usage of SHMEM_MMAP/UNMAP operations.
Signed-off-by: Matej Hrica <mhrica@redhat.com>
---
hw/display/vhost-user-gpu.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index 0ebc2218b9..78a1d090d8 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -643,6 +643,30 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)
}
g->vhost_gpu_fd = -1;
+
+ /*
+ * If shared memory is enabled in the config, the parent (virtio-gpu-pci,
+ * virtio-vga) has already added a shared memory region at this point.
+ * Add a subregion that spans the whole region and register it in
+ * the shmem_list to be usable for SHMEM_MMAP/UNMAP operations.
+ */
+ if (virtio_gpu_hostmem_enabled(g->parent_obj.conf)) {
+ void *hostmem_ptr = mmap(NULL, g->parent_obj.conf.hostmem,
+ PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+ if (hostmem_ptr == MAP_FAILED) {
+ error_setg(errp, "Unable to mmap blank hostmem");
+ return;
+ }
+
+ virtio_new_shmem_region(vdev);
+ MemoryRegion *mr = &vdev->shmem_list[vdev->n_shmem_regions - 1];
+ memory_region_init_ram_ptr(mr,
+ OBJECT(vdev),
+ "vhost-user-gpu-hostmem",
+ g->parent_obj.conf.hostmem, hostmem_ptr);
+ memory_region_add_subregion(&g->parent_obj.hostmem, 0, mr);
+ }
}
static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev)
@@ -653,6 +677,7 @@ static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev)
static Property vhost_user_gpu_properties[] = {
VIRTIO_GPU_BASE_PROPERTIES(VhostUserGPU, parent_obj.conf),
+ DEFINE_PROP_SIZE("hostmem", VhostUserGPU, parent_obj.conf.hostmem, 0),
DEFINE_PROP_END_OF_LIST(),
};
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread