vhost-user-gpu: Add support for blob resources
cover vhost-user-gpu: Add support for blob resources
Hi,
these patches enable a backend vhost user gpu implementation to support blob resources.
The first patch simply forwards required feature flags. The second patch registers a shared memory region for mapping the blob resources in the guest memory.
I am not sure about the shared memory region creation in the second patch. Is it fine to rely on the parent object to create the shared memory region? The parent object should be either virtio-gpu-pci or virtio-vga, though I am not really sure about the class hierarchy.
These patches are based on this RFC:
[RFC PATCH v2 0/5] vhost-user: Add SHMEM_MAP/UNMAP requests.
Since this relies on an RFC patch, I am also sending this as an RFC too.
Matej Hrica (2):
vhost-user-gpu: Forward RESOURCE_BLOB and CONTEXT_INIT flags
vhost-user-gpu: Add shared memory region support
hw/display/vhost-user-gpu.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
Signature · 1 line
2.45.2
RFC PATCH 1/2 vhost-user-gpu: Forward RESOURCE_BLOB and CONTEXT_INIT flags
Forward VIRTIO_GPU_F_RESOURCE_BLOB and VIRTIO_GPU_F_CONTEXT_INIT recieved from a vhost backend to expose it to the guest.
--- hw/display/vhost-user-gpu.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/display/vhost-user-gpu.c +6 -0
@@ -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 ;
Signature · 1 line
2.45.2
RFC PATCH 2/2 vhost-user-gpu: Add shared memory region support
In reply to Matej HricaAdd 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.
--- hw/display/vhost-user-gpu.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
hw/display/vhost-user-gpu.c +25 -0
@@ -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 (), };
Signature · 1 line
2.45.2