All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/20] Various vhost-user-gpu & UI fixes
@ 2021-02-04 10:52 marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 01/20] vhost-user-gpu: check backend for EDID support marcandre.lureau
                   ` (19 more replies)
  0 siblings, 20 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Hi,

Here is a collection of fixes and improvements mostly around vhost-user-gpu. In
combination with spice, they work best with the previously sent fixes ("[PATCH
0/2] Fix (non-vga) QXL async screendump" & "[PATCH v2] spice: delay starting
until display are initialized"). I also use virgl from git, which seems to work
better. You also need mesa with the recent fix !8663 from last week if you test
this.

The last patch is a simple RFC avocado test to have the basics under some
control and avoid simple regressions.

I have further refactoring work pending to separate the DisplayChangeListener
from the GL context. This should allow to run a GL-less qemu with Spice client &
vhost-user-gpu/virgl for example.

v2:
 - styles fixes
 - drop RFC from avocado test

Marc-André Lureau (20):
  vhost-user-gpu: check backend for EDID support
  vhost-user-gpu: handle vhost-user-gpu features in a callback
  vhost-user-gpu: use an extandable state enum for commands
  vhost-user-gpu: handle display-info in a callback
  ui: remove extra #ifdef CONFIG_OPENGL
  ui: remove gl_ctx_get_current
  ui: add gd_gl_area_scanout_disable
  ui: annotate DCLOps callback requirements
  ui: remove console_has_gl_dmabuf()
  vhost-user-gpu: add a configuration flag for dmabuf usage
  ui: add an optional get_flags callback to GraphicHwOps
  ui: add a DCLOps callback to check dmabuf support
  ui: check hw requirements during DCL registration
  ui: add qemu_egl_has_dmabuf helper
  ui: check gtk-egl dmabuf support
  ui: add egl dmabuf import to gtkglarea
  virtio-gpu: avoid re-entering cmdq processing
  display/ui: add a callback to indicate GL state is flushed
  chardev: check if the chardev is registered for yanking
  tests: add some virtio-gpu & vhost-user-gpu acceptance test

 contrib/vhost-user-gpu/vugpu.h          |  10 +-
 include/hw/virtio/virtio-gpu.h          |   6 +-
 include/ui/console.h                    |  35 +++++-
 include/ui/egl-context.h                |   1 -
 include/ui/egl-helpers.h                |   1 +
 include/ui/gtk.h                        |   4 +
 include/ui/sdl2.h                       |   1 -
 chardev/char-socket.c                   |  53 +++++---
 contrib/vhost-user-gpu/vhost-user-gpu.c |  78 +++++++++---
 contrib/vhost-user-gpu/virgl.c          |   2 +-
 hw/display/vhost-user-gpu.c             |  17 +--
 hw/display/virtio-gpu-base.c            |  31 ++++-
 hw/display/virtio-gpu.c                 |   9 +-
 hw/display/virtio-vga.c                 |  20 +++
 hw/vfio/display.c                       |   6 +
 ui/console.c                            |  64 +++++++---
 ui/egl-context.c                        |   5 -
 ui/egl-headless.c                       |   1 -
 ui/egl-helpers.c                        |  10 ++
 ui/gtk-egl.c                            |   3 +
 ui/gtk-gl-area.c                        |  28 +++++
 ui/gtk.c                                |  43 +++++--
 ui/sdl2-gl.c                            |  10 +-
 ui/sdl2.c                               |   1 -
 ui/spice-display.c                      |   2 +-
 tests/acceptance/virtio-gpu.py          | 161 ++++++++++++++++++++++++
 26 files changed, 501 insertions(+), 101 deletions(-)
 create mode 100644 tests/acceptance/virtio-gpu.py

-- 
2.29.0




^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v2 01/20] vhost-user-gpu: check backend for EDID support
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 02/20] vhost-user-gpu: handle vhost-user-gpu features in a callback marcandre.lureau
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

EDID has been enabled by default, but the backend may not implement
it (such as the contrib backend). This results in extra warnings and
potentially other issues in the guest.

The option shouldn't probably have been added to VIRTIO_GPU_BASE, but
it's a bit too late now, report an error and disable EDID when it's
not available.

Fixes: 0a7196625 ("edid: flip the default to enabled")

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/display/vhost-user-gpu.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index 51f1747c4a..55b0ed15f2 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -555,6 +555,12 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)
     if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_VIRGL)) {
         g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED;
     }
+    if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_EDID)) {
+        g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_EDID_ENABLED;
+    } else {
+        error_report("EDID requested but the backend doesn't support it.");
+        g->parent_obj.conf.flags &= ~(1 << VIRTIO_GPU_FLAG_EDID_ENABLED);
+    }
 
     if (!virtio_gpu_base_device_realize(qdev, NULL, NULL, errp)) {
         return;
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 02/20] vhost-user-gpu: handle vhost-user-gpu features in a callback
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 01/20] vhost-user-gpu: check backend for EDID support marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands marcandre.lureau
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Fixes a deadlock where the backend calls QEMU, while QEMU also calls the
backend simultaneously, both ends waiting for each other.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/vhost-user-gpu/vugpu.h          |  2 +-
 contrib/vhost-user-gpu/vhost-user-gpu.c | 37 ++++++++++++++++++-------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
index ad664c4df8..86f3ac86aa 100644
--- a/contrib/vhost-user-gpu/vugpu.h
+++ b/contrib/vhost-user-gpu/vugpu.h
@@ -118,7 +118,7 @@ typedef struct VuGpu {
     int sock_fd;
     int drm_rnode_fd;
     GSource *renderer_source;
-    guint wait_ok;
+    guint wait_in;
 
     bool virgl;
     bool virgl_inited;
diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c
index f445ef28ec..85c16404fb 100644
--- a/contrib/vhost-user-gpu/vhost-user-gpu.c
+++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
@@ -124,7 +124,7 @@ source_wait_cb(gint fd, GIOCondition condition, gpointer user_data)
     }
 
     /* resume */
-    g->wait_ok = 0;
+    g->wait_in = 0;
     vg_handle_ctrl(&g->dev.parent, 0);
 
     return G_SOURCE_REMOVE;
@@ -133,8 +133,8 @@ source_wait_cb(gint fd, GIOCondition condition, gpointer user_data)
 void
 vg_wait_ok(VuGpu *g)
 {
-    assert(g->wait_ok == 0);
-    g->wait_ok = g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP,
+    assert(g->wait_in == 0);
+    g->wait_in = g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP,
                                source_wait_cb, g);
 }
 
@@ -270,7 +270,7 @@ vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd)
         .size = 0,
     };
 
-    assert(vg->wait_ok == 0);
+    assert(vg->wait_in == 0);
 
     vg_send_msg(vg, &msg, -1);
     if (!vg_recv_msg(vg, msg.request, sizeof(dpy_info), &dpy_info)) {
@@ -815,7 +815,7 @@ vg_handle_ctrl(VuDev *dev, int qidx)
     size_t len;
 
     for (;;) {
-        if (vg->wait_ok != 0) {
+        if (vg->wait_in != 0) {
             return;
         }
 
@@ -969,18 +969,17 @@ vg_queue_set_started(VuDev *dev, int qidx, bool started)
     }
 }
 
-static void
-set_gpu_protocol_features(VuGpu *g)
+static gboolean
+protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data)
 {
+    VuGpu *g = user_data;
     uint64_t u64;
     VhostUserGpuMsg msg = {
         .request = VHOST_USER_GPU_GET_PROTOCOL_FEATURES
     };
 
-    assert(g->wait_ok == 0);
-    vg_send_msg(g, &msg, -1);
     if (!vg_recv_msg(g, msg.request, sizeof(u64), &u64)) {
-        return;
+        return G_SOURCE_CONTINUE;
     }
 
     msg = (VhostUserGpuMsg) {
@@ -989,6 +988,24 @@ set_gpu_protocol_features(VuGpu *g)
         .payload.u64 = 0
     };
     vg_send_msg(g, &msg, -1);
+
+    g->wait_in = 0;
+    vg_handle_ctrl(&g->dev.parent, 0);
+
+    return G_SOURCE_REMOVE;
+}
+
+static void
+set_gpu_protocol_features(VuGpu *g)
+{
+    VhostUserGpuMsg msg = {
+        .request = VHOST_USER_GPU_GET_PROTOCOL_FEATURES
+    };
+
+    vg_send_msg(g, &msg, -1);
+    assert(g->wait_in == 0);
+    g->wait_in = g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP,
+                               protocol_features_cb, g);
 }
 
 static int
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 01/20] vhost-user-gpu: check backend for EDID support marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 02/20] vhost-user-gpu: handle vhost-user-gpu features in a callback marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 11:26   ` Philippe Mathieu-Daudé
  2021-02-04 10:52 ` [PATCH v2 04/20] vhost-user-gpu: handle display-info in a callback marcandre.lureau
                   ` (16 subsequent siblings)
  19 siblings, 1 reply; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Introduce a pending state for commands which aren't finished yet, but
are being handled. See following patch.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/vhost-user-gpu/vugpu.h          | 8 +++++++-
 contrib/vhost-user-gpu/vhost-user-gpu.c | 8 ++++----
 contrib/vhost-user-gpu/virgl.c          | 2 +-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
index 86f3ac86aa..04d5615812 100644
--- a/contrib/vhost-user-gpu/vugpu.h
+++ b/contrib/vhost-user-gpu/vugpu.h
@@ -129,12 +129,18 @@ typedef struct VuGpu {
     QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
 } VuGpu;
 
+enum {
+    VG_CMD_STATE_NEW,
+    VG_CMD_STATE_PENDING,
+    VG_CMD_STATE_FINISHED,
+};
+
 struct virtio_gpu_ctrl_command {
     VuVirtqElement elem;
     VuVirtq *vq;
     struct virtio_gpu_ctrl_hdr cmd_hdr;
     uint32_t error;
-    bool finished;
+    int state;
     QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
 };
 
diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c
index 85c16404fb..7dcc02966c 100644
--- a/contrib/vhost-user-gpu/vhost-user-gpu.c
+++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
@@ -246,7 +246,7 @@ vg_ctrl_response(VuGpu *g,
     }
     vu_queue_push(&g->dev.parent, cmd->vq, &cmd->elem, s);
     vu_queue_notify(&g->dev.parent, cmd->vq);
-    cmd->finished = true;
+    cmd->state = VG_CMD_STATE_FINISHED;
 }
 
 void
@@ -800,7 +800,7 @@ vg_process_cmd(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd)
         cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
         break;
     }
-    if (!cmd->finished) {
+    if (cmd->state == VG_CMD_STATE_NEW) {
         vg_ctrl_response_nodata(vg, cmd, cmd->error ? cmd->error :
                                 VIRTIO_GPU_RESP_OK_NODATA);
     }
@@ -825,7 +825,7 @@ vg_handle_ctrl(VuDev *dev, int qidx)
         }
         cmd->vq = vq;
         cmd->error = 0;
-        cmd->finished = false;
+        cmd->state = VG_CMD_STATE_NEW;
 
         len = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,
                          0, &cmd->cmd_hdr, sizeof(cmd->cmd_hdr));
@@ -844,7 +844,7 @@ vg_handle_ctrl(VuDev *dev, int qidx)
             vg_process_cmd(vg, cmd);
         }
 
