qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/19] Enable QEMU TCI to run 32bit guests on browsers
@ 2025-04-16  8:14 Kohei Tokunaga
  2025-04-16  8:14 ` [PATCH 01/19] hw/core/loader.c: Fix type conflict of GLib function pointers Kohei Tokunaga
                   ` (18 more replies)
  0 siblings, 19 replies; 54+ messages in thread
From: Kohei Tokunaga @ 2025-04-16  8:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
	Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
	Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
	Francisco Iglesias, Vikram Garhwal, Jason Wang,
	Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
	Peter Maydell, Zhao Liu, Nicholas Piggin, Daniel Henrique Barboza,
	David Hildenbrand, Richard Henderson, Ilya Leoshkevich,
	Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc, qemu-s390x

This patch series is split from the original "Enable QEMU to run on
browsers" series, focusing solely on the essential code changes needed to
compile QEMU TCI with Emscripten. It also inclues fixes based on feedback
received in the original series, thank you for the comments.

# Supported features in this series

This patch series enables TCI interpreter mode with 32bit guest
support. While the original series included the non-TCI backend and 9pfs
patches, those components are not included here. They will be reintroduced
in follow-up series after the foundational patches have been merged.

# Emscripten-Based Coroutine Backend

Emscripten does not support couroutine methods currently used by QEMU but
provides a coroutine implementation called "fiber". This patch series
introduces a coroutine backend using fiber. However, fiber does not support
submitting coroutines to other threads. As a result, this patch series
doesn't support components like hw/9pfs, which rely on that behavior.

# Overview of build process

This section provides an overview of the build process for compiling QEMU
using Emscripten. Full instructions are available in the sample
repository[1].

To compile QEMU with Emscripten, the following dependencies are required.
The emsdk-wasm32-cross.docker environment includes all necessary components
and can be used as the build environment:

- Emscripten SDK (emsdk) v3.1.50
- Libraries cross-compiled with Emscripten (refer to
  emsdk-wasm32-cross.docker for build steps)
  - GLib v2.84.0
  - zlib v1.3.1
  - libffi v3.4.7
  - Pixman v0.44.2

QEMU can be compiled using Emscripten's emconfigure and emmake, which
automatically set environment variables such as CC for targeting Emscripten.

emconfigure configure --static --disable-tools \
                      --target-list=arm-softmmu --enable-tcg-interpreter
emmake make -j$(nproc)

This process generates the following files:

- qemu-system-arm.js
- qemu-system-arm.wasm
- qemu-system-arm.worker.js

Guest images can be packaged using Emscripten's file_packager.py tool.
For example, if the images are stored in a directory named "pack", the
following command packages them, allowing QEMU to access them through
Emscripten's virtual filesystem:

/path/to/file_packager.py qemu-system-arm.data --preload pack > load.js

This process generates the following files:

- qemu-system-arm.data
- load.js

Emscripten allows passing arguments to the QEMU command via the Module
object in JavaScript:

Module['arguments'] = [
    '-nographic', '-m', '512M', '-machine', 'virt',
    '-L', 'pack/',
    '-global', 'virtio-mmio.force-legacy=false',
    '-device', 'virtio-blk-device,drive=d0',
    '-drive', 'file=pack/rootfs.bin,if=none,format=raw,id=d0',
    '-kernel', 'pack/kernel.img',
    '-append', 'console=ttyAMA0 root=/dev/vda loglevel=7',
];

The sample repository[1] provides a complete setup, including an HTML file
that implements a terminal UI.

[1] https://github.com/ktock/qemu-wasm-sample/tree/tcidev

# Additional references

- Original patch series "Enable QEMU to run on browsers":
  https://patchew.org/QEMU/cover.1744032780.git.ktokunaga.mail@gmail.com/
- A talk at FOSDEM 2025:
  https://fosdem.org/2025/schedule/event/fosdem-2025-6290-running-qemu-inside-browser/

