Skip to contentSkip to conversation

UI patches

GIT PULL Applied [email protected] 4 participants 28 messages Oct 14, 2024 – Jun 11 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

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

The following changes since commit 3860a2a8de56fad71db42f4ad120eb7eff03b51f:

Merge tag 'pull-tcg-20241013' of https://gitlab.com/rth7680/qemu into staging (2024-10-14 11:12:34 +0100)

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 4cd78a3db2478d3c1527905a26c9d3fbee83ccac:

audio/pw: Report more accurate error when connecting to PipeWire fails (2024-10-14 17:35:24 +0400)

----------------------------------------------------------------
UI-related fixes & shareable 2d memory with -display dbus

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

Marc-André Lureau (19):
hw/audio/hda: free timer on exit
hw/audio/hda: fix memory leak on audio setup
ui/dbus: fix leak on message filtering
ui/win32: fix potential use-after-free with dbus shared memory ui/dbus: fix filtering all update messages
ui/dbus: discard display messages on disable
ui/dbus: discard pending CursorDefine on new one util/memfd: report potential errors on free ui/pixman: generalize shared_image_destroy
ui/dbus: do not limit to one listener per connection / bus name ui/dbus: add trace for can_share_map
ui/surface: allocate shared memory on !win32
meson: find_program('gdbus-codegen') directly ui/dbus: make Listener.Win32.Map win32-specific ui/dbus: add Listener.Unix.Map interface XML
ui/dbus: implement Unix.Map
virtio-gpu: allocate shareable 2d resources on !win32
ui: refactor using a common qemu_pixman_shareable
tests: add basic -display dbus Map.Unix test

Michal Privoznik (1):
audio/pw: Report more accurate error when connecting to PipeWire fails

 meson.build                     |   2 +-
 include/hw/virtio/virtio-gpu.h  |   4 +-
 include/ui/qemu-pixman.h        |  24 +++++
 include/ui/surface.h            |  14 ++-
 audio/pwaudio.c                 |   8 +-
 hw/audio/hda-codec.c            |  33 ++++---
 hw/display/virtio-gpu.c         |  69 ++++----------
 tests/qtest/dbus-display-test.c |  72 ++++++++++++++-
 ui/console.c                    |  78 ++++++----------
 ui/dbus-console.c               |  23 +----
 ui/dbus-listener.c              | 159 ++++++++++++++++++++++++++++----
 ui/qemu-pixman.c                |  71 ++++++++++++++
 util/memfd.c                    |   9 +-
 ui/dbus-display1.xml            |  49 ++++++++++
 ui/trace-events                 |   1 +
 15 files changed, 444 insertions(+), 172 deletions(-)
Signature · 1 line
2.47.0
#1 lore raw

[PULL 02/20] hw/audio/hda: fix memory leak on audio setup

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

When SET_STREAM_FORMAT is called, we should clear the existing setup.

Factor out common function to close a stream.

Direct leak of 144 byte(s) in 3 object(s) allocated from:

    #0 0x7f91d38f7350 in calloc (/lib64/libasan.so.8+0xf7350) (BuildId: a4ad7eb954b390cf00f07fa10952988a41d9fc7a)
    #1 0x7f91d2ab7871 in g_malloc0 (/lib64/libglib-2.0.so.0+0x64871) (BuildId: 36b60dbd02e796145a982d0151ce37202ec05649)
    #2 0x562fa2f447ee in timer_new_full /home/elmarco/src/qemu/include/qemu/timer.h:538
    #3 0x562fa2f4486f in timer_new /home/elmarco/src/qemu/include/qemu/timer.h:559
    #4 0x562fa2f448a9 in timer_new_ns /home/elmarco/src/qemu/include/qemu/timer.h:577
    #5 0x562fa2f47955 in hda_audio_setup ../hw/audio/hda-codec.c:490
    #6 0x562fa2f4897e in hda_audio_command ../hw/audio/hda-codec.c:605

Message-ID: <[email protected]>

---
 hw/audio/hda-codec.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
hw/audio/hda-codec.c +20 -13
index 74c0292284..bc661504cf 100644
@@ -472,6 +472,24 @@ static void hda_audio_set_amp(HDAAudioStream *st)
     }
 }
 
+static void hda_close_stream(HDAAudioState *a, HDAAudioStream *st)
+{
+    if (st->node == NULL) {
+        return;
+    }
+    if (a->use_timer) {
+        timer_free(st->buft);
+        st->buft = NULL;
+    }
+    if (st->output) {
+        AUD_close_out(&a->card, st->voice.out);
+        st->voice.out = NULL;
+    } else {
+        AUD_close_in(&a->card, st->voice.in);
+        st->voice.in = NULL;
+    }
+}
+
 static void hda_audio_setup(HDAAudioStream *st)
 {
     bool use_timer = st->state->use_timer;
@@ -484,6 +502,7 @@ static void hda_audio_setup(HDAAudioStream *st)
     trace_hda_audio_format(st->node->name, st->as.nchannels,
                            fmt2name[st->as.fmt], st->as.freq);
 
+    hda_close_stream(st->state, st);
     if (st->output) {
         if (use_timer) {
             cb = hda_audio_output_cb;
@@ -741,23 +760,11 @@ static void hda_audio_init(HDACodecDevice *hda,
 static void hda_audio_exit(HDACodecDevice *hda)
 {
     HDAAudioState *a = HDA_AUDIO(hda);
-    HDAAudioStream *st;
     int i;
 
     dprint(a, 1, "%s\n", __func__);
     for (i = 0; i < ARRAY_SIZE(a->st); i++) {
-        st = a->st + i;
-        if (st->node == NULL) {
-            continue;
-        }
-        if (a->use_timer) {
-            timer_free(st->buft);
-        }
-        if (st->output) {
-            AUD_close_out(&a->card, st->voice.out);
-        } else {
-            AUD_close_in(&a->card, st->voice.in);
-        }
+        hda_close_stream(a, a->st + i);
     }
     AUD_remove_card(&a->card);
 }
Signature · 1 line
2.47.0
#2 lore raw

[PULL 14/20] ui/dbus: make Listener.Win32.Map win32-specific

In reply to [email protected]

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

There are no types specific to Windows, so the code compiles on other platforms, but its useless on !Windows.

Message-ID: <[email protected]>

---
 ui/dbus-display1.xml | 2 ++
 1 file changed, 2 insertions(+)
ui/dbus-display1.xml +2 -0
index ce35d64eea..d5bb279698 100644
@@ -476,6 +476,7 @@
       org.qemu.Display1.Listener on ``/org/qemu/Display1/Listener`` for Windows
       specific shared memory scanouts.
   -->
+  <?if $(env.HOST_OS) == windows?>
   <interface name="org.qemu.Display1.Listener.Win32.Map">
     <!--
         ScanoutMap:
@@ -513,6 +514,7 @@
       <arg type="i" name="height" direction="in"/>
     </method>
   </interface>
+  <?endif?>
 
   <!--
       org.qemu.Display1.Listener.Win32.D3d11:
Signature · 1 line
2.47.0
#3 lore raw

[PULL 04/20] ui/win32: fix potential use-after-free with dbus shared memory

In reply to [email protected]

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

DisplaySurface may be free before the pixman image is freed, since the image is refcounted and used by different objects, including pending dbus messages.

Furthermore, setting the destroy function in create_displaysurface_from() isn't appropriate, as it may not be used, and may be overriden as in ramfb.

Set the destroy function when the shared handle is set, use the HANDLE directly for destroy data, using a single common helper qemu_pixman_win32_image_destroy().

Message-ID: <[email protected]>

---
 include/ui/qemu-pixman.h |  2 ++
 hw/display/virtio-gpu.c  | 14 ++------------
 ui/console.c             | 24 ++----------------------
 ui/qemu-pixman.c         | 15 +++++++++++++++
 4 files changed, 21 insertions(+), 34 deletions(-)
include/ui/qemu-pixman.h +2 -0
index ef13a8210c..e3dd72b9e3 100644
@@ -97,6 +97,8 @@ void qemu_pixman_glyph_render(pixman_image_t *glyph,
 
 void qemu_pixman_image_unref(pixman_image_t *image);
 
+void qemu_pixman_win32_image_destroy(pixman_image_t *image, void *data);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(pixman_image_t, qemu_pixman_image_unref)
 
 #endif /* QEMU_PIXMAN_H */
hw/display/virtio-gpu.c +2 -12
index 3281842bfe..017a0f170c 100644
@@ -238,16 +238,6 @@ static uint32_t calc_image_hostmem(pixman_format_code_t pformat,
     return height * stride;
 }
 
-#ifdef WIN32
-static void
-win32_pixman_image_destroy(pixman_image_t *image, void *data)
-{
-    HANDLE handle = data;
-
-    qemu_win32_map_free(pixman_image_get_data(image), handle, &error_warn);
-}
-#endif
-
 static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
                                           struct virtio_gpu_ctrl_command *cmd)
 {
@@ -308,7 +298,7 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
             bits, c2d.height ? res->hostmem / c2d.height : 0);
 #ifdef WIN32
         if (res->image) {
-            pixman_image_set_destroy_function(res->image, win32_pixman_image_destroy, res->handle);
+            pixman_image_set_destroy_function(res->image, qemu_pixman_win32_image_destroy, res->handle);
         }
 #endif
     }
@@ -1327,7 +1317,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
             return -EINVAL;
         }
 #ifdef WIN32
-        pixman_image_set_destroy_function(res->image, win32_pixman_image_destroy, res->handle);
+        pixman_image_set_destroy_function(res->image, qemu_pixman_win32_image_destroy, res->handle);
 #endif
 
         res->addrs = g_new(uint64_t, res->iov_cnt);
ui/console.c +2 -22
index 105a0e2c70..8f416ff0b9 100644
@@ -461,24 +461,6 @@ void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
     surface->handle = h;
     surface->handle_offset = offset;
 }
-
-static void
-win32_pixman_image_destroy(pixman_image_t *image, void *data)
-{
-    DisplaySurface *surface = data;
-
-    if (!surface->handle) {
-        return;
-    }
-
-    assert(surface->handle_offset == 0);
-
-    qemu_win32_map_free(
-        pixman_image_get_data(surface->image),
-        surface->handle,
-        &error_warn
-    );
-}
 #endif
 
 DisplaySurface *qemu_create_displaysurface(int width, int height)
@@ -504,6 +486,8 @@ DisplaySurface *qemu_create_displaysurface(int width, int height)
 
 #ifdef WIN32
     qemu_displaysurface_win32_set_handle(surface, handle, 0);
+    pixman_image_set_destroy_function(surface->image,
+                                      qemu_pixman_win32_image_destroy, handle);
 #endif
     return surface;
 }
