From dba6d8134919ee087aff92a3eb046e3345720f21 Mon Sep 17 00:00:00 2001 From: JeremySu0818 Date: Mon, 30 Nov 2026 21:41:15 +0800 Subject: [PATCH] docs: record x86 integration validation Document the final x86-exp-isa-fixes evidence: the 79-case kernel matrix and its 20 SMP repeats, the two-CPU API suite, the amd64 Alpine SSH and Python comparisons, and the four lowered-kernel stack-audit configurations. Clarify that CONFIG_WASM_X86 makes every task in an x86-enabled kernel use a 32 KiB shadow stack, while the audit instrumentation is test-only. Preserve the unresolved affinity, wakeup-placement, host-architecture, browser, and workload limitations; the expanded coverage is not a scheduler-resolution claim. --- .agents/kernel.md | 9 ++++-- .agents/testing.md | 4 +-- .agents/x64.md | 10 ++++++ test/x64-audit.md | 78 ++++++++++++++++++++++++++++++---------------- 4 files changed, 69 insertions(+), 32 deletions(-) diff --git a/.agents/kernel.md b/.agents/kernel.md index e23ff54..254eaab 100644 --- a/.agents/kernel.md +++ b/.agents/kernel.md @@ -193,9 +193,12 @@ a patch re-export. with the P4D folded; kwemu walks them like hardware. - vmalloc returns direct-mapped memory (`mm/vmalloc-flat.c`), so `vmap()` of scattered pages returns NULL (nothing in this config hits that). - There is no `VMAP_STACK` and no stack guard; per-cpu memory is - `percpu-km`. Kernel shadow stacks are 32 KiB with `CONFIG_WASM_X86`, - 16 KiB otherwise; overflow is not detected. + There is no `VMAP_STACK` and no production stack guard; per-cpu memory is + `percpu-km`. `CONFIG_WASM_X86` selects `THREAD_SIZE_ORDER = 3` at build + time, so every kernel task in that image has a 32 KiB shadow stack (not + only a task currently running x86); arm64-only images keep 16 KiB. The + x86 stack audit temporarily instruments lowered `vmlinux32.wasm` to catch + a bound violation, but it does not add a guard to production kernels. - uaccess (`copy_{to,from}_user`, `clear_user`, futex ops; fault.c) walks the user page tables in software and faults pages in; `get_user`/`put_user` (asm/uaccess.h) do a single load or store through diff --git a/.agents/testing.md b/.agents/testing.md index 7d9cc1c..5d93e2f 100644 --- a/.agents/testing.md +++ b/.agents/testing.md @@ -14,7 +14,7 @@ Run the row for what you changed, and no more. | --- | --- | | Emulator (`src/`, `test/guest/`, `include/`) | `zig build test` | | Native x86-64/i386 (`src/x64/`, `test/guest/x64/`, `test/guest/i386/`) | `zig build test-x64` on an x86 host (physical CPU differential tests, both guest modes; `test/x64-audit.md`; a host without SHA-NI fails `cryptotest` and `edgetest`), and `zig build test` (the shared core) | -| x86-64 tasks in the kernel (`CONFIG_WASM_X86`, `x86_*.c`) | `kernel/build.sh kernel`; `node js/cli.ts --initrd base-test --append "console=hvc0 rdinit=/usr/bin/kwtest-x86_64"` (`kwtest: 0 failure(s)`) and `rdinit=/usr/bin/abitest-x86_64` (`abitest x86_64: 0x0000000000000000 failure(s)`, exit 253: it exits as PID 1); and arm64's kwtest and abitest | +| x86-64 tasks in the kernel (`CONFIG_WASM_X86`, `x86_*.c`) | `kernel/build.sh kernel`; `node js/cli.ts --initrd base-test --append "console=hvc0 rdinit=/usr/bin/kwtest-x86_64"` (`kwtest: 0 failure(s)`) and `rdinit=/usr/bin/abitest-x86_64` (`abitest x86_64: 0x0000000000000000 failure(s)`, exit 253: it exits as PID 1); and arm64's kwtest and abitest. For a shadow-stack allocation or deep x86 executor change, also run `test/x64-stack-audit.py` on UP/SMP with JIT on/off (it checks lowered `vmlinux32.wasm`). | | Kernel, `kw_emu.h`, JIT | `kernel/build.sh kernel`; `node js/cli.ts --append "console=hvc0 rdinit=/usr/bin/kwtest"` (`kwtest: 0 failure(s)`, exit 0); for JIT changes, again with `--no-jit` | | JIT control flow, regions, budget or polls | the row above; `zig build test -Dkwemu-a64-fuzz=20000` (the A64 block fuzz; a64/jit.md) | | Base initramfs, kw layer, distro images (`guest/`) | `KW_BASE_OUT=/tmp/b kernel/build.sh base`, `KW_BASE_OUT=/tmp/b KW_DISTRO_OUT=/tmp/d guest/build.sh distro`, then `UNKERNEL_TEST_BASE_KERNEL=/tmp/b/unkernel.wasm UNKERNEL_TEST_DISTRO_DIR=/tmp/d pnpm test:distro` and `UNKERNEL_TEST_KERNEL=/tmp/b/unkernel.wasm UNKERNEL_TEST_DISTRO_DIR=/tmp/d pnpm test:api` (or the same in place: `kernel/build.sh base`, `kernel/build.sh distro`, `pnpm test:distro`, `pnpm test:api`); `UNKERNEL_TEST_DISTRO_FORMAT=ext4` for the ext4 images; optional: `node js/cli.ts --timeout 120 --input '{8}uname -a; apk --version\n{2}poweroff\n'` | @@ -61,7 +61,7 @@ contains changes to that area. | Area | Run | | --- | --- | -| Native x86-64/i386 | `zig build test-x64` and `zig build test-x64 -Dkwemu-atomics=true`; after `kernel/build.sh kernel`, `smp`, `base` and `zig build install-x64`: `node test/x64-kernel-audit.mjs` | +| Native x86-64/i386 | `zig build test-x64` and `zig build test-x64 -Dkwemu-atomics=true`; after `kernel/build.sh kernel`, `smp`, `base` and `zig build install-x64`: `node test/x64-kernel-audit.mjs`; for `CONFIG_WASM_X86` stack or deep executor changes, `python test/x64-stack-audit.py --cpus 1`, the same with `--no-jit`, and both forms with `--cpus 2` (lowered `vmlinux32.wasm`). | | Emulator (`src/`, `test/guest/`, `include/`) | `zig build test` (it also reruns the wasm64 unit tests and the guests on a JIT host without wasm SIMD, `a64-nosimd` and `wasm64+jit/nosimd`) and `zig build test -Dkwemu-atomics=true`, then the kernel row | | Kernel or `kw_emu.h` | `kernel/build.sh kernel` and `kernel/build.sh smp`; `node js/cli.ts --append "console=hvc0 rdinit=/usr/bin/kwtest"`, the same with `--kernel vendor/build/kernel/vmlinux`, and both again with `--no-jit` (expect `kwtest: 0 failure(s)`, exit 0); kwtest once more with `kw.isa=armv8` appended (the `isa` checks then expect SIGILL) and once with `--no-vsock`; abitest the same way (`rdinit=/usr/bin/abitest`, `abitest: 0 failure(s)`, exit 0; kernel/tests.md) with and without the JIT and with `--cpus 2`; the SMP kernel (below); `node test/wasi-node.ts` (`PASS`) | | Bundle, kernel patch, `build.sh` | `KPATCH_UP=vendor/build/kernel/vmlinux32.wasm KPATCH_SMP=vendor/build/kernel-smp/vmlinux32.wasm pnpm test:kpatch`; after a change to the stamps or the build, two clean builds into different `KW_BUILD` roots give the same `vmlinux32.wasm` files and bundle (`sha256sum`) | diff --git a/.agents/x64.md b/.agents/x64.md index 2c4820c..c21c735 100644 --- a/.agents/x64.md +++ b/.agents/x64.md @@ -169,6 +169,16 @@ the kernel does not exec it. libm, float formatting), Node 24 (V8's JIT, OpenSSL's AES-GCM, ChaCha20, SHA, Ed25519, PBKDF2, zlib), coreutils, gzip and sort from the amd64 python:3.13-slim and node:24-slim images give the host's output. +- The 2026-11-30 `x86-exp-isa-fixes` integration on an Intel Core Ultra 7 + 270K Plus passed the 79-case kernel matrix: 36 UP memory32/memory64 + JIT/no-JIT cases, 18 regular SMP-2 cases, 5 SMP-4 cases and 20 repeated + SMP `kwtest` cases (five each for arm64/x86-64 on two/four CPUs). It also + passed a disposable amd64 Alpine root on 1/2 CPUs with JIT on/off: an amd64 + OpenSSH client made a public-key login to its amd64 server, and each + configuration made 12 Python comparisons to the native amd64 result. The + integration exercised affinity and migration, but does not resolve the + documented scheduler or placement limitations; `test/x64-audit.md` records + the exact matrix and remaining limits. - `zig build test-x64` (x86 host) compares the x86-64 and i386 test guests (`test/guest/x64`, `test/guest/i386`) with the physical CPU on the native, wasm64, JIT, lowered-JIT, no-SIMD and lockstep runners, and runs diff --git a/test/x64-audit.md b/test/x64-audit.md index e782d36..03e9300 100644 --- a/test/x64-audit.md +++ b/test/x64-audit.md @@ -24,9 +24,10 @@ Encoding coverage and semantic validation are reported separately. 2026-11-30: builds and execution run exclusively through `ssh desktop` on an Intel Core Ultra 7 270K Plus, 24 CPUs, Zig 0.16.0, Node 24.21.0, LLVM 23.1.5, patched LLD 22.1.8 and Binaryen 133. Files move with `scp`; the local computer -is used for editing and inspection. The final review uses the isolated -`/home/jeremy/unkernel-isa-review-20261130` checkout. Earlier evidence is retained -in `/home/jeremy/unkernel-isa-audit-20261129/audit-logs`. +is used for editing and inspection. The final `x86-exp-isa-fixes` integration +uses `/home/jeremy/unkernel-x86-exp-isa-fixes`; its results are retained in that +checkout's `audit-logs/`. Earlier evidence is retained in +`/home/jeremy/unkernel-isa-audit-20261129/audit-logs`. ## Review and repairs @@ -67,11 +68,16 @@ The following groups contain implemented repairs and targeted tests: PROT_NONE handling; #AC priorities and vector/masked/F16C exemptions; faulting scalar RMW flags; POPF NT/RF behavior; TF transitions and MOV/POP SS/LSS interrupt/debug shadow across interpreter, JIT and kernel. -- **Kernel shadow stack:** x86 tasks use a 32 KiB Wasm shadow stack, rather - than the 16 KiB arm64 allocation. Deep reference-SIMD frames otherwise - overrun the task allocation and corrupt SLUB metadata before a later fault. - The stack audit instruments every lowered `__stack_pointer` update and - checks it against the live task allocation. +- **Kernel shadow stack:** `CONFIG_WASM_X86` selects a 32 KiB Wasm shadow + stack (`THREAD_SIZE_ORDER = 3`) at build time, instead of the 16 KiB + arm64-only allocation. It applies to every kernel task in an x86-enabled + image, not only a task currently executing x86 code. Deep x86 + reference-SIMD frames otherwise overrun the task allocation and corrupt + SLUB metadata before a later fault. `x64-stack-audit.py` temporarily + instruments lowered `vmlinux32.wasm`: it guards each ordinary + `__stack_pointer` assignment against the live task allocation, while + excluding stack-switch and new-stack entry points that establish or restore + a task's stack. This is a test guard, not a production stack guard. - **x87:** pending/nonwaiting exceptions, stack faults, environment metadata, control word normalization, NaN/unsupported arithmetic inputs, rounding and wrapped unmasked overflow/underflow, scalar/BCD stores and conversions, @@ -88,7 +94,9 @@ function imports. These helpers are not an external execution backend. The original trap word `c90e79e2c4` corresponds to instruction bytes `c4 e2 79 0e c9`, VTESTPS. Those exact bytes have a direct regression test. Earlier packing/broadcast/shift repairs associated with the OpenSSH failure -were rechecked independently; a successful login is not used as ISA evidence. +were rechecked independently. The final amd64 Alpine regression does include +an actual public-key OpenSSH login by an amd64 client to an amd64 server, but +that successful integration check is not used as ISA-conformance evidence. ## Independent coverage @@ -150,7 +158,14 @@ KW_ARCH=x64 JOBS=24 kernel/build.sh kernel KW_ARCH=x64 JOBS=24 kernel/build.sh smp node test/x64-kernel-audit.mjs python test/x64-stack-audit.py --cpus 1 +python test/x64-stack-audit.py --cpus 1 --no-jit +python test/x64-stack-audit.py --cpus 2 python test/x64-stack-audit.py --cpus 2 --no-jit +KPATCH_UP=vendor/build/kernel/vmlinux32.wasm \ +KPATCH_SMP=vendor/build/kernel-smp/vmlinux32.wasm pnpm test:kpatch +UNKERNEL_TEST_CPUS=2 pnpm test:api +python test/x86-userland-root.py /tmp/amd64-root +node test/x86-userland.mjs /tmp/amd64-root audit-logs/userland ``` The full x64 matrix contains 28 guest/mode entries across seven runners, @@ -169,24 +184,30 @@ The final implementation matrices pass: | XED target representatives | 194,147; zero decode, length or unclassified-UD errors | `completed-xed-dispatch.tsv` | | A64 normal and atomics | 77 runner checks each; 138 passed, one expected skip, zero failures with/without host SIMD; import checks pass | `completed-dual-a64.log`, `completed-dual-a64-atomics.log` | | Rebuilt UP/SMP kernels | Build and bundle complete | `completed-dual-up-build.log`, `completed-dual-smp-build.log` | -| Final kernel matrix | 79/79 | `completed-dual-kernel/summary.json` | -| x86 shadow-stack audit | Five x86 workloads, all lowered stack-pointer writes in UP/SMP and JIT/no-JIT | `completed-stack-{up,smp}-{jit,nojit}.log` | +| Kernel patch | 5/5, including real UP-to-SMP and SMP-to-UP remapping and bundle checks | `completed-kpatch-real.log` | +| Final kernel matrix | 79/79: 36 UP, 18 regular SMP-2, 5 SMP-4, and 20 repeated SMP cases | `completed-dual-kernel/summary.json` | +| x86 shadow-stack audit | Five x86 workloads; 14,637 guarded lowered writes in each UP JIT/no-JIT run and 15,052 in each two-CPU SMP JIT/no-JIT run | `completed-stack-{up,smp}-{jit,nojit}.log` | +| Two-CPU API suite | 156 pass, 0 fail, 3 optional skips | `completed-api-smp.log` | +| amd64 Alpine userland | 1/2 CPUs × JIT/no-JIT: public-key OpenSSH login plus 12 Python native-output comparisons per configuration | `completed-userland/summary.json` | A64/shared source files are unchanged by the final x64-only decoder/BMI delta. -The final kernel matrix uses a host vCPU budget of eight with the same UP/SMP, -JIT/no-JIT and guest CPU configurations. The first review kernel matrix was -41/42: the migration assertion sampled one CPU despite 182 moves, with zero -bad computations. Its isolated repeat sampled both CPUs and passed. A later -matrix's RNG output comparison failed because asynchronous host stderr split -a guest output line in the merged log. The driver now preserves both streams -and compares the guest stdout stream exactly; all property assertions, panic -checks and exit checks remain. These failed records are retained alongside -the final 42/42 run. +The final kernel matrix uses a host vCPU budget of eight. Its 36 UP cases run +all nine programs in memory32/memory64 with JIT on/off; its 18 regular SMP-2 +cases repeat that set with JIT on/off; the five SMP-4 cases are `kwtest`, +`kwtest-x86_64`, `atomic-audit`, `mixed-a64` and `mixed-x86_64`; and its 20 +additional cases run each ISA's `kwtest` SMP subset five times at two and four +CPUs. The first review kernel matrix was 41/42: the migration assertion sampled +one CPU despite 182 moves, with zero bad computations. Its isolated repeat +sampled both CPUs and passed. A later matrix's RNG output comparison failed +because asynchronous host stderr split a guest output line in the merged log. +The driver now preserves both streams and compares the guest stdout stream +exactly; all property assertions, panic checks and exit checks remain. These +failed records are retained; the 79/79 result does not explain them away. The 79-case kernel matrix covers UP memory32/memory64 with JIT on/off, SMP 2/4 CPUs, dual-ABI abitest, native fault-frame comparisons, RNG and -atomic tests, mixed A64/x86 exec, and five additional SMP repetitions. PID 1 -test programs that successfully +atomic tests, mixed A64/x86 exec, and the 20 repetitions above. PID 1 test +programs that successfully exit cause Linux's `Attempted to kill init! exitcode=0` panic and CLI status 253; only the exact successful-exit case with matching output is accepted. An arbitrary panic or failed assertion is rejected. @@ -202,15 +223,18 @@ An arbitrary panic or failed assertion is rejected. 42/42 parallel checkpoint. Their cause is unresolved; passing runs do not erase the failures or prove that they predate the repairs. No register, FP, TLS, atomic or coherence - corruption was reported by those failing placement assertions. + corruption was reported by those failing placement assertions. The final + affinity and migration coverage, including its 20 SMP repetitions, does not + establish that scheduler or placement issues are resolved. - The x86-host SMP matrix does not establish x86 TSO on an AArch64 host or all unaligned atomic interactions. Physical AArch64/qemu-aarch64 differential evidence is unavailable on desktop; the available A64 regressions are run. - Browser tests were not requested and are not run; browser data is preserved. - The original Arch llama CLI/model/browser invocation and an actual OpenSSH - login have not been rerun. Earlier llama CPU-backend validation covered - 115 unary and 30 IQ2_XXS matrix cases in UP/SMP with JIT on/off; no further - llama build work is part of this review. + The original Arch llama CLI/model/browser invocation has not been rerun. + The separate amd64 Alpine regression did rerun its public-key OpenSSH login, + but not an OpenSSH distribution or workload matrix. Earlier llama CPU-backend + validation covered 115 unary and 30 IQ2_XXS matrix cases in UP/SMP with JIT + on/off; no further llama build work is part of this review. - Release/deployment, distro/network and persistent-disk matrices are not covered by these results. The test bundle has no persistent data-disk template.