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 12/16] ui/surface: allocate shared memory on !win32
Date: Mon, 7 Oct 2024 15:47:08 +0400 [thread overview]
Message-ID: <CAMxuvay2B_hwZ4eyqp_cRGe5XH1wWkHbVPDEOgBjScKAE7uosA@mail.gmail.com> (raw)
In-Reply-To: <24a91b5d-89a3-4338-874c-78aaf22b93ac@daynix.com>
On Sat, Oct 5, 2024 at 12:59 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>
> >
> > 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").
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > include/ui/surface.h | 8 ++++++++
> > ui/console.c | 30 ++++++++++++++++++++++++++++--
> > 2 files changed, 36 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/ui/surface.h b/include/ui/surface.h
> > index 345b19169d..dacf12ffe2 100644
> > --- a/include/ui/surface.h
> > +++ b/include/ui/surface.h
> > @@ -23,6 +23,10 @@ typedef struct DisplaySurface {
> > GLenum gltype;
> > GLuint texture;
> > #endif
> > +#ifndef WIN32
> > + int shmfd;
> > + uint32_t shmfd_offset;
> > +#endif
> > #ifdef WIN32
> > HANDLE handle;
>
> What about defining a new struct that contains either of shmfd or
> handle? We can then have a unified set of functions that uses the struct
> to allocate/free a shared pixman image and to set one to DisplaySurface.
Well, that structure is pretty much DisplaySurface. I am not sure if
it's valuable to introduce another abstraction.
>
> > uint32_t handle_offset;
> > @@ -37,6 +41,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);
> > +#ifndef WIN32
> > +void qemu_displaysurface_set_shmfd(DisplaySurface *surface,
> > + int shmfd, uint32_t offset);
> > +#endif
> > #ifdef WIN32
> > void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
> > HANDLE h, uint32_t offset);
> > diff --git a/ui/console.c b/ui/console.c
> > index fdd76c2be4..56f2462c3d 100644
> > --- a/ui/console.c
> > +++ b/ui/console.c
> > @@ -37,6 +37,7 @@
> > #include "trace.h"
> > #include "exec/memory.h"
> > #include "qom/object.h"
> > +#include "qemu/memfd.h"
> >
> > #include "console-priv.h"
> >
> > @@ -452,6 +453,17 @@ qemu_graphic_console_init(Object *obj)
> > {
> > }
> >
> > +#ifndef WIN32
> > +void qemu_displaysurface_set_shmfd(DisplaySurface *surface,
> > + int shmfd, uint32_t offset)
> > +{
> > + assert(surface->shmfd == -1);
> > +
> > + surface->shmfd = shmfd;
> > + surface->shmfd_offset = offset;
> > +}
> > +#endif
> > +
> > #ifdef WIN32
> > void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
> > HANDLE h, uint32_t offset)
> > @@ -469,12 +481,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 +502,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 +519,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 +535,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;
>
next prev parent reply other threads:[~2024-10-07 11:47 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
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 [this message]
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=CAMxuvay2B_hwZ4eyqp_cRGe5XH1wWkHbVPDEOgBjScKAE7uosA@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).