Skip to contentSkip to conversation

Ui patches

GIT PULL Applied [email protected] 7 participants 20 messages Jul 15, 2025 – Jul 17, 2025

lore
Share & tools
lore
#0 lore raw

From: Marc-André Lureau <[email protected]>

The following changes since commit 9a4e273ddec3927920c5958d2226c6b38b543336:

Merge tag 'pull-tcg-20250711' of https://gitlab.com/rth7680/qemu into staging (2025-07-13 01:46:04 -0400)

are available in the Git repository at:

https://gitlab.com/marcandre.lureau/qemu.git tags/ui-pull-request

for you to fetch changes up to df892b3954e5b2782165e6c59e5ffd55c2f7ec5a:

tpm: "qemu -tpmdev help" should return success (2025-07-15 10:22:33 +0400)

----------------------------------------------------------------
UI-related for 10.1

- [PATCH v3 0/2] ui/vnc: Do not copy z_stream
- [PATCH v6 0/7] ui/spice: Enable gl=on option for non-local or remote clients
- [PATCH v6 0/1] Allow injection of virtio-gpu EDID name
- [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and scale option

----------------------------------------------------------------

Akihiko Odaki (2):
ui/vnc: Do not copy z_stream
ui/vnc: Introduce the VncWorker type

Andrew Keesler (1):
hw/display: Allow injection of virtio-gpu EDID name

Marc-André Lureau (1):
tpm: "qemu -tpmdev help" should return success

Vivek Kasireddy (7):
ui/egl-helpers: Error check the fds in egl_dmabuf_export_texture() ui/spice: Enable gl=on option for non-local or remote clients ui/spice: Add an option for users to provide a preferred video codec ui/spice: Add an option to submit gl_draw requests at fixed rate ui/console-gl: Add a helper to create a texture with linear memory
layout
ui/spice: Create a new texture with linear layout when gl=on is
specified
ui/spice: Blit the scanout texture if its memory layout is not linear

Weifeng Liu (2):
ui/gtk: Add keep-aspect-ratio option
ui/gtk: Add scale option

 qapi/ui.json                        |  15 +-
 qapi/virtio.json                    |  18 +-
 include/hw/display/edid.h           |   2 +
 include/hw/qdev-properties-system.h |   5 +
 include/hw/virtio/virtio-gpu.h      |   3 +
 include/ui/console.h                |   3 +
 include/ui/gtk.h                    |   2 +
 include/ui/spice-display.h          |   5 +
 include/ui/surface.h                |   1 +
 ui/vnc.h                            |  49 +--
 hw/core/qdev-properties-system.c    |  44 +++
 hw/display/virtio-gpu-base.c        |  27 ++
 system/tpm.c                        |   5 +-
 ui/console-gl.c                     |  54 ++++
 ui/egl-helpers.c                    |   6 +
 ui/gtk.c                            |  58 ++--
 ui/spice-core.c                     |  32 ++
 ui/spice-display.c                  | 226 +++++++++++++-
 ui/vnc-enc-tight.c                  | 456 +++++++++++++++-------------
 ui/vnc-enc-zlib.c                   |  47 +--
 ui/vnc-enc-zrle.c                   | 122 ++++----
 ui/vnc-jobs.c                       |  13 +-
 ui/vnc.c                            |  83 +++--
 ui/vnc-enc-zrle.c.inc               |  20 +-
 qemu-options.hx                     |  13 +
 25 files changed, 883 insertions(+), 426 deletions(-)
Signature · 1 line
2.50.0
#1 lore raw

[PULL v2 01/13] ui/vnc: Do not copy z_stream

From: Akihiko Odaki <[email protected]>

vnc_worker_thread_loop() copies z_stream stored in its local VncState to the persistent VncState, and the copied one is freed with deflateEnd() later. However, deflateEnd() refuses to operate with a copied z_stream and returns Z_STREAM_ERROR, leaking the allocated memory.

Avoid copying the zlib state to fix the memory leak.

Fixes bd023f953e5e ("vnc: threaded VNC server")

Message-Id: <[email protected]>

---
 ui/vnc.h          |  2 +-
 ui/vnc-enc-zlib.c | 30 +++++++++++++++---------------
 ui/vnc.c          | 13 ++++++++++---
 3 files changed, 26 insertions(+), 19 deletions(-)
ui/vnc.h +1 -1
index b3e07269bb..8df0cbab25 100644
@@ -342,7 +342,7 @@ struct VncState
      *  update vnc_async_encoding_start()
      */
     VncTight *tight;
-    VncZlib zlib;
+    VncZlib *zlib;
     VncHextile hextile;
     VncZrle *zrle;
     VncZywrle zywrle;
ui/vnc-enc-zlib.c +15 -15
index 900ae5b30f..52e9193eab 100644
@@ -48,21 +48,21 @@ void vnc_zlib_zfree(void *x, void *addr)
 
 static void vnc_zlib_start(VncState *vs)
 {
-    buffer_reset(&vs->zlib.zlib);
+    buffer_reset(&vs->zlib->zlib);
 
     // make the output buffer be the zlib buffer, so we can compress it later
-    vs->zlib.tmp = vs->output;
-    vs->output = vs->zlib.zlib;
+    vs->zlib->tmp = vs->output;
+    vs->output = vs->zlib->zlib;
 }
 
 static int vnc_zlib_stop(VncState *vs)
 {
-    z_streamp zstream = &vs->zlib.stream;
+    z_streamp zstream = &vs->zlib->stream;
     int previous_out;
 
     // switch back to normal output/zlib buffers
-    vs->zlib.zlib = vs->output;
-    vs->output = vs->zlib.tmp;
+    vs->zlib->zlib = vs->output;
+    vs->output = vs->zlib->tmp;
 
     // compress the zlib buffer
 
@@ -85,24 +85,24 @@ static int vnc_zlib_stop(VncState *vs)
             return -1;
         }
 
-        vs->zlib.level = vs->tight->compression;
+        vs->zlib->level = vs->tight->compression;
         zstream->opaque = vs;
     }
 
-    if (vs->tight->compression != vs->zlib.level) {
+    if (vs->tight->compression != vs->zlib->level) {
         if (deflateParams(zstream, vs->tight->compression,
                           Z_DEFAULT_STRATEGY) != Z_OK) {
             return -1;
         }
-        vs->zlib.level = vs->tight->compression;
+        vs->zlib->level = vs->tight->compression;
     }
 
     // reserve memory in output buffer
-    buffer_reserve(&vs->output, vs->zlib.zlib.offset + 64);
+    buffer_reserve(&vs->output, vs->zlib->zlib.offset + 64);
 
     // set pointers
-    zstream->next_in = vs->zlib.zlib.buffer;
-    zstream->avail_in = vs->zlib.zlib.offset;
+    zstream->next_in = vs->zlib->zlib.buffer;
+    zstream->avail_in = vs->zlib->zlib.offset;
     zstream->next_out = vs->output.buffer + vs->output.offset;
     zstream->avail_out = vs->output.capacity - vs->output.offset;
     previous_out = zstream->avail_out;
@@ -147,8 +147,8 @@ int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
 
 void vnc_zlib_clear(VncState *vs)
 {
-    if (vs->zlib.stream.opaque) {
-        deflateEnd(&vs->zlib.stream);
+    if (vs->zlib->stream.opaque) {
+        deflateEnd(&vs->zlib->stream);
     }
-    buffer_free(&vs->zlib.zlib);
+    buffer_free(&vs->zlib->zlib);
 }
ui/vnc.c +10 -3
index e9c30aad62..ab74154e4c 100644
@@ -56,6 +56,11 @@
 #include "io/dns-resolver.h"
 #include "monitor/monitor.h"
 
+typedef struct VncConnection {
+    VncState vs;
+    VncZlib zlib;
+} VncConnection;
+
 #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT
 #define VNC_REFRESH_INTERVAL_INC  50
 #define VNC_REFRESH_INTERVAL_MAX  GUI_REFRESH_INTERVAL_IDLE
@@ -1362,7 +1367,7 @@ void vnc_disconnect_finish(VncState *vs)
     vs->magic = 0;
     g_free(vs->zrle);
     g_free(vs->tight);
-    g_free(vs);
+    g_free(container_of(vs, VncConnection, vs));
 }
 
 size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err)
