From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: "Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
"Huang Rui" <ray.huang@amd.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Pierre-Eric Pelloux-Prayer" <pierre-eric.pelloux-prayer@amd.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Yiwei Zhang" <zzyiwei@gmail.com>,
"Sergio Lopez Pascual" <slp@redhat.com>
Cc: "Gert Wollny" <gert.wollny@collabora.com>,
qemu-devel@nongnu.org,
"Gurchetan Singh" <gurchetansingh@chromium.org>,
"Alyssa Ross" <hi@alyssa.is>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Stefano Stabellini" <stefano.stabellini@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Xenia Ragiadakou" <xenia.ragiadakou@amd.com>,
"Honglei Huang" <honglei1.huang@amd.com>,
"Julia Zhang" <julia.zhang@amd.com>,
"Chen Jiqian" <Jiqian.Chen@amd.com>,
"Rob Clark" <robdclark@gmail.com>,
"Robert Beckett" <bob.beckett@collabora.com>
Subject: Re: [RFC PATCH v5 3/4] virtio-gpu: Destroy virgl resources on virtio-gpu reset
Date: Mon, 1 Dec 2025 17:36:08 +0300 [thread overview]
Message-ID: <96b75cbb-7394-41ec-9013-625ea2d8d010@collabora.com> (raw)
In-Reply-To: <97def678-f5cb-482c-b322-8337339f2d58@rsg.ci.i.u-tokyo.ac.jp>
On 12/1/25 14:57, Akihiko Odaki wrote:
> On 2025/11/30 13:09, Dmitry Osipenko wrote:
>> Properly destroy virgl resources on virtio-gpu reset to not leak
>> resources
>> on a hot reboot of a VM.
>>
>> Suggested-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
>> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>> ---
>> hw/display/virtio-gpu-gl.c | 6 ++-
>> hw/display/virtio-gpu-virgl.c | 87 ++++++++++++++++++++++++++--------
>> include/hw/virtio/virtio-gpu.h | 5 +-
>> 3 files changed, 75 insertions(+), 23 deletions(-)
>>
>> diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
>> index b640900fc6f1..bf3fd75e9e6b 100644
>> --- a/hw/display/virtio-gpu-gl.c
>> +++ b/hw/display/virtio-gpu-gl.c
>> @@ -72,7 +72,10 @@ static void virtio_gpu_gl_handle_ctrl(VirtIODevice
>> *vdev, VirtQueue *vq)
>> switch (gl->renderer_state) {
>> case RS_RESET:
>> - virtio_gpu_virgl_reset(g);
>> + if (virtio_gpu_virgl_reset(g)) {
>> + gl->renderer_state = RS_INIT_FAILED;
>> + return;
>> + }
>> /* fallthrough */
>> case RS_START:
>> if (virtio_gpu_virgl_init(g)) {
>> @@ -201,6 +204,7 @@ static void virtio_gpu_gl_class_init(ObjectClass
>> *klass, const void *data)
>> vgc->process_cmd = virtio_gpu_virgl_process_cmd;
>> vgc->update_cursor_data = virtio_gpu_gl_update_cursor_data;
>> + vgc->resource_destroy = virtio_gpu_virgl_resource_destroy;
>> vdc->realize = virtio_gpu_gl_device_realize;
>> vdc->unrealize = virtio_gpu_gl_device_unrealize;
>> vdc->reset = virtio_gpu_gl_reset;
>> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-
>> virgl.c
>> index 6a2aac0b6e5c..60d8fbf0445c 100644
>> --- a/hw/display/virtio-gpu-virgl.c
>> +++ b/hw/display/virtio-gpu-virgl.c
>> @@ -304,14 +304,46 @@ static void
>> virgl_cmd_create_resource_3d(VirtIOGPU *g,
>> virgl_renderer_resource_create(&args, NULL, 0);
>> }
>> +static int
>> +virtio_gpu_virgl_resource_unref(VirtIOGPU *g,
>> + struct virtio_gpu_virgl_resource *res,
>> + bool *cmd_suspended)
>> +{
>> + struct iovec *res_iovs = NULL;
>> + int num_iovs = 0;
>> +#if VIRGL_VERSION_MAJOR >= 1
>> + int ret;
>> +
>> + ret = virtio_gpu_virgl_unmap_resource_blob(g, res, cmd_suspended);
>> + if (ret) {
>> + return ret;
>> + }
>> + if (*cmd_suspended) {
>> + return 0;
>> + }
>> +#endif
>> +
>> + virgl_renderer_resource_detach_iov(res->base.resource_id,
>> + &res_iovs,
>> + &num_iovs);
>> + if (res_iovs != NULL && num_iovs != 0) {
>> + virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs);
>> + }
>> + virgl_renderer_resource_unref(res->base.resource_id);
>> +
>> + QTAILQ_REMOVE(&g->reslist, &res->base, next);
>> +
>> + g_free(res);
>> +
>> + return 0;
>> +}
>> +
>> static void virgl_cmd_resource_unref(VirtIOGPU *g,
>> struct virtio_gpu_ctrl_command
>> *cmd,
>> bool *cmd_suspended)
>> {
>> struct virtio_gpu_resource_unref unref;
>> struct virtio_gpu_virgl_resource *res;
>> - struct iovec *res_iovs = NULL;
>> - int num_iovs = 0;
>> VIRTIO_GPU_FILL_CMD(unref);
>> trace_virtio_gpu_cmd_res_unref(unref.resource_id);
>> @@ -324,27 +356,21 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,
>> return;
>> }
>> -#if VIRGL_VERSION_MAJOR >= 1
>> - if (virtio_gpu_virgl_unmap_resource_blob(g, res, cmd_suspended)) {
>> - cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
>> - return;
>> - }
>> - if (*cmd_suspended) {
>> - return;
>> - }
>> -#endif
>> + virtio_gpu_virgl_resource_unref(g, res, cmd_suspended);
>> +}
>> - virgl_renderer_resource_detach_iov(unref.resource_id,
>> - &res_iovs,
>> - &num_iovs);
>> - if (res_iovs != NULL && num_iovs != 0) {
>> - virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs);
>> - }
>> - virgl_renderer_resource_unref(unref.resource_id);
>> +void virtio_gpu_virgl_resource_destroy(VirtIOGPU *g,
>> + struct
>> virtio_gpu_simple_resource *base,
>> + Error **errp)
>> +{
>> + struct virtio_gpu_virgl_resource *res;
>> + bool suspended = false;
>> - QTAILQ_REMOVE(&g->reslist, &res->base, next);
>> + res = container_of(base, struct virtio_gpu_virgl_resource, base);
>> - g_free(res);
>> + if (virtio_gpu_virgl_resource_unref(g, res, &suspended)) {
>> + error_setg(errp, "failed to destroy virgl resource");
>> + }
>> }
>> static void virgl_cmd_context_create(VirtIOGPU *g,
>> @@ -1273,11 +1299,30 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)
>> }
>> }
>> -void virtio_gpu_virgl_reset(VirtIOGPU *g)
>> +int virtio_gpu_virgl_reset(VirtIOGPU *g)
>> {
>> + struct virtio_gpu_simple_resource *res, *tmp;
>> +
>> + /*
>> + * Virglrender doesn't support context restoring. VirtIO-GPU
>> + * state shall not be reset at runtime. Virgl blob resource
>> + * unmapping can be deferred on unref, ensure that destruction
>> + * is completed.
>> + */
>> + QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) {
>> + virtio_gpu_virgl_resource_destroy(g, res, NULL);
>> + }
>> +
>> + if (!QTAILQ_EMPTY(&g->reslist)) {
>> + error_report("%s: failed to reset virgl resources", __func__);
>> + return -EBUSY;
>
> I think you missed my reply for an old comment (which was too late and
> sent for v3 despite you have already sent v4) so please check it out:
> https://lore.kernel.org/qemu-devel/d88cc89b-
> d796-4bc4-8c90-07da3b88cc7f@rsg.ci.i.u-tokyo.ac.jp/
Totally missed that reply from you, thanks for pointing at it!
Inlining it here:
> No, I meant that virtio_gpu_virgl_resource_unref() may set
> *cmd_suspended true. If that happens, QTAILQ_EMPTY(&g->reslist) will be
> false, but it is fine so no error log should be emitted.
Alright, the virtio_gpu_virgl_resource_destroy() itself should print out
error message when it fails. Will remove the additional error_report().
> It is confusing what "runtime" refers to. This code doesn't care about
> S3 so such a comment shouldn't be necessary.
Will remove the part of comment talking about the runtime. Thanks a lot
for the review.
--
Best regards,
Dmitry
next prev parent reply other threads:[~2025-12-01 14:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-30 4:09 [RFC PATCH v5 0/4] Support mapping virtio-gpu virgl hostmem blobs using MAP_FIXED API Dmitry Osipenko
2025-11-30 4:09 ` [RFC PATCH v5 1/4] virtio-gpu: Remove superfluous memory_region_set_enabled() Dmitry Osipenko
2025-11-30 4:09 ` [RFC PATCH v5 2/4] virtio-gpu: Validate hostmem mapping offset Dmitry Osipenko
2025-11-30 4:09 ` [RFC PATCH v5 3/4] virtio-gpu: Destroy virgl resources on virtio-gpu reset Dmitry Osipenko
2025-12-01 11:57 ` Akihiko Odaki
2025-12-01 14:36 ` Dmitry Osipenko [this message]
2025-11-30 4:09 ` [RFC PATCH v5 4/4] virtio-gpu: Support mapping hostmem blobs with map_fixed Dmitry Osipenko
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=96b75cbb-7394-41ec-9013-625ea2d8d010@collabora.com \
--to=dmitry.osipenko@collabora.com \
--cc=Jiqian.Chen@amd.com \
--cc=alex.bennee@linaro.org \
--cc=alexander.deucher@amd.com \
--cc=bob.beckett@collabora.com \
--cc=christian.koenig@amd.com \
--cc=gert.wollny@collabora.com \
--cc=gurchetansingh@chromium.org \
--cc=hi@alyssa.is \
--cc=honglei1.huang@amd.com \
--cc=julia.zhang@amd.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pierre-eric.pelloux-prayer@amd.com \
--cc=qemu-devel@nongnu.org \
--cc=ray.huang@amd.com \
--cc=robdclark@gmail.com \
--cc=roger.pau@citrix.com \
--cc=slp@redhat.com \
--cc=stefano.stabellini@amd.com \
--cc=xenia.ragiadakou@amd.com \
--cc=zzyiwei@gmail.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).