The bundle (unkernel.wasm) carries a small busybox initramfs that mounts a
distro image labelled kwroot under an overlay root, or starts the base shell
without one. guest/ replaces kernel/guest/: base/, distro/NAME/, shared lib/
and tools/. Images are laid out for their boot by a patched mkfs.erofs and a
recorded boot file list, with a prefetch hint in the image header. Debian
bakes its apt lists and cache, a set of everyday packages and a
command-not-found installer.
The demos' texts called the guest riscv64 (and its CPU a RISC-V
emulator); they now say aarch64. The SQLite demo read the riscv ISA
string from /proc/cpuinfo; it now loads the Features line and groups it
(FP and SIMD, crypto, CRC, LSE atomics). Doom's first run builds in
under a minute, which its README and tile say.
Every visible demo's run.sh was run on the aarch64 guest through the SDK
(2026-11-18): .agents/web.md lists the first-run times. The stand-ins
and qemu-user (x86_64, riscv64, i386, arm) were rechecked too.
Ubuntu 25.10 and later were out of reach on riscv64 (RVA23 with V); the
arm64 baseline is ARMv8.0, so the newest release runs. Pin
ubuntu-base-26.10-base-arm64.tar.gz from its versioned release directory
for kernel/build.sh ubuntu and the page's Ubuntu demo, which was still
fetching the riscv64 24.04.5 tarball. The demo re-extracts a tree whose
bash is not an aarch64 program, and skips the page's download only for
an aarch64 tree.
Checked 2026-11-18: the disk boots to kw-init's shell (glibc 2.44, apt
3.3.3), apt-get update and installs work, systemd 261 boots to running
with no failed units, and the demo's chroot runs apt from the pushed and
from a self-fetched tarball.
A data disk records the architecture of the image that uses it. One
written by another architecture (a riscv64 disk on the aarch64 guest)
loses its installed packages and system changes once, with a notice on
the console and the page; root's home is kept.
The riscv64 interpreter, its JIT emitter, test guests and drivers are
gone; kwemu keeps the ISA-neutral core (MMU, TLBs, code marking, block
cache, JIT core) and the A64 CPU. The arm64 user ABI is one kernel
patch, the last of the series, and the contract between the kernel and
kwemu starts again at KW_ABI_VERSION 2.
busybox, zlib, openssl and apk-tools are rebuilt from pinned aports
commits for kwemu and installed by default. ~/.local/bin is first on
PATH for login shells and kwtty's programs, and the page writes fx,
claude and opencode stand-ins there that install the real program on
first use.
The JIT's ISA-neutral core (regions, thresholds, entry, growth) is
factored out behind ISA hooks, and the A64 emitter sits on it with one
file per op family: ALU, bitfield, multiply and divide kinds with lazy
NZCV, every load and store kind, and every branch kind with side exits.
The decoded-block cache is generic over an ISA's block hooks. A64 code
is decoded once into ops (one instruction, one op) that runOps executes,
with coherence on SMP through a shared code epoch. The tier is tested
against the reference interpreter.
User space is now unmodified aarch64 Linux ELF. kwemu gets an A64
interpreter (src/a64): integer, scalar and vector floating point,
AdvSIMD, exclusives and load-acquire/store-release, the EL0 system
registers, AES, PMULL, SHA1, SHA256 and CRC32. The kernel runs arm64
user space (signal frames, HWCAP, ptrace regsets, the arm64 syscall ABI),
and the guest image, the bundle, kwtest and the page's texts are built
for aarch64.
IP_ADVANCED_ROUTER with IP_MULTIPLE_TABLES gives ip rule and more than one routing table, so tailscaled uses its table 52 instead of falling back to the main table. VETH links network namespaces, DUMMY gives a throwaway interface. Together +64 KB raw, +24 KB gzip and 20 KiB of RAM. kwtest tries all three in a network namespace of its own.
kernel/build.sh smp builds the SMP kernel (kw_defconfig + kw_smp.config,
kwemu with atomics) from the same tree into vendor/build/kernel-smp; all
builds both kernels, and every bundle refresh adds the UP-to-SMP patch
when the SMP kernel is the same build of the tree (KW_SMP=1 requires it,
KW_SMP=0 leaves it out). kernel stays the UP-only quick loop. The patch is
cached in kernel-smp/up.kwpatch. Fixed build stamps (user, host, a build
id hashed from the tree and kwemu sources, the tree's newest commit date)
make kernels and patch reproducible while every other build keeps its own
banner for snapshot matching. Configs are checked against their fragments
after a reconfigure. KW_BUILD, KOUT_SMP, KWEMU_SMP and LINUX_REPO make the
script runnable against another tree and output root.
bundle.mjs --smp refuses two kernels that are not the UP and SMP builds
of one tree (banner, KW_ABI_VERSION, wasm_cpu_start, memory type), with
--smp-optional to warn instead and --smp-patch to reuse a cached patch.
The release workflow builds both kernels, runs kwtest on 2 CPUs and the
kernel patch tests (unexercised).
Off by default: one CPU loads the UP bundle as before. With several the
page loads the SMP bundle (only then) and boots it in worker mode. The
choices are disabled with the reason where the page cannot (no SMP
kernel in the bundle, no cross-origin isolation, no Atomics.waitAsync),
and a failed SMP download or start reloads once on one CPU. Suspend is
hidden with several CPUs; a suspended session is offered to resume on
one CPU.
pnpm build inlines js/node/cpu-entry.ts where js/node/cpu.ts starts it,
in the Node entries and inside the inlined Node kernel worker (WORKERS
nested), so the package starts SMP CPUs without source files. The page
build serves web/kernel/page/: the bundle without its SMP patch section
(the same bytes when there is none) and, only with a patch, the SMP
bundle it makes as a second hashed asset (kernelSmpUrl, unused until the
page has CPU threads).
The five host-device drivers that refused to start on an SMP kernel now
work there; every device import still runs on CPU 0, whose host has the
devices. kwblk: blk-mq calls ->queue_rq() on the submitting CPU in
atomic context, so another CPU's request waits in a list and raises the
block interrupt on CPU 0, which submits it before it reaps. kwshm, kwfb,
kwinput and kwsnd call their imports from process context through
kw_host_call() (at once on CPU 0, else a work item there while the
caller sleeps); kwsnd's timer is pinned to CPU 0, and a start or stop
triggered on another CPU is sent from a work item on CPU 0, in order.
The UP kernel compiles to the same code but for one WARN line number.
Host side: BlockHost.raise() sets IRQ 3 with Kernel.setIrqBits(), an
atomic OR on a shared memory; its plain read-modify-write could drop an
IPI bit another CPU set meanwhile.
Tests: UNKERNEL_TEST_CPUS=n runs test/api.test.ts on an SMP kernel
(snapshot tests skip), and glimmer-check passes --initrd and --smp to
the CLI. The docs describe the funnels, their cost and what snapshots
on SMP would need from them.
Each CPU's thread now has a JitHost of its own, bound to its instance's
function table, so each CPU's kwemu compiles what it finds hot into its
own table; nothing compiled on one CPU is reachable from another. The
host no longer turns the JIT off with more than one CPU. A secondary's
JIT host mirrors its counters into a SharedArrayBuffer: stats().jit is
the sum over CPUs, stats().jitCpus and kwemuCpus are per CPU, and the
CLI's --stats prints a line per CPU.
A secondary CPU's thread never reached its event loop, so V8 ran neither
FinalizationRegistry callbacks nor the last pass of its collections
there: the JIT host saw nothing collected, prompted collections with
ever larger allocations (one stalled a CPU for 0.58 s while a TLB
shootdown waited for it) and would have refused to compile after 2048
frees. Every CPU now yields to its host every 20 ms of user code (the
kernel side is folded into wasm: SMP), and a secondary's sched_yield
returns through its event loop.
kwemu: compiled code reads the interrupt word with i32.atomic.load when
the memory is shared (a plain load in a loop that stores nothing may be
hoisted, and an IPI would go unseen), and an interpreted self-loop that
an interrupt ends now counts its passes towards the compile threshold
(under a stream of IPIs hot loops were never compiled). A unit test
covers the latter.
kwtest gains jit: checks for SMP kernels: hot() and fphot() on every CPU
at once under signals, byte and halfword stores beside AMOs and LR/SC in
one cache line, a thread moved every 4 ms while in compiled loops, and
code that one CPU runs compiled while another rewrites it (with
__builtin___clear_cache), replaces it by mremap() or makes it
non-executable. The docs describe the guarantees (kwemu.md, JIT on
several harts) and the numbers.
A user task may now move to another CPU at the reschedule on its way to
user mode, where its state is all in pt_regs, and starts there on a
fresh stack; switched in on its own CPU it resumes its stack as before.
The load balancer and affinity changes move tasks: sched_setaffinity()
records the mask at once and the task moves on its way to user mode,
instead of failing with EBUSY. A task asleep in a system call stays
until it returns. A workqueue rescuer that serves another CPU's per-CPU
pool moves there instead of running that CPU's work on its own.
The CPU that held a moved task's stack calls the new import
wasm_stack_drop(task), and its host forgets that stack. A secondary
CPU's host also raises the stop IPI on CPU 0 when the session ends there
(exit, trap, fatal error), which the kernel takes even while spinning
with interrupts off, so CPU 0 suspends and its host ends the session.
kwtest gains move checks (threads spreading from one CPU, register, FP
and TLS state across 300 self-moves, affinity changes of a busy and a
sleeping thread, queued signals and pipe and futex ping-pong across
moves) and `kwtest smp`, which runs only the SMP checks. The kernel side
is folded into the sched, kthread and workqueue, and wasm: SMP patches.
A second kernel build (kw_smp.config) runs one instance of the module
per CPU, each in a worker thread on a shared memory. The host's Kernel
is CPU 0 with every device; wasm_cpu_start starts the others through
Platform.spawnCpu (js/node/cpu.ts), which run js/core/cpu.ts: their own
JSPI task switching, the clocks on CPU 0's time base, and console and
exit forwarded to CPU 0's host. The host sets IRQ bits atomically and
ends CPU 0's idle on Atomics.waitAsync of its word, which other CPUs'
IPIs notify. createKernel's cpus option and the CLI's --smp N (which
implies --worker) ask for CPUs; a UP kernel ignores them with a log
line, and more than one CPU runs the interpreter only.
kwemu built with -Dkwemu-atomics makes AMOs atomic, SC a
compare-and-swap against the value LR read, and FENCE a barrier (ABI
7). kwtest gains an smp check (threads on several CPUs counting
through AMOs, LR/SC and a mutex) and skips the park check on an SMP
kernel, which has no parking. The kernel side is in five new patches.
The worker now answers only /vm/<id>/<port>[/...], the guest preview's
relay. The page and its assets load from the network: a cache-first page
stayed old whenever caching a new build failed. Root-relative requests
from a preview are no longer relayed; guest pages use relative URLs.
sw.ts calls registration.update() on every load and after an hour
hidden, since register() with an unchanged URL never looks for a new
script. The old scope-/ registration gets the new script on its next
navigation, deletes the kw-app-* caches and tells old pages an update is
ready; the next load unregisters it. The update indicator, the Offline
copy row and /kw-assets.json go with the offline copy.
alpine.sh always writes alpine-test.cpio: the image followed by a second
cpio archive with kwtest and kwbench, which the kernel unpacks after the
first. alpine.cpio, which build.sh bundles, is the same, or with
KW_RELEASE=1 the image alone. The choice is in alpine.sh because build.sh
is part of the release workflow's cache keys.
The release workflow sets KW_RELEASE=1, so the GitHub release bundle, the
npm package and the deployed page have no test programs. Its kwtest steps
boot the release bundle's kernel with --initrd alpine-test. wasi-node.ts
uses alpine-test.cpio, and the headless lowmem scenario boots to the
shell instead of running kwtest, since the built page runs a release
kernel.
kernel/guest/alpine-opt.sh builds them from Alpine's own source,
patches and configuration (the aports commits the image's packages came
from), with gcc 16 at -O2 for rv64gc + Zba/Zbb/Zbs/Zicond, linked with
lld, against a sysroot of Alpine's packages (the image's musl). alpine.sh
and alpine-disk.sh swap the six files into the images.
Measured in the guest: shell scripts about 20% faster, exec 24%, apk
with both indexes 11%, sha1/sha512/chacha20 22-30%
(.agents/guest-packages.md).
The release workflow installs the host tools and caches the build output
under its own key; no existing cache key, path or hashed file changes.
setup.sh checks the new tools.
The status line's fx button (or Ctrl-A f, or ?fx at load) runs libfx's
wasm fx terminal in a panel docked right of the stage, over it on narrow
screens. Its shell tool runs each command in the guest through
vm.exec(). The sign-in, settings and history stay in module memory only.
vercel.com sends its OAuth discovery document without CORS headers, so
fx's fetch falls back to a copy of the fields it reads. The launcher's
fx demo (the x86_64 binary under qemu) is hidden.