qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [PULL 04/13] virtio-gpu: Handle virtio_gpu_virgl_init() failure
Date: Tue, 29 Oct 2024 12:10:21 +0000	[thread overview]
Message-ID: <20241029121030.4007014-5-alex.bennee@linaro.org> (raw)
In-Reply-To: <20241029121030.4007014-1-alex.bennee@linaro.org>

From: Dmitry Osipenko <dmitry.osipenko@collabora.com>

virtio_gpu_virgl_init() may fail, leading to a further Qemu crash
because Qemu assumes it never fails. Check virtio_gpu_virgl_init()
return code and don't execute virtio commands on error. Failed
virtio_gpu_virgl_init() will result in a timed out virtio commands
for a guest OS.

Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Message-Id: <20241024210311.118220-5-dmitry.osipenko@collabora.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 18b6c3b3a2..71775243e9 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -222,11 +222,18 @@ struct VirtIOGPUClass {
                              Error **errp);
 };
 
+/* VirtIOGPUGL renderer states */
+typedef enum {
+    RS_START,       /* starting state */
+    RS_INIT_FAILED, /* failed initialisation */
+    RS_INITED,      /* initialised and working */
+    RS_RESET,       /* inited and reset pending, moves to start after reset */
+} RenderState;
+
 struct VirtIOGPUGL {
     struct VirtIOGPU parent_obj;
 
-    bool renderer_inited;
-    bool renderer_reset;
+    RenderState renderer_state;
 
     QEMUTimer *fence_poll;
     QEMUTimer *print_stats;
diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index 29d20b0132..ea3413aa56 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -29,9 +29,14 @@ static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g,
                                              struct virtio_gpu_scanout *s,
                                              uint32_t resource_id)
 {
+    VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
     uint32_t width, height;
     uint32_t pixels, *data;
 
+    if (gl->renderer_state != RS_INITED) {
+        return;
+    }
+
     data = virgl_renderer_get_cursor_data(resource_id, &width, &height);
     if (!data) {
         return;
@@ -65,13 +70,22 @@ static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         return;
     }
 
-    if (!gl->renderer_inited) {
-        virtio_gpu_virgl_init(g);
-        gl->renderer_inited = true;
-    }
-    if (gl->renderer_reset) {
-        gl->renderer_reset = false;
+    switch (gl->renderer_state) {
+    case RS_RESET:
         virtio_gpu_virgl_reset(g);
+        /* fallthrough */
+    case RS_START:
+        if (virtio_gpu_virgl_init(g)) {
+            gl->renderer_state = RS_INIT_FAILED;
+            return;
+        }
+
+        gl->renderer_state = RS_INITED;
+        break;
+    case RS_INIT_FAILED:
+        return;
+    case RS_INITED:
+        break;
     }
 
     cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
@@ -98,9 +112,9 @@ static void virtio_gpu_gl_reset(VirtIODevice *vdev)
      * GL functions must be called with the associated GL context in main
      * thread, and when the renderer is unblocked.
      */
-    if (gl->renderer_inited && !gl->renderer_reset) {
+    if (gl->renderer_state == RS_INITED) {
         virtio_gpu_virgl_reset_scanout(g);
-        gl->renderer_reset = true;
+        gl->renderer_state = RS_RESET;
     }
 }
 
-- 
2.39.5



  parent reply	other threads:[~2024-10-29 12:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-29 12:10 [PULL 00/13] virtio-gpu vulkan support Alex Bennée
2024-10-29 12:10 ` [PULL 01/13] virtio-gpu: Use trace events for tracking number of in-flight fences Alex Bennée
2024-10-29 12:10 ` [PULL 02/13] virtio-gpu: Move fence_poll timer to VirtIOGPUGL Alex Bennée
2024-10-29 12:10 ` [PULL 03/13] virtio-gpu: Move print_stats " Alex Bennée
2024-10-29 12:10 ` Alex Bennée [this message]
2024-10-29 12:10 ` [PULL 05/13] virtio-gpu: Unrealize GL device Alex Bennée
2024-10-29 12:10 ` [PULL 06/13] virtio-gpu: Use pkgconfig version to decide which virgl features are available Alex Bennée
2024-10-29 12:10 ` [PULL 07/13] virtio-gpu: Support context-init feature with virglrenderer Alex Bennée
2024-10-29 12:10 ` [PULL 08/13] virtio-gpu: Don't require udmabuf when blobs and virgl are enabled Alex Bennée
2024-10-29 12:10 ` [PULL 09/13] virtio-gpu: Add virgl resource management Alex Bennée
2024-10-29 12:10 ` [PULL 10/13] virtio-gpu: Support suspension of commands processing Alex Bennée
2024-10-29 12:10 ` [PULL 11/13] virtio-gpu: Handle resource blob commands Alex Bennée
2024-11-01 15:35   ` Peter Maydell
2024-11-01 16:04     ` Dmitry Osipenko
2024-11-01 17:17       ` Alex Bennée
2024-11-01 17:16     ` Alex Bennée
2024-11-01 18:23       ` Dmitry Osipenko
2024-11-04 11:48         ` Alex Bennée
2024-11-04 13:50           ` BALATON Zoltan
2024-10-29 12:10 ` [PULL 12/13] virtio-gpu: Register capsets dynamically Alex Bennée
2024-10-29 12:10 ` [PULL 13/13] virtio-gpu: Support Venus context Alex Bennée
2024-10-31 11:29 ` [PULL 00/13] virtio-gpu vulkan support Peter Maydell

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=20241029121030.4007014-5-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=dmitry.osipenko@collabora.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.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).