From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org,
"Michael S. Tsirkin" <mst@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Laurent Vivier" <lvivier@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
belmouss@redhat.com, "Paolo Bonzini" <pbonzini@redhat.com>,
"Thomas Huth" <thuth@redhat.com>
Subject: Re: [PATCH 09/16] ui/pixman: generalize shared_image_destroy
Date: Mon, 7 Oct 2024 15:13:17 +0400 [thread overview]
Message-ID: <CAMxuvawRGtZqZmXAS+KOQr61UJc1vDPjRKcmmAg_MKpDWZAU7w@mail.gmail.com> (raw)
In-Reply-To: <e02d28c2-d192-49d9-9f83-d45204e63642@daynix.com>
Hi
On Sat, Oct 5, 2024 at 12:50 PM Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
>
> On 2024/10/03 20:22, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > Learn to free memfd-allocated shared memory.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > 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(-)
> >
> > diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h
> > index e3dd72b9e3..a97f56d09a 100644
> > --- a/include/ui/qemu-pixman.h
> > +++ b/include/ui/qemu-pixman.h
> > @@ -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)
> >
> > diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> > index 017a0f170c..77f6e76f23 100644
> > --- a/hw/display/virtio-gpu.c
> > +++ b/hw/display/virtio-gpu.c
> > @@ -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);
> > diff --git a/ui/console.c b/ui/console.c
> > index 8f416ff0b9..fdd76c2be4 100644
> > --- a/ui/console.c
> > +++ b/ui/console.c
> > @@ -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;
> > }
> > diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c
> > index 3870e1a215..43050ab7c5 100644
> > --- a/ui/qemu-pixman.c
> > +++ b/ui/qemu-pixman.c
> > @@ -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);
> > +
> > +#ifndef WIN32
>
> I think it is better to have #ifdef instead of #ifndef. It is a common
> pattern to have #ifdef and #elif defined() for the platform-specific
> code and follow them with #else that implements the generic code. This
> allows supporting multiple platform conditions.
indeed! thanks
>
> > + 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);
> > +#else
> > HANDLE handle = data;
> >
> > - qemu_win32_map_free(
> > - pixman_image_get_data(image),
> > - handle,
> > - &error_warn
> > - );
> > -}
> > + qemu_win32_map_free(ptr, handle, &error_warn);
> > #endif
> > +}
>
next prev parent reply other threads:[~2024-10-07 11:13 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-03 11:22 [PATCH 00/16] UI-related fixes & shareable 2d memory with -display dbus marcandre.lureau
2024-10-03 11:22 ` [PATCH 01/16] hw/audio/hda: free timer on exit marcandre.lureau
2024-10-03 11:22 ` [PATCH 02/16] hw/audio/hda: fix memory leak on audio setup marcandre.lureau
2024-10-03 11:22 ` [PATCH 03/16] ui/dbus: fix leak on message filtering marcandre.lureau
2024-10-03 11:22 ` [PATCH 04/16] ui/win32: fix potential use-after-free with dbus shared memory marcandre.lureau
2024-10-03 11:22 ` [PATCH 05/16] ui/dbus: fix filtering all update messages marcandre.lureau
2024-10-05 8:44 ` Akihiko Odaki
2024-10-07 8:59 ` Marc-André Lureau
2024-10-03 11:22 ` [PATCH 06/16] ui/dbus: discard display messages on disable marcandre.lureau
2024-10-03 11:22 ` [PATCH 07/16] ui/dbus: discard pending CursorDefine on new one marcandre.lureau
2024-10-05 8:45 ` Akihiko Odaki
2024-10-07 11:02 ` Marc-André Lureau
2024-10-03 11:22 ` [PATCH 08/16] util/memfd: report potential errors on free marcandre.lureau
2024-10-03 11:22 ` [PATCH 09/16] ui/pixman: generalize shared_image_destroy marcandre.lureau
2024-10-05 8:50 ` Akihiko Odaki
2024-10-07 11:13 ` Marc-André Lureau [this message]
2024-10-03 11:22 ` [PATCH 10/16] ui/dbus: do not limit to one listener per connection / bus name marcandre.lureau
2024-10-03 11:22 ` [PATCH 11/16] ui/dbus: add trace for can_share_map marcandre.lureau
2024-10-03 11:22 ` [PATCH 12/16] ui/surface: allocate shared memory on !win32 marcandre.lureau
2024-10-05 8:59 ` Akihiko Odaki
2024-10-07 11:47 ` Marc-André Lureau
2024-10-07 12:01 ` Akihiko Odaki
2024-10-03 11:22 ` [PATCH 13/16] ui/dbus: add Listener.Unix.Map interface XML marcandre.lureau
2024-10-03 11:22 ` [PATCH 14/16] ui/dbus: implement Unix.Map marcandre.lureau
2024-10-03 11:22 ` [PATCH 15/16] virtio-gpu: allocate shareable 2d resources on !win32 marcandre.lureau
2024-10-03 11:22 ` [PATCH 16/16] tests: add basic -display dbus Map.Unix test marcandre.lureau
2024-10-05 8:31 ` Akihiko Odaki
2024-10-07 12:42 ` Marc-André Lureau
2024-10-07 17:34 ` Akihiko Odaki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMxuvawRGtZqZmXAS+KOQr61UJc1vDPjRKcmmAg_MKpDWZAU7w@mail.gmail.com \
--to=marcandre.lureau@redhat.com \
--cc=akihiko.odaki@daynix.com \
--cc=belmouss@redhat.com \
--cc=kraxel@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).