@@ -519,10 +503,6 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,
                                               width, height,
                                               (void *)data, linesize);
     assert(surface->image != NULL);
-#ifdef WIN32
-    pixman_image_set_destroy_function(surface->image,
-                                      win32_pixman_image_destroy, surface);
-#endif
 
     return surface;
 }
ui/qemu-pixman.c +15 -0
index 6cada8b45e..3870e1a215 100644
@@ -4,6 +4,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "ui/console.h"
 #include "standard-headers/drm/drm_fourcc.h"
 #include "trace.h"
@@ -267,3 +268,17 @@ void qemu_pixman_glyph_render(pixman_image_t *glyph,
     pixman_image_unref(ibg);
 }
 #endif /* CONFIG_PIXMAN */
+
+#ifdef WIN32
+void
+qemu_pixman_win32_image_destroy(pixman_image_t *image, void *data)
+{
+    HANDLE handle = data;
+
+    qemu_win32_map_free(
+        pixman_image_get_data(image),
+        handle,
+        &error_warn
+    );
+}
+#endif
Signature · 1 line
2.47.0
#4 lore raw

[PULL 16/20] ui/dbus: implement Unix.Map

In reply to [email protected]

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

Message-ID: <[email protected]>

---
 ui/dbus-listener.c | 78 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 73 insertions(+), 5 deletions(-)
ui/dbus-listener.c +73 -5
index 7142afcddb..ec47946282 100644
@@ -83,6 +83,8 @@ struct _DBusDisplayListener {
 #ifdef CONFIG_OPENGL
     egl_fb fb;
 #endif
+#else /* !WIN32 */
+    QemuDBusDisplay1ListenerUnixMap *map_proxy;
 #endif
 
     guint dbus_filter;
@@ -441,6 +443,51 @@ dbus_scanout_share_d3d_texture(
     return true;
 }
 #endif /* CONFIG_OPENGL */
+#else /* !WIN32 */
+static bool dbus_scanout_map(DBusDisplayListener *ddl)
+{
+    g_autoptr(GError) err = NULL;
+    g_autoptr(GUnixFDList) fd_list = NULL;
+
+    if (ddl->ds_share == SHARE_KIND_MAPPED) {
+        return true;
+    }
+
+    if (!ddl->can_share_map || ddl->ds->shmfd == -1) {
+        return false;
+    }
+
+    ddl_discard_display_messages(ddl);
+    fd_list = g_unix_fd_list_new();
+    if (g_unix_fd_list_append(fd_list, ddl->ds->shmfd, &err) != 0) {
+        g_debug("Failed to setup scanout map fdlist: %s", err->message);
+        ddl->can_share_map = false;
+        return false;
+    }
+
+    if (!qemu_dbus_display1_listener_unix_map_call_scanout_map_sync(
+            ddl->map_proxy,
+            g_variant_new_handle(0),
+            ddl->ds->shmfd_offset,
+            surface_width(ddl->ds),
+            surface_height(ddl->ds),
+            surface_stride(ddl->ds),
+            surface_format(ddl->ds),
+            G_DBUS_CALL_FLAGS_NONE,
+            DBUS_DEFAULT_TIMEOUT,
+            fd_list,
+            NULL,
+            NULL,
+            &err)) {
+        g_debug("Failed to call ScanoutMap: %s", err->message);
+        ddl->can_share_map = false;
+        return false;
+    }
+
+    ddl->ds_share = SHARE_KIND_MAPPED;
+
+    return true;
+}
 #endif /* WIN32 */
 
 #ifdef CONFIG_OPENGL
@@ -693,16 +740,22 @@ static void dbus_gfx_update(DisplayChangeListener *dcl,
 
     trace_dbus_update(x, y, w, h);
 
-#ifdef WIN32
     if (dbus_scanout_map(ddl)) {
+#ifdef WIN32
         qemu_dbus_display1_listener_win32_map_call_update_map(
             ddl->map_proxy,
             x, y, w, h,
             G_DBUS_CALL_FLAGS_NONE,
             DBUS_DEFAULT_TIMEOUT, NULL, NULL, NULL);
+#else
+        qemu_dbus_display1_listener_unix_map_call_update_map(
+            ddl->map_proxy,
+            x, y, w, h,
+            G_DBUS_CALL_FLAGS_NONE,
+            DBUS_DEFAULT_TIMEOUT, NULL, NULL, NULL);
+#endif
         return;
     }
-#endif
 
     if (x == 0 && y == 0 && w == surface_width(ddl->ds) && h == surface_height(ddl->ds)) {
         return ddl_scanout(ddl);
@@ -879,7 +932,6 @@ dbus_display_listener_get_console(DBusDisplayListener *ddl)
     return ddl->console;
 }
 
-#ifdef WIN32
 static bool
 dbus_display_listener_implements(DBusDisplayListener *ddl, const char *iface)
 {
@@ -894,6 +946,7 @@ dbus_display_listener_implements(DBusDisplayListener *ddl, const char *iface)
     return implements;
 }
 
+#ifdef WIN32
 static bool
 dbus_display_listener_setup_peer_process(DBusDisplayListener *ddl)
 {
@@ -976,10 +1029,11 @@ dbus_display_listener_setup_d3d11(DBusDisplayListener *ddl)
 static void
 dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)
 {
-#ifdef WIN32
     g_autoptr(GError) err = NULL;
 
-    if (!dbus_display_listener_implements(ddl, "org.qemu.Display1.Listener.Win32.Map")) {
+#ifdef WIN32
+    if (!dbus_display_listener_implements(
+            ddl, "org.qemu.Display1.Listener.Win32.Map")) {
         return;
     }
 
@@ -999,6 +1053,20 @@ dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)
         return;
     }
 
+    ddl->can_share_map = true;
+#else /* !WIN32 */
+    if (!dbus_display_listener_implements(
+            ddl, "org.qemu.Display1.Listener.Unix.Map")) {
+        return;
+    }
+    ddl->map_proxy = qemu_dbus_display1_listener_unix_map_proxy_new_sync(
+        ddl->conn, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL,
+        "/org/qemu/Display1/Listener", NULL, &err);
+    if (!ddl->map_proxy) {
+        g_debug("Failed to setup Unix map proxy: %s", err->message);
+        return;
+    }
+
     ddl->can_share_map = true;
 #endif
 }
Signature · 1 line
2.47.0
#5 lore raw

[PULL 09/20] ui/pixman: generalize shared_image_destroy

In reply to [email protected]

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

Learn to free memfd-allocated shared memory.

Message-ID: <[email protected]>

---
 include/ui/qemu-pixman.h |  2 +-
 hw/display/virtio-gpu.c  |  4 ++--
 ui/console.c             |  2 +-
 ui/qemu-pixman.c         | 20 ++++++++++++--------
 4 files changed, 16 insertions(+), 12 deletions(-)
include/ui/qemu-pixman.h +1 -1
index e3dd72b9e3..a97f56d09a 100644
@@ -97,7 +97,7 @@ void qemu_pixman_glyph_render(pixman_image_t *glyph,
 
 void qemu_pixman_image_unref(pixman_image_t *image);
 
-void qemu_pixman_win32_image_destroy(pixman_image_t *image, void *data);
+void qemu_pixman_shared_image_destroy(pixman_image_t *image, void *data);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(pixman_image_t, qemu_pixman_image_unref)
 
hw/display/virtio-gpu.c +2 -2
index 017a0f170c..77f6e76f23 100644
@@ -298,7 +298,7 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
             bits, c2d.height ? res->hostmem / c2d.height : 0);
 #ifdef WIN32
         if (res->image) {
-            pixman_image_set_destroy_function(res->image, qemu_pixman_win32_image_destroy, res->handle);
+            pixman_image_set_destroy_function(res->image, qemu_pixman_shared_image_destroy, res->handle);
         }
 #endif
     }
@@ -1317,7 +1317,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
             return -EINVAL;
         }
 #ifdef WIN32
-        pixman_image_set_destroy_function(res->image, qemu_pixman_win32_image_destroy, res->handle);
+        pixman_image_set_destroy_function(res->image, qemu_pixman_shared_image_destroy, res->handle);
 #endif
 
         res->addrs = g_new(uint64_t, res->iov_cnt);
ui/console.c +1 -1
index 8f416ff0b9..fdd76c2be4 100644
@@ -487,7 +487,7 @@ DisplaySurface *qemu_create_displaysurface(int width, int height)
 #ifdef WIN32
     qemu_displaysurface_win32_set_handle(surface, handle, 0);
     pixman_image_set_destroy_function(surface->image,
-                                      qemu_pixman_win32_image_destroy, handle);
+                                      qemu_pixman_shared_image_destroy, handle);
 #endif
     return surface;
 }
ui/qemu-pixman.c +12 -8
index 3870e1a215..46a91e7f7a 100644
@@ -6,6 +6,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "ui/console.h"
+#include "qemu/memfd.h"
 #include "standard-headers/drm/drm_fourcc.h"
 #include "trace.h"
 
@@ -269,16 +270,19 @@ void qemu_pixman_glyph_render(pixman_image_t *glyph,
 }
 #endif /* CONFIG_PIXMAN */
 
-#ifdef WIN32
 void
-qemu_pixman_win32_image_destroy(pixman_image_t *image, void *data)
+qemu_pixman_shared_image_destroy(pixman_image_t *image, void *data)
 {
+    void *ptr = pixman_image_get_data(image);
+
+#ifdef WIN32
     HANDLE handle = data;
 
-    qemu_win32_map_free(
-        pixman_image_get_data(image),
-        handle,
-        &error_warn
-    );
-}
+    qemu_win32_map_free(ptr, handle, &error_warn);
+#else
+    int shmfd = GPOINTER_TO_INT(data);
+    size_t size = pixman_image_get_height(image) * pixman_image_get_stride(image);
+
+    qemu_memfd_free(ptr, size, shmfd);
 #endif