Kohei Tokunaga (19):
  hw/core/loader.c: Fix type conflict of GLib function pointers
  qom/object.c: Fix type conflict of GLib function pointers
  system/vl.c: Fix type conflict of GLib function pointers
  target/arm/helper.c: Fix type conflict of GLib function pointers
  target/i386/cpu.c: Fix type conflict of GLib function pointers
  contrib/plugins: Fix type conflict of GLib function pointers
  hw/net/can: Fix type conflict of GLib function pointers
  target/ppc: Fix type conflict of GLib function pointers
  target/s390x: Fix type conflict of GLib function pointers
  include/glib-compat.h: Poison g_list_sort and g_slist_sort
  util/cacheflush.c: Update cache flushing mechanism for Emscripten
  block: Update block to compile with Emscripten
  include/qemu/osdep.h: Add Emscripten-specific OS dependencies
  Disable options unsupported on Emscripten
  util/mmap-alloc: Add qemu_ram_mmap implementation for emscripten
  util: Add coroutine backend for emscripten
  meson: Add wasm build in build scripts
  gitlab: Enable CI for wasm build
  MAINTAINERS: Update MAINTAINERS file for wasm-related files

 .gitlab-ci.d/buildtest-template.yml           |  27 ++++
 .gitlab-ci.d/buildtest.yml                    |   9 ++
 .gitlab-ci.d/container-cross.yml              |   5 +
 MAINTAINERS                                   |  10 ++
 block/file-posix.c                            |   6 +
 configs/meson/emscripten.txt                  |   8 +
 configure                                     |   7 +
 contrib/plugins/cache.c                       |  12 +-
 contrib/plugins/cflow.c                       |  10 +-
 contrib/plugins/hotblocks.c                   |   4 +-
 contrib/plugins/hotpages.c                    |   4 +-
 contrib/plugins/howvec.c                      |   4 +-
 contrib/plugins/hwprofile.c                   |   8 +-
 hw/core/loader.c                              |   4 +-
 hw/net/can/xlnx-versal-canfd.c                |   4 +-
 include/glib-compat.h                         |   6 +
 include/qemu/cacheflush.h                     |   3 +-
 include/qemu/osdep.h                          |   8 +-
 include/system/os-posix.h                     |   3 +-
 include/system/os-wasm.h                      | 105 +++++++++++++
 meson.build                                   |  25 ++-
 meson_options.txt                             |   2 +-
 os-wasm.c                                     | 119 ++++++++++++++
 qemu-options.hx                               |   4 +-
 qom/object.c                                  |   7 +-
 scripts/meson-buildoptions.sh                 |   2 +-
 stubs/emscripten.c                            |  13 ++
 stubs/meson.build                             |   4 +
 system/vl.c                                   |   8 +-
 target/arm/helper.c                           |   4 +-
 target/i386/cpu.c                             |  11 +-
 target/ppc/cpu_init.c                         |   4 +-
 target/s390x/cpu_models.c                     |   4 +-
 .../dockerfiles/emsdk-wasm32-cross.docker     | 145 ++++++++++++++++++
 tests/tcg/plugins/mem.c                       |   4 +-
 tests/tcg/plugins/syscall.c                   |   4 +-
 util/cacheflush.c                             |   3 +-
 util/coroutine-wasm.c                         | 127 +++++++++++++++
 util/mmap-alloc.c                             |  18 +++
 39 files changed, 697 insertions(+), 58 deletions(-)
 create mode 100644 configs/meson/emscripten.txt
 create mode 100644 include/system/os-wasm.h
 create mode 100644 os-wasm.c
 create mode 100644 stubs/emscripten.c
 create mode 100644 tests/docker/dockerfiles/emsdk-wasm32-cross.docker
 create mode 100644 util/coroutine-wasm.c

-- 
2.25.1



^ permalink raw reply	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2025-04-21  3:24 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16  8:14 [PATCH 00/19] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 01/19] hw/core/loader.c: Fix type conflict of GLib function pointers Kohei Tokunaga
2025-04-16  8:28   ` Daniel P. Berrangé
2025-04-16  9:00     ` Paolo Bonzini
2025-04-16  9:12       ` Daniel P. Berrangé
2025-04-16  9:31         ` Paolo Bonzini
2025-04-17  9:18           ` Kohei Tokunaga
2025-04-16  9:14       ` Thomas Huth
2025-04-16  9:35     ` Philippe Mathieu-Daudé
2025-04-17  9:07       ` Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 02/19] qom/object.c: " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 03/19] system/vl.c: " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 04/19] target/arm/helper.c: " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 05/19] target/i386/cpu.c: " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 06/19] contrib/plugins: " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 07/19] hw/net/can: " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 08/19] target/ppc: " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 09/19] target/s390x: " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 10/19] include/glib-compat.h: Poison g_list_sort and g_slist_sort Kohei Tokunaga
2025-04-16 11:56   ` BALATON Zoltan
2025-04-17  9:20     ` Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 11/19] util/cacheflush.c: Update cache flushing mechanism for Emscripten Kohei Tokunaga
2025-04-16  9:37   ` Philippe Mathieu-Daudé
2025-04-17  9:27     ` Kohei Tokunaga
2025-04-17  9:50       ` Philippe Mathieu-Daudé
2025-04-16  8:14 ` [PATCH 12/19] block: Update block to compile with Emscripten Kohei Tokunaga
2025-04-16  9:00   ` Philippe Mathieu-Daudé
2025-04-16  9:33     ` Philippe Mathieu-Daudé
2025-04-16 15:45       ` Richard Henderson
2025-04-17  9:32       ` Kohei Tokunaga
2025-04-17  9:55         ` Philippe Mathieu-Daudé
2025-04-18  6:53           ` Kohei Tokunaga
2025-04-18  9:51             ` Philippe Mathieu-Daudé
2025-04-17  9:43     ` Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 13/19] include/qemu/osdep.h: Add Emscripten-specific OS dependencies Kohei Tokunaga
2025-04-17  9:58   ` Philippe Mathieu-Daudé
2025-04-18  6:55     ` Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 14/19] Disable options unsupported on Emscripten Kohei Tokunaga
2025-04-16  9:03   ` Philippe Mathieu-Daudé
2025-04-17  9:33     ` Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 15/19] util/mmap-alloc: Add qemu_ram_mmap implementation for emscripten Kohei Tokunaga
2025-04-16  9:18   ` Philippe Mathieu-Daudé
2025-04-17  9:35     ` Kohei Tokunaga
2025-04-21  3:23       ` Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 16/19] util: Add coroutine backend " Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 17/19] meson: Add wasm build in build scripts Kohei Tokunaga
2025-04-16  9:22   ` Philippe Mathieu-Daudé
2025-04-17  9:37     ` Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 18/19] gitlab: Enable CI for wasm build Kohei Tokunaga
2025-04-16  9:23   ` Philippe Mathieu-Daudé
2025-04-17  9:39     ` Kohei Tokunaga
2025-04-16  8:14 ` [PATCH 19/19] MAINTAINERS: Update MAINTAINERS file for wasm-related files Kohei Tokunaga
2025-04-16  9:34   ` Philippe Mathieu-Daudé
2025-04-17  9:40     ` Kohei Tokunaga

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).