Enforce VEX reserved-field and compatibility-width rules, correct BMI feature gating, and repair affected SIMD and x87 semantics. Serialize every locked x86 RMW path so an unaligned software update cannot race an overlapping aligned host atomic.
Make CONFIG_WASM_X86 kernels use a 32 KiB shadow stack. Deep reference-SIMD frames could exceed the former 16 KiB allocation and later surface as SLUB or page-cache corruption. Capture x86 page-fault present bits before fault handling changes the mapping, and bump the kwemu contract to ABI 6.
Add physical VEX encoding coverage, locked-atomic and mixed-ISA kernel workloads, a stack-bound instrumentation audit, and a disposable amd64 Alpine userland regression. Extend kernel matrix output to retain stdout separately from host stderr so native fault and RNG comparisons remain exact.
The audit covers x64/i386 differential execution, atomics, UP/SMP and JIT/no-JIT kernel runs, and real amd64 SSH and Python userland checks. It retains the documented limits around scheduler placement, non-x86 hosts, browser coverage, and broader workload matrices.
The x86 front end no longer replaces A64 at build time: libkwemu exports
the A64 ABI and the x86 one (kw_x64_run, kw_x64_set_isa,
kw_x64_isa_supported, kw_x64_complete_entropy, kw_x64_load_segment) on
the same struct kw_cpu, and include/kw_emu.h (ABI 5) describes both
(struct kw_x64_regs; KW_EV_FPE, KW_EV_GPF and KW_EV_ENTROPY for x86).
kw_cpu_init and kw_host_reset set up both.
x86 blocks have their own sets in the block cache (blockSetFor: the top
set bit flipped), so the blocks of the two ISAs at one pc never share a
set and switching between an arm64 and an x86 task needs no flush. The
compile-time is_x64 switches in src/emu become comptime hooks of the
tier that looks a block up (Blocks.x86): the i386 key strip, the A64
stats hooks, and the shared x86 code-page set, which only x86 decodes
mark (A64 keeps IC IVAU); a write-TLB fill reads it only once some x86
code has been marked.
zig build test runs the A64 tests as before; zig build test-x64 runs the
x86 ones (kwemu-x64-harness*, installed with the x86 guests by
install-x64). The object bundles compiler-rt (the x86 front end's
128-bit and x87 arithmetic).
Co-authored-by: JeremySu0818 <xinghong.su0818@gmail.com>
The user page tables gain a level: the PGD now holds PUD tables (P4D
folded), and kwemu's walker and the kernel's uaccess walk read four
levels. TASK_SIZE is 1 << 48, and kwemu faults addresses at or above it.
KW_ABI_VERSION stays 4: no release carries ABI 4 yet.
TASK_SIZE was 1 << 38, the lower half of Sv39 carried over from the
riscv64 guest, so the .NET runtime failed at startup ("GC: Reserving
274877906944 bytes (256 GiB) for the regions range failed"). The kernel
never maps its own memory in the user page tables, so user space can
have every address the three levels index. kwemu now faults addresses
at or above 1 << 39 instead of accepting a sign-extended upper half,
which would alias pgd slots 256-511. KW_ABI_VERSION is 4.
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.
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.
On SMP a CPU inside a JIT compile (kwemu's gathering and emitting, the
host's new Module and Instance, V8's first-call compile) or inside its
20 ms yield to the host took no interrupt for 0.1 ms to tens of ms, and
every TLB shootdown to it waited that long.
kwemu (ABI 8) marks a compile with jit_busy in struct kw_cpu and does a
flush another CPU asked for through flush_all when it ends, then looks
the block up again; a compile waits while an interrupt is pending. Every
module returns at once for cpu = 0, and the host calls it so inside
kw_host_jit_compile (new flags argument), so V8's lazy compile falls in
the window. The kernel (patch 0037) skips compiling and yielding CPUs as
it skips lazy ones, and yields after taking pending interrupts. The JIT
host no longer nudges the collector on a free.
kwipi churn on 2 CPUs: shootdown p99.9 130 to 13 us, max 20 to 3.9 ms,
calls over 1 ms 194 to 3; throughput and compile counts unchanged
(kwemu.md, Numbers, Compile stalls).
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.