-        if (!cmd->finished) {
+        if (cmd->state != VG_CMD_STATE_FINISHED) {
             QTAILQ_INSERT_TAIL(&vg->fenceq, cmd, next);
             vg->inflight++;
         } else {
diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c
index e647278052..8bb3c563d9 100644
--- a/contrib/vhost-user-gpu/virgl.c
+++ b/contrib/vhost-user-gpu/virgl.c
@@ -482,7 +482,7 @@ void vg_virgl_process_cmd(VuGpu *g, struct virtio_gpu_ctrl_command *cmd)
         break;
     }
 
-    if (cmd->finished) {
+    if (cmd->state != VG_CMD_STATE_NEW) {
         return;
     }
 
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 04/20] vhost-user-gpu: handle display-info in a callback
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (2 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 05/20] ui: remove extra #ifdef CONFIG_OPENGL marcandre.lureau
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Fixes a deadlock where the backend calls QEMU, while QEMU also calls the
backend simultaneously, both ends waiting for each other.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/vhost-user-gpu/vhost-user-gpu.c | 33 ++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c
index 7dcc02966c..b27990ffdb 100644
--- a/contrib/vhost-user-gpu/vhost-user-gpu.c
+++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
@@ -261,10 +261,33 @@ vg_ctrl_response_nodata(VuGpu *g,
     vg_ctrl_response(g, cmd, &resp, sizeof(resp));
 }
 
+
+static gboolean
+get_display_info_cb(gint fd, GIOCondition condition, gpointer user_data)
+{
+    struct virtio_gpu_resp_display_info dpy_info = { {} };
+    VuGpu *vg = user_data;
+    struct virtio_gpu_ctrl_command *cmd = QTAILQ_LAST(&vg->fenceq);
+
+    g_debug("disp info cb");
+    assert(cmd->cmd_hdr.type == VIRTIO_GPU_CMD_GET_DISPLAY_INFO);
+    if (!vg_recv_msg(vg, VHOST_USER_GPU_GET_DISPLAY_INFO,
+                     sizeof(dpy_info), &dpy_info)) {
+        return G_SOURCE_CONTINUE;
+    }
+
+    QTAILQ_REMOVE(&vg->fenceq, cmd, next);
+    vg_ctrl_response(vg, cmd, &dpy_info.hdr, sizeof(dpy_info));
+
+    vg->wait_in = 0;
+    vg_handle_ctrl(&vg->dev.parent, 0);
+
+    return G_SOURCE_REMOVE;
+}
+
 void
 vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd)
 {
-    struct virtio_gpu_resp_display_info dpy_info = { {} };
     VhostUserGpuMsg msg = {
         .request = VHOST_USER_GPU_GET_DISPLAY_INFO,
         .size = 0,
@@ -273,11 +296,9 @@ vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd)
     assert(vg->wait_in == 0);
 
     vg_send_msg(vg, &msg, -1);
-    if (!vg_recv_msg(vg, msg.request, sizeof(dpy_info), &dpy_info)) {
-        return;
-    }
-
-    vg_ctrl_response(vg, cmd, &dpy_info.hdr, sizeof(dpy_info));
+    vg->wait_in = g_unix_fd_add(vg->sock_fd, G_IO_IN | G_IO_HUP,
+                               get_display_info_cb, vg);
+    cmd->state = VG_CMD_STATE_PENDING;
 }
 
 static void
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 05/20] ui: remove extra #ifdef CONFIG_OPENGL
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (3 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 04/20] vhost-user-gpu: handle display-info in a callback marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 06/20] ui: remove gl_ctx_get_current marcandre.lureau
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Since commit 5cb69566daa8081abb82a13403dcc0fffed02007 ("gtk: remove
CONFIG_GTK_GL"), some #ifdef are redundants.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 ui/gtk.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 26665cd2e6..e1ee0840b3 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -625,8 +625,6 @@ static const DisplayChangeListenerOps dcl_ops = {
 
 /** DisplayState Callbacks (opengl version) **/
 
-#if defined(CONFIG_OPENGL)
-
 static const DisplayChangeListenerOps dcl_gl_area_ops = {
     .dpy_name             = "gtk-egl",
     .dpy_gfx_update       = gd_gl_area_update,
@@ -644,8 +642,6 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = {
     .dpy_gl_update           = gd_gl_area_scanout_flush,
 };
 
-#endif /* CONFIG_OPENGL */
-
 static const DisplayChangeListenerOps dcl_egl_ops = {
     .dpy_name             = "gtk-egl",
     .dpy_gfx_update       = gd_egl_update,
@@ -1993,13 +1989,10 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
 
 #if defined(CONFIG_OPENGL)
     if (display_opengl) {
-#if defined(CONFIG_OPENGL)
         if (gtk_use_gl_area) {
             vc->gfx.drawing_area = gtk_gl_area_new();
             vc->gfx.dcl.ops = &dcl_gl_area_ops;
-        } else
-#endif /* CONFIG_OPENGL */
-        {
+        } else {
             vc->gfx.drawing_area = gtk_drawing_area_new();
             /*
              * gtk_widget_set_double_buffered() was deprecated in 3.14.
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 06/20] ui: remove gl_ctx_get_current
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (4 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 05/20] ui: remove extra #ifdef CONFIG_OPENGL marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 07/20] ui: add gd_gl_area_scanout_disable marcandre.lureau
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

There are no users left.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/console.h     | 2 --
 include/ui/egl-context.h | 1 -
 include/ui/sdl2.h        | 1 -
 ui/console.c             | 6 ------
 ui/egl-context.c         | 5 -----
 ui/egl-headless.c        | 1 -
 ui/gtk.c                 | 2 --
 ui/sdl2-gl.c             | 8 --------
 ui/sdl2.c                | 1 -
 ui/spice-display.c       | 1 -
 10 files changed, 28 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 7a3fc11abf..ce6c72e37c 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -201,7 +201,6 @@ typedef struct DisplayChangeListenerOps {
                                QEMUGLContext ctx);
     int (*dpy_gl_ctx_make_current)(DisplayChangeListener *dcl,
                                    QEMUGLContext ctx);
-    QEMUGLContext (*dpy_gl_ctx_get_current)(DisplayChangeListener *dcl);
 
     void (*dpy_gl_scanout_disable)(DisplayChangeListener *dcl);
     void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl,
@@ -303,7 +302,6 @@ QEMUGLContext dpy_gl_ctx_create(QemuConsole *con,
                                 QEMUGLParams *params);
 void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx);
 int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx);
-QEMUGLContext dpy_gl_ctx_get_current(QemuConsole *con);
 
 bool console_has_gl(QemuConsole *con);
 bool console_has_gl_dmabuf(QemuConsole *con);
diff --git a/include/ui/egl-context.h b/include/ui/egl-context.h
index f004ce11a7..9374fe41e3 100644
--- a/include/ui/egl-context.h
+++ b/include/ui/egl-context.h
@@ -9,6 +9,5 @@ QEMUGLContext qemu_egl_create_context(DisplayChangeListener *dcl,
 void qemu_egl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx);
 int qemu_egl_make_context_current(DisplayChangeListener *dcl,
                                   QEMUGLContext ctx);
-QEMUGLContext qemu_egl_get_current_context(DisplayChangeListener *dcl);
 
 #endif /* EGL_CONTEXT_H */
diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
index 0875b8d56b..f85c117a78 100644
--- a/include/ui/sdl2.h
+++ b/include/ui/sdl2.h
@@ -70,7 +70,6 @@ QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl,
 void sdl2_gl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx);
 int sdl2_gl_make_context_current(DisplayChangeListener *dcl,
                                  QEMUGLContext ctx);
-QEMUGLContext sdl2_gl_get_current_context(DisplayChangeListener *dcl);
 
 void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
 void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
diff --git a/ui/console.c b/ui/console.c
index d80ce7037c..c0b1a3689c 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1803,12 +1803,6 @@ int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx)
     return con->gl->ops->dpy_gl_ctx_make_current(con->gl, ctx);
 }
 
-QEMUGLContext dpy_gl_ctx_get_current(QemuConsole *con)
-{
-    assert(con->gl);
-    return con->gl->ops->dpy_gl_ctx_get_current(con->gl);
-}
-
 void dpy_gl_scanout_disable(QemuConsole *con)
 {
     assert(con->gl);
diff --git a/ui/egl-context.c b/ui/egl-context.c
index 4aa1cbb50c..368ffa49d8 100644
--- a/ui/egl-context.c
+++ b/ui/egl-context.c
@@ -35,8 +35,3 @@ int qemu_egl_make_context_current(DisplayChangeListener *dcl,
    return eglMakeCurrent(qemu_egl_display,
                          EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
 }
-
-QEMUGLContext qemu_egl_get_current_context(DisplayChangeListener *dcl)
-{
-    return eglGetCurrentContext();
-}
diff --git a/ui/egl-headless.c b/ui/egl-headless.c
index fe2a0d1eab..da377a74af 100644
--- a/ui/egl-headless.c
+++ b/ui/egl-headless.c
@@ -160,7 +160,6 @@ static const DisplayChangeListenerOps egl_ops = {
     .dpy_gl_ctx_create       = egl_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
-    .dpy_gl_ctx_get_current  = qemu_egl_get_current_context,
 
     .dpy_gl_scanout_disable  = egl_scanout_disable,
     .dpy_gl_scanout_texture  = egl_scanout_texture,
diff --git a/ui/gtk.c b/ui/gtk.c
index e1ee0840b3..a0e6b60ac4 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -637,7 +637,6 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = {
     .dpy_gl_ctx_create       = gd_gl_area_create_context,
     .dpy_gl_ctx_destroy      = gd_gl_area_destroy_context,
     .dpy_gl_ctx_make_current = gd_gl_area_make_current,
-    .dpy_gl_ctx_get_current  = gd_gl_area_get_current_context,
     .dpy_gl_scanout_texture  = gd_gl_area_scanout_texture,
     .dpy_gl_update           = gd_gl_area_scanout_flush,
 };
@@ -654,7 +653,6 @@ static const DisplayChangeListenerOps dcl_egl_ops = {
     .dpy_gl_ctx_create       = gd_egl_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = gd_egl_make_current,
-    .dpy_gl_ctx_get_current  = qemu_egl_get_current_context,
     .dpy_gl_scanout_disable  = gd_egl_scanout_disable,
     .dpy_gl_scanout_texture  = gd_egl_scanout_texture,
     .dpy_gl_scanout_dmabuf   = gd_egl_scanout_dmabuf,
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index c73d273bf8..82139ba49e 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -185,14 +185,6 @@ int sdl2_gl_make_context_current(DisplayChangeListener *dcl,
     return SDL_GL_MakeCurrent(scon->real_window, sdlctx);
 }
 
-QEMUGLContext sdl2_gl_get_current_context(DisplayChangeListener *dcl)
-{
-    SDL_GLContext sdlctx;
-
-    sdlctx = SDL_GL_GetCurrentContext();
-    return (QEMUGLContext)sdlctx;
-}
-
 void sdl2_gl_scanout_disable(DisplayChangeListener *dcl)
 {
     struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 5e49709283..a203cb0239 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -781,7 +781,6 @@ static const DisplayChangeListenerOps dcl_gl_ops = {
     .dpy_gl_ctx_create       = sdl2_gl_create_context,
     .dpy_gl_ctx_destroy      = sdl2_gl_destroy_context,
     .dpy_gl_ctx_make_current = sdl2_gl_make_context_current,
-    .dpy_gl_ctx_get_current  = sdl2_gl_get_current_context,
     .dpy_gl_scanout_disable  = sdl2_gl_scanout_disable,
     .dpy_gl_scanout_texture  = sdl2_gl_scanout_texture,
     .dpy_gl_update           = sdl2_gl_scanout_flush,
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 0178d5766d..6a5e189a67 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -1102,7 +1102,6 @@ static const DisplayChangeListenerOps display_listener_gl_ops = {
     .dpy_gl_ctx_create       = qemu_spice_gl_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
-    .dpy_gl_ctx_get_current  = qemu_egl_get_current_context,
 
     .dpy_gl_scanout_disable  = qemu_spice_gl_scanout_disable,
     .dpy_gl_scanout_texture  = qemu_spice_gl_scanout_texture,
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 07/20] ui: add gd_gl_area_scanout_disable
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (5 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 06/20] ui: remove gl_ctx_get_current marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 08/20] ui: annotate DCLOps callback requirements marcandre.lureau
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Require the callback, drop the fallback path.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/gtk.h | 1 +
 ui/console.c     | 7 +------
 ui/gtk-gl-area.c | 7 +++++++
 ui/gtk.c         | 1 +
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/include/ui/gtk.h b/include/ui/gtk.h
index 3f395d7f94..7569d090fa 100644
--- a/include/ui/gtk.h
+++ b/include/ui/gtk.h
@@ -140,6 +140,7 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
                                 uint32_t backing_height,
                                 uint32_t x, uint32_t y,
                                 uint32_t w, uint32_t h);
+void gd_gl_area_scanout_disable(DisplayChangeListener *dcl);
 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
                               uint32_t x, uint32_t y, uint32_t w, uint32_t h);
 void gtk_gl_area_init(void);
diff --git a/ui/console.c b/ui/console.c
index c0b1a3689c..ab9224429e 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1806,12 +1806,7 @@ int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx)
 void dpy_gl_scanout_disable(QemuConsole *con)
 {
     assert(con->gl);
-    if (con->gl->ops->dpy_gl_scanout_disable) {
-        con->gl->ops->dpy_gl_scanout_disable(con->gl);
-    } else {
-        con->gl->ops->dpy_gl_scanout_texture(con->gl, 0, false, 0, 0,
-                                             0, 0, 0, 0);
-    }
+    con->gl->ops->dpy_gl_scanout_disable(con->gl);
 }
 
 void dpy_gl_scanout_texture(QemuConsole *con,
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 98c22d23f5..96fbe75387 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -198,6 +198,13 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
                          backing_id, false);
 }
 
+void gd_gl_area_scanout_disable(DisplayChangeListener *dcl)
+{
+    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
+
+    gtk_gl_area_set_scanout_mode(vc, false);
+}
+
 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
                           uint32_t x, uint32_t y, uint32_t w, uint32_t h)
 {
diff --git a/ui/gtk.c b/ui/gtk.c
index a0e6b60ac4..00045881b1 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -638,6 +638,7 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = {
     .dpy_gl_ctx_destroy      = gd_gl_area_destroy_context,
     .dpy_gl_ctx_make_current = gd_gl_area_make_current,
     .dpy_gl_scanout_texture  = gd_gl_area_scanout_texture,
+    .dpy_gl_scanout_disable  = gd_gl_area_scanout_disable,
     .dpy_gl_update           = gd_gl_area_scanout_flush,
 };
 
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 08/20] ui: annotate DCLOps callback requirements
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (6 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 07/20] ui: add gd_gl_area_scanout_disable marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 09/20] ui: remove console_has_gl_dmabuf() marcandre.lureau
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/console.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/include/ui/console.h b/include/ui/console.h
index ce6c72e37c..bea2b6329a 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -174,35 +174,49 @@ typedef struct DisplayState DisplayState;
 typedef struct DisplayChangeListenerOps {
     const char *dpy_name;
 
+    /* optional */
     void (*dpy_refresh)(DisplayChangeListener *dcl);
 
+    /* optional */
     void (*dpy_gfx_update)(DisplayChangeListener *dcl,
                            int x, int y, int w, int h);
+    /* optional */
     void (*dpy_gfx_switch)(DisplayChangeListener *dcl,
                            struct DisplaySurface *new_surface);
+    /* optional */
     bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl,
                                  pixman_format_code_t format);
 
+    /* optional */
     void (*dpy_text_cursor)(DisplayChangeListener *dcl,
                             int x, int y);
+    /* optional */
     void (*dpy_text_resize)(DisplayChangeListener *dcl,
                             int w, int h);
+    /* optional */
     void (*dpy_text_update)(DisplayChangeListener *dcl,
                             int x, int y, int w, int h);
 
+    /* optional */
     void (*dpy_mouse_set)(DisplayChangeListener *dcl,
                           int x, int y, int on);
+    /* optional */
     void (*dpy_cursor_define)(DisplayChangeListener *dcl,
                               QEMUCursor *cursor);
 
+    /* required if GL */
     QEMUGLContext (*dpy_gl_ctx_create)(DisplayChangeListener *dcl,
                                        QEMUGLParams *params);
+    /* required if GL */
     void (*dpy_gl_ctx_destroy)(DisplayChangeListener *dcl,
                                QEMUGLContext ctx);
+    /* required if GL */
     int (*dpy_gl_ctx_make_current)(DisplayChangeListener *dcl,
                                    QEMUGLContext ctx);
 
+    /* required if GL */
     void (*dpy_gl_scanout_disable)(DisplayChangeListener *dcl);
+    /* required if GL */
     void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl,
                                    uint32_t backing_id,
                                    bool backing_y_0_top,
@@ -210,15 +224,20 @@ typedef struct DisplayChangeListenerOps {
                                    uint32_t backing_height,
                                    uint32_t x, uint32_t y,
                                    uint32_t w, uint32_t h);
+    /* optional */
     void (*dpy_gl_scanout_dmabuf)(DisplayChangeListener *dcl,
                                   QemuDmaBuf *dmabuf);
+    /* optional */
     void (*dpy_gl_cursor_dmabuf)(DisplayChangeListener *dcl,
                                  QemuDmaBuf *dmabuf, bool have_hot,
                                  uint32_t hot_x, uint32_t hot_y);
+    /* optional */
     void (*dpy_gl_cursor_position)(DisplayChangeListener *dcl,
                                    uint32_t pos_x, uint32_t pos_y);
+    /* optional */
     void (*dpy_gl_release_dmabuf)(DisplayChangeListener *dcl,
                                   QemuDmaBuf *dmabuf);
+    /* required if GL */
     void (*dpy_gl_update)(DisplayChangeListener *dcl,
                           uint32_t x, uint32_t y, uint32_t w, uint32_t h);
 
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 09/20] ui: remove console_has_gl_dmabuf()
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (7 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 08/20] ui: annotate DCLOps callback requirements marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 10/20] vhost-user-gpu: add a configuration flag for dmabuf usage marcandre.lureau
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

