Files
unkernel/.agents/kernel/devices.md

47 KiB

Devices

The kernel side of each host device. Host sides are in js.md, SMP paths in smp.md (Devices), imports and IRQ numbers in kernel.md.

Display, input, sound, camera, vsock, shm, kwvirtio, kwserial, kwbt and kwusb are lazy: each _init import returns < 0 (kwvirtio, kwserial, kwbt, kwusb: <= 0) when the host has no such device, and then nothing is registered. Display, input and sound allocate nothing until a program opens the device, and the host is told on open and close; the camera tells the host only at STREAMON and STREAMOFF. None of these imports suspends. A new device adds only its own imports (diff the module's imports against a build without it). The CLI offers vsock by default and display, sound, the camera, shm, virtio-gpu, serial ports, Bluetooth and USB on request (--display, --sound, --camera, --shm, --gpu, --serial, --bluetooth, --usb); the page offers all but shm and virtio-gpu.

Sizes (lowered kernel): display +37 KiB, input +49 KiB, sound +142 KiB (30 KiB of it OSS; capture adds 871 bytes, 2026-11-29), vsock +45 KiB (+15.7 KB gzip), kwshm +6 KiB (+1.8 KB gzip) (2026-11-14); 9p +141 KiB (+52 KB gzip, 28 KiB of RAM; 2026-11-15); kwvirtio with DRM and virtio-gpu +660 KB (+217 KB gzip; config.md); kwcam with V4L2 and videobuf2 +241 KB (+83 KB gzip, 64 KiB of RAM; H.264 and its controls 2,364 bytes of it, +1.1 KB gzip, no import; 2026-11-29, config.md). kwserial with serial_core +40.9 KB (+14.5 KB gzip -9; 2026-11-28). kwbt with the Bluetooth core and its crypto +589 KB (+193 KB gzip -9; 2026-11-29, config.md). kwusb with usbcore, usbfs and four USB serial drivers +281.8 KB (+95.7 KB gzip -9; 2026-11-29, config.md).

Console (hvc_wasm)

drivers/tty/hvc/hvc_wasm.c, console=hvc0, on WASI fd 1 (output) and fd 0 (input, read only after a zero-timeout poll_oneoff, so it never blocks). The size comes from wasm_driver_console_size() (rows << 16 | cols, 0 = unknown): set on the tty when it is opened and re-read on each input poll; the host raises IRQ 1 after a resize, and programs get SIGWINCH. The images set TERM=xterm-256color for the console shell (/etc/profile.d/kw-term.sh), replacing busybox init's vt102.

kwblk (block)

drivers/block/kwblk.c: blk-mq, one hw queue (depth 32), disks wda, wdb, ... probed at boot (wasm_driver_block_info); up to 15 partitions, no hot-plug or resize, no FUA (the block layer emulates it with flushes). ->queue_rq() writes the request (op, sector, direct-mapped segment addresses) into its PDU and calls wasm_driver_block_submit, which never suspends, so it is fine in blk-mq's atomic dispatch context (no BLK_MQ_F_BLOCKING, no kthread). The host completes it synchronously (return <= 0 = status) or returns 1, later writes the status into the PDU and raises IRQ 3; the handler drains wasm_driver_block_reap(). Read, write, flush (volatile write cache), discard and write-zeroes (if the backend has them).

Sync (IRQ 4): the handler queues a work item that runs ksys_sync() (writeback of every file system, journal commits, device flushes); requests made before it runs coalesce. Host: Kernel.requestSync() (js.md).

kwnet (network)

drivers/net/kwnet.c: an Ethernet device whose frames are copied to and from the host (wasm_driver_net_init/send/rx_len/recv; net_init < 0 means no device). Received frames raise IRQ 2 and are drained by NAPI into GRO. It claims checksum offload and TSO and marks RX CHECKSUM_UNNECESSARY, so the guest computes no checksums and sends 64 KiB TCP segments. The host stack (10.0.2.15/24, gateway 10.0.2.2, DNS 10.0.2.3) and its limits are in js.md, Network.

kwfb (display)

drivers/video/fbdev/kwfb.c: /dev/fb0, 32 bpp XRGB8888, write and mmap.

  • wasm_driver_fb_init(); wasm_driver_fb_mode() (width << 16 | height, 0 = 640x480), asked at the first open; wasm_driver_fb_attach( pixels, width, height, stride, format) at the first open and on every mode change, NULL at the last close. It returns the picture's size in mm (width << 16 | height, 0 = unknown), which becomes fb_var_screeninfo width and height (X.Org's fbdev driver ignores them and assumes 96 dpi; Qt's linuxfb uses them). The page counts 96 CSS pixels to the inch; the CLI takes --display=WxH@DPI.
  • The host reads the pixels in place whenever the kernel yields (at most about 50 times a second while a program is busy); there is no vsync.
  • The buffer is one contiguous allocation and the buddy allocator gives at most 4 MiB, so each side is clamped to 64..4096 and a mode above 1M pixels is divided by the smallest integer that fits (1920x1032 becomes 960x516); if the allocation still fails, the size is halved. FBIOPUT_VSCREENINFO changes the size only while the caller's file is the only one open and nothing is mapped (EBUSY otherwise); line_length is always 4 * xres.
  • One program has the display at a time: a user open fails with EBUSY while another user open file exists (kernel opens, user == 0, are not refused; there is no fbcon). The claim is the file's, so it lasts through fork and through a mapping that outlives close(), and ends at the file's release, which exit always reaches.
  • mmap inserts the pages directly: vm_insert_page rejects large kmalloc pages here.

kwinput (input)

drivers/input/kwinput.c, present only with the display: event0 "kwinput keyboard" (keys 1..255, no autorepeat), event1 "kwinput mouse" (REL_X, REL_Y, REL_WHEEL, three buttons) and event2 "kwinput tablet", an absolute pointer like QEMU's usb-tablet (ABS_X/ABS_Y 0..32767 over the whole picture, REL_WHEEL, three buttons; no BTN_TOUCH, tool bits or INPUT_PROP_DIRECT, so udev and libinput call it a mouse with absolute motion and X's evdev an absolute pointer). Device numbers 0, 1, 2 in the events and the open mask.

  • wasm_driver_input_init(); wasm_driver_input_state(mask) from the open and close callbacks; wasm_driver_input_read(buf, max) pulls 12-byte events (device, type, code, value) after the host raises IRQ 5. The host delivers events only while a program has the device open.
  • kw_defconfig switches HID (which INPUT turns on) and the hardware input drivers off.
  • Only user space may open these devices: the host routes keys to evdev instead of the console while the keyboard is open, so an in-kernel handler that opens what it matches breaks the console. sysrq's handler is a passive observer (the tty: sysrq patch, passive_observer: it sees events while evdev has the device open, so Alt-SysRq works then, but never calls open). A lower MAGIC_SYSRQ_DEFAULT_ENABLE would not do: writing a non-zero kernel.sysrq registers the handler again, and systemd sets 16. Any new handler (VT kbd, leds, mousedev, joydev) needs the same care; kwtest's input handlers check fails on handlers other than evdev and sysrq, and test/api.test.ts asserts that nothing is open before glimmer opens the devices.

