From: Huang Rui <ray.huang@amd.com>
To: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: "Gerd Hoffmann" <kraxel@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Anthony PERARD" <anthony.perard@citrix.com>,
"Antonio Caggiano" <antonio.caggiano@collabora.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
"Robert Beckett" <bob.beckett@collabora.com>,
"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
"Gurchetan Singh" <gurchetansingh@chromium.org>,
"ernunes@redhat.com" <ernunes@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Alyssa Ross" <hi@alyssa.is>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Deucher, Alexander" <Alexander.Deucher@amd.com>,
"Koenig, Christian" <Christian.Koenig@amd.com>,
"Ragiadakou, Xenia" <Xenia.Ragiadakou@amd.com>,
"Pelloux-Prayer,
Pierre-Eric" <Pierre-eric.Pelloux-prayer@amd.com>,
"Huang, Honglei1" <Honglei1.Huang@amd.com>,
"Zhang, Julia" <Julia.Zhang@amd.com>,
"Chen, Jiqian" <Jiqian.Chen@amd.com>
Subject: Re: [QEMU PATCH v4 10/13] virtio-gpu: Resource UUID
Date: Sat, 9 Sep 2023 17:09:38 +0800 [thread overview]
Message-ID: <ZPw2UjxogIULU722@amd.com> (raw)
In-Reply-To: <58a4e81f-b0ce-49db-8a6a-f6b5bdc3d2d6@daynix.com>
On Thu, Aug 31, 2023 at 06:36:57PM +0800, Akihiko Odaki wrote:
> On 2023/08/31 18:32, Huang Rui wrote:
> > From: Antonio Caggiano <antonio.caggiano@collabora.com>
> >
> > Enable resource UUID feature and implement command resource assign UUID.
> > This is done by introducing a hash table to map resource IDs to their
> > UUIDs.
>
> The hash table does not seem to be stored during migration.
May I know whether you point g->resource_uuids table data in VirtIOGPU
device should be stored in virtio_gpu_save() and resumed in
virtio_gpu_load() for virtio migration?
>
> >
> > Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
> > Signed-off-by: Huang Rui <ray.huang@amd.com>
> > ---
> >
> > v1->v2:
> > - Separate declarations from code.
> >
> > hw/display/trace-events | 1 +
> > hw/display/virtio-gpu-base.c | 2 ++
> > hw/display/virtio-gpu-virgl.c | 21 +++++++++++++++++
> > hw/display/virtio-gpu.c | 41 ++++++++++++++++++++++++++++++++++
> > include/hw/virtio/virtio-gpu.h | 4 ++++
> > 5 files changed, 69 insertions(+)
> >
> > diff --git a/hw/display/trace-events b/hw/display/trace-events
> > index 2336a0ca15..54d6894c59 100644
> > --- a/hw/display/trace-events
> > +++ b/hw/display/trace-events
> > @@ -41,6 +41,7 @@ virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, size %" P
> > virtio_gpu_cmd_res_unref(uint32_t res) "res 0x%x"
> > virtio_gpu_cmd_res_back_attach(uint32_t res) "res 0x%x"
> > virtio_gpu_cmd_res_back_detach(uint32_t res) "res 0x%x"
> > +virtio_gpu_cmd_res_assign_uuid(uint32_t res) "res 0x%x"
> > virtio_gpu_cmd_res_xfer_toh_2d(uint32_t res) "res 0x%x"
> > virtio_gpu_cmd_res_xfer_toh_3d(uint32_t res) "res 0x%x"
> > virtio_gpu_cmd_res_xfer_fromh_3d(uint32_t res) "res 0x%x"
> > diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
> > index 4f2b0ba1f3..f44388715c 100644
> > --- a/hw/display/virtio-gpu-base.c
> > +++ b/hw/display/virtio-gpu-base.c
> > @@ -236,6 +236,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
> > features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
> > }
> >
> > + features |= (1 << VIRTIO_GPU_F_RESOURCE_UUID);
> > +
> > return features;
> > }
> >
> > diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> > index 17b634d4ee..1a996a08fc 100644
> > --- a/hw/display/virtio-gpu-virgl.c
> > +++ b/hw/display/virtio-gpu-virgl.c
> > @@ -36,6 +36,7 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
> > {
> > struct virtio_gpu_resource_create_2d c2d;
> > struct virgl_renderer_resource_create_args args;
> > + struct virtio_gpu_simple_resource *res;
> >
> > VIRTIO_GPU_FILL_CMD(c2d);
> > trace_virtio_gpu_cmd_res_create_2d(c2d.resource_id, c2d.format,
> > @@ -53,6 +54,14 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
> > args.nr_samples = 0;
> > args.flags = VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP;
> > virgl_renderer_resource_create(&args, NULL, 0);
> > +
> > + res = g_new0(struct virtio_gpu_simple_resource, 1);
> > + if (!res) {
> > + cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
> > + return;
>
> virglrenderer thinks the resource is alive in such a situation.
Yes, so we can move the resource allocation in front of below virglrenderer
resource creation.
virgl_renderer_resource_create(&args, NULL, 0);
>
> > + }
> > + res->resource_id = c2d.resource_id;
> > + QTAILQ_INSERT_HEAD(&g->reslist, res, next);
> > }
> >
> > static void virgl_cmd_create_resource_3d(VirtIOGPU *g,
> > @@ -60,6 +69,7 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,
> > {
> > struct virtio_gpu_resource_create_3d c3d;
> > struct virgl_renderer_resource_create_args args;
> > + struct virtio_gpu_simple_resource *res;
> >
> > VIRTIO_GPU_FILL_CMD(c3d);
> > trace_virtio_gpu_cmd_res_create_3d(c3d.resource_id, c3d.format,
> > @@ -77,6 +87,14 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,
> > args.nr_samples = c3d.nr_samples;
> > args.flags = c3d.flags;
> > virgl_renderer_resource_create(&args, NULL, 0);
> > +
> > + res = g_new0(struct virtio_gpu_simple_resource, 1);
> > + if (!res) {
> > + cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
> > + return;
> > + }
> > + res->resource_id = c3d.resource_id;
> > + QTAILQ_INSERT_HEAD(&g->reslist, res, next);
> > }
> >
> > static void virgl_resource_destroy(VirtIOGPU *g,
> > @@ -682,6 +700,9 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
> > /* TODO add security */
> > virgl_cmd_ctx_detach_resource(g, cmd);
> > break;
> > + case VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID:
> > + virtio_gpu_resource_assign_uuid(g, cmd);
> > + break;
> > case VIRTIO_GPU_CMD_GET_CAPSET_INFO:
> > virgl_cmd_get_capset_info(g, cmd);
> > break;
> > diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> > index cc4c1f81bb..770e4747e3 100644
> > --- a/hw/display/virtio-gpu.c
> > +++ b/hw/display/virtio-gpu.c
> > @@ -966,6 +966,37 @@ virtio_gpu_resource_detach_backing(VirtIOGPU *g,
> > virtio_gpu_cleanup_mapping(g, res);
> > }
> >
> > +void virtio_gpu_resource_assign_uuid(VirtIOGPU *g,
> > + struct virtio_gpu_ctrl_command *cmd)
> > +{
> > + struct virtio_gpu_simple_resource *res;
> > + struct virtio_gpu_resource_assign_uuid assign;
> > + struct virtio_gpu_resp_resource_uuid resp;
> > + QemuUUID *uuid = NULL;
>
> This initialization is unnecessary.
Yes, will remove it.
>
> > +
> > + VIRTIO_GPU_FILL_CMD(assign);
> > + virtio_gpu_bswap_32(&assign, sizeof(assign));
> > + trace_virtio_gpu_cmd_res_assign_uuid(assign.resource_id);
> > +
> > + res = virtio_gpu_find_check_resource(g, assign.resource_id, false, __func__, &cmd->error);
> > + if (!res) {
> > + return;
> > + }
> > +
> > + memset(&resp, 0, sizeof(resp));
> > + resp.hdr.type = VIRTIO_GPU_RESP_OK_RESOURCE_UUID;
> > +
> > + uuid = g_hash_table_lookup(g->resource_uuids, GUINT_TO_POINTER(assign.resource_id));
> > + if (!uuid) {
> > + uuid = g_new(QemuUUID, 1);
> > + qemu_uuid_generate(uuid);
> > + g_hash_table_insert(g->resource_uuids, GUINT_TO_POINTER(assign.resource_id), uuid);
> > + }
> > +
> > + memcpy(resp.uuid, uuid, sizeof(QemuUUID));
> > + virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp));
> > +}
> > +
> > void virtio_gpu_simple_process_cmd(VirtIOGPU *g,
> > struct virtio_gpu_ctrl_command *cmd)
> > {
> > @@ -1014,6 +1045,9 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g,
> > case VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING:
> > virtio_gpu_resource_detach_backing(g, cmd);
> > break;
> > + case VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID:
> > + virtio_gpu_resource_assign_uuid(g, cmd);
> > + break;
> > default:
> > cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
> > break;
> > @@ -1393,12 +1427,15 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
> > QTAILQ_INIT(&g->reslist);
> > QTAILQ_INIT(&g->cmdq);
> > QTAILQ_INIT(&g->fenceq);
> > +
> > + g->resource_uuids = g_hash_table_new_full(NULL, NULL, NULL, g_free);
> > }
> >
> > static void virtio_gpu_device_unrealize(DeviceState *qdev)
> > {
> > VirtIOGPU *g = VIRTIO_GPU(qdev);
> >
> > + g_hash_table_destroy(g->resource_uuids);
> > g_clear_pointer(&g->ctrl_bh, qemu_bh_delete);
> > g_clear_pointer(&g->cursor_bh, qemu_bh_delete);
> > g_clear_pointer(&g->reset_bh, qemu_bh_delete);
> > @@ -1452,6 +1489,10 @@ void virtio_gpu_reset(VirtIODevice *vdev)
> > g_free(cmd);
> > }
> >
> > + if (g->resource_uuids) {
>
> Isn't g->resource_uuids always non-NULL?
Yes, right. The if check should be superfluous. Will remove it.
Thanks,
Ray
>
> > + g_hash_table_remove_all(g->resource_uuids);
> > + }
> > +
> > virtio_gpu_base_reset(VIRTIO_GPU_BASE(vdev));
> > }
> >
> > diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
> > index b9adc28071..aa94b1b697 100644
> > --- a/include/hw/virtio/virtio-gpu.h
> > +++ b/include/hw/virtio/virtio-gpu.h
> > @@ -208,6 +208,8 @@ struct VirtIOGPU {
> > QTAILQ_HEAD(, VGPUDMABuf) bufs;
> > VGPUDMABuf *primary[VIRTIO_GPU_MAX_SCANOUTS];
> > } dmabuf;
> > +
> > + GHashTable *resource_uuids;
> > };
> >
> > struct VirtIOGPUClass {
> > @@ -285,6 +287,8 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,
> > struct iovec *iov, uint32_t count);
> > void virtio_gpu_cleanup_mapping(VirtIOGPU *g,
> > struct virtio_gpu_simple_resource *res);
> > +void virtio_gpu_resource_assign_uuid(VirtIOGPU *g,
> > + struct virtio_gpu_ctrl_command *cmd);
> > void virtio_gpu_process_cmdq(VirtIOGPU *g);
> > void virtio_gpu_device_realize(DeviceState *qdev, Error **errp);
> > void virtio_gpu_reset(VirtIODevice *vdev);
next prev parent reply other threads:[~2023-09-09 9:16 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 9:32 [QEMU PATCH v4 00/13] Support blob memory and venus on qemu Huang Rui
2023-08-31 9:32 ` [QEMU PATCH v4 01/13] virtio: Add shared memory capability Huang Rui
2023-08-31 9:32 ` [QEMU PATCH v4 02/13] virtio-gpu: CONTEXT_INIT feature Huang Rui
2023-08-31 9:32 ` [QEMU PATCH v4 03/13] virtio-gpu: hostmem Huang Rui
2023-08-31 9:32 ` [QEMU PATCH v4 04/13] virtio-gpu: blob prep Huang Rui
2023-08-31 9:32 ` [QEMU PATCH v4 05/13] virtio-gpu: Support context init feature with virglrenderer Huang Rui
2023-08-31 9:41 ` Philippe Mathieu-Daudé
2023-08-31 9:32 ` [QEMU PATCH v4 06/13] virtio-gpu: Configure context init for virglrenderer Huang Rui
2023-08-31 9:39 ` Philippe Mathieu-Daudé
2023-09-04 6:45 ` Huang Rui via
2023-08-31 9:32 ` [QEMU PATCH v4 07/13] softmmu/memory: enable automatic deallocation of memory regions Huang Rui
2023-08-31 10:10 ` Akihiko Odaki
2023-09-05 9:07 ` Huang Rui
2023-09-05 9:17 ` Akihiko Odaki
2023-09-05 13:29 ` Huang Rui
2023-08-31 9:32 ` [QEMU PATCH v4 08/13] virtio-gpu: Don't require udmabuf when blobs and virgl are enabled Huang Rui
2023-08-31 9:32 ` [QEMU PATCH v4 09/13] virtio-gpu: Handle resource blob commands Huang Rui
2023-08-31 10:24 ` Akihiko Odaki
2023-09-05 9:08 ` Huang Rui
2023-09-05 9:20 ` Akihiko Odaki
2023-09-06 3:09 ` Huang Rui
2023-09-06 3:39 ` Akihiko Odaki
2023-09-06 7:56 ` Huang Rui
2023-09-06 14:16 ` Akihiko Odaki
2023-08-31 9:32 ` [QEMU PATCH v4 10/13] virtio-gpu: Resource UUID Huang Rui
2023-08-31 10:36 ` Akihiko Odaki
2023-09-09 9:09 ` Huang Rui [this message]
2023-09-10 4:21 ` Akihiko Odaki
2023-09-13 7:55 ` Albert Esteve
2023-09-13 10:34 ` Akihiko Odaki
2023-09-13 11:34 ` Albert Esteve
2023-09-13 12:22 ` Akihiko Odaki
2023-09-13 12:58 ` Albert Esteve
2023-09-13 13:43 ` Akihiko Odaki
2023-09-13 14:18 ` Albert Esteve
2023-09-13 14:27 ` Albert Esteve
2023-09-14 7:17 ` Akihiko Odaki
2023-09-14 8:29 ` Albert Esteve
2023-09-14 16:55 ` Akihiko Odaki
2023-09-15 9:56 ` Albert Esteve
2023-08-31 9:32 ` [QEMU PATCH v4 11/13] virtio-gpu: Support Venus capset Huang Rui
2023-08-31 10:43 ` Akihiko Odaki
2023-09-09 9:29 ` Huang Rui
2023-09-10 4:32 ` Akihiko Odaki
2023-08-31 9:32 ` [QEMU PATCH v4 12/13] virtio-gpu: Initialize Venus Huang Rui
2023-08-31 10:40 ` Antonio Caggiano
2023-08-31 15:51 ` Dmitry Osipenko
2023-09-09 10:53 ` Huang Rui via
2023-09-12 13:44 ` Dmitry Osipenko
2023-09-09 10:52 ` Huang Rui
2023-08-31 9:32 ` [QEMU PATCH v4 13/13] virtio-gpu: Enable virglrenderer render server flag for venus Huang Rui
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=ZPw2UjxogIULU722@amd.com \
--to=ray.huang@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=Christian.Koenig@amd.com \
--cc=Honglei1.Huang@amd.com \
--cc=Jiqian.Chen@amd.com \
--cc=Julia.Zhang@amd.com \
--cc=Pierre-eric.Pelloux-prayer@amd.com \
--cc=Xenia.Ragiadakou@amd.com \
--cc=akihiko.odaki@daynix.com \
--cc=alex.bennee@linaro.org \
--cc=anthony.perard@citrix.com \
--cc=antonio.caggiano@collabora.com \
--cc=bob.beckett@collabora.com \
--cc=dgilbert@redhat.com \
--cc=dmitry.osipenko@collabora.com \
--cc=ernunes@redhat.com \
--cc=gurchetansingh@chromium.org \
--cc=hi@alyssa.is \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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).