+}
Signature · 1 line
2.47.0
#6 lore raw

[PULL 17/20] virtio-gpu: allocate shareable 2d resources on !win32

In reply to [email protected]

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

Similar to what was done in commit 9462ff46 ("virtio-gpu/win32: allocate shareable 2d resources/images") for win32, allocate resource memory with memfd, so the associated display surface memory can be shared with a different process.

Message-ID: <[email protected]>

---
 include/hw/virtio/virtio-gpu.h |  2 ++
 hw/display/virtio-gpu.c        | 39 +++++++++++++++++++++++-----------
 2 files changed, 29 insertions(+), 12 deletions(-)
include/hw/virtio/virtio-gpu.h +2 -0
index 7a59379f5a..7509d13265 100644
@@ -53,6 +53,8 @@ struct virtio_gpu_simple_resource {
     pixman_image_t *image;
 #ifdef WIN32
     HANDLE handle;
+#else
+    int shmfd;
 #endif
     uint64_t hostmem;
 
hw/display/virtio-gpu.c +27 -12
index 77f6e76f23..23ebefa59c 100644
@@ -28,6 +28,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/qdev-properties.h"
 #include "qemu/log.h"
+#include "qemu/memfd.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
@@ -238,6 +239,20 @@ static uint32_t calc_image_hostmem(pixman_format_code_t pformat,
     return height * stride;
 }
 
+static void
+resource_set_image_destroy(struct virtio_gpu_simple_resource *res)
+{
+    if (!res) {
+        return;
+    }
+#ifdef WIN32
+    void *data = res->handle;
+#else
+    void *data = GINT_TO_POINTER(res->shmfd);
+#endif
+    pixman_image_set_destroy_function(res->image, qemu_pixman_shared_image_destroy, data);
+}
+
 static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
                                           struct virtio_gpu_ctrl_command *cmd)
 {
@@ -287,25 +302,21 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
         void *bits = NULL;
 #ifdef WIN32
         bits = qemu_win32_map_alloc(res->hostmem, &res->handle, &error_warn);
+#else
+        bits = qemu_memfd_alloc("virtio-gpu-res", res->hostmem, 0, &res->shmfd, &error_warn);
+#endif
         if (!bits) {
             goto end;
         }
-#endif
         res->image = pixman_image_create_bits(
             pformat,
             c2d.width,
             c2d.height,
             bits, c2d.height ? res->hostmem / c2d.height : 0);
-#ifdef WIN32
-        if (res->image) {
-            pixman_image_set_destroy_function(res->image, qemu_pixman_shared_image_destroy, res->handle);
-        }
-#endif
+        resource_set_image_destroy(res);
     }
 
-#ifdef WIN32
 end:
-#endif
     if (!res->image) {
         qemu_log_mask(LOG_GUEST_ERROR,
                       "%s: resource creation failed %d %d %d\n",
@@ -678,6 +689,8 @@ static bool virtio_gpu_do_set_scanout(VirtIOGPU *g,
         scanout->ds = qemu_create_displaysurface_pixman(rect);
 #ifdef WIN32
         qemu_displaysurface_win32_set_handle(scanout->ds, res->handle, fb->offset);
+#else
+        qemu_displaysurface_set_shmfd(scanout->ds, res->shmfd, fb->offset);
 #endif
 
         pixman_image_unref(rect);
@@ -1303,11 +1316,13 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
         res->hostmem = calc_image_hostmem(pformat, res->width, res->height);
 #ifdef WIN32
         bits = qemu_win32_map_alloc(res->hostmem, &res->handle, &error_warn);
+#else
+        bits = qemu_memfd_alloc("virtio-gpu-res", res->hostmem, 0, &res->shmfd, &error_warn);
+#endif
         if (!bits) {
             g_free(res);
             return -EINVAL;
         }
-#endif
         res->image = pixman_image_create_bits(
             pformat,
             res->width, res->height,
@@ -1316,9 +1331,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
             g_free(res);
             return -EINVAL;
         }
-#ifdef WIN32
-        pixman_image_set_destroy_function(res->image, qemu_pixman_shared_image_destroy, res->handle);
-#endif
+        resource_set_image_destroy(res);
 
         res->addrs = g_new(uint64_t, res->iov_cnt);
         res->iov = g_new(struct iovec, res->iov_cnt);
@@ -1453,6 +1466,8 @@ static int virtio_gpu_post_load(void *opaque, int version_id)
             scanout->ds = qemu_create_displaysurface_pixman(res->image);
 #ifdef WIN32
             qemu_displaysurface_win32_set_handle(scanout->ds, res->handle, 0);
+#else
+            qemu_displaysurface_set_shmfd(scanout->ds, res->shmfd, 0);
 #endif
             dpy_gfx_replace_surface(scanout->con, scanout->ds);
         }
Signature · 1 line
2.47.0
#7 lore raw

[PULL 01/20] hw/audio/hda: free timer on exit

In reply to [email protected]

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

Fixes 280c1e1cd ("audio/hda: create millisecond timers that handle IO")

Message-ID: <[email protected]>

---
 hw/audio/hda-codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/audio/hda-codec.c +1 -1
index b40eec9604..74c0292284 100644
@@ -751,7 +751,7 @@ static void hda_audio_exit(HDACodecDevice *hda)
             continue;
         }
         if (a->use_timer) {
-            timer_del(st->buft);
+            timer_free(st->buft);
         }
         if (st->output) {
             AUD_close_out(&a->card, st->voice.out);
Signature · 1 line
2.47.0
#8 lore raw

[PULL 11/20] ui/dbus: add trace for can_share_map

In reply to [email protected]

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

Message-ID: <[email protected]>

---
 ui/dbus-listener.c | 1 +
 ui/trace-events    | 1 +
 2 files changed, 2 insertions(+)
ui/dbus-listener.c +1 -0
index eca6890ce6..7142afcddb 100644
@@ -1089,6 +1089,7 @@ dbus_display_listener_new(const char *bus_name,
     ddl->console = console;
 
     dbus_display_listener_setup_shared_map(ddl);
+    trace_dbus_can_share_map(ddl->can_share_map);
     dbus_display_listener_setup_d3d11(ddl);
 
     con = qemu_console_lookup_by_index(dbus_display_console_get_index(console));
ui/trace-events +1 -0
index fb253c1666..3da0d5e280 100644
@@ -166,6 +166,7 @@ dbus_clipboard_unregister(const char *bus_name) "peer %s"
 dbus_scanout_texture(uint32_t tex_id, bool backing_y_0_top, uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h) "tex_id:%u y0top:%d back:%ux%u %u+%u-%ux%u"
 dbus_gl_gfx_switch(void *p) "surf: %p"
 dbus_filter(unsigned int serial, unsigned int filter) "serial=%u (<= %u)"
+dbus_can_share_map(bool share) "can_share_map: %d"
 
 # egl-helpers.c
 egl_init_d3d11_device(void *p) "d3d device: %p"
Signature · 1 line
2.47.0
#9 lore raw

[PULL 18/20] ui: refactor using a common qemu_pixman_shareable

In reply to [email protected]

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

Use a common shareable type for win32 & unix, and helper functions. This simplify the code as it avoids a lot of #ifdef'ery.

Note: if it helps review, commits could be reordered to introduce the common type before introducing shareable memory for unix.

Message-ID: <[email protected]>

---
 include/hw/virtio/virtio-gpu.h |  6 +--
 include/ui/qemu-pixman.h       | 24 +++++++++-
 include/ui/surface.h           | 20 +++------
 hw/display/virtio-gpu.c        | 72 ++++++++----------------------
 ui/console.c                   | 80 ++++++++++++----------------------
 ui/dbus-listener.c             | 12 ++---
 ui/qemu-pixman.c               | 68 +++++++++++++++++++++++++----
 7 files changed, 142 insertions(+), 140 deletions(-)
include/hw/virtio/virtio-gpu.h +1 -5
index 7509d13265..e343110e23 100644
@@ -51,11 +51,7 @@ struct virtio_gpu_simple_resource {
     unsigned int iov_cnt;
     uint32_t scanout_bitmask;
     pixman_image_t *image;
-#ifdef WIN32
-    HANDLE handle;
-#else
-    int shmfd;
-#endif
+    qemu_pixman_shareable share_handle;
     uint64_t hostmem;
 
     uint64_t blob_size;
include/ui/qemu-pixman.h +23 -1
index a97f56d09a..193bc046d1 100644
@@ -12,6 +12,8 @@
 #include "pixman-minimal.h"
 #endif
 
+#include "qapi/error.h"
+
 /*
  * pixman image formats are defined to be native endian,
  * that means host byte order on qemu.  So we go define
@@ -97,7 +99,27 @@ void qemu_pixman_glyph_render(pixman_image_t *glyph,
 
 void qemu_pixman_image_unref(pixman_image_t *image);
 
-void qemu_pixman_shared_image_destroy(pixman_image_t *image, void *data);
+#ifdef WIN32
+typedef HANDLE qemu_pixman_shareable;
+#define SHAREABLE_NONE (NULL)
+#define SHAREABLE_TO_PTR(handle) (handle)
+#define PTR_TO_SHAREABLE(ptr) (ptr)
+#else
+typedef int qemu_pixman_shareable;
+#define SHAREABLE_NONE (-1)
+#define SHAREABLE_TO_PTR(handle) GINT_TO_POINTER(handle)
+#define PTR_TO_SHAREABLE(ptr) GPOINTER_TO_INT(ptr)
+#endif
+
+bool qemu_pixman_image_new_shareable(
+    pixman_image_t **image,
+    qemu_pixman_shareable *handle,
+    const char *name,
+    pixman_format_code_t format,
+    int width,
+    int height,
+    int rowstride_bytes,
+    Error **errp);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(pixman_image_t, qemu_pixman_image_unref)
 
include/ui/surface.h +6 -14
index 37d03be4af..f16f7be8be 100644
@@ -23,13 +23,8 @@ typedef struct DisplaySurface {
     GLenum gltype;
     GLuint texture;
 #endif
-#ifdef WIN32
-    HANDLE handle;
-    uint32_t handle_offset;
-#else
-    int shmfd;
-    uint32_t shmfd_offset;
-#endif
+    qemu_pixman_shareable share_handle;
+    uint32_t share_handle_offset;
 } DisplaySurface;
 
 PixelFormat qemu_default_pixelformat(int bpp);
@@ -40,13 +35,10 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,
 DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
 DisplaySurface *qemu_create_placeholder_surface(int w, int h,
                                                 const char *msg);
-#ifdef WIN32
-void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
-                                          HANDLE h, uint32_t offset);
-#else
-void qemu_displaysurface_set_shmfd(DisplaySurface *surface,
-                                   int shmfd, uint32_t offset);
-#endif
+
+void qemu_displaysurface_set_share_handle(DisplaySurface *surface,
+                                          qemu_pixman_shareable handle,
+                                          uint32_t offset);
 
 DisplaySurface *qemu_create_displaysurface(int width, int height);
 void qemu_free_displaysurface(DisplaySurface *surface);
hw/display/virtio-gpu.c +19 -53

113 lines not on this page · raw message

ui/console.c +27 -53

111 lines not on this page · raw message

ui/dbus-listener.c +6 -6
index ec47946282..99738e769b 100644
@@ -336,13 +336,13 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)
         return true;
     }
 
-    if (!ddl->can_share_map || !ddl->ds->handle) {
+    if (!ddl->can_share_map || !ddl->ds->share_handle) {
         return false;
     }
 
     success = DuplicateHandle(
         GetCurrentProcess(),
-        ddl->ds->handle,
+        ddl->ds->share_handle,
         ddl->peer_process,
         &target_handle,
         FILE_MAP_READ | SECTION_QUERY,
@@ -359,7 +359,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)
     if (!qemu_dbus_display1_listener_win32_map_call_scanout_map_sync(
             ddl->map_proxy,
             GPOINTER_TO_UINT(target_handle),
-            ddl->ds->handle_offset,
+            ddl->ds->share_handle_offset,
             surface_width(ddl->ds),
             surface_height(ddl->ds),
             surface_stride(ddl->ds),
@@ -453,13 +453,13 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)
         return true;
     }
 
-    if (!ddl->can_share_map || ddl->ds->shmfd == -1) {
+    if (!ddl->can_share_map || ddl->ds->share_handle == SHAREABLE_NONE) {
         return false;
     }
 
     ddl_discard_display_messages(ddl);
     fd_list = g_unix_fd_list_new();
-    if (g_unix_fd_list_append(fd_list, ddl->ds->shmfd, &err) != 0) {
+    if (g_unix_fd_list_append(fd_list, ddl->ds->share_handle, &err) != 0) {
         g_debug("Failed to setup scanout map fdlist: %s", err->message);
         ddl->can_share_map = false;
         return false;
@@ -468,7 +468,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)
     if (!qemu_dbus_display1_listener_unix_map_call_scanout_map_sync(
             ddl->map_proxy,
             g_variant_new_handle(0),
-            ddl->ds->shmfd_offset,
+            ddl->ds->share_handle_offset,
             surface_width(ddl->ds),
             surface_height(ddl->ds),
             surface_stride(ddl->ds),
ui/qemu-pixman.c +60 -8

79 lines not on this page · raw message

Signature · 1 line
2.47.0
#10 lore raw

Re: [PULL 18/20] ui: refactor using a common qemu_pixman_shareable

Quoted 6 lines · On Mon, 14 Oct 2024 at 14:41, <[email protected]> wrote:

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

Use a common shareable type for win32 & unix, and helper functions. This simplify the code as it avoids a lot of #ifdef'ery.

Quoted 7 lines

Note: if it helps review, commits could be reordered to introduce the common type before introducing shareable memory for unix.

Message-ID: <[email protected]>

Hi; this is a rather old commit (now 1ff788db9781615b in git), but I have just noticed that it seems to break the usage of qemu_create_displaysurface_from() by hw/display/xlnx_dp.c.

ui/console.c DisplaySurface *qemu_create_displaysurface_from(int width, int height, · line 525

Quoted 10 lines
ui/console.c +0 -6
@@ -517,14 +482,25 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,
     DisplaySurface *surface = g_new0(DisplaySurface, 1);
 
     trace_displaysurface_create_from(surface, width, height, format);
-#ifndef WIN32
-    surface->shmfd = -1;
-#endif
-    surface->image = pixman_image_create_bits(format,
-                                              width, height,
-                                              (void *)data, linesize);

Before this refactoring, qemu_create_displaysurface_from() always calls pixman_image_create_bits(). That pixman function allows you to pass NULL to mean "allocate me the memory for the data". If you do that, pixman will always compute the stride for the data (by looking at the pixel format and the width), so the input linesize here is ignored. The xlnx_dp.c code takes advantage of this in calls like:

        s->g_plane.surface
                = qemu_create_displaysurface_from(width, height,
                                                  s->g_plane.format, 0, NULL);
Quoted 8 lines
ui/console.c +6 -1
-    assert(surface->image != NULL);
+    surface->share_handle = SHAREABLE_NONE;
 
+    if (data) {
+        surface->image = pixman_image_create_bits(format,
+                                                  width, height,
+                                                  (void *)data, linesize);
+    } else {

ui/console.c DisplaySurface *qemu_create_displaysurface_from(int width, int height, · line 501

Quoted 10 lines
ui/console.c +10 -0
+        qemu_pixman_image_new_shareable(&surface->image,
+                                        &surface->share_handle,
+                                        "displaysurface",
+                                        format,
+                                        width,
+                                        height,
+                                        linesize,
+                                        &error_abort);
+        surface->flags = QEMU_ALLOCATED_FLAG;
+    }

In the refactored version, although non-NULL data still results in a call to pixman_image_create_bits(), now a NULL data pointer means we call qemu_pixman_image_new_shareable().

ui/qemu-pixman.c void qemu_pixman_glyph_render(pixman_image_t *glyph, · line 317

Quoted 12 lines
ui/qemu-pixman.c +12 -0
+bool
+qemu_pixman_image_new_shareable(pixman_image_t **image,
+                                qemu_pixman_shareable *handle,
+                                const char *name,
+                                pixman_format_code_t format,
+                                int width,
+                                int height,
+                                int rowstride_bytes,
+                                Error **errp)
+{
+    ERRP_GUARD();
+    size_t size = height * rowstride_bytes;

This function assumes that rowstride_bytes is not zero, so the previously-working "pass 0, NULL" now results in a size value of 0 here and an attempt to allocate 0 bytes in qemu_pixman_shareable_alloc(), which winds up triggering an abort in qemu_memfd_alloc().

Presumably:
(1) qemu_pixman_image_new_shareable() should calculate the rowstride_bytes as pixman does, rather than requiring it to be passed in
(2) qemu_memfd_alloc() ought not to abort on zero size

For a repro case:

$ cat /tmp/xlnx-dp.txt
writel 0xfd4a0194 0x00000780
writel 0xfd4a0198 0x00000438
$ ./build/arm/qemu-system-aarch64 -accel qtest -M xlnx-zcu102
-display none -chardev
file,id=repro,path=/dev/null,input-path=/tmp/xlnx-dp.txt -qtest
chardev:repro
[I 0.000000] OPENED
pulseaudio: set_sink_input_volume() failed Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed Reason: Invalid argument
[R +0.121066] writel 0xfd4a0194 0x00000780
[S +0.121092] OK
[R +0.121096] writel 0xfd4a0198 0x00000438
Unexpected error in qemu_memfd_alloc() at ../../util/memfd.c:143:
qemu-system-aarch64: failed to allocate shared memory: Invalid argument
Aborted (core dumped)

thanks
-- PMM

#11 lore raw

Re: [PULL 18/20] ui: refactor using a common qemu_pixman_shareable

Ping -- does anybody have suggestions for the best fix for this regression ?

thanks
-- PMM

Quoted 114 lines · Peter Maydell
Quoted 6 lines · On Mon, 14 Oct 2024 at 14:41, <[email protected]> wrote:

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

Use a common shareable type for win32 & unix, and helper functions. This simplify the code as it avoids a lot of #ifdef'ery.

Quoted 7 lines

Note: if it helps review, commits could be reordered to introduce the common type before introducing shareable memory for unix.

Message-ID: <[email protected]>

Hi; this is a rather old commit (now 1ff788db9781615b in git), but I have just noticed that it seems to break the usage of qemu_create_displaysurface_from() by hw/display/xlnx_dp.c.

ui/console.c DisplaySurface *qemu_create_displaysurface_from(int width, int height, · line 525

Quoted 10 lines
ui/console.c +0 -6
@@ -517,14 +482,25 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,
     DisplaySurface *surface = g_new0(DisplaySurface, 1);
 
     trace_displaysurface_create_from(surface, width, height, format);
-#ifndef WIN32
-    surface->shmfd = -1;
-#endif
-    surface->image = pixman_image_create_bits(format,
-                                              width, height,
-                                              (void *)data, linesize);

Before this refactoring, qemu_create_displaysurface_from() always calls pixman_image_create_bits(). That pixman function allows you to pass NULL to mean "allocate me the memory for the data". If you do that, pixman will always compute the stride for the data (by looking at the pixel format and the width), so the input linesize here is ignored. The xlnx_dp.c code takes advantage of this in calls like:

        s->g_plane.surface
                = qemu_create_displaysurface_from(width, height,
                                                  s->g_plane.format, 0, NULL);
Quoted 8 lines
ui/console.c +6 -1
-    assert(surface->image != NULL);
+    surface->share_handle = SHAREABLE_NONE;
 
+    if (data) {
+        surface->image = pixman_image_create_bits(format,
+                                                  width, height,
+                                                  (void *)data, linesize);
+    } else {

ui/console.c DisplaySurface *qemu_create_displaysurface_from(int width, int height, · line 501

Quoted 10 lines
ui/console.c +10 -0
+        qemu_pixman_image_new_shareable(&surface->image,
+                                        &surface->share_handle,
+                                        "displaysurface",
+                                        format,
+                                        width,
+                                        height,
+                                        linesize,
+                                        &error_abort);
+        surface->flags = QEMU_ALLOCATED_FLAG;
+    }

In the refactored version, although non-NULL data still results in a call to pixman_image_create_bits(), now a NULL data pointer means we call qemu_pixman_image_new_shareable().

ui/qemu-pixman.c void qemu_pixman_glyph_render(pixman_image_t *glyph, · line 317

Quoted 12 lines
ui/qemu-pixman.c +12 -0
+bool
+qemu_pixman_image_new_shareable(pixman_image_t **image,
+                                qemu_pixman_shareable *handle,
+                                const char *name,
+                                pixman_format_code_t format,
+                                int width,
+                                int height,
+                                int rowstride_bytes,
+                                Error **errp)
+{
+    ERRP_GUARD();
+    size_t size = height * rowstride_bytes;

This function assumes that rowstride_bytes is not zero, so the previously-working "pass 0, NULL" now results in a size value of 0 here and an attempt to allocate 0 bytes in qemu_pixman_shareable_alloc(), which winds up triggering an abort in qemu_memfd_alloc().

Presumably:
(1) qemu_pixman_image_new_shareable() should calculate the rowstride_bytes as pixman does, rather than requiring it to be passed in
(2) qemu_memfd_alloc() ought not to abort on zero size

For a repro case:

$ cat /tmp/xlnx-dp.txt
writel 0xfd4a0194 0x00000780
writel 0xfd4a0198 0x00000438
$ ./build/arm/qemu-system-aarch64 -accel qtest -M xlnx-zcu102
-display none -chardev
file,id=repro,path=/dev/null,input-path=/tmp/xlnx-dp.txt -qtest
chardev:repro
[I 0.000000] OPENED
pulseaudio: set_sink_input_volume() failed Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed Reason: Invalid argument
[R +0.121066] writel 0xfd4a0194 0x00000780
[S +0.121092] OK
[R +0.121096] writel 0xfd4a0198 0x00000438
Unexpected error in qemu_memfd_alloc() at ../../util/memfd.c:143:
qemu-system-aarch64: failed to allocate shared memory: Invalid argument
Aborted (core dumped)

thanks
-- PMM

#12 lore raw

Re: [PULL 18/20] ui: refactor using a common qemu_pixman_shareable

Hi Peter

Quoted 4 lines · Peter Maydell

Ping -- does anybody have suggestions for the best fix for this regression ?

Sorry I missed it, I will send fixes.
thanks

Quoted 119 lines

thanks
-- PMM

Quoted 114 lines · Peter Maydell
Quoted 6 lines · On Mon, 14 Oct 2024 at 14:41, <[email protected]> wrote:

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

Use a common shareable type for win32 & unix, and helper functions. This simplify the code as it avoids a lot of #ifdef'ery.

Quoted 7 lines

Note: if it helps review, commits could be reordered to introduce the common type before introducing shareable memory for unix.

Message-ID: <[email protected]>

Hi; this is a rather old commit (now 1ff788db9781615b in git), but I have just noticed that it seems to break the usage of qemu_create_displaysurface_from() by hw/display/xlnx_dp.c.

ui/console.c DisplaySurface *qemu_create_displaysurface_from(int width, int height, · line 525

Quoted 10 lines
ui/console.c +0 -6
@@ -517,14 +482,25 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,
     DisplaySurface *surface = g_new0(DisplaySurface, 1);
 
     trace_displaysurface_create_from(surface, width, height, format);
-#ifndef WIN32
-    surface->shmfd = -1;
-#endif
-    surface->image = pixman_image_create_bits(format,
-                                              width, height,
-                                              (void *)data, linesize);

Before this refactoring, qemu_create_displaysurface_from() always calls pixman_image_create_bits(). That pixman function allows you to pass NULL to mean "allocate me the memory for the data". If you do that, pixman will always compute the stride for the data (by looking at the pixel format and the width), so the input linesize here is ignored. The xlnx_dp.c code takes advantage of this in calls like:

        s->g_plane.surface
                = qemu_create_displaysurface_from(width, height,
                                                  s->g_plane.format, 0, NULL);
Quoted 8 lines
ui/console.c +6 -1
-    assert(surface->image != NULL);
+    surface->share_handle = SHAREABLE_NONE;
 
+    if (data) {
+        surface->image = pixman_image_create_bits(format,
+                                                  width, height,
+                                                  (void *)data, linesize);
+    } else {

ui/console.c DisplaySurface *qemu_create_displaysurface_from(int width, int height, · line 501

Quoted 10 lines
ui/console.c +10 -0
+        qemu_pixman_image_new_shareable(&surface->image,
+                                        &surface->share_handle,
+                                        "displaysurface",
+                                        format,
+                                        width,
+                                        height,
+                                        linesize,
+                                        &error_abort);
+        surface->flags = QEMU_ALLOCATED_FLAG;
+    }

In the refactored version, although non-NULL data still results in a call to pixman_image_create_bits(), now a NULL data pointer means we call qemu_pixman_image_new_shareable().

ui/qemu-pixman.c void qemu_pixman_glyph_render(pixman_image_t *glyph, · line 317

Quoted 12 lines
ui/qemu-pixman.c +12 -0
+bool
+qemu_pixman_image_new_shareable(pixman_image_t **image,
+                                qemu_pixman_shareable *handle,
+                                const char *name,
+                                pixman_format_code_t format,
+                                int width,
+                                int height,
+                                int rowstride_bytes,
+                                Error **errp)
+{
+    ERRP_GUARD();
+    size_t size = height * rowstride_bytes;

This function assumes that rowstride_bytes is not zero, so the previously-working "pass 0, NULL" now results in a size value of 0 here and an attempt to allocate 0 bytes in qemu_pixman_shareable_alloc(), which winds up triggering an abort in qemu_memfd_alloc().

Presumably:
(1) qemu_pixman_image_new_shareable() should calculate the rowstride_bytes as pixman does, rather than requiring it to be passed in
(2) qemu_memfd_alloc() ought not to abort on zero size

For a repro case:

$ cat /tmp/xlnx-dp.txt
writel 0xfd4a0194 0x00000780
writel 0xfd4a0198 0x00000438
$ ./build/arm/qemu-system-aarch64 -accel qtest -M xlnx-zcu102
-display none -chardev
file,id=repro,path=/dev/null,input-path=/tmp/xlnx-dp.txt -qtest
chardev:repro
[I 0.000000] OPENED
pulseaudio: set_sink_input_volume() failed Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed Reason: Invalid argument
[R +0.121066] writel 0xfd4a0194 0x00000780
[S +0.121092] OK
[R +0.121096] writel 0xfd4a0198 0x00000438
Unexpected error in qemu_memfd_alloc() at ../../util/memfd.c:143:
qemu-system-aarch64: failed to allocate shared memory: Invalid argument
Aborted (core dumped)

thanks
-- PMM

#13 lore raw

[PULL 08/20] util/memfd: report potential errors on free

In reply to [email protected]

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

Message-ID: <[email protected]>

---
 util/memfd.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
util/memfd.c +7 -2
index 4a3c07e0be..8a2e906962 100644
@@ -28,6 +28,7 @@
 #include "qemu/osdep.h"
 
 #include "qapi/error.h"
+#include "qemu/error-report.h"
 #include "qemu/memfd.h"
 #include "qemu/host-utils.h"
 
@@ -149,11 +150,15 @@ err:
 void qemu_memfd_free(void *ptr, size_t size, int fd)
 {
     if (ptr) {
-        munmap(ptr, size);
+        if (munmap(ptr, size) != 0) {
+            error_report("memfd munmap() failed: %s", strerror(errno));
+        }
     }
 
     if (fd != -1) {
-        close(fd);
+        if (close(fd) != 0) {
+            error_report("memfd close() failed: %s", strerror(errno));
+        }
     }
 }
 
Signature · 1 line
2.47.0
#14 lore raw

[PULL 10/20] ui/dbus: do not limit to one listener per connection / bus name

In reply to [email protected]

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

This is an arbitrary limitation that doesn't concern QEMU directly and may make some use cases unnecessarily more complicated.

Message-ID: <[email protected]>

---
 ui/dbus-console.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)
ui/dbus-console.c +5 -18
index 578b67f62b..5eb1d40d16 100644
@@ -41,7 +41,7 @@ struct _DBusDisplayConsole {
     DisplayChangeListener dcl;
 
     DBusDisplay *display;
-    GHashTable *listeners;
+    GPtrArray *listeners;
     QemuDBusDisplay1Console *iface;
 
     QemuDBusDisplay1Keyboard *iface_kbd;
@@ -142,8 +142,7 @@ dbus_display_console_init(DBusDisplayConsole *object)
 {
     DBusDisplayConsole *ddc = DBUS_DISPLAY_CONSOLE(object);
 
-    ddc->listeners = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                            NULL, g_object_unref);
+    ddc->listeners = g_ptr_array_new_with_free_func(g_object_unref);
     ddc->dcl.ops = &dbus_console_dcl_ops;
 }
 
@@ -157,7 +156,7 @@ dbus_display_console_dispose(GObject *object)
     g_clear_object(&ddc->iface_mouse);
     g_clear_object(&ddc->iface_kbd);
     g_clear_object(&ddc->iface);
-    g_clear_pointer(&ddc->listeners, g_hash_table_unref);
+    g_clear_pointer(&ddc->listeners, g_ptr_array_unref);
     g_clear_pointer(&ddc->kbd, qkbd_state_free);
 
     G_OBJECT_CLASS(dbus_display_console_parent_class)->dispose(object);
@@ -179,7 +178,7 @@ listener_vanished_cb(DBusDisplayListener *listener)
 
     trace_dbus_listener_vanished(name);
 
-    g_hash_table_remove(ddc->listeners, name);
+    g_ptr_array_remove_fast(ddc->listeners, listener);
     qkbd_state_lift_all_keys(ddc->kbd);
 }
 
@@ -267,16 +266,6 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,
     DBusDisplayListener *listener;
     int fd;
 
-    if (sender && g_hash_table_contains(ddc->listeners, sender)) {
-        g_dbus_method_invocation_return_error(
-            invocation,
-            DBUS_DISPLAY_ERROR,
-            DBUS_DISPLAY_ERROR_INVALID,
-            "`%s` is already registered!",
-            sender);
-        return DBUS_METHOD_INVOCATION_HANDLED;
-    }
-
 #ifdef G_OS_WIN32
     if (!dbus_win32_import_socket(invocation, arg_listener, &fd)) {
         return DBUS_METHOD_INVOCATION_HANDLED;
@@ -331,9 +320,7 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,
         return DBUS_METHOD_INVOCATION_HANDLED;
     }
 
-    g_hash_table_insert(ddc->listeners,
-                        (gpointer)dbus_display_listener_get_bus_name(listener),
-                        listener);
+    g_ptr_array_add(ddc->listeners, listener);
     g_object_connect(listener_conn,
                      "swapped-signal::closed", listener_vanished_cb, listener,
                      NULL);
Signature · 1 line
2.47.0
#15 lore raw

[PULL 13/20] meson: find_program('gdbus-codegen') directly

In reply to [email protected]

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

gio.pc variable is a bit bogus in context of cross-compilation, since it contains an absolute path, relative to the sysroot directory. On Fedora, it ends up as:
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/usr/bin/gdbus-codegen path which does not exist because it is not shipped by Fedora mingw packages.

Instead, we can rely on meson find_program() behaviour to do a better job based on its search order and capabilities.

Message-ID: <[email protected]>

---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meson.build +1 -1
index aecc381932..ed0d2086cb 100644
@@ -1036,7 +1036,7 @@ if not get_option('gio').auto() or have_system
     gio = not_found
   endif
   if gio.found()
-    gdbus_codegen = find_program(gio.get_variable('gdbus_codegen'),
+    gdbus_codegen = find_program('gdbus-codegen',
                                  required: get_option('gio'))
     gio_unix = dependency('gio-unix-2.0', required: get_option('gio'),
                           method: 'pkg-config')
Signature · 1 line
2.47.0
#16 lore raw

[PULL 06/20] ui/dbus: discard display messages on disable

In reply to [email protected]

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

Message-ID: <[email protected]>

---
 ui/dbus-listener.c | 2 ++
 1 file changed, 2 insertions(+)
ui/dbus-listener.c +2 -0
index c69afc05a8..19cb74e92b 100644
@@ -107,6 +107,8 @@ static void dbus_scanout_disable(DisplayChangeListener *dcl)
 {
     DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
 
+    ddl_discard_display_messages(ddl);
+
     qemu_dbus_display1_listener_call_disable(
         ddl->proxy, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
 }
Signature · 1 line
2.47.0
#17 lore raw

[PULL 07/20] ui/dbus: discard pending CursorDefine on new one

In reply to [email protected]

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

Similar to scanout updates, let's discard pending cursor changes.

Message-ID: <[email protected]>

---
 ui/dbus-listener.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
ui/dbus-listener.c +28 -0
index 19cb74e92b..eca6890ce6 100644
@@ -87,6 +87,7 @@ struct _DBusDisplayListener {
 
     guint dbus_filter;
     guint32 display_serial_to_discard;
+    guint32 cursor_serial_to_discard;
 };
 
 G_DEFINE_TYPE(DBusDisplayListener, dbus_display_listener, G_TYPE_OBJECT)
@@ -102,6 +103,14 @@ static void ddl_discard_display_messages(DBusDisplayListener *ddl)
     g_atomic_int_set(&ddl->display_serial_to_discard, serial);
 }
 
+static void ddl_discard_cursor_messages(DBusDisplayListener *ddl)
+{
+    guint32 serial = g_dbus_connection_get_last_serial(
+        g_dbus_proxy_get_connection(G_DBUS_PROXY(ddl->proxy)));
+
+    g_atomic_int_set(&ddl->cursor_serial_to_discard, serial);
+}
+
 #ifdef CONFIG_OPENGL
 static void dbus_scanout_disable(DisplayChangeListener *dcl)
 {
@@ -502,6 +511,8 @@ static void dbus_cursor_dmabuf(DisplayChangeListener *dcl,
         return;
     }
 
+    ddl_discard_cursor_messages(ddl);
+
     egl_dmabuf_import_texture(dmabuf);
     texture = qemu_dmabuf_get_texture(dmabuf);
     if (!texture) {
@@ -745,6 +756,8 @@ static void dbus_cursor_define(DisplayChangeListener *dcl,
     DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
     GVariant *v_data = NULL;
 
+    ddl_discard_cursor_messages(ddl);
+
     v_data = g_variant_new_from_data(
         G_VARIANT_TYPE("ay"),
         c->data,
@@ -1028,6 +1041,21 @@ dbus_filter(GDBusConnection *connection,
         }
     }
 
+    discard_serial = g_atomic_int_get(&ddl->cursor_serial_to_discard);
+    if (serial <= discard_serial) {
+        const gchar *member = g_dbus_message_get_member(message);
+        static const char *const cursor_messages[] = {
+            "CursorDefine",
+            NULL
+        };
+
+        if (g_strv_contains(cursor_messages, member)) {
+            trace_dbus_filter(serial, discard_serial);
+            g_object_unref(message);
+            return NULL;
+        }
+    }
+
     return message;
 }
 
Signature · 1 line
2.47.0
#18 lore raw

[PULL 20/20] audio/pw: Report more accurate error when connecting to PipeWire fails

In reply to [email protected]

From: Michal Privoznik <[email protected]>

According to its man page [1], pw_context_connect() sets errno on failure:

Returns a Core on success or NULL with errno set on error.

It may be handy to see errno when figuring out why PipeWire failed to connect. That leaves us with just one possible path to reach 'fail_error' label which is then moved to that path and also its error message is adjusted slightly.

1: https://docs.pipewire.org/group__pw__core.html#ga5994e3a54e4ec718094ca02a1234815b

Message-ID: <3a78811ad5b0e87816b7616ab21d2eeef00b9c52.1726647033.git.mprivozn@redhat.com>

---
 audio/pwaudio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
audio/pwaudio.c +4 -4
index 3b14e04fbb..8e13b58286 100644
@@ -769,13 +769,15 @@ qpw_audio_init(Audiodev *dev, Error **errp)
     pw->core = pw_context_connect(pw->context, NULL, 0);
     if (pw->core == NULL) {
         pw_thread_loop_unlock(pw->thread_loop);
-        goto fail_error;
+        error_setg_errno(errp, errno, "Failed to connect to PipeWire instance");
+        goto fail;
     }
 
     if (pw_core_add_listener(pw->core, &pw->core_listener,
                              &core_events, pw) < 0) {
         pw_thread_loop_unlock(pw->thread_loop);
-        goto fail_error;
+        error_setg(errp, "Failed to add PipeWire listener");
+        goto fail;
     }
     if (wait_resync(pw) < 0) {
         pw_thread_loop_unlock(pw->thread_loop);
@@ -785,8 +787,6 @@ qpw_audio_init(Audiodev *dev, Error **errp)
 
     return g_steal_pointer(&pw);
 
-fail_error:
-    error_setg(errp, "Failed to initialize PW context");
 fail:
     if (pw->thread_loop) {
         pw_thread_loop_stop(pw->thread_loop);
Signature · 1 line
2.47.0
#19 lore raw

[PULL 15/20] ui/dbus: add Listener.Unix.Map interface XML

In reply to [email protected]

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

Message-ID: <[email protected]>

---
 ui/dbus-display1.xml | 47 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
ui/dbus-display1.xml +47 -0
index d5bb279698..e70f2848b7 100644
@@ -469,6 +469,53 @@
     <property name="Interfaces" type="as" access="read"/>
   </interface>
 
+  <!--
+      org.qemu.Display1.Listener.Unix.Map:
+
+      This optional client-side interface can complement
+      org.qemu.Display1.Listener on ``/org/qemu/Display1/Listener`` for
+      Unix-specific shared memory scanouts.
+  -->
+  <?if $(env.HOST_OS) != windows?>
+  <interface name="org.qemu.Display1.Listener.Unix.Map">
+    <!--
+        ScanoutMap:
+        @handle: the shared map FD.
+        @offset: mapping offset, in bytes.
+        @width: display width, in pixels.
+        @height: display height, in pixels.
+        @stride: stride, in bytes.
+        @pixman_format: image format (ex: ``PIXMAN_X8R8G8B8``).
+
+        Resize and update the display content with a shared map.
+    -->
+    <method name="ScanoutMap">
+      <arg type="h" name="handle" direction="in"/>
+      <arg type="u" name="offset" direction="in"/>
+      <arg type="u" name="width" direction="in"/>
+      <arg type="u" name="height" direction="in"/>
+      <arg type="u" name="stride" direction="in"/>
+      <arg type="u" name="pixman_format" direction="in"/>
+    </method>
+
+    <!--
+        UpdateMap:
+        @x: the X update position, in pixels.
+        @y: the Y update position, in pixels.
+        @width: the update width, in pixels.
+        @height: the update height, in pixels.
+
+        Update the display content with the current shared map and the given region.
+    -->
+    <method name="UpdateMap">
+      <arg type="i" name="x" direction="in"/>
+      <arg type="i" name="y" direction="in"/>
+      <arg type="i" name="width" direction="in"/>
+      <arg type="i" name="height" direction="in"/>
+    </method>
+  </interface>
+  <?endif?>
+
   <!--
       org.qemu.Display1.Listener.Win32.Map:
 
Signature · 1 line
2.47.0
#20 lore raw

[PULL 12/20] ui/surface: allocate shared memory on !win32

In reply to [email protected]

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

Use qemu_memfd_alloc() to allocate the display surface memory, which will fallback on tmpfile/mmap() on systems without memfd, and allow to share the display with other processes.

This is similar to how display memory is allocated on win32 since commit 09b4c198 ("console/win32: allocate shareable display surface").

Message-ID: <[email protected]>

---
 include/ui/surface.h |  6 ++++++
 ui/console.c         | 28 ++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)
include/ui/surface.h +6 -0
index 345b19169d..37d03be4af 100644
@@ -26,6 +26,9 @@ typedef struct DisplaySurface {
 #ifdef WIN32
     HANDLE handle;
     uint32_t handle_offset;
+#else
+    int shmfd;
+    uint32_t shmfd_offset;
 #endif
 } DisplaySurface;
 
@@ -40,6 +43,9 @@ DisplaySurface *qemu_create_placeholder_surface(int w, int h,
 #ifdef WIN32
 void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
                                           HANDLE h, uint32_t offset);
+#else
+void qemu_displaysurface_set_shmfd(DisplaySurface *surface,
+                                   int shmfd, uint32_t offset);
 #endif
 
 DisplaySurface *qemu_create_displaysurface(int width, int height);
ui/console.c +26 -2
index fdd76c2be4..3a2aaba3c7 100644
@@ -37,6 +37,7 @@
 #include "trace.h"
 #include "exec/memory.h"
 #include "qom/object.h"
+#include "qemu/memfd.h"
 
 #include "console-priv.h"
 
@@ -461,6 +462,15 @@ void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
     surface->handle = h;
     surface->handle_offset = offset;
 }
+#else
+void qemu_displaysurface_set_shmfd(DisplaySurface *surface,
+                                   int shmfd, uint32_t offset)
+{
+    assert(surface->shmfd == -1);
+
+    surface->shmfd = shmfd;
+    surface->shmfd_offset = offset;
+}
 #endif
 
 DisplaySurface *qemu_create_displaysurface(int width, int height)
@@ -469,12 +479,16 @@ DisplaySurface *qemu_create_displaysurface(int width, int height)
     void *bits = NULL;
 #ifdef WIN32
     HANDLE handle = NULL;
+#else
+    int shmfd = -1;
 #endif
 
     trace_displaysurface_create(width, height);
 
 #ifdef WIN32
     bits = qemu_win32_map_alloc(width * height * 4, &handle, &error_abort);
+#else
+    bits = qemu_memfd_alloc("displaysurface", width * height * 4, 0, &shmfd, &error_abort);
 #endif
 
     surface = qemu_create_displaysurface_from(
@@ -486,9 +500,13 @@ DisplaySurface *qemu_create_displaysurface(int width, int height)
 
 #ifdef WIN32
     qemu_displaysurface_win32_set_handle(surface, handle, 0);
-    pixman_image_set_destroy_function(surface->image,
-                                      qemu_pixman_shared_image_destroy, handle);
+    void *data = handle;
+#else
+    qemu_displaysurface_set_shmfd(surface, shmfd, 0);
+    void *data = GINT_TO_POINTER(shmfd);
 #endif
+    pixman_image_set_destroy_function(surface->image, qemu_pixman_shared_image_destroy, data);
+
     return surface;
 }
 
@@ -499,6 +517,9 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,
     DisplaySurface *surface = g_new0(DisplaySurface, 1);
 
     trace_displaysurface_create_from(surface, width, height, format);
+#ifndef WIN32
+    surface->shmfd = -1;
+#endif
     surface->image = pixman_image_create_bits(format,
                                               width, height,
                                               (void *)data, linesize);
@@ -512,6 +533,9 @@ DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image)
     DisplaySurface *surface = g_new0(DisplaySurface, 1);
 
     trace_displaysurface_create_pixman(surface);
+#ifndef WIN32
+    surface->shmfd = -1;
+#endif
     surface->image = pixman_image_ref(image);
 
     return surface;
Signature · 1 line
2.47.0
#21 lore raw

[PULL 03/20] ui/dbus: fix leak on message filtering

In reply to [email protected]

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

A filter function that wants to drop a message should return NULL, in which case it must also unref the message itself.

Fixes fa88b85de ("ui/dbus: filter out pending messages when scanout")

Message-ID: <[email protected]>

---
 ui/dbus-listener.c | 1 +
 1 file changed, 1 insertion(+)
ui/dbus-listener.c +1 -0
index a54123acea..434bd608f2 100644
@@ -1001,6 +1001,7 @@ dbus_filter(GDBusConnection *connection,
     serial = g_dbus_message_get_serial(message);
     if (serial <= ddl->out_serial_to_discard) {
         trace_dbus_filter(serial, ddl->out_serial_to_discard);
+        g_object_unref(message);
         return NULL;
     }
 
Signature · 1 line
2.47.0
#22 lore raw

[PULL 05/20] ui/dbus: fix filtering all update messages

In reply to [email protected]

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

Filtering pending messages when a new scanout is given shouldn't discard pending cursor changes, for example.

Since filtering happens in a different thread, use atomic set/get.

Fixes fa88b85dea ("ui/dbus: filter out pending messages when scanout")

Message-ID: <[email protected]>

---
 ui/dbus-listener.c | 45 +++++++++++++++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 12 deletions(-)
ui/dbus-listener.c +33 -12
index 434bd608f2..c69afc05a8 100644
@@ -26,6 +26,7 @@
 #include "qapi/error.h"
 #include "sysemu/sysemu.h"
 #include "dbus.h"
+#include "glib.h"
 #ifdef G_OS_UNIX
 #include <gio/gunixfdlist.h>
 #endif
@@ -85,7 +86,7 @@ struct _DBusDisplayListener {
 #endif
 
     guint dbus_filter;
-    guint32 out_serial_to_discard;
+    guint32 display_serial_to_discard;
 };
 
 G_DEFINE_TYPE(DBusDisplayListener, dbus_display_listener, G_TYPE_OBJECT)
@@ -93,10 +94,12 @@ G_DEFINE_TYPE(DBusDisplayListener, dbus_display_listener, G_TYPE_OBJECT)
 static void dbus_gfx_update(DisplayChangeListener *dcl,
                             int x, int y, int w, int h);
 
-static void ddl_discard_pending_messages(DBusDisplayListener *ddl)
+static void ddl_discard_display_messages(DBusDisplayListener *ddl)
 {
-    ddl->out_serial_to_discard = g_dbus_connection_get_last_serial(
+    guint32 serial = g_dbus_connection_get_last_serial(
         g_dbus_proxy_get_connection(G_DBUS_PROXY(ddl->proxy)));
+
+    g_atomic_int_set(&ddl->display_serial_to_discard, serial);
 }
 
 #ifdef CONFIG_OPENGL
@@ -290,7 +293,7 @@ static void dbus_scanout_dmabuf(DisplayChangeListener *dcl,
         return;
     }
 
-    ddl_discard_pending_messages(ddl);
+    ddl_discard_display_messages(ddl);
 
     width = qemu_dmabuf_get_width(dmabuf);
     height = qemu_dmabuf_get_height(dmabuf);
@@ -338,7 +341,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)
         return false;
     }
 
-    ddl_discard_pending_messages(ddl);
+    ddl_discard_display_messages(ddl);
 
     if (!qemu_dbus_display1_listener_win32_map_call_scanout_map_sync(
             ddl->map_proxy,
@@ -401,7 +404,7 @@ dbus_scanout_share_d3d_texture(
         return false;
     }
 
-    ddl_discard_pending_messages(ddl);
+    ddl_discard_display_messages(ddl);
 
     qemu_dbus_display1_listener_win32_d3d11_call_scanout_texture2d(
         ddl->d3d11_proxy,
@@ -659,7 +662,7 @@ static void ddl_scanout(DBusDisplayListener *ddl)
         surface_stride(ddl->ds) * surface_height(ddl->ds), TRUE,
         (GDestroyNotify)pixman_image_unref, pixman_image_ref(ddl->ds->image));
 
-    ddl_discard_pending_messages(ddl);
+    ddl_discard_display_messages(ddl);
 
     qemu_dbus_display1_listener_call_scanout(
         ddl->proxy, surface_width(ddl->ds), surface_height(ddl->ds),
@@ -992,17 +995,35 @@ dbus_filter(GDBusConnection *connection,
             gpointer         user_data)
 {
     DBusDisplayListener *ddl = DBUS_DISPLAY_LISTENER(user_data);
-    guint32 serial;
+    guint32 serial, discard_serial;
 
     if (incoming) {
         return message;
     }
 
     serial = g_dbus_message_get_serial(message);
-    if (serial <= ddl->out_serial_to_discard) {
-        trace_dbus_filter(serial, ddl->out_serial_to_discard);
-        g_object_unref(message);
-        return NULL;
+
+    discard_serial = g_atomic_int_get(&ddl->display_serial_to_discard);
+    if (serial <= discard_serial) {
+        const char *member = g_dbus_message_get_member(message);
+        static const char *const display_messages[] = {
+            "Scanout",
+            "Update",
+#ifdef CONFIG_GBM
+            "ScanoutDMABUF",
+            "UpdateDMABUF",
+#endif
+            "ScanoutMap",
+            "UpdateMap",
+            "Disable",
+            NULL,
+        };
+
+        if (g_strv_contains(display_messages, member)) {
+            trace_dbus_filter(serial, discard_serial);
+            g_object_unref(message);
+            return NULL;
+        }
     }
 
     return message;
Signature · 1 line
2.47.0
#23 lore raw

[PULL 19/20] tests: add basic -display dbus Map.Unix test

In reply to [email protected]

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

Only check we eventually get a shared memory scanout.

Message-ID: <[email protected]>

---
 tests/qtest/dbus-display-test.c | 72 ++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 5 deletions(-)
tests/qtest/dbus-display-test.c +67 -5
index 0390bdcb41..f7fc873bfb 100644
@@ -2,9 +2,14 @@
 #include "qemu/sockets.h"
 #include "qemu/dbus.h"
 #include "qemu/sockets.h"
+#include "glib.h"
+#include "glibconfig.h"
 #include <gio/gio.h>
 #include <gio/gunixfdlist.h>
 #include "libqtest.h"
+#ifndef WIN32
+#include <sys/mman.h>
+#endif
 #include "ui/dbus-display1.h"
 
 static GDBusConnection*
@@ -82,6 +87,7 @@ typedef struct TestDBusConsoleRegister {
     GThread *thread;
     GDBusConnection *listener_conn;
     GDBusObjectManagerServer *server;
+    bool with_map;
 } TestDBusConsoleRegister;
 
 static gboolean listener_handle_scanout(
@@ -94,13 +100,49 @@ static gboolean listener_handle_scanout(
     GVariant *arg_data,
     TestDBusConsoleRegister *test)
 {
+    if (!test->with_map) {
+        g_main_loop_quit(test->loop);
+    }
+
+    return DBUS_METHOD_INVOCATION_HANDLED;
+}
+
+#ifndef WIN32
+static gboolean listener_handle_scanout_map(
+    QemuDBusDisplay1ListenerUnixMap *object,
+    GDBusMethodInvocation *invocation,
+    GUnixFDList *fd_list,
+    GVariant *arg_handle,
+    guint arg_offset,
+    guint arg_width,
+    guint arg_height,
+    guint arg_stride,
+    guint arg_pixman_format,
+    TestDBusConsoleRegister *test)
+{
+    int fd = -1;
+    gint32 handle = g_variant_get_handle(arg_handle);
+    g_autoptr(GError) error = NULL;
+    void *addr = NULL;
+    size_t len = arg_height * arg_stride;
+
+    g_assert_cmpuint(g_unix_fd_list_get_length(fd_list), ==, 1);
+    fd = g_unix_fd_list_get(fd_list, handle, &error);
+    g_assert_no_error(error);
+
+    addr = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, arg_offset);
+    g_assert_no_errno(addr == MAP_FAILED ? -1 : 0);
+    g_assert_no_errno(munmap(addr, len));
+
     g_main_loop_quit(test->loop);
 
+    close(fd);
     return DBUS_METHOD_INVOCATION_HANDLED;
 }
+#endif
 
 static void
-test_dbus_console_setup_listener(TestDBusConsoleRegister *test)
+test_dbus_console_setup_listener(TestDBusConsoleRegister *test, bool with_map)
 {
     g_autoptr(GDBusObjectSkeleton) listener = NULL;
     g_autoptr(QemuDBusDisplay1ListenerSkeleton) iface = NULL;
@@ -114,6 +156,25 @@ test_dbus_console_setup_listener(TestDBusConsoleRegister *test)
                      NULL);
     g_dbus_object_skeleton_add_interface(listener,
                                          G_DBUS_INTERFACE_SKELETON(iface));
+    if (with_map) {
+#ifdef WIN32
+        g_test_skip("map test lacking on win32");
+        return;
+#else
+        g_autoptr(QemuDBusDisplay1ListenerUnixMapSkeleton) iface_map =
+            QEMU_DBUS_DISPLAY1_LISTENER_UNIX_MAP_SKELETON(
+                qemu_dbus_display1_listener_unix_map_skeleton_new());
+
+        g_object_connect(iface_map,
+                         "signal::handle-scanout-map", listener_handle_scanout_map, test,
+                         NULL);
+        g_dbus_object_skeleton_add_interface(listener,
+                                             G_DBUS_INTERFACE_SKELETON(iface_map));
+        g_object_set(iface, "interfaces",
+            (const gchar *[]) { "org.qemu.Display1.Listener.Unix.Map", NULL },
+            NULL);
+#endif
+    }
     g_dbus_object_manager_server_export(test->server, listener);
     g_dbus_object_manager_server_set_connection(test->server,
                                                 test->listener_conn);
@@ -145,7 +206,7 @@ test_dbus_console_registered(GObject *source_object,
     g_assert_no_error(err);
 
     test->listener_conn = g_thread_join(test->thread);
-    test_dbus_console_setup_listener(test);
+    test_dbus_console_setup_listener(test, test->with_map);
 }
 
 static gpointer
@@ -155,7 +216,7 @@ test_dbus_p2p_server_setup_thread(gpointer data)
 }
 
 static void
-test_dbus_display_console(void)
+test_dbus_display_console(const void* data)
 {
     g_autoptr(GError) err = NULL;
     g_autoptr(GDBusConnection) conn = NULL;
@@ -163,7 +224,7 @@ test_dbus_display_console(void)
     g_autoptr(GMainLoop) loop = NULL;
     QTestState *qts = NULL;
     int pair[2];
-    TestDBusConsoleRegister test = { 0, };
+    TestDBusConsoleRegister test = { 0, .with_map = GPOINTER_TO_INT(data) };
 #ifdef WIN32
     WSAPROTOCOL_INFOW info;
     g_autoptr(GVariant) listener = NULL;
@@ -299,7 +360,8 @@ main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
 
     qtest_add_func("/dbus-display/vm", test_dbus_display_vm);
-    qtest_add_func("/dbus-display/console", test_dbus_display_console);
+    qtest_add_data_func("/dbus-display/console", GINT_TO_POINTER(false), test_dbus_display_console);
+    qtest_add_data_func("/dbus-display/console/map", GINT_TO_POINTER(true), test_dbus_display_console);
     qtest_add_func("/dbus-display/keyboard", test_dbus_display_keyboard);
 
     return g_test_run();
Signature · 1 line
2.47.0
#24 lore raw
In reply to [email protected]
Quoted 9 lines · On Mon, 14 Oct 2024 at 14:39, <[email protected]> wrote:

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

The following changes since commit 3860a2a8de56fad71db42f4ad120eb7eff03b51f:

Merge tag 'pull-tcg-20241013' of https://gitlab.com/rth7680/qemu into staging (2024-10-14 11:12:34 +0100)

are available in the Git repository at:

Quoted 9 lines

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

for you to fetch changes up to 4cd78a3db2478d3c1527905a26c9d3fbee83ccac:

audio/pw: Report more accurate error when connecting to PipeWire fails (2024-10-14 17:35:24 +0400)

----------------------------------------------------------------
UI-related fixes & shareable 2d memory with -display dbus

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/9.2
for any user-visible changes.

-- PMM

#25 lore raw
In reply to [email protected]
Quoted 40 lines · On 14.10.2024 16:39, [email protected] wrote:

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

The following changes since commit 3860a2a8de56fad71db42f4ad120eb7eff03b51f:

   Merge tag 'pull-tcg-20241013' of https://gitlab.com/rth7680/qemu into staging (2024-10-14 11:12:34 +0100)

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 4cd78a3db2478d3c1527905a26c9d3fbee83ccac:

audio/pw: Report more accurate error when connecting to PipeWire fails (2024-10-14 17:35:24 +0400)

----------------------------------------------------------------
UI-related fixes & shareable 2d memory with -display dbus

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

Marc-André Lureau (19):
hw/audio/hda: free timer on exit
hw/audio/hda: fix memory leak on audio setup ui/dbus: fix leak on message filtering
ui/win32: fix potential use-after-free with dbus shared memory ui/dbus: fix filtering all update messages
ui/dbus: discard display messages on disable ui/dbus: discard pending CursorDefine on new one util/memfd: report potential errors on free ui/pixman: generalize shared_image_destroy
ui/dbus: do not limit to one listener per connection / bus name ui/dbus: add trace for can_share_map
ui/surface: allocate shared memory on !win32
meson: find_program('gdbus-codegen') directly ui/dbus: make Listener.Win32.Map win32-specific ui/dbus: add Listener.Unix.Map interface XML ui/dbus: implement Unix.Map
virtio-gpu: allocate shareable 2d resources on !win32
ui: refactor using a common qemu_pixman_shareable
tests: add basic -display dbus Map.Unix test

Quoted 2 lines

Michal Privoznik (1):
audio/pw: Report more accurate error when connecting to PipeWire fails

Or, actually, here (I replied to a wrong thread) -- is there something for qemu-stable in there? First 7 changes seems to be good fit there.

Thanks,

/mjt

#26 lore raw

Hi Michael

Quoted 44 lines · Michael Tokarev
Quoted 3 lines · On 14.10.2024 16:39, [email protected] wrote:

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

The following changes since commit

3860a2a8de56fad71db42f4ad120eb7eff03b51f:

Quoted 2 lines
   Merge tag 'pull-tcg-20241013' of https://gitlab.com/rth7680/qemu

into staging (2024-10-14 11:12:34 +0100)

Quoted 8 lines

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 4cd78a3db2478d3c1527905a26c9d3fbee83ccac:

audio/pw: Report more accurate error when connecting to PipeWire

fails (2024-10-14 17:35:24 +0400)

Quoted 27 lines

----------------------------------------------------------------
UI-related fixes & shareable 2d memory with -display dbus

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

Marc-André Lureau (19):
hw/audio/hda: free timer on exit
hw/audio/hda: fix memory leak on audio setup ui/dbus: fix leak on message filtering
ui/win32: fix potential use-after-free with dbus shared memory ui/dbus: fix filtering all update messages
ui/dbus: discard display messages on disable ui/dbus: discard pending CursorDefine on new one util/memfd: report potential errors on free ui/pixman: generalize shared_image_destroy
ui/dbus: do not limit to one listener per connection / bus name ui/dbus: add trace for can_share_map
ui/surface: allocate shared memory on !win32
meson: find_program('gdbus-codegen') directly ui/dbus: make Listener.Win32.Map win32-specific ui/dbus: add Listener.Unix.Map interface XML ui/dbus: implement Unix.Map
virtio-gpu: allocate shareable 2d resources on !win32
ui: refactor using a common qemu_pixman_shareable
tests: add basic -display dbus Map.Unix test

Quoted 6 lines
Quoted 2 lines

Michal Privoznik (1):
audio/pw: Report more accurate error when connecting to PipeWire fails

Or, actually, here (I replied to a wrong thread) -- is there something for qemu-stable in there? First 7 changes seems to be good fit there.

Or only the first 5. It would be nice to have a second look before!

thanks

Signature · 1 line
Marc-André Lureau
#27 lore raw
Quoted 10 lines · Marc-André Lureau

Hi Michael

> Marc-André Lureau (19):
>    hw/audio/hda: free timer on exit
>    hw/audio/hda: fix memory leak on audio setup
>    ui/dbus: fix leak on message filtering
>    ui/win32: fix potential use-after-free with dbus shared memory >    ui/dbus: fix filtering all update messages

Quoted 5 lines

Or, actually, here (I replied to a wrong thread) -- is there something for qemu-stable in there?  First 7 changes seems to be good fit there.

Or only the first 5. It would be nice to have a second look before!

So.. the second look has apparently been needed ;)

See https://gitlab.com/qemu-project/qemu/-/issues/2639

I'm not yet sure what's going on there, but will try to take a look hopefullt later today.

/mjt