kwsnd (sound)

sound/drivers/kwsnd.c: ALSA card 0, hw:0,0, playback, and capture when the host has a source, U8 and S16_LE, mono or stereo, 8000-48000 Hz, plus OSS /dev/dsp (SND_PCM_OSS); no mixer, no PCM timer, no /proc/asound.

  • wasm_driver_sound_init() (the host's preferred rate, or 0, with bit 30 KWSND_INIT_CAPTURE set when the host has a capture source: only then is there a capture substream, /dev/snd/pcmC0D0c, so a host that does not know of capture never gets the capture imports called); wasm_driver_sound_event(event, rate, channels, format) (0 close, 1 open, 2 prepare, 3 start, 4 stop); wasm_driver_sound_write(buf, bytes), which the host copies during the call and answers with the frames it has queued. Capture: wasm_driver_sound_capture_event() (the same events) and wasm_driver_sound_read(buf, bytes), which the host fills during the call, answering with the bytes it wrote.
  • A kernel timer per stream on the host's monotonic clock hands over the frames the elapsed time is worth every 2-10 ms (the period, 2 ms or more, in a buffer of 10 ms or more); no IRQ bit. A late tick hands over at most three ticks' worth (15 ms' worth when ticks are shorter than 5 ms), and an underrun stops the stream, so nothing spins. A capture tick asks the host for that many frames and fills what it did not have with silence, so a capture never waits for the host (a microphone not granted yet records silence); a program that does not read gets an overrun.
  • A blocking read or write has no timeout (substream->wait_time): ALSA's default (1.1 buffers, 100 ms at least) is for a DMA engine that stopped, and here a wait that long only means the host did not run the kernel (a busy page thread, a frozen tab, the first moments of a restore), after which every such wait ended in EIO (arecord: read error) although the next tick woke it.

kwcam (camera)

drivers/media/platform/kwcam.c, host js/core/camera.ts: a V4L2 capture device, /dev/video0 (driver and card kwcam, "unkernel host camera"), with one camera input; controls only with H.264 (below).

  • Formats YUV420 (I420, "YU12": Y, then the Cb and Cr planes; bytesperline the Y plane's), NV12 and YUYV (single plane), and H.264 where the host encodes it (below), in that ENUM_FMT order, sizes 320x240, 640x480 and 1280x720, 30, 25, 20, 15, 10 or 5 frames a second, all discrete (ENUM_FMT, ENUM_FRAMESIZES, ENUM_FRAMEINTERVALS; S_FMT takes the nearest size, EBUSY while the queue has buffers, and an unknown format becomes the first; S_PARM the nearest rate, EBUSY for another rate while streaming; both persist across opens, as with uvcvideo); default 640x480 YUV420 at 30. YUV420 first and the default because players take it as is: ffmpeg's v4l2 input with no -input_format tries the formats of its table in order, yuv420p (YUV420) first, YUYV after it, NV12 near the end, so it gets yuv420p, and mpv's av://v4l2 (through it) shows it with no [autoconvert] (with YUYV first it took yuyv422, which mpv's --vo=gpu converts to yuv422p in software); the host copies a camera's 4:2:0 VideoFrame straight into it (js.md). v4l2-ctl streams the current format (the default until a program sets one); GStreamer's v4l2src ranks formats itself (YUY2 first: gst-launch-1.0 v4l2src ! videoconvert ! fakesink and cheese take YUYV, 1280x720, whatever the order); guest Chromium's capture prefers I420 too. The size a program last set stays (ffmpeg without -video_size asks the current one, so an earlier 1280x720 stream gives the next plain ffmpeg -f v4l2 -i /dev/video0 1280x720); 640x480 at power-on keeps that first stream cheap. Colorimetry as webcams report it: sRGB, BT.601, limited range. The format table (kwcam_all_formats) has the host's init bit of each compressed format; others can be added there.
  • Buffers are videobuf2-dma-contig on the platform device kwcam (32-bit DMA mask): dma-direct's contiguous direct-mapped pages, which the host writes at their linear address and mmap maps with remap_pfn_range(). videobuf2-vmalloc does not work here: vmalloc_user() is a large kmalloc under VMALLOC_FLAT, and vm_insert_page() refuses its head page (PGTY_large_kmalloc). MMAP, read() and DMABUF; EXPBUF exports a buffer as a dma-buf. A buffer's kernel address is taken at QBUF (buf_prepare), where an imported dma-buf is mapped under its reservation lock, which the timer could not take; one the kernel cannot map is refused (EFAULT). KWCAM_IOC_FRAME refuses every buffer of a compressed stream (ENOENT), which has no frame ids. At most 32 buffers, as uvcvideo (queue_setup; vb2 wants max_num_buffers of 64 or more): GStreamer's v4l2src io-mode=dmabuf into vavp9enc holds 17 or more (the encoder keeps its reference frames' input buffers; at 16 its pool failed with ENOBUFS and the pipeline crashed, 2026-11-29). A 1280x720 YUYV buffer is 1.8 MiB, one order-9 allocation.
  • wasm_driver_camera_init() (< 0: no camera; else bits of the compressed formats the host encodes, bit 0 KWCAM_INIT_H264, so a host that answers 0 gets the raw formats only and never a compressed stream); wasm_driver_camera_stream(fourcc, width, height, num, den, bitrate, gop) at STREAMON (a frame every num/den s; the last two are the H.264 controls) and with fourcc 0 at STREAMOFF or when the streaming file is closed; wasm_driver_camera_frame(buf, bytes, id, chunk), which the host answers for a raw stream (chunk NULL) by writing its current frame during the call (returning bytes) or with 0; with a frame it may also write the frame's id, 16 bytes at id (the buffer's record; zeroed first and for a black frame). Hosts ignore the arguments they do not know (the last ones were added later).
  • Frame ids (include/uapi/linux/kwcam.h): the host's id of each frame (128 random bits, from its frame store, js.md; zero where it keeps none) stays with the buffer. KWCAM_IOC_FRAME (_IOWR('V', 192, struct kwcam_frame), on any open of the device, under the queue's lock) takes a dma-buf fd and, where it is one of the device's MMAP buffers exported by VIDIOC_EXPBUF (its ops are kwcam's), gives the buffer's index, its frame's id and sequence number, the stream's format, size and pitch, and flags: DEQUEUED (user space holds it, so its pixels are that frame's as the host wrote them) and WRITABLE; else ENOENT. For WRITABLE the memory ops are videobuf2-dma-contig's with alloc, put, mmap and get_dmabuf wrapped: a table of the planes' buf_priv (64 entries, a spinlock; a plane not in it counts as writable) marks a plane writable at a PROT_WRITE mapping, through V4L2 mmap or the dma-buf (whose ops become a copy of vb2-dc's with mmap wrapped, also how the ioctl tells kwcam's dma-bufs), for as long as the buffer lives; a read-only mapping loses VM_MAYWRITE, so mprotect cannot make it writable later (EACCES). The VA-API driver uses it to name a camera buffer's frame to the host instead of sending its pixels (va.md, Camera to encoder). Not considered: a device writing an exported camera buffer (nothing in this guest imports a foreign dma-buf for writing).
  • No IRQ: an hrtimer on the host's monotonic clock ticks at the frame interval while streaming; each tick takes the oldest queued buffer, asks the host for the frame, fills a black one (Y 16, Cb and Cr 128) where the host had none, and completes it with the tick's time and the next sequence number. So a program gets frames at its rate from STREAMON on, black until the host has a picture (a camera not granted yet), and never waits for the host. A tick with no buffer queued drops its frame (the sequence number counts it); a late tick delivers one frame and skips the missed ones (hrtimer_forward_now()).
  • H.264 (V4L2_PIX_FMT_H264, listed with V4L2_FMT_FLAG_COMPRESSED by the V4L2 core; bytesperline 0, sizeimage the frame's size as NV12): the host encodes, the guest copies the stream, as from a UVC camera with its own encoder. Each frame import writes the host's next chunk (an Annex B access unit; a key frame with SPS and PPS first and after any chunk the host dropped) and returns its size, or 0 when none waits, and the buffer then stays queued for a later tick: never a black, repeated or reordered one. chunk is a struct kwcam_chunk (host ABI, in kwcam.c): out flags (KWCAM_CHUNK_KEY) and age_us (since its frame was captured), in the controls' bitrate and gop and request (KWCAM_REQ_KEY, a key frame asked for). Ticks come four times a frame interval (4 ms at least), each delivering what the host has while buffers are queued (eight at most), so a chunk waits a quarter of an interval at most once a buffer is queued; the buffer's timestamp is the tick's less the chunk's age (up to 10 s), kept increasing (1 µs past the last). Sequence numbers count the chunks delivered; buffers get V4L2_BUF_FLAG_KEYFRAME or PFRAME (the host encodes for real time: no B-frames). A chunk larger than the buffer never reaches it (the host drops it, js.md; a host that returned more is ignored, logged once).
  • Controls, only where H.264 is offered (a camera without it has none, and no event ioctls): the codec class's V4L2_CID_MPEG_VIDEO_BITRATE (50,000 to 20,000,000), V4L2_CID_MPEG_VIDEO_GOP_SIZE (1 to 1000) and the button V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME, through a control handler with control events (v4l2_ctrl_subscribe_event); the first two are inactive for the raw formats. Until a program sets them they follow the format and rate (S_FMT, S_PARM): about 0.1 bit a pixel (921,600 at 640x480 and 30 fps) and a key frame a second; like the format they persist across opens. The host gets them at STREAMON and in every frame import, and a key frame asked for with the next import (from CPU 0's tick).
  • kw_defconfig: MEDIA_SUPPORT with MEDIA_SUPPORT_FILTER and every media category off (so no media controller, which CAMERA or PLATFORM support would force on), MEDIA_SUBDRV_AUTOSELECT off (it selects I2C), and VIDEO_KWCAM, which selects VIDEO_DEV and VIDEOBUF2_DMA_CONTIG itself (its Kconfig entry is in drivers/media/Kconfig's media drivers menu). The kw layer's rc gives /dev/video* to video (0660) and writes its udev database entry (kernel/guest.md), without which libudev's enumeration leaves the node out (it lists a device node only once udev initialised it) and GStreamer's device monitor, so cheese ("No device found"), and guvcview found no camera.
  • Guest tool: kwcap (guest/src/test/kwcap.c, not in release bundles): V4L2 MMAP or read() capture with per-frame hashes, and kwcap h264 with each chunk's key-frame flag, the controls, a forced key frame and a stall (testing.md).
  • Consumers (2026-11-29, Debian trixie): ffmpeg 7.1.5's v4l2 input takes compressed H.264, MJPEG (and JPEG), MPEG-4 and CPIA, and no HEVC, VP8, VP9, AV1 or H.263 (its -v debug shows the fourccs it tries); it needs H.264 as Annex B with SPS and PPS in band (its parser makes the stream's extradata from the first frame), and -c:v copy to mkv or mp4 works (1280x720 for 5 s: 151 frames, 5.018 s, decodes). Its v4l2 demuxer parses only the first frame (AVSTREAM_PARSE_FULL_ONCE), which leaves the second packet without a timestamp ("Timestamps are unset in a packet"; the demuxer does this for any H.264 device): the muxer gives it the first's, so the first interval is 0 and the next one long. GStreamer 1.26's v4l2src ! video/x-h264 ! h264parse and v4l2-ctl --stream-mmap take it too. v4l2-compliance -s 10 (Debian's v4l-utils 1.30.1) passes 57 of 57 with YUYV or with H.264 as the format, -s 10 -f (every format, size and rate streamed) 129 of 129 (with YUV420 the default, 57 and 129, 2026-11-29). The guest's CPU by format (2026-11-29, i7-10700K, Node 24, one CPU, JIT, the CLI's --camera, ffmpeg -f v4l2 -input_format F -video_size S -framerate 30 -i /dev/video0 -frames:v 90 -f null -, medians of 3, start-up included): 11.5 to 12.6 ms a frame whatever the format, all at 30 frames a second; with -vf format=yuv420p (what an encoder or a player taking planar 4:2:0 needs) yuv420p 11.2 to 11.9 ms, nv12 12.8 and 13.6, yuyv422 14.3 and 21.9 (640x480, 1280x720): YUYV's conversion costs 3 ms a frame at 640x480 and 10 at 1280x720. mpv on Wayland: va.md, Results.

kwvsock (AF_VSOCK)

net/vmw_vsock/kwvsock.c, host js/core/vsock.ts: an AF_VSOCK transport on virtio_transport_common, registered as the G2H transport the way vsock_loopback registers its local one (KWVSOCK selects VIRTIO_VSOCKETS_COMMON and needs no VIRTIO; virtio_transport_stream_allow lives in virtio_transport.c, so kwvsock has its own).

  • Guest CID 3 (KWVSOCK_GUEST_CID), host CID 2; streams only (no seqpacket, no datagrams), with virtio-vsock's credit flow control. Packets are virtio-vsock's (struct virtio_vsock_hdr, then the payload); the host runs the other end of the protocol. Without the device connect() fails with ENODEV.
  • Sends keep their order: a packet the host refuses (-EAGAIN) goes back to the head of the queue and is retried after IRQ 6 (the SDK refuses only through its refuse test hook, since credit bounds the data).
  • RX takes packets into linear skbs of at most rx_max (32 KiB less the shared info; the host keeps every packet within it) and calls virtio_transport_recv_pkt(..., NULL) (global mode, like virtio-vsock); a failed skb allocation leaves the packet with the host and retries 10 ms later.
  • After a snapshot restore it resets connections (parking.md).
  • kw_defconfig: VSOCKETS, VSOCKETS_DIAG (ss --vsock), KWVSOCK, not VSOCKETS_LOOPBACK.
  • Guest tools (guest.md): kwvsock, kwtty (terminal sessions, programs on pipes and TCP relays for the host, port 1022), kw9p, the guest GL forwarder kwbox vtest (connects to host port 1019; gl.md), and wland's relay /usr/lib/kw/wlandr (the Debian image's; connects to host port 1023, the page's WAYLAND_PORT; its buffers are kwshm exports, below; web.md, Wayland desktop).

kwshm (shared memory)

drivers/misc/kwshm.c, UAPI include/uapi/linux/kwshm.h, host js/core/shm.ts: the host reads and writes the pages of guest shmem files (memfds, /dev/shm files) in place. The host opens or creates files in /dev/shm by name; guest programs export a shmem fd through /dev/kwshm (ioctl KWSHM_IOC_EXPORT, magic 0xBB, listed in ioctl-number.rst) and send the id to the host over any channel.

  • An export is a file or a page-aligned range of one, with an id (IDR, cyclic from 1, shared by host and guest exports; at most 4096, and at most half of RAM pinned). Its folios are pinned with memfd_pin_folios() (FOLL_PIN with FOLL_LONGTERM semantics, udmabuf's interface), which also allocates holes, so every page the host sees is the file's. A pin rather than a reference: it is the documented way to give something outside the kernel's mappings long-lived access, lets compaction skip the folio early (folio_maybe_dma_pinned()), and moves pages out of ZONE_MOVABLE/CMA first (none here). F_SEAL_WRITE uses the same refcount test, so it fails with EBUSY while exported.
  • A truncation or hole punch removes pinned folios from the page cache (folio->mapping becomes NULL) but cannot free them, so the host never touches freed or reused memory; its view may go stale: another size (i_size against the export's; range exports are clamped to their range) or a held folio whose mapping or index no longer matches. There is no change notification; the host learns staleness with a check, a round trip. Unpinning marks a writable export's folios dirty (folio_mark_dirty_lock()).
  • Host writes bypass kwemu: code the host writes into a page a guest program executes is not seen until an IC IVAU or a flush.
  • Ordering: every export is announced (attach) when it is made, refreshed and released, so a guest export's page list is at the host before the guest sends its id, and an attach comes before the reply to the request that caused it. A refresh unpins the old pages only after the new list's attach, a release only after the detach returned. A host that reads the pages from another thread (worker mode on the SMP kernel's shared memory, js.md, shm) keeps this by waiting inside those imports for its reader to let go.
  • Host opens look the name up in PID 1's fs (scoped_with_init_fs(): a kworker's own root is nullfs) without following a final symlink.
  • Closing /dev/kwshm releases its exports; an export is writable for the host only if the fd is writable and not sealed against writes. One mutex covers everything. At power-off the kernel releases nothing; the host forgets every export.
  • kw_defconfig: KWSHM (depends on SHMEM and MEMFD_CREATE).

kwvirtio (virtio transport) and virtio-gpu (/dev/dri)

drivers/virtio/kwvirtio.c, host js/core/virtio.ts: a virtio transport whose registers are host imports, so that stock virtio drivers run unmodified against device models in the SDK. Only virtio-gpu (drivers/gpu/drm/virtio, host js/core/virtio-gpu.ts) is enabled.

  • Imports (wasm_driver_virtio_*): init(index) (the device ID of the host's device index, <= 0: none; devices are 0, 1, ... without holes, at most 8), features, set_features (after vring_transport_features; VIRTIO_F_VERSION_1 is required), config(dev, offset, buf, len, write), status (0 resets; the kernel keeps the status byte itself), queue_max, queue_set(dev, queue, num, desc, avail, used) (num 0 takes it down), notify(dev, queue), interrupt(dev) (reads and clears the interrupt status: bit 0 used buffers, bit 1 config change). None suspends; notify comes in atomic context.
  • Split rings from vring_create_virtqueue(), no indirect descriptors, no event index, no ACCESS_PLATFORM. Without ACCESS_PLATFORM virtio_ring and virtio-gpu do not use the DMA API for the rings and commands (vring_use_map_api() and virtio_gpu_use_dma_api() are false), so every address is physical, i.e. a kernel memory offset, and the host reads and writes rings and buffers in place.
  • One IRQ for all devices: WASM_IRQ_VIRTIO (10), IRQF_SHARED; each device's handler runs virtio_config_changed() and vring_interrupt() on its queues.
  • Each device's parent is a platform device kwvirtio.N with a 32-bit DMA mask. virtio-gpu makes the parent its DRM device, and drm_gem_shmem_get_pages_sgt() maps a buffer's sg table with dma_map_sgtable() on it, which dma-direct does one to one; virtio-gpu passes orig_nents page addresses to the host anyway. libdrm (Debian 13's 2.4.124) takes the parent as it is: drmGetDevice2() reads device/subsystem (platform) and, with no OF node, the MODALIAS (platform:kwvirtio) for the device's name, and Mesa's loader, finding no PCI ids, names the driver from DRM_IOCTL_VERSION (virtio_gpu), as it logs: "device is not located on the PCI bus", "using driver virtio_gpu". Nothing in the kernel was needed for that (2026-11-21).
  • SMP: the process-context calls go through kw_host_call(); a notify on another CPU sets the queue's bit in the device's pending mask and raises WASM_IRQ_VIRTIO on CPU 0, whose handler sends it before it reads the interrupt status.

virtio-gpu: /dev/dri/card0 and renderD128, driver name virtio_gpu, one CRTC and connector, KMS with dumb buffers (GEM shmem objects in the guest, their pages handed to the host as the resource's backing), and 3D when the host offers VIRTIO_GPU_F_VIRGL (createKernel({ gl, gpu }) in a browser: two capsets, VIRGL and VIRGL2, from the renderer's WebGL2 context; gl.md, The DRM path). Without it Mesa falls back to software. There is no udev: the kw layer's rc gives card* to video (0660) and renderD* to everyone (0666), as udev's rules do (guest.md).

  • Display size: the connector's one mode is the host's EDID mode (the host's display size, preferred). A size change on the host is the config space's VIRTIO_GPU_EVENT_DISPLAY with a config interrupt (kwvirtio's KWVIRTIO_INT_CONFIG, virtio_config_changed()); the stock driver's work item asks for the EDID and display info again and calls drm_kms_helper_hotplug_event(): a change uevent of card0 with HOTPLUG=1 on the kernel's netlink group, and nothing else (no fbdev client). The modes are refreshed when a DRM master probes the connector (GETCONNECTOR with no modes; /sys/class/drm/card0-Virtual-1/status "detect"). With no udev a program hears of it only from netlink itself (test/gpu/kms-hotplug.c); libudev monitors (X's modesetting driver) listen to udevd's group and hear nothing. Nothing in the kernel was needed (js.md, virtio-gpu).

  • What the kernel side does not use: vmap() (VMALLOC_FLAT cannot map scattered pages). The 2D paths pass backing as page lists and never vmap; only drm_gem_shmem_vmap() callers would (fbdev emulation, the panic screen, dma-buf importers that vmap), and DRM_FBDEV_EMULATION and DRM_PANIC are off. PRIME between openers of the device (a client's dmabuf imported by a compositor) is a self-import, which maps nothing (test/gpu/prime.c; gl.md, The DRM path). virtio-gpu has no vblank interrupt from the host: it emulates one with DRM's vblank timer (DRM_CRTC_VBLANK_TIMER_FUNCS, at the mode's refresh, 60 Hz from the EDID), so a page-flipping client runs at most at 60 frames a second (kmscube: 59.97, 2026-11-21), and so do DIRTYFB updates. The timer runs on for drm.vblankoffdelay after its last use (100 ms: the kw layer's rc lowers the kernel's 5 s, kernel/guest.md) (test/gpu/flip-check.mjs counts the host's idles), then an idle guest has no periodic timer. No kthreads (its work items run on the system workqueue), so parking needs nothing new.

  • A DIRTYFB transfers its rectangle only: the series backports a9cc9905ddb7 ("drm/virtio: Recalculate ignore_damage_clips on every update", 7.4), without which the flag sticks after the first commit that changes the framebuffer, and 730f8554f35c, which keeps a rendered resource's damage clips across page flips.

  • DRM_IOCTL_VIRTGPU_GET_CAPS waits up to 30 s for a capset the kernel has not cached, killably (patch 0048, "drm/virtio: wait up to 30 s for a capset"; upstream 5 s, then -EBUSY): the host loads its 3D renderer on the first capset request, which may fetch it over the network (gl.md, Loading on first use).

  • Snapshots: the host refuses one ("virtio-gpu resources", or "virtio-gpu contexts" with 3D: at once, before the guest parks; -EBUSY at the snapshot point for unanswered commands) while the device holds resources, contexts or unanswered commands, which a KMS client that has exited no longer does; otherwise it saves the transport state (status, features, each queue's addresses and next available index) and a restore picks it up, with nothing in the kernel (no restore notifier).

  • kw_defconfig: VIRTIO_MENU, KWVIRTIO, DRM, DRM_VIRTIO_GPU, DRM_VIRTIO_GPU_KMS; not VIRTIO_MMIO, VIRTIO_BALLOON, VIRTIO_INPUT, DRM_FBDEV_EMULATION, DRM_PANIC, DRM_DDC, DRM_HDMI_INFOFRAMES, DRM_PANEL_BRIDGE, NET_DEVMEM.

  • Check: node test/gpu/check.mjs (a dumb-buffer client, test/gpu/kms-dumb.c, against the host's frame, and display size changes heard by test/gpu/kms-hotplug.c; testing.md).

kwserial (serial ports)

drivers/tty/serial/kwserial.c, host js/core/serial.ts: the host's serial ports (Web Serial's in a browser) as /dev/ttyACM0 to ttyACM3 on serial_core, one per port wasm_driver_serial_init() offers (1..4). No 8250 and no console on them; the major is dynamic. The name is cdc_acm's (this kernel has no cdc_acm: a CDC ACM device on kwusb gets no tty), so that serial programs list the ports: pyserial (3.5) globs ttyACM* among others and drops ports whose sysfs parent is on the platform bus, which these are not (the parent is serial_core's port device, on serial-base); it lists all four, with or without a device (checked 2026-11-29).

  • Imports (wasm_driver_serial_*): init; open(port) at the first open (0, or -ENODEV with no port in that slot; the host opens the physical port afterwards, and a failure there comes as the hangup event); close(port) at the last; config(port, baud, cfg) from set_termios (cfg bits 0-3 data bits, 4 two stop bits, 5-6 parity, 0 none, 1 odd, 2 even, 7 CRTSCTS; baud 50 to 4000000; mark and space parity are cleared); write(port, buf, len) and read(port, buf, max), which return the bytes the host took or gave during the call (buf a kernel address, i64 at the JS boundary like the other drivers'); set_signals(port, bits) (DTR, RTS, BREAK: the whole state); status(port): levels (CTS, DSR, DCD, RI, a port attached, the host's transmit queue empty) and events the read clears (bytes received, room to transmit, an input changed, hangup; break, framing, parity and overrun). Every call is made on CPU 0 with the port's lock held and interrupts off; none suspends.
  • One IRQ for all ports, WASM_IRQ_SERIAL (12). Its handler reads each open port's status and reports the receive errors first (the host cannot place them in the byte stream): a break reads as a NUL, flagged with BRKINT or PARMRK; with INPCK a flagged NUL stands for the character with a framing or parity error, so PARMRK gives \377 \0 \0; an overrun is counted and flagged, which n_tty only logs; IGNBRK and IGNPAR drop them as 8250 does, and every one is counted (TIOCGICOUNT). Then the bytes go into the tty, 512 per read and at most 64 KiB per interrupt (a work item on CPU 0 takes the rest), DCD and CTS changes go through serial_core, and every edge of the four inputs (RI's both) counts for TIOCMIWAIT. TIOCMGET reports the inputs of the last status read.
  • Output: start_tx hands the transmit FIFO to write; after a short count the rest waits for the room event. tx_empty reads the status, so tcdrain returns once the host's queue is empty; fifosize 4096 is the host's window (without CRTSCTS serial_core gives a drain up after twice the time that many characters take).
  • Flow control: with CRTSCTS the host does RTS and CTS (serial_core's AUTORTS and AUTOCTS), and in every mode a throttle (UPSTAT_SYNC_FIFO) stops the driver reading from the host, which keeps the bytes, until unthrottle; a full tty buffer is retried 10 ms later. Nothing received is dropped in the kernel.
  • Hangup: the event hangs the tty up (readers get EOF, writers EIO), and the last close closes the host's port; the next open asks the host again. serial_core lets CAP_SYS_ADMIN open a port whose startup failed (for setserial, with EIO on every read and write); the driver's tty open fails it for root too, so an empty slot is ENODEV for everyone.
  • Snapshots: the host keeps no port state, so the park restore notifier hangs up every port that was open (parking.md).
  • No kthreads; the retry work item runs on CPU 0 (system_percpu_wq). It allocates only with host ports (about 1 KiB a port, and serial_core's 4 KiB transmit buffer while a port is open).
  • No udev: the kw layer's rc gives /dev/ttyACM* to dialout with mode 0666, since the images' user is not in dialout (guest.md); on the base shell they stay root's (0600).
  • kw_defconfig: SERIAL_KWSERIAL (selects SERIAL_CORE); not SERIAL_8250 or a serial console.
  • Check: pnpm test:serial (the host's unit tests and test/serial.test.ts: test/serial/ttyacm.c on FakeSerialBackend's loopback, on the UP kernel and on 2 CPUs with the program on CPU 1: termios, signals, break, data, inputs, errors, hangup; no ports without the option, ENODEV for an empty slot, the rc's modes on Alpine, a restored snapshot's hangup).

kwbt (Bluetooth)

drivers/bluetooth/kwbt.c, host js/core/bluetooth.ts: a plain HCI transport to the host's Bluetooth controller, hci0 while one is attached. H4 packets (the type byte, then the command, ACL, SCO, ISO or event packet) cross through imports, which copy them during the call; the driver knows nothing of what is behind them (an emulated LE controller over Web Bluetooth, js/core/bluetooth-le.ts, or a real controller's HCI). The bus the host reports becomes hdev->bus (HCI_VIRTUAL for the emulated one); the parent is the platform device kwbt.

  • Imports (wasm_driver_bt_*): init (> 0: the host has the device; <= 0: none, nothing registered or allocated); status (the attached controller's id in bits 16-31, 0 for none, and events the read clears: bit 0 packets received, bit 1 room to send after -EAGAIN, bit 2 a controller attached or detached); info(id) (the bus), open(id) and close(id) (hdev open and close: the guest's power on and off, and the kernel's setup at registration); send(id, pkt, len) (0, -EAGAIN while the host's queue is full, -ENODEV); rx_len(id) and recv(id, buf, max) (the next received packet, its length with the type byte; recv drops it). Every call names the id, and the host refuses an id that is no longer attached, so packets never reach the wrong controller. None suspends.
  • One IRQ, WASM_IRQ_BT (14). Its handler reads the status, drains received packets into hci_recv_frame() (64 per interrupt, the rest from a work item; a failed allocation leaves the packet with the host and retries 10 ms later) and sends what waits. hdev->send queues the packet and the queue goes to the host in order; after -EAGAIN the rest waits for the room event. HCI's own flow control (command credits, Number of Completed Packets) keeps the queue short.
  • Hot attach and detach, like a USB dongle: a work item (on CPU 0) registers an hci_dev when the host attaches a controller and unregisters it when the controller goes or another replaces it, so switching from the emulated controller to a real one needs nothing in the guest. The name is the first free index: hci0 again unless something (an open socket) still holds the old device, then hci1.
  • Snapshots: the new host has none of the controller's state, so the park restore notifier makes the hci_dev stale at once (nothing more is sent or received for it) and the work item unregisters it and registers whatever the new machine attached: a detach and an attach (parking.md). Connected sockets fail (ECONNABORTED), as on a detach.
  • No kthreads: the hci_dev's two ordered workqueues have no rescuer (no WQ_MEM_RECLAIM) and the driver's work items run on CPU 0 (system_percpu_wq); BT core starts none with RFCOMM, BNEP and HIDP off.
  • A host without the imports (an SDK older than kwbt) leaves them unresolved; the SDK's stub for any unresolved wasm_driver_*_init answers -ENODEV (js/core/kernel.ts), so the guest has no adapter and the boot goes on.
  • kw_defconfig: BT (with BT_BREDR, BT_LE and BT_LE_L2CAP_ECRED, the defaults; BR/EDR costs 14 KB and keeps a real dual-mode controller whole later), BT_KWBT; BT selects the crypto it needs (ECDH, the AES library for SMP). Not RFCOMM, BNEP, HIDP (each brings a kthread), UHID (needs the HID core; BlueZ's HID over GATT uses it, and browsers block the HID service anyway), RFKILL or the AF_ALG user APIs: bluetoothd 5.82 runs without them (it logs that the kernel lacks BNEP and that SAP cannot listen on RFCOMM). config.md has the size.
  • BT_KWBT is tristate (BT too). As a module (kw_modules.config, kmod.md) its init runs on the loading task's CPU, so on SMP it probes through kw_host_call(); it has no exit and stays loaded.
  • Guest: nothing in the images. Debian's apt install bluez works at run time, and its init script starts bluetoothd (with dbus) at boot from then on (kw-init runs sysv-rc); bluetoothctl works as the image's user, btmgmt and btmon as root. Alpine: apk add bluez (bluez-btmon for btmon), then, with no service manager running, mkdir -p /run/dbus; dbus-daemon --system; /usr/lib/bluetooth/bluetoothd & by hand (checked 2026-11-29: scan, connect, the battery level). No device nodes are involved (sockets only; no /dev/rfkill).
  • Checked 2026-11-29 with BlueZ 5.82 (Debian trixie) on the CLI's --bluetooth fake peripheral, UP and 2 CPUs in worker mode: bluetoothd powers the adapter, bluetoothctl scan on lists the device with its name, services and RSSI, connect resolves its services (the battery level shows in info), gatt.list-attributes, read, write, notify on (with the loopback's notification) work; pair fails with AuthenticationFailed and the device disconnects (SMP gets Pairing Not Supported); advertise on fails (org.bluez.Error.Failed: the controller answers advertising commands with Unknown HCI Command). btmon shows no other refused command. bluetoothd's "Set Default System Configuration: Invalid Parameters" at start is BlueZ's own.
  • Check: pnpm test:bluetooth (the host's unit tests and test/bluetooth.test.ts: test/bluetooth/kwbt.c on raw sockets (management to power on and discover, L2CAP ATT for GATT) against the fake peripheral, on the UP kernel and on 2 CPUs with the program on CPU 1: discovery, connect, MTU, GATT discovery, read, write, notifications, a remote disconnect, a detach while connected, a new controller; no adapter without the option, a host without the imports, a restored snapshot's replaced hci0).

kwusb (USB host controller)

drivers/usb/host/kwusb.c, host js/core/usb.ts: a USB host controller whose URBs the host serves (WebUSB devices in a browser), so usbcore, usbfs and the USB drivers run unmodified. A platform device kwusb with two usb_hcds sharing it (HCD_SHARED): bus 1 a USB 2.0 root hub (has_tt, low, full and high speed devices), bus 2 a USB 3 root hub (SuperSpeed), each with wasm_driver_usb_init() ports (1..8; the SDK offers 4); a slot's device is on the hub of its speed, with the same port number. No hubs below the root hubs (usbcore refuses URBs for a device whose parent is not a root hub).

  • Imports (wasm_driver_usb_*): init; submit(xfer): a struct kwusb_xfer (host ABI, in kwusb.c: id, slot, endpoint address, type, flags ZERO_PACKET and SHORT_NOT_OK, length, segment count, wMaxPacketSize, interval, isochronous packet count, the setup packet's and the isochronous table's addresses, then {addr, len} segments) that the host reads during the call, copying OUT data out of guest memory then; 0 or a negative errno (no device in the slot: -ENODEV), which urb_enqueue returns. reap(done, max): up to max 16-byte struct kwusb_done records (id, status, actual length, isochronous error count); before it returns, the host writes each one's IN data into the URB's segments and the isochronous packets' actual lengths and statuses into urb->iso_frame_desc. cancel(id): the host forgets the URB, including a completion it had not handed over yet, and writes nothing for it afterwards. changed(): a bit per slot with port events; port(slot): connected (bit 0), the speed (bits 1-3, enum usb_device_speed), and events the read clears: a connection change (bit 8, also when a device went and another came between two reads) and a finished reset (bit 9); port_op(slot, op): a port reset (op 1), answered 1 when done at once, 0 when the host reports its end later (bit 9), < 0 with no device. None suspends; each is called with kwusb_lock held and interrupts off.
  • One IRQ for everything, WASM_IRQ_USB (13). The handler hands the host what other CPUs queued, sends their cancels and resets, reaps in batches of 64 and updates the ports, then gives the URBs back (usb_hcd_giveback_urb(), no HCD_BH: completion handlers run in the handler, interrupts off) and polls the root hubs (uses_new_polling, no timer: an idle machine has no periodic USB work).
  • Data: no HCD_DMA, so usbcore maps nothing and transfer_buffer is the kernel address the host copies to and from; sg_tablesize is ~0 with no_sg_constraint, and an URB's scatterlist goes as segments (sg_virt()), so usbfs submits a large bulk transfer as one URB of 16 KiB pieces (USBDEVFS_CAP_BULK_SCATTER_GATHER; libusb then submits a transfer whole). usbfs's mmap buffers are kmalloc pages mapped with remap_pfn_range() (hcd_buffer_alloc_pages without DMA).
  • Dequeue: usb_hcd_check_unlink_urb(), then on CPU 0 cancel and the giveback at once, with the unlink status; elsewhere the URB waits on a cancel list for CPU 0 (it may still complete meanwhile; usbcore gives the unlink status either way). The host cannot stop a WebUSB transfer: it keeps what it brings for the endpoint's next URB (js.md, USB).
  • Ports: the root hubs' status words live here (vhci_hcd's model). A connection sets CONNECTION and C_CONNECTION; a port reset clears ENABLE, asks the host (port_op) and enables the port (with LOW_SPEED or HIGH_SPEED on bus 1) when the host says it ended; only an enabled port takes URBs (-ENODEV otherwise). Suspend (bus 1) resumes at once; power, link state, U1/U2 timeouts and the BOS descriptor of bus 2 are kept or answered here. No CONFIG_PM in this kernel, so no bus suspend.
  • Snapshots: the park restore notifier gives every URB back with -ESHUTDOWN, disconnects every port that had a device and reads all ports from the host again (a work item on CPU 0; also run once at probe, for devices attached before the handler was registered), so a restored guest sees its devices unplugged (parking.md).
  • SMP: an enqueue, dequeue or port reset on another CPU, in any context, is queued (submits in one list, so an endpoint's URBs keep their order) and raises WASM_IRQ_USB on CPU 0 (smp.md).
  • Allocates nothing without host ports. With them: the two buses and root hubs, a 16-byte header and 16 bytes a segment per URB in flight (from the submitter's mem_flags), an IDR of the ids. usbcore itself (usbfs, the hub driver) registers at boot either way. A device attached and enumerated took about 210 KiB more RAM (88 KiB of it slab), the build 92 KiB less RAM available at boot (2026-11-29).
  • No udev: devtmpfs makes /dev/bus/usb/BBB/DDD (and a USB serial driver's /dev/ttyUSB*) when a device comes, root's with mode 0600, and kwhotplug, which the kw layer's rc starts, gives them mode 0666 on their uevent (/dev/ttyUSB* also the group dialout; guest.md). On the base shell they stay root's.
  • kw_defconfig: USB_SUPPORT, USB, USB_KWUSB_HCD, USB_SERIAL with FTDI_SIO, CP210X, CH341 and PL2303; not USB_ACM (kwserial is ttyACM), HID, USB_STORAGE, sound or video class drivers (WebUSB cannot claim those classes), USB_NET_DRIVERS or SND_USB (menus with nothing on).
  • Check: pnpm test:usb (the host's unit tests and test/usb.test.ts: test/usb/usbtest.c on usbfs against FakeUsbBackend, on the UP kernel and on 2 CPUs in worker mode with the program on CPU 1: descriptors with the HID interface hidden, control, bulk loopback of 4 MiB in one URB and 8 MiB with URBs in flight, a zero-length packet, a short read, interrupt IN, an unlinked IN whose data reaches the next URB, stall and CLEAR_HALT, isochronous IN, USBDEVFS_RESET, URBs pending at an unplug (ESHUTDOWN), a new device in the port; a SuperSpeed and a full-speed device; no controller without the option; a restored snapshot's ESHUTDOWN).

9p (host file systems)

Host file systems use the stock 9p client with the fd transport: no driver and no host import (host js/core/9p.ts, guest guest/src/kw9p.c). kwbox 9p NAME DIR [ro] connects an AF_VSOCK socket to the host (CID 2, port 564) and mounts 9P2000.L with trans=fd,rfdno=S,wfdno=S, cache=readahead and metatimeout=1000; the client takes its own references to the socket, so kw9p exits after mount(2) and unmounting closes the connection. mount and df show kw9p:NAME. What the guest caches and the numbers: js.md, Host file systems.

The patch 9p: add metatimeout adds metatimeout=MS, because stock fs/9p has no attribute timeout and no way for the server to invalidate a guest cache: CACHE_META with an expiry per inode (v9fs_inode.attr_expire, set in v9fs_stat2inode_dotl), checked in __v9fs_lookup_revalidate and v9fs_vfs_getattr_dotl; v9fs_refresh_inode_dotl then drops the pages of a file whose qid.version, size or mtime changed and leaves a name that now holds another qid.path invalid. Negative dentries get the same expiry. It is meant for 9P2000.L (with the legacy protocols lookups always revalidate, but a stat of a cached inode is not refreshed); without the option nothing changes. v9fs_get_tree refuses it with EINVAL in any cache mode with CACHE_WRITEBACK (mmap, loose, fscache, or a bitmask with that bit): the CACHE_META getattr path skips the flush of dirty pages and a refresh rewrites the inode from the server, which could truncate pending writes.

kw_defconfig: NETWORK_FILESYSTEMS (the menu that holds 9P_FS; nothing else in it is on), NET_9P (selects NETFS_SUPPORT), NET_9P_FD, 9P_FS; not 9P_FS_POSIX_ACL, 9P_FSCACHE or the virtio, Xen, RDMA and USB transports. kwtest checks that the type is registered.