Commit Graph

293 Commits

Author SHA1 Message Date
minchenlee
bba44ebc06 kernel: limit FUSE readdir replies to one page with a flat vmalloc (#127) 2026-12-02 12:58:35 +01:00
hELLO,tHIS'S jOSHUA
303320394b vk: skip readback for storage buffers shaders only read (#122) 2026-12-02 12:57:32 +01:00
Coenraad Loubser
a023438bba block: Preserve discards during an in-flight save (#86) 2026-12-02 12:55:52 +01:00
pi0x
b6f98d9e2b js: add an SNI/Host sniffing backend with a policy callback (#152) 2026-12-02 12:51:13 +01:00
pi0x
dd108fa943 kwemu: chain compiled modules in desktop Safari, where it measures 10-16% faster on Perl, and add /jit-probe.html, which times guest work with chaining off and on in a browser (KW_JIT_TAIL=1 or 0 answers instead of the engine test) (#148) 2026-12-02 10:09:14 +01:00
pi0x
bdcc90c51f js: start the inlined Node workers from data: URLs (#143) 2026-12-02 09:51:17 +01:00
pi0x
8580d4e79a docs: document SDK defaults and limits for embedders (#145) 2026-12-02 09:48:01 +01:00
pi0x
903ac21686 test: make the SDK API suite pass reliably (#147)
* test: expect the JIT host's fused multiply-add, tail call and chaining caps, and export jitTail() beside jitSimd() and jitFma()

The JIT rework added caps bits 6 (fused relaxed multiply-adds), 7 (cheap
tail calls), 8 (module format v2, KW_JIT_V2=1) and 9 (chaining, unless
KW_JIT_CHAIN=0), but the JitHost test still expected bits 0-5 only, so it
failed on every run (755, not 51, on Node 24 on x86-64). The test now
derives the expected caps from the same probes and variables.

* test: expect shm views in place in worker mode with an SMP kernel

With UNKERNEL_TEST_CPUS=2 the worker shares the kernel's memory with this
thread (shm.ts, In place), so views() works there instead of failing with
EOPNOTSUPP; the shm test failed on every 2-CPU run. It now checks the
views on the shared memory there, and the EOPNOTSUPP on the UP kernel.

* test: find the forced H.264 key frame by the source's request, not by a chunk window

The camera H.264 test wanted the key frame kwcap forces after the 16th
chunk among chunks 16 to 22. The source makes it next, but the chunks it
made before reach the guest first: the host's queue and the guest's
filled buffers, as many as the guest lags behind the source's clock. With
the full suite at once the inline kernel's timer ran late, the pattern
source caught up several frames at a time, and the forced key frame came
later (or on the GOP's own key frame at 24). The test now records the
chunk the source makes after each key frame request, checks that the
guest gets that chunk as a key frame, with only the GOP's key frames
before it and the GOP counting from it, and streams 60 chunks, enough for
the queue's 32 and the guest's buffers.

* test: judge shm reads through the ring by the reads during which this thread was free

The ring's answer comes as a message to this thread, which also runs the
suite's inline kernels. The check skipped itself when this thread's timer
delay was high, but it measured that delay only after the 25 reads, so a
busy spell during the reads failed it (median 32.5 ms with a delay of
1.4 ms measured afterwards). Each read now records this thread's longest
timer delay while it runs, and the median is asserted over the reads that
saw no delay of 3 ms or more (when there are at least 3 of them).

* test: run worker-mode capture from a read() source after the concurrent suite

In worker mode the sound in and camera tests' read() sources answer on this
thread, and the worker records silence or a black frame wherever the
answer comes late. With the whole suite at once this thread runs every
inline kernel, and the source fell 200 ms or more behind at the start of a
stream: kwrec got 2357 and 2854 of its 3000 samples (worker; worker with
messages), the camera 3 of 8 pictures (worker with messages). Those four
tests now run in a suite of their own after the concurrent one, alongside
each other only, with their assertions unchanged; the inline ones and the
onRing ones (a producer on a thread of its own) stay in the concurrent
suite.

* test: read a guest's background counter again when its file is empty

The snapshot and session tests' guests count in the background with
echo $i > FILE, which truncates the file before it writes, so a cat in
between reads nothing, 0, and fails a "counts on" check (or weakens the
next one). The host now reads the counter again while its file is empty,
at most 50 times. A rename per write in the guest would also do, but at a
fork per write it loads the guest (and, inline, this thread) twice as
much.

* test: let a restored recording end before boot() returns in the snapshot capture test

A restore hides the stopped time from the guest's clock, so the restored
guest has what was left of its 3 s recording. Where the snapshot landed
late in it (a busy host), kwrec's own stop and close came before boot()
returned, and the test, which wanted nothing after the replayed open,
prepare and start, failed. It now asserts the replay first, then nothing
or the guest's stop and close, with capturing to match.

* test: derive the SMP kernel once for UNKERNEL_TEST_CPUS runs instead of at every boot

Given the bundle and more than one CPU, createKernel() derives the SMP
kernel from it on the calling thread at every boot (about 0.2 s of
patching), and in a 2-CPU run every boot() did that. The suite's boots at
once held this thread, which runs the inline kernels and the device
sources, for over 3 s: glimmer's 3 s of sound took 6.3 to 6.8 s, the PCM
ring from the worker CPU (2.97 s of that stream) overflowed and dropped
346 to 890 frames glimmer had written without an underrun, and the H.264
source made too few chunks during the guest's stall to overflow the
queue. With UNKERNEL_TEST_CPUS > 1, boot() now boots the SMP kernel that
compileTestKernel() derives once wherever it runs on more than one CPU;
sharedKernel() still boots the bundle.

---------

Co-authored-by: Pooya Parsa <pooya@pi0.io>
2026-12-02 09:41:39 +01:00
pi0x
f06079e947 js: unwind a stopped kernel's stacks so that it can be collected (#141) 2026-12-01 23:25:57 +01:00
pi0x
8360c5d82b js: use a cached distro image without the network or a full rehash, and fall back to a temporary cache directory (#142)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
2026-12-01 23:25:32 +01:00
pi0x
c742c69de7 js: make createKernel()'s signal abort the boot only, not the running kernel (#140)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
2026-12-01 23:21:49 +01:00
pi0x
4d2ccde92c docs: allow several kernels per thread and give the Debian image's real size (#138) 2026-12-01 23:19:46 +01:00
pi0x
cd674065cf js: read file: URLs and paths in the Node entry's loadKernelModule() and loadBytes() (#139) 2026-12-01 23:18:09 +01:00
pi0x
07f198bd1f kwemu: JIT rework (chaining, exact code marks, fused multiply-add) (#135) 2026-12-01 21:20:37 +01:00
Harrison @ Movenis
ad2302694d web: keep the Transfers button visible while idle (#118)
Co-authored-by: harrisonk0 <238985628+harrisonk0@users.noreply.github.com>
2026-11-30 23:46:14 +01:00
Pooya Parsa
3ef745b6d1 web: add a Kubernetes app: k3s in the Debian guest, running a single-node cluster with an nginx sample or joining one; apps can need a number of CPUs (the app needs 2: the SMP kernel) v0.3.0-261130-3ef745b 2026-11-30 14:25:37 +01:00
Pooya Parsa
bf46d833d0 kernel: give the Kubernetes options a bpf(2) for device filters only
BPF_SYSCALL with CGROUP_BPF was 70% of what the options cost, for runc's device filter. A new generic patch, BPF_CGDEV_ONLY, loads and attaches cgroup device programs only and runs them on the interpreter, with a verifier of its own: the SMP kernel grows 128 KB gzip instead of 460 KB. Checked with a runc container on cgroup v2.
2026-11-30 14:25:37 +01:00
Pooya Parsa
ed876d7f79 kernel: make kwdiff take a far match only when it is clearly longer, so the SMP patch compresses better
A match more than 4 KiB away from where the current one continues now has to be 32 bytes longer instead of 8. New code otherwise became tens of thousands of short copies from unrelated places, each a seek a compressor cannot predict. The SMP patch with the Kubernetes options goes from 1.51 to 1.30 MB gzip; the format, the loader and the time to make it are unchanged.
2026-11-30 14:25:37 +01:00
Pooya Parsa
708a18ef58 kernel: enable what a Kubernetes node needs in the SMP kernel
The cgroup v2 memory, CPU and cpuset controllers with CPU limits, bpf(2)
with cgroup BPF, keys, bridge netfilter, the iptables pieces kube-proxy and
flannel use, nft ct and masq, the conntrack table in procfs, and VXLAN, in
kw_smp.config only: k3s needs cpuset, which needs SMP, so the UP kernel
stays as it is.

Co-authored-by: Greg Bell <code@gregbell.ca>
2026-11-30 14:25:37 +01:00
pi0x
6234100fc9 docs: fill the SDK documentation gaps and refresh the README's features (#110)
* docs: document snapshots, host commands, Tailscale, VA-API, fetchRoutes, UDP, the microphone and the camera in the SDK docs and README, and list the newer devices and uses in the README's introduction

* docs: split the Display page into Display and Input, and Sound and Camera

---------

Co-authored-by: Pooya Parsa <pooya@pi0.io>
2026-11-30 11:23:00 +01:00
pi0x
d7b538a7a3 sdk: name virgl.wasm in the web entry so that bundlers emit it: Vite and Rolldown copied virgl.mjs as an asset without the virgl.wasm it loads next to itself, so createKernel({ gl }) failed on the guest's first GL use; the entry hands the URL to the module (locateFile), and gl.wasm does the same for a gl.module of your own (#108)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
2026-11-30 11:17:04 +01:00
pi0x
7e4f3d73cd kernel: leave BPF arena maps out with a flat vmalloc (#107)
A BPF arena needs get_vm_area(), which VMALLOC_FLAT does not have; with
the patch, arena maps fail with EINVAL as on kernels without an MMU.
BPF_SYSCALL stays off in kw_defconfig, so the patch is dormant by
default; it lets a kernel turn BPF on without importing get_vm_area.

Co-authored-by: Greg Bell <code@gregbell.ca>
2026-11-30 10:42:27 +01:00
Pooya Parsa
6f3b27b94d web: add a Camera app (Media): the camera's H.264 decoded on VA-API in an mpv window (low-latency, untimed, sized to the desktop; 720, 1080 and raw options), and mic.sh, the microphone as a waveform with a level meter; apps can need the camera (?cam=0 disables the tile) 2026-11-29 23:29:45 +00:00
Pooya Parsa
fef3d85844 web: do not report the browser's ResizeObserver loop notice as a page error (a Wayland app's new size resizing its window raised it as a toast, or a fatal error during boot) 2026-11-29 22:11:14 +00:00
Pooya Parsa
6bde669dbd Let the guest's Chromium decode video on VA-API: the Chromium app installs libva (libva2, libva-drm2), which chromium loads but does not depend on, and /etc/chromium.d/kw-wayland names guest GL's render node with --hardware-video-device-path where libva's DRM backend is installed 2026-11-29 21:31:20 +00:00
Pooya Parsa
0097a7989a kernel: export only what the host and the build tools read instead of every symbol, so the lowering drops unused code (the bundle is 1.35 MB smaller) 2026-11-29 20:33:57 +00:00
Pooya Parsa
61519ce4e5 test: skip the capture and camera tests on a bundle without kwrec and kwcap (a release build), and restore the 3 s recording v0.3.0-261129-61519ce 2026-11-29 20:11:37 +00:00
Pooya Parsa
599746c2dc test: bound the capture snapshot tests' waits for a device event, and record 10 s so the snapshot lands mid-recording on a slow host 2026-11-29 19:29:41 +00:00
Pooya Parsa
e8f60af86a web: redesign the top bar's right side as applets, each a status item with its own panel that opens on hover or click: CPU, Memory, Disk, Network (with Tailscale, a mode row and a sketch of the traffic's path), Ports, Display (the theme and the GPU), Sound and media (with a live microphone and camera indicator), Bluetooth, Serial, USB and Transfers (with the clipboard); bigger spacing, icons on a plate over the wallpaper, glassy popovers, and a Kernel log that opens at its bottom 2026-11-29 19:27:49 +00:00
Pooya Parsa
5425a685a4 kernel: enable FAT, exFAT and iso9660 (Joliet, zisofs), with UTF-8 as the default NLS 2026-11-29 18:46:40 +00:00
Pooya Parsa
ace904ec78 kernel: enable squashfs (zlib, lz4, lzo, xz, zstd, xattrs) and erofs microLZMA 2026-11-29 18:24:50 +00:00
Pooya Parsa
3729b2e6e7 Measure the OPFS data disk's extent files while it opens, so the page's attach line shows the bytes they hold instead of 0 KiB 2026-11-29 17:45:38 +00:00
Pooya Parsa
73856e96f4 Bump the version to 0.3.0 2026-11-29 17:40:14 +00:00
Pooya Parsa
d8e442a641 Keep the page's data disk in OPFS in worker mode: OpfsDisk (8 MiB extent files), the SDK's backend option for the data disk, a one-way migration from IndexedDB, a storage quota block and a free Disk size in Settings, and a question in a second tab instead of an in-memory copy 2026-11-29 17:37:06 +00:00
Pooya Parsa
c76f9d239d guest: add kwhotplug, which opens hot-plugged USB device nodes to the image's user, and drop the page's own chmod 2026-11-29 16:20:21 +00:00
Pooya Parsa
495fe30a91 Add guest USB on WebUSB: kwusb (a USB host controller whose transfers the host serves, with usbfs and the FTDI, CP210x, CH341 and PL2303 serial drivers), the SDK's usb option and vm.usb with a fake test device, and a USB devices section in the page's Settings 2026-11-29 15:43:56 +00:00
Pooya Parsa
42b91da2a8 Add guest Bluetooth on Web Bluetooth: kwbt (an HCI transport, hci0 while a controller is attached), the SDK's bluetooth option and vm.bluetooth with an emulated LE controller, Bluetooth and Serial ports sections in the page's Settings with Terminal buttons, and the Bluetooth and Serial Monitor launcher apps 2026-11-29 15:22:20 +00:00
Pooya Parsa
ab334389af Add guest serial ports on Web Serial: kwserial (/dev/ttyACM0..3), the SDK's serial option and vm.serial, Connect in the page's Settings and from a toast, and the Thonny and GTKTerm launcher apps 2026-11-29 13:31:16 +00:00
Pooya Parsa
ed872875f2 Fetch a distro image's warm set only once the guest reads in it, and leave apt's srcpkgcache.bin out of Debian's 2026-11-29 12:29:20 +00:00
Pooya Parsa
a7daa0443d kernel: create no dummy0 at boot (DUMMY_NUMDUMMIES=0); dummy links are added when needed, as tailscale0 is 2026-11-29 12:15:06 +00:00
Pooya Parsa
68f0b98048 js: run the Tailscale guest address scripts as root, so tailscale0 is set up on the distro images 2026-11-29 12:09:15 +00:00
Pooya Parsa
a9c8aef517 js: add Tailscale exit nodes, and rework the page's Tailscale settings
With net.tailscale.exitNode (--tailscale-exit-node, setExitNode() at run
time) a tailnet device that offers 0.0.0.0/0 takes all the guest's other
IPv4 traffic and its DNS in place of the backend; while it is not usable
that traffic is refused. WireGuard's source check is now the longest
prefix across peers. The page lists the tailnet's devices, picks the
exit node from a select box in Settings and the top bar panel, and shows
a set-up node's status and live controls apart from the setup form. The
README gains a section on joining a tailnet.
2026-11-29 11:16:22 +00:00
Pooya Parsa
4b713a5aed Merge branch 'main' into tailscale 2026-11-29 10:24:54 +00:00
Pooya Parsa
1b229902b2 Add a guest microphone and camera: kwsnd capture, kwcam (V4L2, raw and host-encoded H.264), and camera frames named to the kwva encoder
Microphone: kwsnd gains a capture substream fed by the host (SDK option
soundIn, the page's Microphone setting and ?mic=0, the CLI's
--sound-in-wav and --sound-in).

Camera: kwcam is a V4L2 capture device (/dev/video0) fed by the host: I420,
NV12 and YUYV at 320x240 to 1280x720, and H.264 encoded by the host's
WebCodecs encoder where it has one, with bitrate, GOP and key frame
controls (SDK option camera, the page's Camera setting and ?cam=0, the
CLI's --camera). The base's rc writes the udev database entry of
/dev/video*, so programs that list cameras through libudev find it.

kwva (protocol 5): an encode whose input surface is a camera buffer's
dma-buf names the frame to the host instead of sending its pixels, and
pixels an app writes into an exported surface reach the host (put).
2026-11-29 10:23:01 +00:00
Pooya Parsa
b9db51200e web: drop window errors from scripts not of the page's origin (a browser's wallet or an extension), which could fail the boot 2026-11-28 22:31:25 +00:00
Pooya Parsa
d382f7fa9b js: add a pure-JS Tailscale network device (work in progress)
The guest joins a tailnet from Node or the page: ts2021 control over
WebSocket, DERP relays, WireGuard and the packet filter in JS, loaded as
a separate chunk only when the option is used. SDK net option, CLI
--tailscale* flags and a page panel. Relay only; exit nodes, IPv6 and
real peer traffic are not covered yet.
2026-11-28 22:06:18 +00:00
Pooya Parsa
df6d726178 web: build the docs origin when it is used, not at module load, which ran before docs.ts set DOCS_URL (circular import) v0.2.0-261128-df6d726 2026-11-28 21:41:54 +00:00
Adam H
0c92b2370c web: Light / Dark / Auto theme (#53)
* web: add a terminal colour theme option (Auto, Dark, Light)

* web: add an option to turn off the Terminal window's see-through glass

* web: default the terminal colours to Auto

* web: add a page colour theme option (Auto, Dark, Light)

* web: give the chrome's materials in style.css a light variant

* web: give the components' chrome classes a light variant

* web: follow the theme in the charts, the alerts' caution badge and the Docs window

* web: fix the light theme's Dock glyphs, Resume card veil and Browser toolbar hover

* web: read the shown theme from the store and type the option field names

* web: darken the light theme's faint and error colours to 4.5:1 on tints

* web: give the light terminal mid-tone colours that read under black text

* web: lighten the light terminal's green, yellow and cyan for black text on them

* web: use the dark terminal's green in the light terminal

* web: give the light terminal's green, yellow and cyan 4.5:1 on white, as its red, blue and magenta

* web: give the light theme a white status bar on iOS

* web: make the Docs window opaque

* web: post a theme change to the Docs window instead of reloading it

* docs: upgrade undocs nightly, for the Docs window's theme messages

---------

Co-authored-by: Pooya Parsa <pooya@pi0.io>
2026-11-28 22:34:15 +01:00
pi0x
45a024e879 kernel: let busy workqueue workers finish before kernel threads park on SMP, and serve a requested grace period first, so that a park cycle right after a netns teardown no longer fails (#76)
On the SMP kernel a workqueue worker in the middle of an item could wait
for kernel threads that had already parked, never reach its own park
point, and end the cycle with -EBUSY naming it. A netns teardown's
cleanup_net() does that: it waits for grace periods, the expedited
grace-period worker and other work items. A cycle started right after an
`unshare -n` exit failed 13 times in 15 on 2 CPUs and 12 in 15 on 4; beside
a loop of netns teardowns 22 of 30 and 20 of 30 failed. Docker's
containers (#59) make such teardowns routine in Debian guests.

- The TREE_RCU grace-period kthread parks only while no grace period is
  in progress or requested, so that a kernel thread in synchronize_rcu()
  or rcu_barrier() can reach its park point (a fixup of the park points
  patch).
- Between the user and the kernel-thread phases kwparkd waits, at most
  HZ/2, until every workqueue worker is idle (in TASK_IDLE), while every
  kernel thread still runs (kw_park_settle_work(), a fixup of the arch
  patch).

With both, every cycle of those runs passed (120 on 2 and 4 CPUs). An idle
cycle's median went from 17.9 ms to 0.3 ms on 2 CPUs; a cycle that waits
for a teardown takes 60-230 ms. kwtest's park check is unchanged (2-5 ms
mean). parking.md describes the settle step and the grace-period rule.

Based on Martin Brook's patches on the android branch of
martinbrook/unkernel (cc78ca9, 4849ed9). His settle step also ran
rcu_barrier() and waited only for workers in an uninterruptible sleep:
here the barrier cost 40-50 ms in every cycle, and a worker between two
waits (runnable) ended the wait early, so 11 of 15 cycles still failed.

Co-authored-by: Pooya Parsa <pooya@pi0.io>
Co-authored-by: Martin Brook <martin.brook100@googlemail.com>
2026-11-28 22:33:07 +01:00
pi0x
0059e61af5 kernel: read and write aligned user words in one access; lock kwfb mode changes against mmap (#75)
get_user() and put_user() of an aligned 1, 2, 4 or 8 bytes are now one
load or store through kw_user_addr() instead of a memcpy (memory.copy,
which the Wasm spec does not make single-copy atomic on a shared
memory), so a futex word read beside another CPU's stores cannot tear;
an unaligned access still goes through raw_copy_*_user().

kwfb's set_par checks the mappings, allocates and switches the buffer
under info->mm_lock, which fbdev's mmap holds (check_var reads the count
under it too): an mmap racing FBIOPUT_VSCREENINFO from another thread
could map the old buffer.

kwtest checks both (uaccess: FUTEX_WAIT and getcpu beside another CPU's
stores, fault-in, EFAULT and a put_user across a page; kwfb: 200 mmaps
beside a thread changing the mode), and `kwtest smp` runs the kwfb
checks. Ported from VOD-Studio/unkernel@25e90b3f.

Co-authored-by: Pooya Parsa <pooya@pi0.io>
Co-authored-by: xfy <i@rua.plus>
2026-11-28 22:22:20 +01:00