This check is currently limited. It only is used by vhost-user-gpu (not
by vfio-display), and will print an error repeatedly during run-time.

We are going to dissociate the GL context from the
DisplayChangeListener, and listeners may come and go. The following
patches will address this differently.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/console.h        | 1 -
 hw/display/vhost-user-gpu.c | 5 -----
 ui/console.c                | 5 -----
 3 files changed, 11 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index bea2b6329a..ac989fdf70 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -323,7 +323,6 @@ void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx);
 int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx);
 
 bool console_has_gl(QemuConsole *con);
-bool console_has_gl_dmabuf(QemuConsole *con);
 
 static inline int surface_stride(DisplaySurface *s)
 {
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index 55b0ed15f2..dd587436ff 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -224,11 +224,6 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg)
             close(dmabuf->fd);
             dmabuf->fd = -1;
         }
-        if (!console_has_gl_dmabuf(con)) {
-            /* it would be nice to report that error earlier */
-            error_report("console doesn't support dmabuf!");
-            break;
-        }
         dpy_gl_release_dmabuf(con, dmabuf);
         if (fd == -1) {
             dpy_gl_scanout_disable(con);
diff --git a/ui/console.c b/ui/console.c
index ab9224429e..b5bc3f7699 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1463,11 +1463,6 @@ bool console_has_gl(QemuConsole *con)
     return con->gl != NULL;
 }
 
-bool console_has_gl_dmabuf(QemuConsole *con)
-{
-    return con->gl != NULL && con->gl->ops->dpy_gl_scanout_dmabuf != NULL;
-}
-
 void register_displaychangelistener(DisplayChangeListener *dcl)
 {
     static const char nodev[] =
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 10/20] vhost-user-gpu: add a configuration flag for dmabuf usage
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (8 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 09/20] ui: remove console_has_gl_dmabuf() marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 11/20] ui: add an optional get_flags callback to GraphicHwOps marcandre.lureau
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Let's inform VirtioGPUBase that vhost-user-gpu require DMABUF messages.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/virtio/virtio-gpu.h | 3 +++
 hw/display/vhost-user-gpu.c    | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 1aed7275c8..4f3dbf79f9 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -71,6 +71,7 @@ enum virtio_gpu_base_conf_flags {
     VIRTIO_GPU_FLAG_VIRGL_ENABLED = 1,
     VIRTIO_GPU_FLAG_STATS_ENABLED,
     VIRTIO_GPU_FLAG_EDID_ENABLED,
+    VIRTIO_GPU_FLAG_DMABUF_ENABLED,
 };
 
 #define virtio_gpu_virgl_enabled(_cfg) \
@@ -79,6 +80,8 @@ enum virtio_gpu_base_conf_flags {
     (_cfg.flags & (1 << VIRTIO_GPU_FLAG_STATS_ENABLED))
 #define virtio_gpu_edid_enabled(_cfg) \
     (_cfg.flags & (1 << VIRTIO_GPU_FLAG_EDID_ENABLED))
+#define virtio_gpu_dmabuf_enabled(_cfg) \
+    (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED))
 
 struct virtio_gpu_base_conf {
     uint32_t max_outputs;
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index dd587436ff..b7bde9feb6 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -547,6 +547,8 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)
         return;
     }
 
+    /* existing backend may send DMABUF, so let's add that requirement */
+    g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED;
     if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_VIRGL)) {
         g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED;
     }
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 11/20] ui: add an optional get_flags callback to GraphicHwOps
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (9 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 10/20] vhost-user-gpu: add a configuration flag for dmabuf usage marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 12/20] ui: add a DCLOps callback to check dmabuf support marcandre.lureau
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Those flags can be used to express different requirements for the
display or other needs.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/console.h         |  9 +++++++++
 hw/display/virtio-gpu-base.c | 18 ++++++++++++++++++
 hw/display/virtio-vga.c      |  9 +++++++++
 hw/vfio/display.c            |  6 ++++++
 4 files changed, 42 insertions(+)

diff --git a/include/ui/console.h b/include/ui/console.h
index ac989fdf70..0595aa9953 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -368,7 +368,16 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
     *dest = ch;
 }
 
+enum {
+    GRAPHIC_FLAGS_NONE     = 0,
+    /* require a console/display with GL callbacks */
+    GRAPHIC_FLAGS_GL       = 1 << 0,
+    /* require a console/display with DMABUF import */
+    GRAPHIC_FLAGS_DMABUF   = 1 << 1,
+};
+
 typedef struct GraphicHwOps {
+    int (*get_flags)(void *opaque); /* optional, default 0 */
     void (*invalidate)(void *opaque);
     void (*gfx_update)(void *opaque);
     bool gfx_update_async; /* if true, calls graphic_hw_update_done() */
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index 40ccd00f94..f27a6fbe75 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -114,7 +114,25 @@ virtio_gpu_gl_block(void *opaque, bool block)
     }
 }
 
+static int
+virtio_gpu_get_flags(void *opaque)
+{
+    VirtIOGPUBase *g = opaque;
+    int flags = GRAPHIC_FLAGS_NONE;
+
+    if (virtio_gpu_virgl_enabled(g->conf)) {
+        flags |= GRAPHIC_FLAGS_GL;
+    }
+
+    if (virtio_gpu_dmabuf_enabled(g->conf)) {
+        flags |= GRAPHIC_FLAGS_DMABUF;
+    }
+
+    return flags;
+}
+
 static const GraphicHwOps virtio_gpu_ops = {
+    .get_flags = virtio_gpu_get_flags,
     .invalidate = virtio_gpu_invalidate_display,
     .gfx_update = virtio_gpu_update_display,
     .text_update = virtio_gpu_text_update,
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index 81f776ee36..b071909b68 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -68,7 +68,16 @@ static void virtio_vga_base_gl_block(void *opaque, bool block)
     }
 }
 
+static int virtio_vga_base_get_flags(void *opaque)
+{
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
+
+    return g->hw_ops->get_flags(g);
+}
+
 static const GraphicHwOps virtio_vga_base_ops = {
+    .get_flags = virtio_vga_base_get_flags,
     .invalidate = virtio_vga_base_invalidate_display,
     .gfx_update = virtio_vga_base_update_display,
     .text_update = virtio_vga_base_text_update,
diff --git a/hw/vfio/display.c b/hw/vfio/display.c
index 42d67e870b..f04473e3ce 100644
--- a/hw/vfio/display.c
+++ b/hw/vfio/display.c
@@ -335,7 +335,13 @@ static void vfio_display_dmabuf_update(void *opaque)
     }
 }
 