@@ -3241,11 +3246,13 @@ static void vnc_refresh(DisplayChangeListener *dcl)
 static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc,
                         bool skipauth, bool websocket)
 {
-    VncState *vs = g_new0(VncState, 1);
+    VncConnection *vc = g_new0(VncConnection, 1);
+    VncState *vs = &vc->vs;
     bool first_client = QTAILQ_EMPTY(&vd->clients);
     int i;
 
     trace_vnc_client_connect(vs, sioc);
+    vs->zlib = &vc->zlib;
     vs->zrle = g_new0(VncZrle, 1);
     vs->tight = g_new0(VncTight, 1);
     vs->magic = VNC_MAGIC;
@@ -3268,7 +3275,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc,
 #ifdef CONFIG_PNG
     buffer_init(&vs->tight->png,      "vnc-tight-png/%p", sioc);
 #endif
-    buffer_init(&vs->zlib.zlib,      "vnc-zlib/%p", sioc);
+    buffer_init(&vc->zlib.zlib,      "vnc-zlib/%p", sioc);
     buffer_init(&vs->zrle->zrle,      "vnc-zrle/%p", sioc);
     buffer_init(&vs->zrle->fb,        "vnc-zrle-fb/%p", sioc);
     buffer_init(&vs->zrle->zlib,      "vnc-zrle-zlib/%p", sioc);
Signature · 1 line
2.50.0
#2 lore raw

Re: [PULL v2 01/13] ui/vnc: Do not copy z_stream

Quoted 13 lines · On 15.07.2025 09:32, [email protected] wrote:

From: Akihiko Odaki <[email protected]>

vnc_worker_thread_loop() copies z_stream stored in its local VncState to the persistent VncState, and the copied one is freed with deflateEnd() later. However, deflateEnd() refuses to operate with a copied z_stream and returns Z_STREAM_ERROR, leaking the allocated memory.

Avoid copying the zlib state to fix the memory leak.

Fixes bd023f953e5e ("vnc: threaded VNC server")
Quoted 6 lines

Message-Id: <[email protected]>

---
  ui/vnc.h          |  2 +-
  ui/vnc-enc-zlib.c | 30 +++++++++++++++---------------
  ui/vnc.c          | 13 ++++++++++---
  3 files changed, 26 insertions(+), 19 deletions(-)

This looks like a qemu-stable material, is it not?

Thanks,

/mjt

#3 lore raw

Re: [PULL v2 01/13] ui/vnc: Do not copy z_stream

Quoted 21 lines · Michael Tokarev
Quoted 13 lines · On 15.07.2025 09:32, [email protected] wrote:

From: Akihiko Odaki <[email protected]>

vnc_worker_thread_loop() copies z_stream stored in its local VncState to the persistent VncState, and the copied one is freed with deflateEnd() later. However, deflateEnd() refuses to operate with a copied z_stream and returns Z_STREAM_ERROR, leaking the allocated memory.

Avoid copying the zlib state to fix the memory leak.

Fixes bd023f953e5e ("vnc: threaded VNC server")
Quoted 6 lines

Message-Id: <[email protected]>

---
  ui/vnc.h          |  2 +-
  ui/vnc-enc-zlib.c | 30 +++++++++++++++---------------
  ui/vnc.c          | 13 ++++++++++---
  3 files changed, 26 insertions(+), 19 deletions(-)
Quoted 1 line

This looks like a qemu-stable material, is it not?

Yes, please cherry-pick this.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw

[PULL v2 02/13] ui/vnc: Introduce the VncWorker type

In reply to [email protected]

From: Akihiko Odaki <[email protected]>

The worker thread copies data in VncState to avoid race, but some data are too big to copy. Such data are held with pointers to avoid the overhead to copy, but it requires tedious memory management and makes them vulnerable to race.

Introduce the VncWorker type to contain all data shared without copying. It allows allocating and freeing all shared data at once and shows that the race with the worker thread needs to be taken care of when accessing them.

Message-Id: <[email protected]>

---
 ui/vnc.h              |  49 +++--
 ui/vnc-enc-tight.c    | 456 ++++++++++++++++++++++--------------------
 ui/vnc-enc-zlib.c     |  47 ++---
 ui/vnc-enc-zrle.c     | 122 +++++------
 ui/vnc-jobs.c         |  13 +-
 ui/vnc.c              |  86 ++++----
 ui/vnc-enc-zrle.c.inc |  20 +-
 7 files changed, 405 insertions(+), 388 deletions(-)
ui/vnc.h +31 -18
index 8df0cbab25..f2dab2f4d9 100644
@@ -272,8 +272,6 @@ struct VncState
     gboolean disconnecting;
 
     DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS);
-    uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
-                           * vnc-jobs-async.c */
 
     VncDisplay *vd;
     VncStateUpdate update; /* Most recent pending request from client */
@@ -341,10 +339,7 @@ struct VncState
     /* Encoding specific, if you add something here, don't forget to
      *  update vnc_async_encoding_start()
      */
-    VncTight *tight;
-    VncZlib *zlib;
     VncHextile hextile;
-    VncZrle *zrle;
     VncZywrle zywrle;
 
     Notifier mouse_mode_notifier;
@@ -356,6 +351,19 @@ struct VncState
     QTAILQ_ENTRY(VncState) next;
 };
 
+typedef struct VncWorker {
+    uint8_t lossy_rect[VNC_STAT_ROWS][VNC_STAT_COLS];
+
+    VncTight tight;
+    VncZlib zlib;
+    VncZrle zrle;
+} VncWorker;
+
+typedef struct VncConnection {
+    VncState vs;
+    VncWorker worker;
+} VncConnection;
+
 
 /*****************************************************************************
  *
@@ -602,10 +610,11 @@ int vnc_server_fb_stride(VncDisplay *vd);
 
 void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
 double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
-void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h);
+void vnc_sent_lossy_rect(VncWorker *worker, int x, int y, int w, int h);
 
 /* Encodings */
-int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
+int vnc_send_framebuffer_update(VncState *vs, VncWorker *worker,
+                                int x, int y, int w, int h);
 
 int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
 
@@ -615,17 +624,21 @@ void vnc_hextile_set_pixel_conversion(VncState *vs, int generic);
 
 void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size);
 void vnc_zlib_zfree(void *x, void *addr);
