From: Kohei Tokunaga <ktokunaga.mail@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Thomas Huth" <thuth@redhat.com>, "Kevin Wolf" <kwolf@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Kohei Tokunaga" <ktokunaga.mail@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
"Pavel Pisa" <pisa@cmp.felk.cvut.cz>,
"Francisco Iglesias" <francisco.iglesias@amd.com>,
"Vikram Garhwal" <vikram.garhwal@bytedance.com>,
"Jason Wang" <jasowang@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Peter Xu" <peterx@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Zhao Liu" <zhao1.liu@intel.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
qemu-block@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org,
qemu-s390x@nongnu.org
Subject: [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers
Date: Tue, 22 Apr 2025 14:27:04 +0900 [thread overview]
Message-ID: <cover.1745295397.git.ktokunaga.mail@gmail.com> (raw)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
- Fixed typo in the comment in include/glib-compat.h: s/insted/instead/
- In util/cacheflush.c patch, added an explanation for the change to both
the code comment and the commit message.
- Split the block/file-posix.c hunk that adds "#include <sys/ioctl.h>" into
a separate commit and revised the commit message to clarify the purpose of
the patch.
- Removed the Emscripten-specific stub of copy_file_range in
stubs/emscripten.c. Instead, updated the type of the existing
copy_file_range stub in block/file-posix.c to match the declaration in the
Emscripten headers and avoid a compilation error.
- Moved the change that was incorrectly applied to os-posix.h into os-wasm.h
- Split MAINTAINERS file change to each commit that adds new files.
- Unified two consecutive #ifndef macros into a single condition in
qemu-options.hx.
- Instead of porting mmap-alloc.c to Emscripten, this version excludes the
file entirely. The rationale is described in the commit message.
- In meson.build, added a check to ensure TCI is enabled for the wasm build.
- Split the Dockerfile addition from the previous 18th patch into a separate
commit.
V1:
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 (20):
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: Add including of ioctl header for Emscripten build
block: Fix type confict of the copy_file_range stub
include/qemu/osdep.h: Add Emscripten-specific OS dependencies
Disable options unsupported on Emscripten
util: exclude mmap-alloc.c from compilation target on Emscripten
util: Add coroutine backend for emscripten
meson: Add wasm build in build scripts
tests: Add Dockerfile containing dependencies for Emscripten build
gitlab: Enable CI for wasm build
.gitlab-ci.d/buildtest-template.yml | 27 ++++
.gitlab-ci.d/buildtest.yml | 9 ++
.gitlab-ci.d/container-cross.yml | 5 +
MAINTAINERS | 9 ++
backends/meson.build | 6 +-
block/file-posix.c | 8 +-
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 | 7 +
include/qemu/osdep.h | 8 +-
include/system/os-wasm.h | 104 +++++++++++++
meson.build | 29 +++-
meson_options.txt | 2 +-
os-wasm.c | 119 ++++++++++++++
qemu-options.hx | 4 +-
qom/object.c | 7 +-
scripts/meson-buildoptions.sh | 2 +-
system/memory.c | 2 +-
system/physmem.c | 9 +-
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 | 4 +
util/coroutine-wasm.c | 127 +++++++++++++++
util/meson.build | 4 +-
util/oslib-posix.c | 28 ++++
40 files changed, 709 insertions(+), 66 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 tests/docker/dockerfiles/emsdk-wasm32-cross.docker
create mode 100644 util/coroutine-wasm.c
--
2.25.1
next reply other threads:[~2025-04-22 5:28 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 5:27 Kohei Tokunaga [this message]
2025-04-22 5:27 ` [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers Kohei Tokunaga
2025-04-22 6:41 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 02/20] qom/object.c: " Kohei Tokunaga
2025-04-25 14:53 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 03/20] system/vl.c: " Kohei Tokunaga
2025-04-22 6:41 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 04/20] target/arm/helper.c: " Kohei Tokunaga
2025-04-25 14:53 ` Philippe Mathieu-Daudé
2025-04-26 6:38 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 05/20] target/i386/cpu.c: " Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 06/20] contrib/plugins: " Kohei Tokunaga
2025-04-22 6:40 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 07/20] hw/net/can: " Kohei Tokunaga
2025-04-25 14:51 ` Philippe Mathieu-Daudé
2025-04-25 15:03 ` Francisco Iglesias
2025-04-22 5:27 ` [PATCH v2 08/20] target/ppc: " Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 09/20] target/s390x: " Kohei Tokunaga
2025-04-25 9:33 ` Thomas Huth
2025-04-22 5:27 ` [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort Kohei Tokunaga
2025-04-25 9:36 ` Thomas Huth
2025-04-26 6:36 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten Kohei Tokunaga
2025-04-22 6:43 ` Philippe Mathieu-Daudé
2025-04-22 6:48 ` Philippe Mathieu-Daudé
2025-04-23 6:01 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build Kohei Tokunaga
2025-04-22 6:52 ` Philippe Mathieu-Daudé
2025-04-22 14:02 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub Kohei Tokunaga
2025-04-22 6:43 ` Philippe Mathieu-Daudé
2025-04-22 14:01 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 14/20] include/qemu/osdep.h: Add Emscripten-specific OS dependencies Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 15/20] Disable options unsupported on Emscripten Kohei Tokunaga
2025-04-22 6:53 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 16/20] util: exclude mmap-alloc.c from compilation target " Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 17/20] util: Add coroutine backend for emscripten Kohei Tokunaga
2025-04-22 13:59 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 18/20] meson: Add wasm build in build scripts Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 19/20] tests: Add Dockerfile containing dependencies for Emscripten build Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 20/20] gitlab: Enable CI for wasm build Kohei Tokunaga
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=cover.1745295397.git.ktokunaga.mail@gmail.com \
--to=ktokunaga.mail@gmail.com \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=danielhb413@gmail.com \
--cc=david@redhat.com \
--cc=eduardo@habkost.net \
--cc=erdnaxe@crans.org \
--cc=francisco.iglesias@amd.com \
--cc=hreitz@redhat.com \
--cc=iii@linux.ibm.com \
--cc=jasowang@redhat.com \
--cc=kwolf@redhat.com \
--cc=ma.mandourr@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=npiggin@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=pisa@cmp.felk.cvut.cz \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
--cc=vikram.garhwal@bytedance.com \
--cc=zhao1.liu@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.