+static int vfio_display_get_flags(void *opaque)
+{
+    return GRAPHIC_FLAGS_GL | GRAPHIC_FLAGS_DMABUF;
+}
+
 static const GraphicHwOps vfio_display_dmabuf_ops = {
+    .get_flags  = vfio_display_get_flags,
     .gfx_update = vfio_display_dmabuf_update,
     .ui_info    = vfio_display_edid_ui_info,
 };
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 12/20] ui: add a DCLOps callback to check dmabuf support
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (10 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 11/20] ui: add an optional get_flags callback to GraphicHwOps marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 13/20] ui: check hw requirements during DCL registration marcandre.lureau
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/console.h |  2 ++
 ui/console.c         | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/include/ui/console.h b/include/ui/console.h
index 0595aa9953..875885d9c7 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -224,6 +224,8 @@ typedef struct DisplayChangeListenerOps {
                                    uint32_t backing_height,
                                    uint32_t x, uint32_t y,
                                    uint32_t w, uint32_t h);
+    /* optional (default to true if has dpy_gl_scanout_dmabuf) */
+    bool (*dpy_has_dmabuf)(DisplayChangeListener *dcl);
     /* optional */
     void (*dpy_gl_scanout_dmabuf)(DisplayChangeListener *dcl,
                                   QemuDmaBuf *dmabuf);
diff --git a/ui/console.c b/ui/console.c
index b5bc3f7699..a645418ada 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1463,6 +1463,19 @@ bool console_has_gl(QemuConsole *con)
     return con->gl != NULL;
 }
 
+static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl)
+{
+    if (dcl->ops->dpy_has_dmabuf) {
+        return dcl->ops->dpy_has_dmabuf(dcl);
+    }
+
+    if (dcl->ops->dpy_gl_scanout_dmabuf) {
+        return true;
+    }
+
+    return false;
+}
+
 void register_displaychangelistener(DisplayChangeListener *dcl)
 {
     static const char nodev[] =
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 13/20] ui: check hw requirements during DCL registration
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (11 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 12/20] ui: add a DCLOps callback to check dmabuf support marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 14/20] ui: add qemu_egl_has_dmabuf helper marcandre.lureau
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 ui/console.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/ui/console.c b/ui/console.c
index a645418ada..d8cc640c28 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1476,12 +1476,37 @@ static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl)
     return false;
 }
 
+static bool dpy_compatible_with(QemuConsole *con,
+                                DisplayChangeListener *dcl, Error **errp)
+{
+    ERRP_GUARD();
+    int flags;
+
+    flags = con->hw_ops->get_flags ? con->hw_ops->get_flags(con->hw) : 0;
+
+    if (flags & GRAPHIC_FLAGS_GL &&
+        !console_has_gl(con)) {
+        error_setg(errp, "The console requires a GL context.");
+        return false;
+
+    }
+
+    if (flags & GRAPHIC_FLAGS_DMABUF &&
+        !displaychangelistener_has_dmabuf(dcl)) {
+        error_setg(errp, "The console requires display DMABUF support.");
+        return false;
+    }
+
+    return true;
+}
+
 void register_displaychangelistener(DisplayChangeListener *dcl)
 {
     static const char nodev[] =
         "This VM has no graphic display device.";
     static DisplaySurface *dummy;
     QemuConsole *con;
+    Error *err = NULL;
 
     assert(!dcl->ds);
 
@@ -1496,6 +1521,11 @@ void register_displaychangelistener(DisplayChangeListener *dcl)
         dcl->con->gl = dcl;
     }
 
+    if (dcl->con && !dpy_compatible_with(dcl->con, dcl, &err)) {
+        error_report_err(err);
+        exit(1);
+    }
+
     trace_displaychangelistener_register(dcl, dcl->ops->dpy_name);
     dcl->ds = get_alloc_displaystate();
     QLIST_INSERT_HEAD(&dcl->ds->listeners, dcl, next);
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 14/20] ui: add qemu_egl_has_dmabuf helper
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (12 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 13/20] ui: check hw requirements during DCL registration marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 15/20] ui: check gtk-egl dmabuf support marcandre.lureau
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/egl-helpers.h |  1 +
 ui/egl-helpers.c         | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h
index 94a4b3e6f3..5b1f7fafe0 100644
--- a/include/ui/egl-helpers.h
+++ b/include/ui/egl-helpers.h
@@ -51,5 +51,6 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
 int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode);
 int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);
 EGLContext qemu_egl_init_ctx(void);
+bool qemu_egl_has_dmabuf(void);
 
 #endif /* EGL_HELPERS_H */
diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
index 7c530c2825..73fe61f878 100644
--- a/ui/egl-helpers.c
+++ b/ui/egl-helpers.c
@@ -441,6 +441,16 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)
 #endif
 }
 
+bool qemu_egl_has_dmabuf(void)
+{
+    if (qemu_egl_display == EGL_NO_DISPLAY) {
+        return false;
+    }
+
+    return epoxy_has_egl_extension(qemu_egl_display,
+                                   "EGL_EXT_image_dma_buf_import");
+}
+
 EGLContext qemu_egl_init_ctx(void)
 {
     static const EGLint ctx_att_core[] = {
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 15/20] ui: check gtk-egl dmabuf support
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (13 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 14/20] ui: add qemu_egl_has_dmabuf helper marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 16/20] ui: add egl dmabuf import to gtkglarea marcandre.lureau
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/gtk.h | 1 +
 ui/gtk.c         | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/include/ui/gtk.h b/include/ui/gtk.h
index 7569d090fa..aaef884b95 100644
--- a/include/ui/gtk.h
+++ b/include/ui/gtk.h
@@ -48,6 +48,7 @@ typedef struct VirtualGfxConsole {
     int cursor_y;
     bool y0_top;
     bool scanout_mode;
+    bool has_dmabuf;
 #endif
 } VirtualGfxConsole;
 
diff --git a/ui/gtk.c b/ui/gtk.c
index 00045881b1..f41c396cb9 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -623,6 +623,13 @@ static const DisplayChangeListenerOps dcl_ops = {
 
 #if defined(CONFIG_OPENGL)
 
+static bool gd_has_dmabuf(DisplayChangeListener *dcl)
+{
+    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
+
+    return vc->gfx.has_dmabuf;
+}
+
 /** DisplayState Callbacks (opengl version) **/
 
 static const DisplayChangeListenerOps dcl_gl_area_ops = {
@@ -661,6 +668,7 @@ static const DisplayChangeListenerOps dcl_egl_ops = {
     .dpy_gl_cursor_position  = gd_egl_cursor_position,
     .dpy_gl_release_dmabuf   = gd_egl_release_dmabuf,
     .dpy_gl_update           = gd_egl_scanout_flush,
+    .dpy_has_dmabuf          = gd_has_dmabuf,
 };
 
 #endif /* CONFIG_OPENGL */
@@ -2004,6 +2012,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
             gtk_widget_set_double_buffered(vc->gfx.drawing_area, FALSE);
 #pragma GCC diagnostic pop
             vc->gfx.dcl.ops = &dcl_egl_ops;
+            vc->gfx.has_dmabuf = qemu_egl_has_dmabuf();
         }
     } else
 #endif
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 16/20] ui: add egl dmabuf import to gtkglarea
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (14 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 15/20] ui: check gtk-egl dmabuf support marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing marcandre.lureau
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

GtkGLArea is used on wayland, where EGL is usually available.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/gtk.h |  2 ++
 ui/gtk-gl-area.c | 18 ++++++++++++++++++
 ui/gtk.c         | 22 ++++++++++++++++++++++
 3 files changed, 42 insertions(+)

diff --git a/include/ui/gtk.h b/include/ui/gtk.h
index aaef884b95..3c1cd98db8 100644
--- a/include/ui/gtk.h
+++ b/include/ui/gtk.h
@@ -134,6 +134,8 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
                                         QEMUGLParams *params);
 void gd_gl_area_destroy_context(DisplayChangeListener *dcl,
                                 QEMUGLContext ctx);
+void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
+                               QemuDmaBuf *dmabuf);
 void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
                                 uint32_t backing_id,
                                 bool backing_y_0_top,
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 96fbe75387..72bcd94918 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -213,6 +213,24 @@ void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
     gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
 }
 
+void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
+                               QemuDmaBuf *dmabuf)
+{
+#ifdef CONFIG_OPENGL_DMABUF
+    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
+
+    gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
+    egl_dmabuf_import_texture(dmabuf);
+    if (!dmabuf->texture) {
+        return;
+    }
+
+    gd_gl_area_scanout_texture(dcl, dmabuf->texture,
+                               false, dmabuf->width, dmabuf->height,
+                               0, 0, dmabuf->width, dmabuf->height);
+#endif
+}
+
 void gtk_gl_area_init(void)
 {
     display_opengl = 1;
diff --git a/ui/gtk.c b/ui/gtk.c
index f41c396cb9..79dc240120 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -627,6 +627,12 @@ static bool gd_has_dmabuf(DisplayChangeListener *dcl)
 {
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
 
+    if (gtk_use_gl_area && !gtk_widget_get_realized(vc->gfx.drawing_area)) {
+        /* FIXME: Assume it will work, actual check done after realize */
+        /* fixing this would require delaying listener registration */
+        return true;
+    }
+
     return vc->gfx.has_dmabuf;
 }
 
@@ -647,6 +653,8 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = {
     .dpy_gl_scanout_texture  = gd_gl_area_scanout_texture,
     .dpy_gl_scanout_disable  = gd_gl_area_scanout_disable,
     .dpy_gl_update           = gd_gl_area_scanout_flush,
+    .dpy_gl_scanout_dmabuf   = gd_gl_area_scanout_dmabuf,
+    .dpy_has_dmabuf          = gd_has_dmabuf,
 };
 
 static const DisplayChangeListenerOps dcl_egl_ops = {
@@ -1983,6 +1991,18 @@ static GtkWidget *gd_create_menu_machine(GtkDisplayState *s)
     return machine_menu;
 }
 
+#if defined(CONFIG_OPENGL)
+static void gl_area_realize(GtkGLArea *area, VirtualConsole *vc)
+{
+    gtk_gl_area_make_current(area);
+    qemu_egl_display = eglGetCurrentDisplay();
+    vc->gfx.has_dmabuf = qemu_egl_has_dmabuf();
+    if (!vc->gfx.has_dmabuf) {
+        error_report("GtkGLArea console lacks DMABUF support.");
+    }
+}
+#endif
+
 static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
                               QemuConsole *con, int idx,
                               GSList *group, GtkWidget *view_menu)