-int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
-void vnc_zlib_clear(VncState *vs);
-
-int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
-int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y,
-                                          int w, int h);
-void vnc_tight_clear(VncState *vs);
-
-int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
-int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
-void vnc_zrle_clear(VncState *vs);
+int vnc_zlib_send_framebuffer_update(VncState *vs, VncWorker *worker,
+                                     int x, int y, int w, int h);
+void vnc_zlib_clear(VncWorker *worker);
+
+int vnc_tight_send_framebuffer_update(VncState *vs, VncWorker *worker,
+                                      int x, int y, int w, int h);
+int vnc_tight_png_send_framebuffer_update(VncState *vs, VncWorker *worker,
+                                          int x, int y, int w, int h);
+void vnc_tight_clear(VncWorker *worker);
+
+int vnc_zrle_send_framebuffer_update(VncState *vs, VncWorker *worker,
+                                     int x, int y, int w, int h);
+int vnc_zywrle_send_framebuffer_update(VncState *vs, VncWorker *worker,
+                                       int x, int y, int w, int h);
+void vnc_zrle_clear(VncWorker *worker);
 
 /* vnc-clipboard.c */
 void vnc_server_cut_text_caps(VncState *vs);
ui/vnc-enc-tight.c +240 -216

1,072 lines not on this page · raw message

ui/vnc-enc-zlib.c +24 -23

104 lines not on this page · raw message

ui/vnc-enc-zrle.c +62 -60

227 lines not on this page · raw message

ui/vnc-jobs.c +4 -9
index d3486af9e2..bed33950a8 100644
@@ -185,14 +185,10 @@ static void vnc_async_encoding_start(VncState *orig, VncState *local)
     local->vnc_encoding = orig->vnc_encoding;
     local->features = orig->features;
     local->vd = orig->vd;
-    local->lossy_rect = orig->lossy_rect;
     local->write_pixels = orig->write_pixels;
     local->client_pf = orig->client_pf;
     local->client_endian = orig->client_endian;
-    local->tight = orig->tight;
-    local->zlib = orig->zlib;
     local->hextile = orig->hextile;
-    local->zrle = orig->zrle;
     local->client_width = orig->client_width;
     local->client_height = orig->client_height;
 }
@@ -200,11 +196,7 @@ static void vnc_async_encoding_start(VncState *orig, VncState *local)
 static void vnc_async_encoding_end(VncState *orig, VncState *local)
 {
     buffer_free(&local->output);
-    orig->tight = local->tight;
-    orig->zlib = local->zlib;
     orig->hextile = local->hextile;
-    orig->zrle = local->zrle;
-    orig->lossy_rect = local->lossy_rect;
 }
 
 static bool vnc_worker_clamp_rect(VncState *vs, VncJob *job, VncRect *rect)
@@ -237,6 +229,7 @@ static bool vnc_worker_clamp_rect(VncState *vs, VncJob *job, VncRect *rect)
 
 static int vnc_worker_thread_loop(VncJobQueue *queue)
 {
+    VncConnection *vc;
     VncJob *job;
     VncRectEntry *entry, *tmp;
     VncState vs = {};
@@ -256,6 +249,7 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
     }
 
     assert(job->vs->magic == VNC_MAGIC);
