On Thu, Jul 16, 2026 at 3:25 PM Dorinda Bassey <[email protected]> wrote:
>
> From: Matej Hrica <[email protected]>
>
> Add a 'hostmem' property to the vhost-user-gpu which enables the shared
> memory in the parent object.
>
> Register a container MR in the shmem_list for SHMEM_MAP/UNMAP
> operations. A container MR is used so that SHMEM_MAP FD-backed
> subregions each get their own KVM memory slot with the correct
> backing fd.
>
> Signed-off-by: Matej Hrica <[email protected]>
> Signed-off-by: Dorinda Bassey <[email protected]>
> ---
>  hw/display/vhost-user-gpu.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
> index 06549c98e07..7e4580aa895 100644
> --- a/hw/display/vhost-user-gpu.c
> +++ b/hw/display/vhost-user-gpu.c
> @@ -655,6 +655,21 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error 
> **errp)
>      }
>
>      g->vhost_gpu_fd = -1;
> +
> +    /*
> +     * If shared memory is enabled, register the hostmem region for
> +     * SHMEM_MAP/UNMAP operations.
> +     */
> +    if (virtio_gpu_hostmem_enabled(g->parent_obj.conf)) {
> +        VirtioSharedMemory *shmem = g_new0(VirtioSharedMemory, 1);
> +        shmem->shmid = VIRTIO_GPU_SHM_ID_HOST_VISIBLE;
> +        memory_region_init(&shmem->mr, OBJECT(vdev),
> +                           "vhost-user-gpu-shmem",
> +                           g->parent_obj.conf.hostmem);
> +        memory_region_add_subregion(&g->parent_obj.hostmem, 0, &shmem->mr);
> +        QTAILQ_INIT(&shmem->mmaps);
> +        QSIMPLEQ_INSERT_TAIL(&vdev->shmem_list, shmem, entry);
> +    }

Why not just use virtio_new_shmem_region()?

>  }
>
>  static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev)
> @@ -665,6 +680,7 @@ static struct vhost_dev 
> *vhost_user_gpu_get_vhost(VirtIODevice *vdev)
>
>  static const Property vhost_user_gpu_properties[] = {
>      VIRTIO_GPU_BASE_PROPERTIES(VhostUserGPU, parent_obj.conf),
> +    DEFINE_PROP_SIZE("hostmem", VhostUserGPU, parent_obj.conf.hostmem, 0),
>  };
>
>  static void
> --
> 2.52.0
>


Reply via email to