@@ -1998,6 +2018,8 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
     if (display_opengl) {
         if (gtk_use_gl_area) {
             vc->gfx.drawing_area = gtk_gl_area_new();
+            g_signal_connect(vc->gfx.drawing_area, "realize",
+                             G_CALLBACK(gl_area_realize), vc);
             vc->gfx.dcl.ops = &dcl_gl_area_ops;
         } else {
             vc->gfx.drawing_area = gtk_drawing_area_new();
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (15 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 16/20] ui: add egl dmabuf import to gtkglarea marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-05  8:09   ` Alexander Bulekov
  2021-02-04 10:52 ` [PATCH v2 18/20] display/ui: add a callback to indicate GL state is flushed marcandre.lureau
                   ` (2 subsequent siblings)
  19 siblings, 1 reply; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

The next patch will notify the GL context got flush, which will resume
the queue processing. However, if this happens within the caller
context, it will end up with a stack overflow flush/update loop.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/virtio/virtio-gpu.h | 1 +
 hw/display/virtio-gpu.c        | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 4f3dbf79f9..0043268e90 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -148,6 +148,7 @@ struct VirtIOGPU {
 
     uint64_t hostmem;
 
+    bool processing_cmdq;
     bool renderer_inited;
     bool renderer_reset;
     QEMUTimer *fence_poll;
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 0e833a462b..7eb4265a6d 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -814,6 +814,10 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
 {
     struct virtio_gpu_ctrl_command *cmd;
 
+    if (g->processing_cmdq) {
+        return;
+    }
+    g->processing_cmdq = true;
     while (!QTAILQ_EMPTY(&g->cmdq)) {
         cmd = QTAILQ_FIRST(&g->cmdq);
 
@@ -843,6 +847,7 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
             g_free(cmd);
         }
     }
+    g->processing_cmdq = false;
 }
 
 static void virtio_gpu_gl_unblock(VirtIOGPUBase *b)
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 18/20] display/ui: add a callback to indicate GL state is flushed
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (16 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 19/20] chardev: check if the chardev is registered for yanking marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test marcandre.lureau
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Displaying rendered resources requires blocking qemu GPU to avoid extra
framebuffer copies. For an external display, via Spice currently, there
is a callback to block/unblock the rendering in the same thread.

But with the vhost-user-gpu backend, the qemu process doesn't handle
the rendering itself, and the blocking callback isn't effective.
Instead, the backend must be notified when the display code is done.

Fix this by adding a new GraphicHwOps callback to indicate the GL state
is flushed, and we are done manipulating the shared GL resources. Call
it from gtk and spice display.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/virtio/virtio-gpu.h |  2 +-
 include/ui/console.h           |  2 ++
 hw/display/vhost-user-gpu.c    |  4 ++--
 hw/display/virtio-gpu-base.c   | 17 ++++++++++++-----
 hw/display/virtio-gpu.c        |  4 ++--
 hw/display/virtio-vga.c        | 11 +++++++++++
 ui/console.c                   |  9 +++++++++
 ui/gtk-egl.c                   |  3 +++
 ui/gtk-gl-area.c               |  3 +++
 ui/sdl2-gl.c                   |  2 ++
 ui/spice-display.c             |  1 +
 11 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 0043268e90..fae149235c 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -121,7 +121,7 @@ struct VirtIOGPUBase {
 struct VirtIOGPUBaseClass {
     VirtioDeviceClass parent;
 
-    void (*gl_unblock)(VirtIOGPUBase *g);
+    void (*gl_flushed)(VirtIOGPUBase *g);
 };
 
 #define VIRTIO_GPU_BASE_PROPERTIES(_state, _conf)                       \
diff --git a/include/ui/console.h b/include/ui/console.h
index 875885d9c7..d30e972d0b 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -387,6 +387,7 @@ typedef struct GraphicHwOps {
     void (*update_interval)(void *opaque, uint64_t interval);
     int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
     void (*gl_block)(void *opaque, bool block);
+    void (*gl_flushed)(void *opaque);
 } GraphicHwOps;
 
 QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head,
@@ -402,6 +403,7 @@ void graphic_hw_update_done(QemuConsole *con);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
 void graphic_hw_gl_block(QemuConsole *con, bool block);
+void graphic_hw_gl_flushed(QemuConsole *con);
 
 void qemu_console_early_init(void);
 
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index b7bde9feb6..4d8cb3525b 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -360,7 +360,7 @@ vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blocked)
 }
 
 static void
-vhost_user_gpu_gl_unblock(VirtIOGPUBase *b)
+vhost_user_gpu_gl_flushed(VirtIOGPUBase *b)
 {
     VhostUserGPU *g = VHOST_USER_GPU(b);
 
@@ -578,7 +578,7 @@ vhost_user_gpu_class_init(ObjectClass *klass, void *data)
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
     VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_CLASS(klass);
 
-    vgc->gl_unblock = vhost_user_gpu_gl_unblock;
+    vgc->gl_flushed = vhost_user_gpu_gl_flushed;
 
     vdc->realize = vhost_user_gpu_device_realize;
     vdc->reset = vhost_user_gpu_reset;
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index f27a6fbe75..4a57350917 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -97,21 +97,27 @@ static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
 }
 
 static void
-virtio_gpu_gl_block(void *opaque, bool block)
+virtio_gpu_gl_flushed(void *opaque)
 {
     VirtIOGPUBase *g = opaque;
     VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_GET_CLASS(g);
 
+    if (vgc->gl_flushed) {
+        vgc->gl_flushed(g);
+    }
+}
+
+static void
+virtio_gpu_gl_block(void *opaque, bool block)
+{
+    VirtIOGPUBase *g = opaque;
+
     if (block) {
         g->renderer_blocked++;
     } else {
         g->renderer_blocked--;
     }
     assert(g->renderer_blocked >= 0);
-
-    if (g->renderer_blocked == 0) {
-        vgc->gl_unblock(g);
-    }
 }
 
 static int
@@ -138,6 +144,7 @@ static const GraphicHwOps virtio_gpu_ops = {
     .text_update = virtio_gpu_text_update,
     .ui_info = virtio_gpu_ui_info,
     .gl_block = virtio_gpu_gl_block,
+    .gl_flushed = virtio_gpu_gl_flushed,
 };
 
 bool
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 7eb4265a6d..2e4a9822b6 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -850,7 +850,7 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
     g->processing_cmdq = false;
 }
 
-static void virtio_gpu_gl_unblock(VirtIOGPUBase *b)
+static void virtio_gpu_gl_flushed(VirtIOGPUBase *b)
 {
     VirtIOGPU *g = VIRTIO_GPU(b);
 
@@ -1257,7 +1257,7 @@ static void virtio_gpu_class_init(ObjectClass *klass, void *data)
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
     VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_CLASS(klass);
 
-    vgc->gl_unblock = virtio_gpu_gl_unblock;
+    vgc->gl_flushed = virtio_gpu_gl_flushed;
     vdc->realize = virtio_gpu_device_realize;
     vdc->reset = virtio_gpu_reset;
     vdc->get_config = virtio_gpu_get_config;
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index b071909b68..d3c6404061 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -68,6 +68,16 @@ static void virtio_vga_base_gl_block(void *opaque, bool block)
     }
 }
 
+static void virtio_vga_base_gl_flushed(void *opaque)
+{
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
+
+    if (g->hw_ops->gl_flushed) {
+        g->hw_ops->gl_flushed(g);
+    }
+}
+
 static int virtio_vga_base_get_flags(void *opaque)
 {
     VirtIOVGABase *vvga = opaque;
@@ -83,6 +93,7 @@ static const GraphicHwOps virtio_vga_base_ops = {
     .text_update = virtio_vga_base_text_update,
     .ui_info = virtio_vga_base_ui_info,
     .gl_block = virtio_vga_base_gl_block,
+    .gl_flushed = virtio_vga_base_gl_flushed,
 };
 
 static const VMStateDescription vmstate_virtio_vga_base = {
diff --git a/ui/console.c b/ui/console.c
index d8cc640c28..c5d11bc701 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -294,6 +294,15 @@ void graphic_hw_gl_block(QemuConsole *con, bool block)
     }
 }
 
+void graphic_hw_gl_flushed(QemuConsole *con)
+{
+    assert(con != NULL);
+
+    if (con->hw_ops->gl_flushed) {
+        con->hw_ops->gl_flushed(con->hw);
+    }
+}
+
 int qemu_console_get_window_id(QemuConsole *con)
 {
     return con->window_id;
diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 71c3d698b4..588e7b1bb1 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -92,6 +92,9 @@ void gd_egl_draw(VirtualConsole *vc)
         vc->gfx.scale_x = (double)ww / surface_width(vc->gfx.ds);
         vc->gfx.scale_y = (double)wh / surface_height(vc->gfx.ds);
     }
+
+    glFlush();
+    graphic_hw_gl_flushed(vc->gfx.dcl.con);
 }
 
 void gd_egl_update(DisplayChangeListener *dcl,
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 72bcd94918..e7ca73c7b1 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -70,6 +70,9 @@ void gd_gl_area_draw(VirtualConsole *vc)
         surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh);
         surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds);
     }
+
+    glFlush();
+    graphic_hw_gl_flushed(vc->gfx.dcl.con);
 }
 
 void gd_gl_area_update(DisplayChangeListener *dcl,
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index 82139ba49e..fd594d7461 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -58,6 +58,7 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)
 
     surface_gl_render_texture(scon->gls, scon->surface);
     SDL_GL_SwapWindow(scon->real_window);
+    graphic_hw_gl_flushed(scon->dcl.con);
 }
 
 void sdl2_gl_update(DisplayChangeListener *dcl,
@@ -240,4 +241,5 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
     egl_fb_blit(&scon->win_fb, &scon->guest_fb, !scon->y0_top);
 
     SDL_GL_SwapWindow(scon->real_window);
+    graphic_hw_gl_flushed(dcl->con);
 }
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 6a5e189a67..7247a93924 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -826,6 +826,7 @@ static void qemu_spice_gl_unblock_bh(void *opaque)
     SimpleSpiceDisplay *ssd = opaque;
 
     qemu_spice_gl_block(ssd, false);
+    graphic_hw_gl_flushed(ssd->dcl.con);
 }
 
 static void qemu_spice_gl_block_timer(void *opaque)
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 19/20] chardev: check if the chardev is registered for yanking
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (17 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 18/20] display/ui: add a callback to indicate GL state is flushed marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-04 10:52 ` [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test marcandre.lureau
  19 siblings, 0 replies; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Not all chardevs are created via qmp_chardev_open_socket(), and those
should not call the yank function registration, as this will eventually
assert() not being registered.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 chardev/char-socket.c | 53 +++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 20 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 8a707d766c..9061981f6d 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -417,8 +417,9 @@ static void tcp_chr_free_connection(Chardev *chr)
 
     tcp_set_msgfds(chr, NULL, 0);
     remove_fd_in_watch(chr);
-    if (s->state == TCP_CHARDEV_STATE_CONNECTING
-        || s->state == TCP_CHARDEV_STATE_CONNECTED) {
+    if (s->registered_yank &&
+        (s->state == TCP_CHARDEV_STATE_CONNECTING
+        || s->state == TCP_CHARDEV_STATE_CONNECTED)) {
         yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
                                  yank_generic_iochannel,
                                  QIO_CHANNEL(s->sioc));
@@ -940,9 +941,11 @@ static int tcp_chr_add_client(Chardev *chr, int fd)
     }
     tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
     tcp_chr_set_client_ioc_name(chr, sioc);
-    yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
-                           yank_generic_iochannel,
-                           QIO_CHANNEL(sioc));
+    if (s->registered_yank) {
+        yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
+                               yank_generic_iochannel,
+                               QIO_CHANNEL(sioc));
+    }
     ret = tcp_chr_new_client(chr, sioc);
     object_unref(OBJECT(sioc));
     return ret;
@@ -957,9 +960,11 @@ static void tcp_chr_accept(QIONetListener *listener,
 
     tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
     tcp_chr_set_client_ioc_name(chr, cioc);
-    yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
-                           yank_generic_iochannel,
-                           QIO_CHANNEL(cioc));
+    if (s->registered_yank) {
+        yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
+                               yank_generic_iochannel,
+                               QIO_CHANNEL(cioc));
+    }
     tcp_chr_new_client(chr, cioc);
 }
 
@@ -975,9 +980,11 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp)
         object_unref(OBJECT(sioc));
         return -1;
     }
-    yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
-                           yank_generic_iochannel,
-                           QIO_CHANNEL(sioc));
+    if (s->registered_yank) {
+        yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
+                               yank_generic_iochannel,
+                               QIO_CHANNEL(sioc));
+    }
     tcp_chr_new_client(chr, sioc);
     object_unref(OBJECT(sioc));
     return 0;
@@ -993,9 +1000,11 @@ static void tcp_chr_accept_server_sync(Chardev *chr)
     tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
     sioc = qio_net_listener_wait_client(s->listener);
     tcp_chr_set_client_ioc_name(chr, sioc);
-    yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
-                           yank_generic_iochannel,
-                           QIO_CHANNEL(sioc));
+    if (s->registered_yank) {
+        yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
+                               yank_generic_iochannel,
+                               QIO_CHANNEL(sioc));
+    }
     tcp_chr_new_client(chr, sioc);
     object_unref(OBJECT(sioc));
 }
@@ -1124,9 +1133,11 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque)
 
     if (qio_task_propagate_error(task, &err)) {
         tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
-        yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
-                                 yank_generic_iochannel,
-                                 QIO_CHANNEL(sioc));
+        if (s->registered_yank) {
+            yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
+                                     yank_generic_iochannel,
+                                     QIO_CHANNEL(sioc));
+        }
         check_report_connect_error(chr, err);
         goto cleanup;
     }