+    vc = container_of(job->vs, VncConnection, vs);
 
     vnc_lock_output(job->vs);
     if (job->vs->ioc == NULL || job->vs->abort == true) {
@@ -295,7 +289,8 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
         }
 
         if (vnc_worker_clamp_rect(&vs, job, &entry->rect)) {
-            n = vnc_send_framebuffer_update(&vs, entry->rect.x, entry->rect.y,
+            n = vnc_send_framebuffer_update(&vs, &vc->worker,
+                                            entry->rect.x, entry->rect.y,
                                             entry->rect.w, entry->rect.h);
 
             if (n >= 0) {
ui/vnc.c +34 -52

210 lines not on this page · raw message

ui/vnc-enc-zrle.c.inc +10 -10
index 2ef7501d52..68d28f58b7 100644
@@ -62,16 +62,16 @@
 #define ZRLE_ENCODE_TILE     ZRLE_CONCAT2(zrle_encode_tile,  ZRLE_ENCODE_SUFFIX)
 #define ZRLE_WRITE_PALETTE   ZRLE_CONCAT2(zrle_write_palette,ZRLE_ENCODE_SUFFIX)
 
-static void ZRLE_ENCODE_TILE(VncState *vs, ZRLE_PIXEL *data, int w, int h,
-                             int zywrle_level);
+static void ZRLE_ENCODE_TILE(VncState *vs, VncZrle *zrle, ZRLE_PIXEL *data,
+                             int w, int h, int zywrle_level);
 
 #if ZRLE_BPP != 8
 #include "vnc-enc-zywrle-template.c"
 #endif
 
 
-static void ZRLE_ENCODE(VncState *vs, int x, int y, int w, int h,
-                        int zywrle_level)
+static void ZRLE_ENCODE(VncState *vs, VncZrle *zrle,
+                        int x, int y, int w, int h, int zywrle_level)
 {
     int ty;
 
@@ -87,16 +87,16 @@ static void ZRLE_ENCODE(VncState *vs, int x, int y, int w, int h,
 
             tw = MIN(VNC_ZRLE_TILE_WIDTH, x + w - tx);
 
-            buf = zrle_convert_fb(vs, tx, ty, tw, th, ZRLE_BPP);
-            ZRLE_ENCODE_TILE(vs, buf, tw, th, zywrle_level);
+            buf = zrle_convert_fb(vs, zrle, tx, ty, tw, th, ZRLE_BPP);
+            ZRLE_ENCODE_TILE(vs, zrle, buf, tw, th, zywrle_level);
         }
     }
 }
 
-static void ZRLE_ENCODE_TILE(VncState *vs, ZRLE_PIXEL *data, int w, int h,
-                             int zywrle_level)
+static void ZRLE_ENCODE_TILE(VncState *vs, VncZrle *zrle, ZRLE_PIXEL *data,
+                             int w, int h, int zywrle_level)
 {
-    VncPalette *palette = &vs->zrle->palette;
+    VncPalette *palette = &zrle->palette;
 
     int runs = 0;
     int single_pixels = 0;
@@ -236,7 +236,7 @@ static void ZRLE_ENCODE_TILE(VncState *vs, ZRLE_PIXEL *data, int w, int h,
 #if ZRLE_BPP != 8
         if (zywrle_level > 0 && !(zywrle_level & 0x80)) {
             ZYWRLE_ANALYZE(data, data, w, h, w, zywrle_level, vs->zywrle.buf);
-            ZRLE_ENCODE_TILE(vs, data, w, h, zywrle_level | 0x80);
+            ZRLE_ENCODE_TILE(vs, zrle, data, w, h, zywrle_level | 0x80);
         }
         else
 #endif
Signature · 1 line
2.50.0
#5 lore raw

[PULL v2 03/13] ui/egl-helpers: Error check the fds in egl_dmabuf_export_texture()

In reply to [email protected]

From: Vivek Kasireddy <[email protected]>

While trying to export and obtain fds associated with a texture, it is possible that the fds returned after eglExportDMABUFImageMESA() call have error values. Therefore, we need to evaluate the value of all fds and return false if any of them are negative.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>

Message-Id: <[email protected]>

---
 ui/egl-helpers.c | 6 ++++++
 1 file changed, 6 insertions(+)
ui/egl-helpers.c +6 -0
index 5503a795e4..e3f2872cc1 100644
@@ -295,6 +295,7 @@ bool egl_dmabuf_export_texture(uint32_t tex_id, int *fd, EGLint *offset,
 {
     EGLImageKHR image;
     EGLuint64KHR modifiers[DMABUF_MAX_PLANES];
+    int i;
 
     image = eglCreateImageKHR(qemu_egl_display, eglGetCurrentContext(),
                               EGL_GL_TEXTURE_2D_KHR,
@@ -314,6 +315,11 @@ bool egl_dmabuf_export_texture(uint32_t tex_id, int *fd, EGLint *offset,
         *modifier = modifiers[0];
     }
 
+    for (i = 0; i < *num_planes; i++) {
+        if (fd[i] < 0) {
+            return false;
+        }
+    }
     return true;
 }
 
Signature · 1 line
2.50.0
#6 lore raw

[PULL v2 06/13] ui/spice: Add an option to submit gl_draw requests at fixed rate

In reply to [email protected]

From: Vivek Kasireddy <[email protected]>

In the specific case where the display layer (virtio-gpu) is using dmabuf, and if remote clients are enabled (-spice gl=on,port=xxxx), it makes sense to limit the maximum (streaming) rate (refresh rate) to a fixed value using the GUI refresh timer. Otherwise, the updates or gl_draw requests would be sent as soon as the Guest submits a new frame which is not optimal as it would lead to increased network traffic and wastage of GPU cycles if the frames get dropped.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>

Message-Id: <[email protected]>

---
 include/ui/spice-display.h |  1 +
 ui/spice-core.c            | 12 ++++++++
 ui/spice-display.c         | 62 ++++++++++++++++++++++++++++++++------
 qemu-options.hx            |  5 +++
 4 files changed, 70 insertions(+), 10 deletions(-)
include/ui/spice-display.h +1 -0
index 6c55f38c8b..9bdde78266 100644
@@ -152,6 +152,7 @@ struct SimpleSpiceCursor {
 
 extern bool spice_opengl;
 extern bool spice_remote_client;
+extern int spice_max_refresh_rate;
 
 int qemu_spice_rect_is_empty(const QXLRect* r);
 void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
ui/spice-core.c +12 -0
index 51bdcef1af..5992f9daec 100644
@@ -56,6 +56,8 @@ struct SpiceTimer {
     QEMUTimer *timer;
 };
 
+#define DEFAULT_MAX_REFRESH_RATE 30
+
 static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque)
 {
     SpiceTimer *timer;
@@ -491,6 +493,9 @@ static QemuOptsList qemu_spice_opts = {
         },{
             .name = "video-codec",
             .type = QEMU_OPT_STRING,
+        },{
+            .name = "max-refresh-rate",
+            .type = QEMU_OPT_NUMBER,
         },{
             .name = "agent-mouse",
             .type = QEMU_OPT_BOOL,
@@ -804,6 +809,13 @@ static void qemu_spice_init(void)
         spice_server_set_streaming_video(spice_server, SPICE_STREAM_VIDEO_OFF);
     }
 
+    spice_max_refresh_rate = qemu_opt_get_number(opts, "max-refresh-rate",
+                                                 DEFAULT_MAX_REFRESH_RATE);
+    if (spice_max_refresh_rate <= 0) {
+        error_report("max refresh rate/fps is invalid");
+        exit(1);
+    }
+
     spice_server_set_agent_mouse
         (spice_server, qemu_opt_get_bool(opts, "agent-mouse", 1));
     spice_server_set_playback_compression
ui/spice-display.c +52 -10

102 lines not on this page · raw message

qemu-options.hx +5 -0
index 8f6a228a89..ac09abfd71 100644
@@ -2282,6 +2282,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "       [,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"
     "       [,playback-compression=[on|off]][,seamless-migration=[on|off]]\n"
     "       [,video-codec=<codec>\n"
+    "       [,max-refresh-rate=rate\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is mandatory\n",
@@ -2377,6 +2378,10 @@ SRST
         would be used as default. And, for the case where gl=off, the
         default codec to be used is determined by the Spice server.
 
+    ``max-refresh-rate=rate``
+        Provide the maximum refresh rate (or FPS) at which the encoding
+        requests should be sent to the Spice server. Default would be 30.
+
     ``gl=[on|off]``
         Enable/disable OpenGL context. Default is off.
 
Signature · 1 line
2.50.0
#7 lore raw

[PULL v2 04/13] ui/spice: Enable gl=on option for non-local or remote clients

In reply to [email protected]

From: Vivek Kasireddy <[email protected]>

Newer versions of Spice server should be able to accept dmabuf fds from Qemu for clients that are connected via the network. In other words, when this option is enabled, Qemu would share a dmabuf fd with Spice which would encode and send the data associated with the fd to a client that could be located on a different machine.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>

Message-Id: <[email protected]>

---
 include/ui/spice-display.h | 1 +
 ui/spice-core.c            | 4 ++++
 ui/spice-display.c         | 1 +
 3 files changed, 6 insertions(+)
include/ui/spice-display.h +1 -0
index e1a9b36185..6c55f38c8b 100644
@@ -151,6 +151,7 @@ struct SimpleSpiceCursor {
 };
 
 extern bool spice_opengl;
+extern bool spice_remote_client;
 
 int qemu_spice_rect_is_empty(const QXLRect* r);
 void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
ui/spice-core.c +4 -0
index 0326c63bec..5acbdd3955 100644
@@ -836,9 +836,13 @@ static void qemu_spice_init(void)
 #ifdef HAVE_SPICE_GL
     if (qemu_opt_get_bool(opts, "gl", 0)) {
         if ((port != 0) || (tls_port != 0)) {
+#if SPICE_SERVER_VERSION >= 0x000f03 /* release 0.15.3 */
+            spice_remote_client = 1;
+#else
             error_report("SPICE GL support is local-only for now and "
                          "incompatible with -spice port/tls-port");
             exit(1);
+#endif
         }
         egl_init(qemu_opt_get(opts, "rendernode"), DISPLAY_GL_MODE_ON, &error_fatal);
         spice_opengl = 1;
ui/spice-display.c +1 -0
index 9c39d2c5c8..0fb72f6d6f 100644
@@ -31,6 +31,7 @@
 #include "standard-headers/drm/drm_fourcc.h"
 
 bool spice_opengl;
+bool spice_remote_client;
 
 int qemu_spice_rect_is_empty(const QXLRect* r)
 {
Signature · 1 line
2.50.0
#8 lore raw

[PULL v2 12/13] ui/gtk: Add scale option

In reply to [email protected]

From: Weifeng Liu <[email protected]>

Allow user to set a preferred scale (defaulting to 1) of the virtual display. Along with zoom-to-fix=false, this would be helpful for users running QEMU on hi-dpi host desktop to achieve pixel to pixel display -- e.g., if the scale factor of a user's host desktop is set to 200%, then they can set a 0.5 scale for the virtual display to avoid magnification that might cause blurriness.

Message-Id: <[email protected]>

---
 qapi/ui.json     |  5 ++++-
 include/ui/gtk.h |  1 +
 ui/gtk.c         | 46 +++++++++++++++++++++++++++++-----------------
 3 files changed, 34 insertions(+), 18 deletions(-)
qapi/ui.json +4 -1
index 9e496b4835..a465d671c7 100644
@@ -1338,6 +1338,8 @@
 # @keep-aspect-ratio: Keep width/height aspect ratio of guest content when
 #     resizing host window.  Defaults to "on". (Since 10.1)
 #
+# @scale: Set preferred scale of the display.  Defaults to 1.0.  (Since 10.1)
+#
 # Since: 2.12
 ##
 { 'struct'  : 'DisplayGTK',
@@ -1345,7 +1347,8 @@
                 '*zoom-to-fit'       : 'bool',
                 '*show-tabs'         : 'bool',
                 '*show-menubar'      : 'bool',
-                '*keep-aspect-ratio' : 'bool'  } }
+                '*keep-aspect-ratio' : 'bool',
+                '*scale'             : 'number'  } }
 
 ##
 # @DisplayEGLHeadless:
include/ui/gtk.h +1 -0
index b7cfbf218e..3e6ce3cb48 100644
@@ -41,6 +41,7 @@ typedef struct VirtualGfxConsole {
     DisplaySurface *ds;
     pixman_image_t *convert;
     cairo_surface_t *surface;
+    double preferred_scale;
     double scale_x;
     double scale_y;
 #if defined(CONFIG_OPENGL)
ui/gtk.c +29 -17

88 lines not on this page · raw message

Signature · 1 line
2.50.0
#9 lore raw

[PULL v2 09/13] ui/spice: Blit the scanout texture if its memory layout is not linear

In reply to [email protected]

From: Vivek Kasireddy <[email protected]>

In cases where the scanout buffer is provided as a texture (e.g. Virgl) we need to check to see if it has a linear memory layout or not. If it doesn't have a linear layout, then blitting it onto the texture associated with the display surface (which already has a linear layout) seems to ensure that there is no corruption seen regardless of which encoder or decoder is used.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>

Message-Id: <[email protected]>

---
 include/ui/spice-display.h |  3 ++
 ui/spice-display.c         | 81 +++++++++++++++++++++++++++++++++++---
 2 files changed, 78 insertions(+), 6 deletions(-)
include/ui/spice-display.h +3 -0
index 9bdde78266..690ece7380 100644
@@ -132,6 +132,9 @@ struct SimpleSpiceDisplay {
     egl_fb guest_fb;
     egl_fb blit_fb;
     egl_fb cursor_fb;
+    bool backing_y_0_top;
+    bool blit_scanout_texture;
+    bool new_scanout_texture;
     bool have_hot;
 #endif
 };
ui/spice-display.c +75 -6

111 lines not on this page · raw message

Signature · 1 line
2.50.0
#10 lore raw

Re: [PULL v2 09/13] ui/spice: Blit the scanout texture if its memory layout is not linear

Quoted 9 lines · On Tue, 15 Jul 2025 at 07:43, <[email protected]> wrote:

From: Vivek Kasireddy <[email protected]>

In cases where the scanout buffer is provided as a texture (e.g. Virgl) we need to check to see if it has a linear memory layout or not. If it doesn't have a linear layout, then blitting it onto the texture associated with the display surface (which already has a linear layout) seems to ensure that there is no corruption seen regardless of which encoder or decoder is used.

Hi; Coverity points out (CID 1612367) that this change introduces a use of an uninitialized variable:

ui/spice-display.c static void qemu_spice_gl_update(DisplayChangeListener *dcl, · line 1333

Quoted 6 lines
ui/spice-display.c +2 -0
@@ -1269,6 +1329,15 @@ static void qemu_spice_gl_update(DisplayChangeListener *dcl,
         glFlush();
     }
 
+    if (spice_remote_client && ssd->blit_scanout_texture) {
+        egl_fb scanout_tex_fb;

We don't initialize scanout_tex_fb...

ui/spice-display.c static void qemu_spice_gl_update(DisplayChangeListener *dcl, · line 1335

Quoted 2 lines
ui/spice-display.c +2 -0
+
+        ret = spice_gl_blit_scanout_texture(ssd, &scanout_tex_fb);

...and we immediately pass it to spice_gl_blit_scanout_texture(), which will unconditionally call egl_fb_destroy() on it.

ui/spice-display.c static void qemu_spice_gl_update(DisplayChangeListener *dcl, · line 1339

Quoted 4 lines
ui/spice-display.c +4 -0
+        if (!ret) {
+            return;
+        }
+    }

thanks
-- PMM

#11 lore raw

RE: [PULL v2 09/13] ui/spice: Blit the scanout texture if its memory layout is not linear

Hi Peter, Marc-Andre,

Quoted 25 lines

Subject: Re: [PULL v2 09/13] ui/spice: Blit the scanout texture if its memory layout is not linear

Quoted 9 lines · On Tue, 15 Jul 2025 at 07:43, <[email protected]> wrote:

From: Vivek Kasireddy <[email protected]>

In cases where the scanout buffer is provided as a texture (e.g. Virgl) we need to check to see if it has a linear memory layout or not. If it doesn't have a linear layout, then blitting it onto the texture associated with the display surface (which already has a linear layout) seems to ensure that there is no corruption seen regardless of which encoder or decoder is used.

Hi; Coverity points out (CID 1612367) that this change introduces a use of an uninitialized variable:

Review static void

Quoted 1 line
(quoted diff) +0 -0
@@ -1269,6 +1329,15 @@ static void

qemu_spice_gl_update(DisplayChangeListener *dcl,

ui/spice-display.c static void qemu_spice_gl_update(DisplayChangeListener *dcl, · line 1333

Quoted 5 lines
ui/spice-display.c +2 -0
         glFlush();
     }
 
+    if (spice_remote_client && ssd->blit_scanout_texture) {
+        egl_fb scanout_tex_fb;
Quoted 7 lines

We don't initialize scanout_tex_fb...

ui/spice-display.c static void qemu_spice_gl_update(DisplayChangeListener *dcl, · line 1335

Quoted 2 lines
ui/spice-display.c +2 -0
+
+        ret = spice_gl_blit_scanout_texture(ssd, &scanout_tex_fb);

...and we immediately pass it to spice_gl_blit_scanout_texture(), which will unconditionally call egl_fb_destroy() on it.

I'll send out a patch in a day or two to fix this issue.

Thanks,
Vivek

Quoted 8 lines

ui/spice-display.c static void qemu_spice_gl_update(DisplayChangeListener *dcl, · line 1339

Quoted 5 lines
ui/spice-display.c +4 -0
+        if (!ret) {
+            return;
+        }
+    }

thanks
-- PMM

#12 lore raw

[PULL v2 05/13] ui/spice: Add an option for users to provide a preferred video codec

In reply to [email protected]

From: Vivek Kasireddy <[email protected]>

Giving users an option to choose a particular codec will enable them to make an appropriate decision based on their hardware and use-case. Note that, the Spice server would use this codec with Gstreamer encoder and only when gl=on is specified.

If no codec is provided, then the codec gstreamer:h264 would be used as default. And, for the case where gl=off, the default codec to be used is determined by the Spice server.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
[ Marc-Andre - fix unused variables warnings ]

Message-Id: <[email protected]>

---
 ui/spice-core.c | 16 ++++++++++++++++
 qemu-options.hx |  8 ++++++++
 2 files changed, 24 insertions(+)
ui/spice-core.c +16 -0
index 5acbdd3955..51bdcef1af 100644
@@ -488,6 +488,9 @@ static QemuOptsList qemu_spice_opts = {
         },{
             .name = "streaming-video",
             .type = QEMU_OPT_STRING,
+        },{
+            .name = "video-codec",
+            .type = QEMU_OPT_STRING,
         },{
             .name = "agent-mouse",
             .type = QEMU_OPT_BOOL,
@@ -837,7 +840,20 @@ static void qemu_spice_init(void)
     if (qemu_opt_get_bool(opts, "gl", 0)) {
         if ((port != 0) || (tls_port != 0)) {
 #if SPICE_SERVER_VERSION >= 0x000f03 /* release 0.15.3 */
+            const char *video_codec = NULL;
+            g_autofree char *enc_codec = NULL;
+
             spice_remote_client = 1;
+
+            video_codec = qemu_opt_get(opts, "video-codec");
+            if (video_codec) {
+                enc_codec = g_strconcat("gstreamer:", video_codec, NULL);
+            }
+            if (spice_server_set_video_codecs(spice_server,
+                                              enc_codec ?: "gstreamer:h264")) {
+                error_report("invalid video codec");
+                exit(1);
+            }
 #else
             error_report("SPICE GL support is local-only for now and "
                          "incompatible with -spice port/tls-port");
qemu-options.hx +8 -0
index 1f862b19a6..8f6a228a89 100644
@@ -2281,6 +2281,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "       [,streaming-video=[off|all|filter]][,disable-copy-paste=on|off]\n"
     "       [,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"
     "       [,playback-compression=[on|off]][,seamless-migration=[on|off]]\n"
+    "       [,video-codec=<codec>\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is mandatory\n",
@@ -2369,6 +2370,13 @@ SRST
     ``seamless-migration=[on|off]``
         Enable/disable spice seamless migration. Default is off.
 
+    ``video-codec=<codec>``
+        Provide the preferred codec the Spice server should use with the
+        Gstreamer encoder. This option is only relevant when gl=on is
+        specified. If no codec is provided, then the codec gstreamer:h264
+        would be used as default. And, for the case where gl=off, the
+        default codec to be used is determined by the Spice server.
+
     ``gl=[on|off]``
         Enable/disable OpenGL context. Default is off.
 
Signature · 1 line
2.50.0
#13 lore raw

[PULL v2 08/13] ui/spice: Create a new texture with linear layout when gl=on is specified

In reply to [email protected]

From: Vivek Kasireddy <[email protected]>

Since most encoders/decoders (invoked by Spice) may not work properly with tiled memory associated with a texture, we need to create another texture that has linear memory layout and use that instead.

Note that, there does not seem to be a direct way to indicate to the GL implementation that a texture's backing memory needs to be linear. Instead, we have to do it in a roundabout way where we need to first create a tiled texture and import that as a memory object to create a new texture that has a linear memory layout.

Message-Id: <[email protected]>

---
 include/ui/surface.h |  1 +
 ui/console-gl.c      |  6 ++++
 ui/spice-display.c   | 82 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+)
include/ui/surface.h +1 -0
index f16f7be8be..006b1986bb 100644
@@ -22,6 +22,7 @@ typedef struct DisplaySurface {
     GLenum glformat;
     GLenum gltype;
     GLuint texture;
+    GLuint mem_obj;
 #endif
     qemu_pixman_shareable share_handle;
     uint32_t share_handle_offset;
ui/console-gl.c +6 -0
index afb36dba64..403fc36fbd 100644
@@ -184,6 +184,12 @@ void surface_gl_destroy_texture(QemuGLShader *gls,
     }
     glDeleteTextures(1, &surface->texture);
     surface->texture = 0;
+#ifdef GL_EXT_memory_object_fd
+    if (surface->mem_obj) {
+        glDeleteMemoryObjectsEXT(1, &surface->mem_obj);
+        surface->mem_obj = 0;
+    }
+#endif
 }
 
 void surface_gl_setup_viewport(QemuGLShader *gls,
ui/spice-display.c +82 -0

100 lines not on this page · raw message

Signature · 1 line
2.50.0
#14 lore raw

[PULL v2 13/13] tpm: "qemu -tpmdev help" should return success

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Like other "-foo help" CLI, the qemu process should return 0 for "-tpmdev help".

While touching this, switch to is_help_option() utility function as suggested by Peter Maydell.

Message-Id: <[email protected]>

---
 system/tpm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
system/tpm.c +3 -2
index 8df0f6e72b..903b29c043 100644
@@ -21,6 +21,7 @@
 #include "system/tpm.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
+#include "qemu/help_option.h"
 
 static QLIST_HEAD(, TPMBackend) tpm_backends =
     QLIST_HEAD_INITIALIZER(tpm_backends);
@@ -179,9 +180,9 @@ int tpm_config_parse(QemuOptsList *opts_list, const char *optstr)
 {
     QemuOpts *opts;
 
-    if (!strcmp(optstr, "help")) {
+    if (is_help_option(optstr)) {
         tpm_display_backend_drivers();
-        return -1;
+        exit(EXIT_SUCCESS);
     }
     opts = qemu_opts_parse_noisily(opts_list, optstr, true);
     if (!opts) {
Signature · 1 line
2.50.0
#15 lore raw

[PULL v2 07/13] ui/console-gl: Add a helper to create a texture with linear memory layout

In reply to [email protected]

From: Vivek Kasireddy <[email protected]>

There are cases where we do not want the memory layout of a texture to be tiled as the component processing the texture would not know how to de-tile either via software or hardware. Therefore, ensuring that the memory backing the texture has a linear layout is absolutely necessary in these situations.

Message-Id: <[email protected]>

---
 include/ui/console.h |  3 +++
 ui/console-gl.c      | 48 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
include/ui/console.h +3 -0
index 46b3128185..98feaa58bd 100644
@@ -422,6 +422,9 @@ bool console_gl_check_format(DisplayChangeListener *dcl,
                              pixman_format_code_t format);
 void surface_gl_create_texture(QemuGLShader *gls,
                                DisplaySurface *surface);
+bool surface_gl_create_texture_from_fd(DisplaySurface *surface,
+                                       int fd, GLuint *texture,
+                                       GLuint *mem_obj);
 void surface_gl_update_texture(QemuGLShader *gls,
                                DisplaySurface *surface,
                                int x, int y, int w, int h);
ui/console-gl.c +48 -0

60 lines not on this page · raw message

Signature · 1 line
2.50.0
#16 lore raw

[PULL v2 11/13] ui/gtk: Add keep-aspect-ratio option

In reply to [email protected]

From: Weifeng Liu <[email protected]>

When aspect ratio of host window and that of guest display are not aligned, we can either zoom the guest content to fill the whole host window or add padding to respect aspect ratio of the guest. Add an option keep-aspect-ratio to allow users to select their preferred behavior in this case.

Message-Id: <[email protected]>

---
 qapi/ui.json     | 12 ++++++++----
 include/ui/gtk.h |  1 +
 ui/gtk.c         | 12 ++++++++++--
 3 files changed, 19 insertions(+), 6 deletions(-)
qapi/ui.json +8 -4
index 514fa159b1..9e496b4835 100644
@@ -1335,13 +1335,17 @@
 # @show-menubar: Display the main window menubar.  Defaults to "on".
 #     (Since 8.0)
 #
+# @keep-aspect-ratio: Keep width/height aspect ratio of guest content when
+#     resizing host window.  Defaults to "on". (Since 10.1)
+#
 # Since: 2.12
 ##
 { 'struct'  : 'DisplayGTK',
-  'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool',
-                '*show-tabs'     : 'bool',
-                '*show-menubar'  : 'bool'  } }
+  'data'    : { '*grab-on-hover'     : 'bool',
+                '*zoom-to-fit'       : 'bool',
+                '*show-tabs'         : 'bool',
+                '*show-menubar'      : 'bool',
+                '*keep-aspect-ratio' : 'bool'  } }
 
 ##
 # @DisplayEGLHeadless:
include/ui/gtk.h +1 -0
index d3944046db..b7cfbf218e 100644
@@ -140,6 +140,7 @@ struct GtkDisplayState {
     GdkCursor *null_cursor;
     Notifier mouse_mode_notifier;
     gboolean free_scale;
+    gboolean keep_aspect_ratio;
 
     bool external_pause_update;
 
ui/gtk.c +10 -2
index 8c4a94c8f6..9104509ee1 100644
@@ -828,8 +828,12 @@ void gd_update_scale(VirtualConsole *vc, int ww, int wh, int fbw, int fbh)
 
         sx = (double)ww / fbw;
         sy = (double)wh / fbh;
-
-        vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
+        if (vc->s->keep_aspect_ratio) {
+            vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
+        } else {
+            vc->gfx.scale_x = sx;
+            vc->gfx.scale_y = sy;
+        }
     }
 }
 /**
@@ -2328,6 +2332,10 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
         s->free_scale = true;
     }
 
+    s->keep_aspect_ratio = true;
+    if (s->opts->u.gtk.has_keep_aspect_ratio)
+        s->keep_aspect_ratio = s->opts->u.gtk.keep_aspect_ratio;
+
     for (i = 0; i < INPUT_EVENT_SLOTS_MAX; i++) {
         struct touch_slot *slot = &touch_slots[i];
         slot->tracking_id = -1;
Signature · 1 line
2.50.0
#17 lore raw

[PULL v2 10/13] hw/display: Allow injection of virtio-gpu EDID name

In reply to [email protected]

From: Andrew Keesler <[email protected]>

Thanks to 72d277a7, 1ed2cb32, and others, EDID (Extended Display Identification Data) is propagated by QEMU such that a virtual display presents legitimate metadata (e.g., name, serial number, preferred resolutions, etc.) to its connected guest.

This change adds the ability to specify the EDID name for a particular virtio-vga display. Previously, every virtual display would have the same
name: "QEMU Monitor". Now, we can inject names of displays in order to test guest behavior that is specific to display names. We provide the ability to inject the display name from the frontend since this is guest visible data. Furthermore, this makes it clear where N potential display outputs would get their name from (which will be added in a future change).

Note that we have elected to use a struct here for output data for extensibility - we intend to add per-output fields like resolution in a future change.

It should be noted that EDID names longer than 12 bytes will be truncated per spec (I think?).

Testing: verified that when I specified 2 outputs for a virtio-gpu with edid_name set, the names matched those that I configured with my vnc display.

  -display vnc=localhost:0,id=aaa,display=vga,head=0 \
  -display vnc=localhost:1,id=bbb,display=vga,head=1 \
  -device '{"driver":"virtio-vga",
            "max_outputs":2,
            "id":"vga",
            "outputs":[
              {
                 "name":"AAA"
              },
              {
                 "name":"BBB"
              }
            ]}'

Message-Id: <[email protected]>

---
 qapi/virtio.json                    | 18 ++++++++++--
 include/hw/display/edid.h           |  2 ++
 include/hw/qdev-properties-system.h |  5 ++++
 include/hw/virtio/virtio-gpu.h      |  3 ++
 hw/core/qdev-properties-system.c    | 44 +++++++++++++++++++++++++++++
 hw/display/virtio-gpu-base.c        | 27 ++++++++++++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)
qapi/virtio.json +16 -2
index 73df718a26..5e658a7033 100644
@@ -963,17 +963,31 @@
 { 'struct': 'IOThreadVirtQueueMapping',
   'data': { 'iothread': 'str', '*vqs': ['uint16'] } }
 
+##
+# @VirtIOGPUOutput:
+#
+# Describes configuration of a VirtIO GPU output.
+#
+# @name: the name of the output
+#
+# Since: 10.1
+##
+
+{ 'struct': 'VirtIOGPUOutput',
+  'data': { 'name': 'str' } }
+
 ##
 # @DummyVirtioForceArrays:
 #
 # Not used by QMP; hack to let us use IOThreadVirtQueueMappingList
-# internally
+# and VirtIOGPUOutputList internally
 #
 # Since: 9.0
 ##
 
 { 'struct': 'DummyVirtioForceArrays',
-  'data': { 'unused-iothread-vq-mapping': ['IOThreadVirtQueueMapping'] } }
+  'data': { 'unused-iothread-vq-mapping': ['IOThreadVirtQueueMapping'],
+            'unused-virtio-gpu-output': ['VirtIOGPUOutput'] } }
 
 ##
 # @GranuleMode:
include/hw/display/edid.h +2 -0
index 520f8ec202..91c0a428af 100644
@@ -1,6 +1,8 @@
 #ifndef EDID_H
 #define EDID_H
 
+#define EDID_NAME_MAX_LENGTH 12
+
 typedef struct qemu_edid_info {
     const char *vendor; /* http://www.uefi.org/pnp_id_list */
     const char *name;
include/hw/qdev-properties-system.h +5 -0
index b921392c52..9601a11a09 100644
@@ -32,6 +32,7 @@ extern const PropertyInfo qdev_prop_cpus390entitlement;
 extern const PropertyInfo qdev_prop_iothread_vq_mapping_list;
 extern const PropertyInfo qdev_prop_endian_mode;
 extern const PropertyInfo qdev_prop_vmapple_virtio_blk_variant;
+extern const PropertyInfo qdev_prop_virtio_gpu_output_list;
 
 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d)                   \
     DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
@@ -110,4 +111,8 @@ extern const PropertyInfo qdev_prop_vmapple_virtio_blk_variant;
                          qdev_prop_vmapple_virtio_blk_variant, \
                          VMAppleVirtioBlkVariant)
 
+#define DEFINE_PROP_VIRTIO_GPU_OUTPUT_LIST(_name, _state, _field) \
+    DEFINE_PROP(_name, _state, _field, qdev_prop_virtio_gpu_output_list, \
+                VirtIOGPUOutputList *)
+
 #endif
include/hw/virtio/virtio-gpu.h +3 -0
index a42957c4e2..9f16f89a36 100644
@@ -20,6 +20,7 @@
 #include "hw/virtio/virtio.h"
 #include "qemu/log.h"
 #include "system/vhost-user-backend.h"
+#include "qapi/qapi-types-virtio.h"
 
 #include "standard-headers/linux/virtio_gpu.h"
 #include "standard-headers/linux/virtio_ids.h"
@@ -128,6 +129,7 @@ struct virtio_gpu_base_conf {
     uint32_t xres;
     uint32_t yres;
     uint64_t hostmem;
+    VirtIOGPUOutputList *outputs;
 };
 
 struct virtio_gpu_ctrl_command {
@@ -167,6 +169,7 @@ struct VirtIOGPUBaseClass {
 
 #define VIRTIO_GPU_BASE_PROPERTIES(_state, _conf)                       \
     DEFINE_PROP_UINT32("max_outputs", _state, _conf.max_outputs, 1),    \
+    DEFINE_PROP_VIRTIO_GPU_OUTPUT_LIST("outputs", _state, _conf.outputs), \
     DEFINE_PROP_BIT("edid", _state, _conf.flags, \
                     VIRTIO_GPU_FLAG_EDID_ENABLED, true), \
     DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1280), \
hw/core/qdev-properties-system.c +44 -0

47 lines not on this page · raw message

hw/display/virtio-gpu-base.c +27 -0
index 9eb806b71f..7269477a1c 100644
@@ -19,6 +19,7 @@
 #include "qemu/error-report.h"
 #include "hw/display/edid.h"
 #include "trace.h"
+#include "qapi/qapi-types-virtio.h"
 
 void
 virtio_gpu_base_reset(VirtIOGPUBase *g)
@@ -56,6 +57,8 @@ void
 virtio_gpu_base_generate_edid(VirtIOGPUBase *g, int scanout,
                               struct virtio_gpu_resp_edid *edid)
 {
+    size_t output_idx;
+    VirtIOGPUOutputList *node;
     qemu_edid_info info = {
         .width_mm = g->req_state[scanout].width_mm,
         .height_mm = g->req_state[scanout].height_mm,
@@ -64,6 +67,14 @@ virtio_gpu_base_generate_edid(VirtIOGPUBase *g, int scanout,
         .refresh_rate = g->req_state[scanout].refresh_rate,
     };
 
+    for (output_idx = 0, node = g->conf.outputs;
+         output_idx <= scanout && node; output_idx++, node = node->next) {
+        if (output_idx == scanout && node->value && node->value->name) {
+            info.name = node->value->name;
+            break;
+        }
+    }
+
     edid->size = cpu_to_le32(sizeof(edid->edid));
     qemu_edid_generate(edid->edid, sizeof(edid->edid), &info);
 }
@@ -172,6 +183,8 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
                                VirtIOHandleOutput cursor_cb,
                                Error **errp)
 {
+    size_t output_idx;
+    VirtIOGPUOutputList *node;
     VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
     VirtIOGPUBase *g = VIRTIO_GPU_BASE(qdev);
     int i;
@@ -181,6 +194,20 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
         return false;
     }
 
+    for (output_idx = 0, node = g->conf.outputs;
+         node; output_idx++, node = node->next) {
+        if (output_idx == g->conf.max_outputs) {
+            error_setg(errp, "invalid outputs > %d", g->conf.max_outputs);
+            return false;
+        }
+        if (node->value && node->value->name &&
+            strlen(node->value->name) > EDID_NAME_MAX_LENGTH) {
+            error_setg(errp, "invalid output name '%s' > %d",
+                       node->value->name, EDID_NAME_MAX_LENGTH);
+            return false;
+        }
+    }
+
     if (virtio_gpu_virgl_enabled(g->conf)) {
         error_setg(&g->migration_blocker, "virgl is not yet migratable");
         if (migrate_add_blocker(&g->migration_blocker, errp) < 0) {
Signature · 1 line
2.50.0
#18 lore raw
In reply to [email protected]

Hi

Quoted 23 lines · On Tue, Jul 15, 2025 at 10:36 AM <[email protected]> wrote:

From: Marc-André Lureau <[email protected]>

The following changes since commit 9a4e273ddec3927920c5958d2226c6b38b543336:

Merge tag 'pull-tcg-20250711' of https://gitlab.com/rth7680/qemu into staging (2025-07-13 01:46:04 -0400)

are available in the Git repository at:

https://gitlab.com/marcandre.lureau/qemu.git tags/ui-pull-request

for you to fetch changes up to df892b3954e5b2782165e6c59e5ffd55c2f7ec5a:

tpm: "qemu -tpmdev help" should return success (2025-07-15 10:22:33 +0400)

----------------------------------------------------------------
UI-related for 10.1

- [PATCH v3 0/2] ui/vnc: Do not copy z_stream
- [PATCH v6 0/7] ui/spice: Enable gl=on option for non-local or remote clients
- [PATCH v6 0/1] Allow injection of virtio-gpu EDID name
- [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and scale option

Quoted 5 lines

----------------------------------------------------------------

Akihiko Odaki (2):
ui/vnc: Do not copy z_stream
ui/vnc: Introduce the VncWorker type

Checkpatch complains with a false positive here:
ERROR: spaces required around that '*' (ctx:WxB)
#250: FILE: ui/vnc-enc-tight.c:356:

+        data = (uint##bpp##_t *)tight->tight.buffer;                    \
                               ^

ERROR: spaces required around that '*' (ctx:WxV)
#327: FILE: ui/vnc-enc-tight.c:614:

+                               uint##bpp##_t *buf, int w, int h) {      \
                                              ^

total: 2 errors, 0 warnings, 1790 lines checked

Please ignore

Quoted 53 lines

Andrew Keesler (1):
hw/display: Allow injection of virtio-gpu EDID name

Marc-André Lureau (1):
tpm: "qemu -tpmdev help" should return success

Vivek Kasireddy (7):
ui/egl-helpers: Error check the fds in egl_dmabuf_export_texture() ui/spice: Enable gl=on option for non-local or remote clients ui/spice: Add an option for users to provide a preferred video codec ui/spice: Add an option to submit gl_draw requests at fixed rate ui/console-gl: Add a helper to create a texture with linear memory
layout
ui/spice: Create a new texture with linear layout when gl=on is
specified
ui/spice: Blit the scanout texture if its memory layout is not linear

Weifeng Liu (2):
ui/gtk: Add keep-aspect-ratio option
ui/gtk: Add scale option

 qapi/ui.json                        |  15 +-
 qapi/virtio.json                    |  18 +-
 include/hw/display/edid.h           |   2 +
 include/hw/qdev-properties-system.h |   5 +
 include/hw/virtio/virtio-gpu.h      |   3 +
 include/ui/console.h                |   3 +
 include/ui/gtk.h                    |   2 +
 include/ui/spice-display.h          |   5 +
 include/ui/surface.h                |   1 +
 ui/vnc.h                            |  49 +--
 hw/core/qdev-properties-system.c    |  44 +++
 hw/display/virtio-gpu-base.c        |  27 ++
 system/tpm.c                        |   5 +-
 ui/console-gl.c                     |  54 ++++
 ui/egl-helpers.c                    |   6 +
 ui/gtk.c                            |  58 ++--
 ui/spice-core.c                     |  32 ++
 ui/spice-display.c                  | 226 +++++++++++++-
 ui/vnc-enc-tight.c                  | 456 +++++++++++++++-------------
 ui/vnc-enc-zlib.c                   |  47 +--
 ui/vnc-enc-zrle.c                   | 122 ++++----
 ui/vnc-jobs.c                       |  13 +-
 ui/vnc.c                            |  83 +++--
 ui/vnc-enc-zrle.c.inc               |  20 +-
 qemu-options.hx                     |  13 +
 25 files changed, 883 insertions(+), 426 deletions(-)

--
2.50.0

Signature · 1 line
Marc-André Lureau