[PATCH v5 0/3] ui/cocoa: Run qemu_init in the main thread

Akihiko Odaki posted 3 patches 1 year, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220819132756.74641-1-akihiko.odaki@gmail.com
Maintainers: Alexander Bulekov <alxndr@bu.edu>, Paolo Bonzini <pbonzini@redhat.com>, Bandan Das <bsd@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Thomas Huth <thuth@redhat.com>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, Laurent Vivier <lvivier@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Akihiko Odaki <akihiko.odaki@gmail.com>, Gerd Hoffmann <kraxel@redhat.com>
docs/devel/fuzzing.rst   |   4 +-
include/qemu-main.h      |   3 +-
include/qemu/main-loop.h |  13 ----
include/sysemu/sysemu.h  |   2 +-
meson.build              |  10 +--
softmmu/main.c           |  10 +--
softmmu/vl.c             |   2 +-
tests/qtest/fuzz/fuzz.c  |   2 +-
ui/cocoa.m               | 144 ++++++++++++++-------------------------
9 files changed, 64 insertions(+), 126 deletions(-)
[PATCH v5 0/3] ui/cocoa: Run qemu_init in the main thread
Posted by Akihiko Odaki 1 year, 7 months ago
This work is based on:
https://patchew.org/QEMU/20220317125534.38706-1-philippe.mathieu.daude@gmail.com/

Simplify the initialization dance by running qemu_init() in the main
thread before the Cocoa event loop starts. The secondary thread only
runs only qemu_main_loop() and qemu_cleanup().

This fixes a case where addRemovableDevicesMenuItems() calls
qmp_query_block() while expecting the main thread to still hold
the BQL.

Overriding the code after calling qemu_init() is done by dynamically
replacing a function pointer variable, qemu_main when initializing
ui/cocoa, which unifies the static implementation of main() for
builds with ui/cocoa and ones without ui/cocoa.

v5: Rebased to 4d65d4ba57372c57a1236fb5cb789dbcc100645c, restoring the
    exit() call in call_qemu_main() and dropping Reviewed-by from
    "ui/cocoa: Run qemu_init in the main thread".

v4: Asynchronously call -[NSApplication terminate:] to avoid potential
    deadlock with qemu_thread_join(). (Paolo Bonzini)

v3: Document functions involved in startup. (Peter Maydell)

v2: Restore allow_events flag to fix the crash reported by
    Philippe Mathieu-Daudé.

Akihiko Odaki (3):
  ui/cocoa: Run qemu_init in the main thread
  Revert "main-loop: Disable block backend global state assertion on
    Cocoa"
  meson: Allow to enable gtk and sdl while cocoa is enabled

 docs/devel/fuzzing.rst   |   4 +-
 include/qemu-main.h      |   3 +-
 include/qemu/main-loop.h |  13 ----
 include/sysemu/sysemu.h  |   2 +-
 meson.build              |  10 +--
 softmmu/main.c           |  10 +--
 softmmu/vl.c             |   2 +-
 tests/qtest/fuzz/fuzz.c  |   2 +-
 ui/cocoa.m               | 144 ++++++++++++++-------------------------
 9 files changed, 64 insertions(+), 126 deletions(-)

-- 
2.32.1 (Apple Git-133)


Re: [PATCH v5 0/3] ui/cocoa: Run qemu_init in the main thread
Posted by Gerd Hoffmann 1 year, 6 months ago
On Fri, Aug 19, 2022 at 10:27:53PM +0900, Akihiko Odaki wrote:
> This work is based on:
> https://patchew.org/QEMU/20220317125534.38706-1-philippe.mathieu.daude@gmail.com/
> 
> Simplify the initialization dance by running qemu_init() in the main
> thread before the Cocoa event loop starts. The secondary thread only
> runs only qemu_main_loop() and qemu_cleanup().
> 
> This fixes a case where addRemovableDevicesMenuItems() calls
> qmp_query_block() while expecting the main thread to still hold
> the BQL.
> 
> Overriding the code after calling qemu_init() is done by dynamically
> replacing a function pointer variable, qemu_main when initializing
> ui/cocoa, which unifies the static implementation of main() for
> builds with ui/cocoa and ones without ui/cocoa.
> 
> v5: Rebased to 4d65d4ba57372c57a1236fb5cb789dbcc100645c, restoring the
>     exit() call in call_qemu_main() and dropping Reviewed-by from
>     "ui/cocoa: Run qemu_init in the main thread".
> 
> v4: Asynchronously call -[NSApplication terminate:] to avoid potential
>     deadlock with qemu_thread_join(). (Paolo Bonzini)
> 
> v3: Document functions involved in startup. (Peter Maydell)
> 
> v2: Restore allow_events flag to fix the crash reported by
>     Philippe Mathieu-Daudé.
> 
> Akihiko Odaki (3):
>   ui/cocoa: Run qemu_init in the main thread
>   Revert "main-loop: Disable block backend global state assertion on
>     Cocoa"
>   meson: Allow to enable gtk and sdl while cocoa is enabled

Patches added to queue.

thanks,
  Gerd