@@ -1160,9 +1171,11 @@ static void tcp_chr_connect_client_async(Chardev *chr)
     tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
     sioc = qio_channel_socket_new();
     tcp_chr_set_client_ioc_name(chr, sioc);
-    yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
-                           yank_generic_iochannel,
-                           QIO_CHANNEL(sioc));
+    if (s->registered_yank) {
+        yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
+                               yank_generic_iochannel,
+                               QIO_CHANNEL(sioc));
+    }
     /*
      * Normally code would use the qio_channel_socket_connect_async
      * method which uses a QIOTask + qio_task_set_error internally
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test
  2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
                   ` (18 preceding siblings ...)
  2021-02-04 10:52 ` [PATCH v2 19/20] chardev: check if the chardev is registered for yanking marcandre.lureau
@ 2021-02-04 10:52 ` marcandre.lureau
  2021-02-16 16:34   ` Alex Bennée
  19 siblings, 1 reply; 28+ messages in thread
From: marcandre.lureau @ 2021-02-04 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, kraxel

From: Marc-André Lureau <marcandre.lureau@redhat.com>

This will check virtio/vhost-user-vga & virgl are correctly initialized
by the Linux kernel on an egl-headless display.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/acceptance/virtio-gpu.py | 161 +++++++++++++++++++++++++++++++++
 1 file changed, 161 insertions(+)
 create mode 100644 tests/acceptance/virtio-gpu.py

diff --git a/tests/acceptance/virtio-gpu.py b/tests/acceptance/virtio-gpu.py
new file mode 100644
index 0000000000..211f02932f
--- /dev/null
+++ b/tests/acceptance/virtio-gpu.py
@@ -0,0 +1,161 @@
+# virtio-gpu tests
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later.  See the COPYING file in the top-level directory.
+
+
+from avocado_qemu import Test
+from avocado_qemu import BUILD_DIR
+from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import exec_command_and_wait_for_pattern
+from avocado_qemu import is_readable_executable_file
+
+from qemu.accel import kvm_available
+
+import os
+import socket
+import subprocess
+
+
+ACCEL_NOT_AVAILABLE_FMT = "%s accelerator does not seem to be available"
+KVM_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "KVM"
+
+
+def pick_default_vug_bin():
+    relative_path = "./contrib/vhost-user-gpu/vhost-user-gpu"
+    if is_readable_executable_file(relative_path):
+        return relative_path
+
+    bld_dir_path = os.path.join(BUILD_DIR, relative_path)
+    if is_readable_executable_file(bld_dir_path):
+        return bld_dir_path
+
+
+class VirtioGPUx86(Test):
+    """
+    :avocado: tags=virtio-gpu
+    """
+
+    KERNEL_COMMON_COMMAND_LINE = "printk.time=0 "
+    KERNEL_URL = (
+        "https://archives.fedoraproject.org/pub/fedora"
+        "/linux/releases/33/Everything/x86_64/os/images"
+        "/pxeboot/vmlinuz"
+    )
+    INITRD_URL = (
+        "https://archives.fedoraproject.org/pub/fedora"
+        "/linux/releases/33/Everything/x86_64/os/images"
+        "/pxeboot/initrd.img"
+    )
+
+    def wait_for_console_pattern(self, success_message, vm=None):
+        wait_for_console_pattern(
+            self,
+            success_message,
+            failure_message="Kernel panic - not syncing",
+            vm=vm,
+        )
+
+    def test_virtio_vga_virgl(self):
+        """
+        :avocado: tags=arch:x86_64
+        :avocado: tags=device:virtio-vga
+        """
+        kernel_command_line = (
+            self.KERNEL_COMMON_COMMAND_LINE + "console=ttyS0 rdinit=/bin/bash"
+        )
+        # FIXME: should check presence of virtio, virgl etc
+        if not kvm_available(self.arch, self.qemu_bin):
+            self.cancel(KVM_NOT_AVAILABLE)
+
+        kernel_path = self.fetch_asset(self.KERNEL_URL)
+        initrd_path = self.fetch_asset(self.INITRD_URL)
+
+        self.vm.set_console()
+        self.vm.add_args("-cpu", "host")
+        self.vm.add_args("-m", "2G")
+        self.vm.add_args("-machine", "pc,accel=kvm")
+        self.vm.add_args("-device", "virtio-vga,virgl=on")
+        self.vm.add_args("-display", "egl-headless")
+        self.vm.add_args(
+            "-kernel",
+            kernel_path,
+            "-initrd",
+            initrd_path,
+            "-append",
+            kernel_command_line,
+        )
+        self.vm.launch()
+        self.wait_for_console_pattern("as init process")
+        exec_command_and_wait_for_pattern(
+            self, "/usr/sbin/modprobe virtio_gpu", ""
+        )
+        self.wait_for_console_pattern("features: +virgl +edid")
+
+    def test_vhost_user_vga_virgl(self):
+        """
+        :avocado: tags=arch:x86_64
+        :avocado: tags=device:vhost-user-vga
+        """
+        kernel_command_line = (
+            self.KERNEL_COMMON_COMMAND_LINE + "console=ttyS0 rdinit=/bin/bash"
+        )
+        # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
+        if not kvm_available(self.arch, self.qemu_bin):
+            self.cancel(KVM_NOT_AVAILABLE)
+
+        vug = pick_default_vug_bin()
+        if not vug:
+            self.cancel("Could not find vhost-user-gpu")
+
+        kernel_path = self.fetch_asset(self.KERNEL_URL)
+        initrd_path = self.fetch_asset(self.INITRD_URL)
+
+        # Create socketpair to connect proxy and remote processes
+        qemu_sock, vug_sock = socket.socketpair(
+            socket.AF_UNIX, socket.SOCK_STREAM
+        )
+        os.set_inheritable(qemu_sock.fileno(), True)
+        os.set_inheritable(vug_sock.fileno(), True)
+
+        self._vug_log_path = os.path.join(
+            self.vm._test_dir, "vhost-user-gpu.log"
+        )
+        self._vug_log_file = open(self._vug_log_path, "wb")
+        print(self._vug_log_path)
+
+        vugp = subprocess.Popen(
+            [vug, "--virgl", "--fd=%d" % vug_sock.fileno()],
+            stdin=subprocess.DEVNULL,
+            stdout=self._vug_log_file,
+            stderr=subprocess.STDOUT,
+            shell=False,
+            close_fds=False,
+        )
+
+        self.vm.set_console()
+        self.vm.add_args("-cpu", "host")
+        self.vm.add_args("-m", "2G")
+        self.vm.add_args("-object", "memory-backend-memfd,id=mem,size=2G")
+        self.vm.add_args("-machine", "pc,memory-backend=mem,accel=kvm")
+        self.vm.add_args("-chardev", "socket,id=vug,fd=%d" % qemu_sock.fileno())
+        self.vm.add_args("-device", "vhost-user-vga,chardev=vug")
+        self.vm.add_args("-display", "egl-headless")
+        self.vm.add_args(
+            "-kernel",
+            kernel_path,
+            "-initrd",
+            initrd_path,
+            "-append",
+            kernel_command_line,
+        )
+        self.vm.launch()
+        self.wait_for_console_pattern("as init process")
+        exec_command_and_wait_for_pattern(
+            self, "/usr/sbin/modprobe virtio_gpu", ""
+        )
+        self.wait_for_console_pattern("features: +virgl -edid")
+        self.vm.shutdown()
+        qemu_sock.close()
+        vugp.terminate()
+        vugp.wait()
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands
  2021-02-04 10:52 ` [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands marcandre.lureau
@ 2021-02-04 11:26   ` Philippe Mathieu-Daudé
  2021-02-04 13:43     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 28+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-02-04 11:26 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel; +Cc: kraxel

On 2/4/21 11:52 AM, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Introduce a pending state for commands which aren't finished yet, but
> are being handled. See following patch.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  contrib/vhost-user-gpu/vugpu.h          | 8 +++++++-
>  contrib/vhost-user-gpu/vhost-user-gpu.c | 8 ++++----
>  contrib/vhost-user-gpu/virgl.c          | 2 +-
>  3 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
> index 86f3ac86aa..04d5615812 100644
> --- a/contrib/vhost-user-gpu/vugpu.h
> +++ b/contrib/vhost-user-gpu/vugpu.h
> @@ -129,12 +129,18 @@ typedef struct VuGpu {
>      QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
>  } VuGpu;
>  
> +enum {
> +    VG_CMD_STATE_NEW,

Maybe VG_CMD_STATE_STARTING?

> +    VG_CMD_STATE_PENDING,

Maybe introduce VG_CMD_STATE_PENDING in the
patch using it.

> +    VG_CMD_STATE_FINISHED,
> +};

Can we use a typedef ...

> +
>  struct virtio_gpu_ctrl_command {
>      VuVirtqElement elem;
>      VuVirtq *vq;
>      struct virtio_gpu_ctrl_hdr cmd_hdr;
>      uint32_t error;
> -    bool finished;
> +    int state;

... and use it here?

Or directly declare in place:

       enum {
           VG_CMD_STATE_STARTING,
           VG_CMD_STATE_PENDING,
           VG_CMD_STATE_FINISHED,
       } state;

>      QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
>  };
>  

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands
  2021-02-04 11:26   ` Philippe Mathieu-Daudé
@ 2021-02-04 13:43     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 28+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-02-04 13:43 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel; +Cc: kraxel

On 2/4/21 12:26 PM, Philippe Mathieu-Daudé wrote:
> On 2/4/21 11:52 AM, marcandre.lureau@redhat.com wrote:
>> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>>
>> Introduce a pending state for commands which aren't finished yet, but
>> are being handled. See following patch.
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>  contrib/vhost-user-gpu/vugpu.h          | 8 +++++++-
>>  contrib/vhost-user-gpu/vhost-user-gpu.c | 8 ++++----
>>  contrib/vhost-user-gpu/virgl.c          | 2 +-
>>  3 files changed, 12 insertions(+), 6 deletions(-)
>>
>> diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
>> index 86f3ac86aa..04d5615812 100644
>> --- a/contrib/vhost-user-gpu/vugpu.h
>> +++ b/contrib/vhost-user-gpu/vugpu.h
>> @@ -129,12 +129,18 @@ typedef struct VuGpu {
>>      QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
>>  } VuGpu;
>>  
>> +enum {
>> +    VG_CMD_STATE_NEW,
> 
> Maybe VG_CMD_STATE_STARTING?
> 
>> +    VG_CMD_STATE_PENDING,
> 
> Maybe introduce VG_CMD_STATE_PENDING in the
> patch using it.
> 
>> +    VG_CMD_STATE_FINISHED,
>> +};
> 
> Can we use a typedef ...
> 
>> +
>>  struct virtio_gpu_ctrl_command {
>>      VuVirtqElement elem;
>>      VuVirtq *vq;
>>      struct virtio_gpu_ctrl_hdr cmd_hdr;
>>      uint32_t error;
>> -    bool finished;
>> +    int state;
> 
> ... and use it here?
> 
> Or directly declare in place:
> 
>        enum {
>            VG_CMD_STATE_STARTING,
>            VG_CMD_STATE_PENDING,
>            VG_CMD_STATE_FINISHED,
>        } state;
> 
>>      QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
>>  };
>>  
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Since Gerd was willing to queue v1, feel free to ignore my
comments at this point. R-b stands.



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing
  2021-02-04 10:52 ` [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing marcandre.lureau
@ 2021-02-05  8:09   ` Alexander Bulekov
  0 siblings, 0 replies; 28+ messages in thread
From: Alexander Bulekov @ 2021-02-05  8:09 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: qemu-devel, kraxel

On 210204 1452, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> The next patch will notify the GL context got flush, which will resume
> the queue processing. However, if this happens within the caller
> context, it will end up with a stack overflow flush/update loop.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

I know this was pulled already, but FWIW I think this is
Buglink: https://bugs.launchpad.net/qemu/+bug/1888606

> ---
>  include/hw/virtio/virtio-gpu.h | 1 +
>  hw/display/virtio-gpu.c        | 5 +++++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
> index 4f3dbf79f9..0043268e90 100644
> --- a/include/hw/virtio/virtio-gpu.h
> +++ b/include/hw/virtio/virtio-gpu.h
> @@ -148,6 +148,7 @@ struct VirtIOGPU {
>  
>      uint64_t hostmem;
>  
> +    bool processing_cmdq;
>      bool renderer_inited;
>      bool renderer_reset;
>      QEMUTimer *fence_poll;
> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> index 0e833a462b..7eb4265a6d 100644
> --- a/hw/display/virtio-gpu.c
> +++ b/hw/display/virtio-gpu.c
> @@ -814,6 +814,10 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
>  {
>      struct virtio_gpu_ctrl_command *cmd;
>  
> +    if (g->processing_cmdq) {
> +        return;
> +    }
> +    g->processing_cmdq = true;
>      while (!QTAILQ_EMPTY(&g->cmdq)) {
>          cmd = QTAILQ_FIRST(&g->cmdq);
>  
> @@ -843,6 +847,7 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
>              g_free(cmd);
>          }
>      }
> +    g->processing_cmdq = false;
>  }
>  
>  static void virtio_gpu_gl_unblock(VirtIOGPUBase *b)
> -- 
> 2.29.0
> 
> 


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test
  2021-02-04 10:52 ` [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test marcandre.lureau
@ 2021-02-16 16:34   ` Alex Bennée
  2021-02-16 17:43     ` Cleber Rosa
  0 siblings, 1 reply; 28+ messages in thread
From: Alex Bennée @ 2021-02-16 16:34 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Cleber Rosa, kraxel, qemu-devel


marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> This will check virtio/vhost-user-vga & virgl are correctly initialized
> by the Linux kernel on an egl-headless display.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/acceptance/virtio-gpu.py | 161 +++++++++++++++++++++++++++++++++
>  1 file changed, 161 insertions(+)
>  create mode 100644 tests/acceptance/virtio-gpu.py

This failed when I got to master:

  2021-02-16 14:33:46,266 qmp              L0255 DEBUG| >>> {'execute': 'qmp_capabilities'}
  2021-02-16 14:33:46,441 machine          L0385 DEBUG| Error launching VM
  2021-02-16 14:33:46,441 machine          L0387 DEBUG| Command: './qemu-system-x86_64 -display none -vga none -chardev socket,id=mon,path=/var/tmp/avo_qemu_sock_xy9ndjnm/qemu
  -29492-monitor.sock -mon chardev=mon,mode=control -chardev socket,id=console,path=/var/tmp/avo_qemu_sock_xy9ndjnm/qemu-29492-console.sock,server=on,wait=off -serial chardev:
  console -cpu host -m 2G -machine pc,accel=kvm -device virtio-vga,virgl=on -display egl-headless -kernel /home/alex.bennee/avocado/data/cache/by_location/892ae21f3ae7d04994d8
  1e1c0bf204ecebe555bb/vmlinuz -initrd /home/alex.bennee/avocado/data/cache/by_location/892ae21f3ae7d04994d81e1c0bf204ecebe555bb/initrd.img -append printk.time=0 console=ttyS0
   rdinit=/bin/bash'
  2021-02-16 14:33:46,441 machine          L0389 DEBUG| Output: "qemu-system-x86_64: -device virtio-vga,virgl=on: Property 'virtio-vga.virgl' not found\n"
  2021-02-16 14:33:46,441 stacktrace       L0039 ERROR|

I'm going to assume this is because the beefy server I was building on
didn't have the VirGL headers to enable this feature. In lieu of feature
probing you might have to do what I did for the plugins test:

        try:
            vm.launch()
        except:
            # TODO: probably fails because plugins not enabled but we
            # can't currently probe for the feature.
            self.cancel("TCG Plugins not enabled?")


>
> diff --git a/tests/acceptance/virtio-gpu.py b/tests/acceptance/virtio-gpu.py
> new file mode 100644
> index 0000000000..211f02932f
> --- /dev/null
> +++ b/tests/acceptance/virtio-gpu.py
> @@ -0,0 +1,161 @@
> +# virtio-gpu tests
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# later.  See the COPYING file in the top-level directory.
> +
> +
> +from avocado_qemu import Test
> +from avocado_qemu import BUILD_DIR
> +from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import exec_command_and_wait_for_pattern
> +from avocado_qemu import is_readable_executable_file
> +
> +from qemu.accel import kvm_available
> +
> +import os
> +import socket
> +import subprocess
> +
> +
> +ACCEL_NOT_AVAILABLE_FMT = "%s accelerator does not seem to be available"
> +KVM_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "KVM"
> +
> +
> +def pick_default_vug_bin():
> +    relative_path = "./contrib/vhost-user-gpu/vhost-user-gpu"
> +    if is_readable_executable_file(relative_path):
> +        return relative_path
> +
> +    bld_dir_path = os.path.join(BUILD_DIR, relative_path)
> +    if is_readable_executable_file(bld_dir_path):
> +        return bld_dir_path
> +
> +
> +class VirtioGPUx86(Test):
> +    """
> +    :avocado: tags=virtio-gpu
> +    """
> +
> +    KERNEL_COMMON_COMMAND_LINE = "printk.time=0 "
> +    KERNEL_URL = (
> +        "https://archives.fedoraproject.org/pub/fedora"
> +        "/linux/releases/33/Everything/x86_64/os/images"
> +        "/pxeboot/vmlinuz"
> +    )
> +    INITRD_URL = (
> +        "https://archives.fedoraproject.org/pub/fedora"
> +        "/linux/releases/33/Everything/x86_64/os/images"
> +        "/pxeboot/initrd.img"
> +    )
> +
> +    def wait_for_console_pattern(self, success_message, vm=None):
> +        wait_for_console_pattern(
> +            self,
> +            success_message,
> +            failure_message="Kernel panic - not syncing",
> +            vm=vm,
> +        )
> +
> +    def test_virtio_vga_virgl(self):
> +        """
> +        :avocado: tags=arch:x86_64
> +        :avocado: tags=device:virtio-vga
> +        """
> +        kernel_command_line = (
> +            self.KERNEL_COMMON_COMMAND_LINE + "console=ttyS0 rdinit=/bin/bash"
> +        )
> +        # FIXME: should check presence of virtio, virgl etc
> +        if not kvm_available(self.arch, self.qemu_bin):
> +            self.cancel(KVM_NOT_AVAILABLE)
> +
> +        kernel_path = self.fetch_asset(self.KERNEL_URL)
> +        initrd_path = self.fetch_asset(self.INITRD_URL)
> +
> +        self.vm.set_console()
> +        self.vm.add_args("-cpu", "host")
> +        self.vm.add_args("-m", "2G")
> +        self.vm.add_args("-machine", "pc,accel=kvm")
> +        self.vm.add_args("-device", "virtio-vga,virgl=on")
> +        self.vm.add_args("-display", "egl-headless")
> +        self.vm.add_args(
> +            "-kernel",
> +            kernel_path,
> +            "-initrd",
> +            initrd_path,
> +            "-append",
> +            kernel_command_line,
> +        )
> +        self.vm.launch()
> +        self.wait_for_console_pattern("as init process")
> +        exec_command_and_wait_for_pattern(
> +            self, "/usr/sbin/modprobe virtio_gpu", ""
> +        )
> +        self.wait_for_console_pattern("features: +virgl +edid")
> +
> +    def test_vhost_user_vga_virgl(self):
> +        """
> +        :avocado: tags=arch:x86_64
> +        :avocado: tags=device:vhost-user-vga
> +        """
> +        kernel_command_line = (
> +            self.KERNEL_COMMON_COMMAND_LINE + "console=ttyS0 rdinit=/bin/bash"
> +        )
> +        # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
> +        if not kvm_available(self.arch, self.qemu_bin):
> +            self.cancel(KVM_NOT_AVAILABLE)
> +
> +        vug = pick_default_vug_bin()
> +        if not vug:
> +            self.cancel("Could not find vhost-user-gpu")
> +
> +        kernel_path = self.fetch_asset(self.KERNEL_URL)
> +        initrd_path = self.fetch_asset(self.INITRD_URL)
> +
> +        # Create socketpair to connect proxy and remote processes
> +        qemu_sock, vug_sock = socket.socketpair(
> +            socket.AF_UNIX, socket.SOCK_STREAM
> +        )
> +        os.set_inheritable(qemu_sock.fileno(), True)
> +        os.set_inheritable(vug_sock.fileno(), True)
> +
> +        self._vug_log_path = os.path.join(
> +            self.vm._test_dir, "vhost-user-gpu.log"
> +        )
> +        self._vug_log_file = open(self._vug_log_path, "wb")
> +        print(self._vug_log_path)
> +
> +        vugp = subprocess.Popen(
> +            [vug, "--virgl", "--fd=%d" % vug_sock.fileno()],
> +            stdin=subprocess.DEVNULL,
> +            stdout=self._vug_log_file,
> +            stderr=subprocess.STDOUT,
> +            shell=False,
> +            close_fds=False,
> +        )
> +
> +        self.vm.set_console()
> +        self.vm.add_args("-cpu", "host")
> +        self.vm.add_args("-m", "2G")
> +        self.vm.add_args("-object", "memory-backend-memfd,id=mem,size=2G")
> +        self.vm.add_args("-machine", "pc,memory-backend=mem,accel=kvm")
> +        self.vm.add_args("-chardev", "socket,id=vug,fd=%d" % qemu_sock.fileno())
> +        self.vm.add_args("-device", "vhost-user-vga,chardev=vug")
> +        self.vm.add_args("-display", "egl-headless")
> +        self.vm.add_args(
> +            "-kernel",
> +            kernel_path,
> +            "-initrd",
> +            initrd_path,
> +            "-append",
> +            kernel_command_line,
> +        )
> +        self.vm.launch()
> +        self.wait_for_console_pattern("as init process")
> +        exec_command_and_wait_for_pattern(
> +            self, "/usr/sbin/modprobe virtio_gpu", ""
> +        )
> +        self.wait_for_console_pattern("features: +virgl -edid")
> +        self.vm.shutdown()
> +        qemu_sock.close()
> +        vugp.terminate()
> +        vugp.wait()


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test
  2021-02-16 16:34   ` Alex Bennée
@ 2021-02-16 17:43     ` Cleber Rosa
  2021-02-17  8:27       ` Marc-André Lureau
  0 siblings, 1 reply; 28+ messages in thread
From: Cleber Rosa @ 2021-02-16 17:43 UTC (permalink / raw)
  To: Alex Bennée; +Cc: marcandre.lureau, kraxel, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 3248 bytes --]

On Tue, Feb 16, 2021 at 04:34:06PM +0000, Alex Bennée wrote:
> 
> marcandre.lureau@redhat.com writes:
> 
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > This will check virtio/vhost-user-vga & virgl are correctly initialized
> > by the Linux kernel on an egl-headless display.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  tests/acceptance/virtio-gpu.py | 161 +++++++++++++++++++++++++++++++++
> >  1 file changed, 161 insertions(+)
> >  create mode 100644 tests/acceptance/virtio-gpu.py
> 
> This failed when I got to master:
> 
>   2021-02-16 14:33:46,266 qmp              L0255 DEBUG| >>> {'execute': 'qmp_capabilities'}
>   2021-02-16 14:33:46,441 machine          L0385 DEBUG| Error launching VM
>   2021-02-16 14:33:46,441 machine          L0387 DEBUG| Command: './qemu-system-x86_64 -display none -vga none -chardev socket,id=mon,path=/var/tmp/avo_qemu_sock_xy9ndjnm/qemu
>   -29492-monitor.sock -mon chardev=mon,mode=control -chardev socket,id=console,path=/var/tmp/avo_qemu_sock_xy9ndjnm/qemu-29492-console.sock,server=on,wait=off -serial chardev:
>   console -cpu host -m 2G -machine pc,accel=kvm -device virtio-vga,virgl=on -display egl-headless -kernel /home/alex.bennee/avocado/data/cache/by_location/892ae21f3ae7d04994d8
>   1e1c0bf204ecebe555bb/vmlinuz -initrd /home/alex.bennee/avocado/data/cache/by_location/892ae21f3ae7d04994d81e1c0bf204ecebe555bb/initrd.img -append printk.time=0 console=ttyS0
>    rdinit=/bin/bash'
>   2021-02-16 14:33:46,441 machine          L0389 DEBUG| Output: "qemu-system-x86_64: -device virtio-vga,virgl=on: Property 'virtio-vga.virgl' not found\n"
>   2021-02-16 14:33:46,441 stacktrace       L0039 ERROR|
> 
> I'm going to assume this is because the beefy server I was building on
> didn't have the VirGL headers to enable this feature. In lieu of feature
> probing you might have to do what I did for the plugins test:
> 
>         try:
>             vm.launch()
>         except:
>             # TODO: probably fails because plugins not enabled but we
>             # can't currently probe for the feature.
>             self.cancel("TCG Plugins not enabled?")
> 
>

While this pattern is indeed an improvement over test errors, checking
for "build time features" is far from a new testing requirement, and
its still not properly solved.  A long time ago I proposed a way to
look at the Makefile variables during test time, but it had a number
of shortcomings.  I guess it's now time to revisit this issue.

First, I'm a strong believer in limiting the *probing* that the test itself
does with regards to build time features.  The probing and authoritative
information should already be with the build system.  I'm pretty sure that
meson makes it easy to grab that kind of information.

Once it's understood and agreed that the build system will provide
that information, the question becomes whether tests will get that
information from the build system (and thus require a build tree) or
if that information will be persisted in the QEMU binary and be
available for introspection.

Thoughts? Does this sound like something other people would be
interested in?

Regards,
- Cleber.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test
  2021-02-16 17:43     ` Cleber Rosa
@ 2021-02-17  8:27       ` Marc-André Lureau
  2021-02-17 12:12         ` Alex Bennée
  0 siblings, 1 reply; 28+ messages in thread
From: Marc-André Lureau @ 2021-02-17  8:27 UTC (permalink / raw)
  To: Cleber Rosa; +Cc: Alex Bennée, Hoffmann, Gerd, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 3852 bytes --]

Hi

On Tue, Feb 16, 2021 at 9:43 PM Cleber Rosa <crosa@redhat.com> wrote:

> On Tue, Feb 16, 2021 at 04:34:06PM +0000, Alex Bennée wrote:
> >
> > marcandre.lureau@redhat.com writes:
> >
> > > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> > >
> > > This will check virtio/vhost-user-vga & virgl are correctly initialized
> > > by the Linux kernel on an egl-headless display.
> > >
> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > ---
> > >  tests/acceptance/virtio-gpu.py | 161 +++++++++++++++++++++++++++++++++
> > >  1 file changed, 161 insertions(+)
> > >  create mode 100644 tests/acceptance/virtio-gpu.py
> >
> > This failed when I got to master:
> >
> >   2021-02-16 14:33:46,266 qmp              L0255 DEBUG| >>> {'execute':
> 'qmp_capabilities'}
> >   2021-02-16 14:33:46,441 machine          L0385 DEBUG| Error launching
> VM
> >   2021-02-16 14:33:46,441 machine          L0387 DEBUG| Command:
> './qemu-system-x86_64 -display none -vga none -chardev
> socket,id=mon,path=/var/tmp/avo_qemu_sock_xy9ndjnm/qemu
> >   -29492-monitor.sock -mon chardev=mon,mode=control -chardev
> socket,id=console,path=/var/tmp/avo_qemu_sock_xy9ndjnm/qemu-29492-console.sock,server=on,wait=off
> -serial chardev:
> >   console -cpu host -m 2G -machine pc,accel=kvm -device
> virtio-vga,virgl=on -display egl-headless -kernel
> /home/alex.bennee/avocado/data/cache/by_location/892ae21f3ae7d04994d8
> >   1e1c0bf204ecebe555bb/vmlinuz -initrd
> /home/alex.bennee/avocado/data/cache/by_location/892ae21f3ae7d04994d81e1c0bf204ecebe555bb/initrd.img
> -append printk.time=0 console=ttyS0
> >    rdinit=/bin/bash'
> >   2021-02-16 14:33:46,441 machine          L0389 DEBUG| Output:
> "qemu-system-x86_64: -device virtio-vga,virgl=on: Property
> 'virtio-vga.virgl' not found\n"
> >   2021-02-16 14:33:46,441 stacktrace       L0039 ERROR|
> >
> > I'm going to assume this is because the beefy server I was building on
> > didn't have the VirGL headers to enable this feature. In lieu of feature
> > probing you might have to do what I did for the plugins test:
> >
> >         try:
> >             vm.launch()
> >         except:
> >             # TODO: probably fails because plugins not enabled but we
> >             # can't currently probe for the feature.
> >             self.cancel("TCG Plugins not enabled?")
> >
> >
>
> While this pattern is indeed an improvement over test errors, checking
> for "build time features" is far from a new testing requirement, and
> its still not properly solved.  A long time ago I proposed a way to
> look at the Makefile variables during test time, but it had a number
> of shortcomings.  I guess it's now time to revisit this issue.
>
> First, I'm a strong believer in limiting the *probing* that the test itself
> does with regards to build time features.  The probing and authoritative
> information should already be with the build system.  I'm pretty sure that
> meson makes it easy to grab that kind of information.
>
> Once it's understood and agreed that the build system will provide
> that information, the question becomes whether tests will get that
> information from the build system (and thus require a build tree) or
> if that information will be persisted in the QEMU binary and be
> available for introspection.
>
> Thoughts? Does this sound like something other people would be
> interested in?
>

It would be more reliable and flexible to do runtime introspection. It
would allow installed tests, and some runtime checks for example.

Given the variability of builds, is there something that does introspection
in avocado-vt already?  I think we could rely on qmp introspection,
qom-list-types etc.

In the meantime Alex, could you send a patch to ignore the test the way you
propose?

[-- Attachment #2: Type: text/html, Size: 4891 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test
  2021-02-17  8:27       ` Marc-André Lureau
@ 2021-02-17 12:12         ` Alex Bennée
  0 siblings, 0 replies; 28+ messages in thread
From: Alex Bennée @ 2021-02-17 12:12 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, Hoffmann, Gerd, Cleber Rosa


Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Hi
>
> On Tue, Feb 16, 2021 at 9:43 PM Cleber Rosa <crosa@redhat.com> wrote:
>
>> On Tue, Feb 16, 2021 at 04:34:06PM +0000, Alex Bennée wrote:
>> >
>> > marcandre.lureau@redhat.com writes:
>> >
>> > > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > >
>> > > This will check virtio/vhost-user-vga & virgl are correctly initialized
>> > > by the Linux kernel on an egl-headless display.
>> > >
>> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > > ---
>> > >  tests/acceptance/virtio-gpu.py | 161 +++++++++++++++++++++++++++++++++
>> > >  1 file changed, 161 insertions(+)
>> > >  create mode 100644 tests/acceptance/virtio-gpu.py
>> >
>> > This failed when I got to master:
>> >
>> >   2021-02-16 14:33:46,266 qmp              L0255 DEBUG| >>> {'execute':
>> 'qmp_capabilities'}
>> >   2021-02-16 14:33:46,441 machine          L0385 DEBUG| Error launching
>> VM
>> >   2021-02-16 14:33:46,441 machine          L0387 DEBUG| Command:
>> './qemu-system-x86_64 -display none -vga none -chardev
>> socket,id=mon,path=/var/tmp/avo_qemu_sock_xy9ndjnm/qemu
>> >   -29492-monitor.sock -mon chardev=mon,mode=control -chardev
>> socket,id=console,path=/var/tmp/avo_qemu_sock_xy9ndjnm/qemu-29492-console.sock,server=on,wait=off
>> -serial chardev:
>> >   console -cpu host -m 2G -machine pc,accel=kvm -device
>> virtio-vga,virgl=on -display egl-headless -kernel
>> /home/alex.bennee/avocado/data/cache/by_location/892ae21f3ae7d04994d8
>> >   1e1c0bf204ecebe555bb/vmlinuz -initrd
>> /home/alex.bennee/avocado/data/cache/by_location/892ae21f3ae7d04994d81e1c0bf204ecebe555bb/initrd.img
>> -append printk.time=0 console=ttyS0
>> >    rdinit=/bin/bash'
>> >   2021-02-16 14:33:46,441 machine          L0389 DEBUG| Output:
>> "qemu-system-x86_64: -device virtio-vga,virgl=on: Property
>> 'virtio-vga.virgl' not found\n"
>> >   2021-02-16 14:33:46,441 stacktrace       L0039 ERROR|
>> >
>> > I'm going to assume this is because the beefy server I was building on
>> > didn't have the VirGL headers to enable this feature. In lieu of feature
>> > probing you might have to do what I did for the plugins test:
>> >
>> >         try:
>> >             vm.launch()
>> >         except:
>> >             # TODO: probably fails because plugins not enabled but we
>> >             # can't currently probe for the feature.
>> >             self.cancel("TCG Plugins not enabled?")
>> >
>> >
>>
>> While this pattern is indeed an improvement over test errors, checking
>> for "build time features" is far from a new testing requirement, and
>> its still not properly solved.  A long time ago I proposed a way to
>> look at the Makefile variables during test time, but it had a number
>> of shortcomings.  I guess it's now time to revisit this issue.
>>
>> First, I'm a strong believer in limiting the *probing* that the test itself
>> does with regards to build time features.  The probing and authoritative
>> information should already be with the build system.  I'm pretty sure that
>> meson makes it easy to grab that kind of information.
>>
>> Once it's understood and agreed that the build system will provide
>> that information, the question becomes whether tests will get that
>> information from the build system (and thus require a build tree) or
>> if that information will be persisted in the QEMU binary and be
>> available for introspection.
>>
>> Thoughts? Does this sound like something other people would be
>> interested in?
>>
>
> It would be more reliable and flexible to do runtime introspection. It
> would allow installed tests, and some runtime checks for example.
>
> Given the variability of builds, is there something that does introspection
> in avocado-vt already?  I think we could rely on qmp introspection,
> qom-list-types etc.
>
> In the meantime Alex, could you send a patch to ignore the test the way you
> propose?

Sure.


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2021-02-17 12:13 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 01/20] vhost-user-gpu: check backend for EDID support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 02/20] vhost-user-gpu: handle vhost-user-gpu features in a callback marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands marcandre.lureau
2021-02-04 11:26   ` Philippe Mathieu-Daudé
2021-02-04 13:43     ` Philippe Mathieu-Daudé
2021-02-04 10:52 ` [PATCH v2 04/20] vhost-user-gpu: handle display-info in a callback marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 05/20] ui: remove extra #ifdef CONFIG_OPENGL marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 06/20] ui: remove gl_ctx_get_current marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 07/20] ui: add gd_gl_area_scanout_disable marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 08/20] ui: annotate DCLOps callback requirements marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 09/20] ui: remove console_has_gl_dmabuf() marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 10/20] vhost-user-gpu: add a configuration flag for dmabuf usage marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 11/20] ui: add an optional get_flags callback to GraphicHwOps marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 12/20] ui: add a DCLOps callback to check dmabuf support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 13/20] ui: check hw requirements during DCL registration marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 14/20] ui: add qemu_egl_has_dmabuf helper marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 15/20] ui: check gtk-egl dmabuf support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 16/20] ui: add egl dmabuf import to gtkglarea marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing marcandre.lureau
2021-02-05  8:09   ` Alexander Bulekov
2021-02-04 10:52 ` [PATCH v2 18/20] display/ui: add a callback to indicate GL state is flushed marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 19/20] chardev: check if the chardev is registered for yanking marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test marcandre.lureau
2021-02-16 16:34   ` Alex Bennée
2021-02-16 17:43     ` Cleber Rosa
2021-02-17  8:27       ` Marc-André Lureau
2021-02-17 12:12         ` Alex Bennée

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.