From: Matej Hrica <mhrica@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, dbassey@redhat.com,
aesteve@redhat.com, slp@redhat.com,
Matej Hrica <mhrica@redhat.com>
Subject: [RFC PATCH 2/2] vhost-user-gpu: Add shared memory region support
Date: Thu, 18 Jul 2024 14:12:47 +0200 [thread overview]
Message-ID: <20240718121247.181510-3-mhrica@redhat.com> (raw)
In-Reply-To: <20240718121247.181510-1-mhrica@redhat.com>
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
prev parent reply other threads:[~2024-07-18 12:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240718121247.181510-3-mhrica@redhat.com \
--to=mhrica@redhat.com \
--cc=aesteve@redhat.com \
--cc=dbassey@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=slp@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).