Hardware
Every node lists its own hardware from /sys and keeps one Device per piece in the store, applied when it turns up and deleted when it is gone (a rescan every half minute): kith get device lists them. A Device is named NODE-CLASS-NAME (lower case, cut to 63 characters); its spec has node, class and the device node as path. The class is gpu (a DRM card, /dev/dri/card0), display (a connector with a screen; no path), input (/dev/input/event3), audio (a sound card, /dev/snd/controlC0), camera (/dev/video0) or usb (not a hub, /dev/bus/usb/001/004).
- Labels (a selector can name them). All:
kith.dev/node,class,kith.dev/discovered: "true". GPUs and USB devices alsovendor,model; a GPUdriverand, where known,vramin bytes, anddmem, the region of its memory where its driver gives the kernel's dmem cgroup one and kithd can give its containers the controller (drm/0000:03:00.0/vram); inputs and sound cardsmodel. An input alsoidentity, a hash of its name, port, serial and ids: another device behind the same event index is taken from its holder. A USB device alsobus, its port (1-2), andserial, a hash of its serial where it says one: its ids are the stick's own to say, so name one stick byserialorbuswithkith.dev/node; another serial (or none) in its port takes it from its holder. NODE-seat0is aSeatnaming the node's displays, inputs, sound cards and GPUs. What carrieskith.dev/discoveredis kept in step (rewritten if you edit it, deleted when the hardware goes); aDeviceorSeatyou wrote yourself is never touched.- Do not name nodes
alphaandalpha-gpu: a Device belongs to the node with the longest name that starts it. A join that would take a listed Device is refused. - NVIDIA's own driver. A card on it also has
nodes: what CUDA, OpenGL and Vulkan open beside the card (/dev/nvidiactl,nvidia-uvm,nvidia-uvm-tools,nvidia-modeset,/dev/nvidiaN), those that exist. Not tried on a real card. - A sound card also has
nodes: its own playback PCM nodes (/dev/snd/pcmC1D3p, one per output, not capture and not another card's), so a claim of it, or of a seat that has it, plays sound as well as opening the control node.
Claiming hardware #
A workload names DeviceClaims (same namespace) in its template's deviceClaims. A claim names a seat, a device or a selector over Device labels, and access: exclusive (default) or shared:
apiVersion: kith.dev/v1
kind: DeviceClaim
metadata: { name: render }
spec:
selector: { class: gpu, kith.dev/node: n1 }
access: exclusive
---
apiVersion: kith.dev/v1
kind: Workload
metadata: { name: renderer }
spec:
template:
containers: [{ name: run, image: example/renderer }]
deviceClaims: [render]
- The workload runs only on the node of the Devices its claims reach. A selector that matches Devices on several nodes takes those of the lowest-named node; add
kith.dev/nodeto fix the node. Claims that reach two nodes hold nothing (the status says so). - One workload holds a Device at a time. A second exclusive holder waits (
unschedulable:waiting for DeviceClaim render, held by Workload/default/renderer) and takes over when the first is gone.sharedclaims may have any number of holders, none beside an exclusive one.kith get deviceclaim render -o yamlshowsstatus.node,devices,holdersormessage. - A container gets its Devices' nodes in its own
/dev, besidenull,zero,full,random,urandom,tty; a GPU brings its render node (/dev/dri/renderD*). A missing Device or claim stops the unit and says which./dev/mem,/dev/kmem,/dev/portand/dev/tpm*are given to no pod, whatever a Device says. Nor is/dev/kmsg, a disk's or flash's raw node (/dev/sg*,/dev/nvme0,/dev/ng*,/dev/mtd*,/dev/mapper/control), any block device (/dev/sda,/dev/block/8:0), a link or a plain file: a Device grants a node only if it is a character device that is there, whoever wrote the Device. One path that is not (or is missing, an unplugged camera or a driver not yet loaded) stops the unit, and its status says which Device and path. The kernel subsystems refused arescsi_generic,bsg,nvme,nvme-generic,mtd,tpm,tpmrm,msr,dax,ubi,ublk-char,vfio,i2c-dev,nvram,cpuid,mei,watchdog,vfio-dev,uio,spidev,ipmi,usbmon,drm_dp_auxanddrm_dp_aux_dev(read from/sys/dev/char), and so are char major 21 (sg) and the misc nodes the kernel reports only asmisc: nvram (10:144), watchdog (10:130), vfio (10:196), mcelog (10:227), snapshot (10:231), cpu/microcode (10:184) and hpet (10:228). Where/sys/dev/charis there and a node's subsystem cannot be read, the node is refused too. This is a list of what to refuse, not of what to allow: a Device is set by the admin for hardware no list could name, and an allowlist would break it. Other raw nodes may exist; a Device is the admin's grant. Given on purpose:/dev/kvm(10:232) is given: VM workloads need it.hidrawnodes are given: security keys and gamepads are such devices./dev/loop-control(10:237) is given: it does nothing without a block device, which is never granted.userfaultfdis given: it is a syscall, not a node a Device grants./dev/hwrng(10:183) is given: it only reads random bytes.
- On kith OS a device filter on each container's cgroup checks every open and
mknod: it lets through the usual few, the terminals of the container's own/dev/ptsand each device it was given, and refuses the rest, even to a root pod. A pod that made its own node (/dev/net/tun), or a FUSE program (/dev/fuse; kith OS's kernel has FUSE), needs aDevicewithclass: otherand itspath, claimed. Where kithd is your own service there is no filter: no one in a user namespace can make a node. - The right to apply a
DeviceClaimand a workload that names it is the grant: a Role rule withkinds: ["*"]covers both, so give it only to someone you trust with any hardware.
Who may claim what. A Device or Seat is given to namespaces by its label kith.dev/namespaces, a comma-separated list (default, desktop). A claim in namespace N reaches it only if the label lists N, or N is kith-system, the cluster's own. With no label, a gpu is open to every namespace, and every other Device (input, audio, camera, display, usb, other) and every Seat is kith-system's alone. A seat claim also needs each of the Seat's labelled Devices to be given to N. The label is an admin's (metadata.labels, kith apply -f): discovery keeps it, and a worker cannot add, change or drop it. Removing it refuses a claim at the next pass; its status.message says why. A labelled Device or Seat whose hardware is gone is kept, so the label is there when it comes back, and marked kith.dev/absent: "true" until then: a claim naming it is refused ("is absent") and a selector passes over it.
A share of a GPU's vram. A shared claim may say share: { vram: 512Mi }: what it asks of each Device it holds, counted against the Device's vram label. A workload's shares add up; one that does not fit waits, and its message gives the numbers (status.share). On a Device with a dmem label the share is also a ceiling: each of the workload's containers gets the sum of its shares there as dmem.max in its cgroup, and the kernel refuses it more of the GPU's memory (status.share.DEVICE.enforced: true). That is where the driver gives the region (amdgpu, xe, NVIDIA's) and kithd may hand the controller down to its containers (root, or a delegation with dmem; a kithd that cannot gives its Devices no dmem label). Elsewhere a share is cooperative. Read back on a PC with a Radeon iGPU and kithd as root, a 256Mi share gave the container's cgroup drm/0000:74:00.0/vram 268435456 in dmem.max, and the claim enforced: true. Untried: MPS, MIG partitions.
An app as a workload of its own, in a session's window #
A DeviceClaim on a seat with access: client takes none of the seat's devices, so any number of workloads hold it beside the session, each on the seat's node, in the session's namespace and only while a workload of that namespace holds the seat. Each gets the render nodes of the seat's GPUs (not the card) and the seat's directory /run/seat, to read. A session that puts its Wayland and PipeWire sockets there (the desktop packages set XDG_RUNTIME_DIR=/run/seat) is where the app opens its window:
apiVersion: kith.dev/v1
kind: DeviceClaim
metadata: { name: office-apps }
spec: { seat: office-pc-seat0, access: client }
---
apiVersion: kith.dev/v1
kind: Workload
metadata: { name: editor }
spec:
template:
deviceClaims: [office-apps]
containers:
- name: editor
image: registry.example/me/editor:3
env:
- { name: WAYLAND_DISPLAY, value: /run/seat/wayland-0 }
- { name: PIPEWIRE_RUNTIME_DIR, value: /run/seat }
- The app has its own image, limits, volumes and rollback, and shows as one of the claim's
status.holders. It must run as the session's user: the directory is that user's alone. - Input hot-plug. An input device plugged in or pulled while a container holds its seat appears in or leaves its
/dev/inputat the next scan, with no restart (on kith OS, for a container that had an input device at start); elsewhere, or when a changed claim or seat takes one away, the unit restarts. Not yet: an app on another node shown in this session; a NodeWorkload claim. A client of a session is in it: see SECURITY.md.
Running a Flatpak app in a session #
examples/session/ is a session and one Flatpak app in its window, both in the desktop namespace on the seat desk-seat0. After the seat exists, kith apply -f examples/session/session.yaml applies it; put your own image names and app ID in place of the placeholders.
What makes it work:
- One user. The session and the app both run as uid 1000 (
runAsUser), a user the example's Containerfile makes. The seat's directory is that user's alone, so an app as another user cannot open the sockets in it. - The session holds the seat.
desk-seatis exclusive, so the session takes the seat's devices.session-start.shstarts the session bus at/run/seat/busand the compositor on/run/seat/wayland-0, withXDG_RUNTIME_DIR=/run/seat. - The app is a client.
desk-appshasaccess: client: it takes no seat device, only the seat's directory and the render nodes. ItsWAYLAND_DISPLAYandDBUS_SESSION_BUS_ADDRESSpoint at those sockets. ItsXDG_RUNTIME_DIRis its own,/run/user/1000, because the seat's directory is read-only to it. - A home that lasts.
HOMEis/home/app, a Volume (app-home) on the seat's node, so the app's data outlives its container.userNamespaces: truelets Flatpak's sandbox start, andreadOnlyRoot: falselets it install into the image's root.
Untried: nothing here has run on a seat. Not checked: that Flatpak accepts an absolute WAYLAND_DISPLAY, that weston reaches the DRM device as uid 1000 without the video and render groups, and that flatpak run finds an app installed in the image. The repository does not build or pull the example image. An app that shares the session's user, bus and seat directory is in the session's trust: see SECURITY.md.
What a seat keeps for itself #
apiVersion: kith.dev/v1
kind: Seat
metadata: { name: desk-seat0 }
spec:
node: desk
devices: [desk-gpu-card0]
reserve: { cpu: 4, memory: 8Gi } # kept for whatever holds the seat
---
apiVersion: kith.dev/v1
kind: Workload
metadata: { name: training }
spec:
template:
containers: [{ name: run, image: registry.example/train:1 }]
yieldTo: { seat: desk-seat0, when: [fullscreen] } # step back while a game is up
- A seat's
reservecomes off its node for every workload that does not hold the seat, held or not. The holder fits only what it wants beyond it; its units are guaranteed the reserve's memory (memory.min) and go first for CPU and disk (cpu.weightandio.weightat 10000; all else 100). CPUs are not pinned; a GPU is not shared out (not yet). - kithd sets
status.activityof a held seat itself, every few seconds:fullscreenwhile the seat's sound card plays (any playback counts, music too),activefor three minutes after its keyboard, mouse or pad is touched (kithd notes only that something came, never what),idleotherwise. A seat nobody holds is idle, and one with no sound card or input is left as it is. A session may say better withPOST /v1/seats/desk-seat0/activity?state=active|idle|fullscreen(it needs an Identity whose Role may applySeats): a POST wins for ten minutes, then kithd judges again. Posting the same value again does not extend the ten minutes (there is no heartbeat yet): a session that must stayfullscreenlonger than that has a sound card or input that says so. (A POST of the value already there, or one made before the node first looks at the seat, is not seen as a POST.) A plan withwaitForIdleSeatswaits for a node whose seat isactiveorfullscreen. - A workload with
yieldToruns on a twentieth of a CPU on that seat's node while the seat is in a state it names, and gets its limit back when the state changes (about ten seconds). - A template that says
priority: idlegoes further down:cpu.idle, the lowestio.weightand amemory.high, on every node and whatever the seat does. Batch work beside a desktop takes only spare cycles (see idle work).
A TV or kiosk seat #
A PC on a TV that shows one web page (a media server's TV page) is a seat held by one container: a Wayland compositor (cage) with a browser in it. The seat's sound goes out of the TV's HDMI. The node runs a kith OS image with the card's driver built in (gpu-nvidia-pascal for a GeForce GTX 10xx, gpu-amd-phoenix for a Ryzen's GPU: kith OS).
The image is yours to build. kith ships no kiosk image: this recipe starts from stock Alpine and you build and push one image of your own, with the packages in it, to a registry the nodes reach. Nothing is installed when the seat starts, so the session needs no root and no network but the page's:
FROM docker.io/library/alpine:3.22@sha256:<digest of the Alpine you checked>
RUN apk add --no-cache cage chromium mesa-dri-gallium mesa-gbm alsa-utils wlr-randr font-noto \
&& adduser -D -u 1000 kiosk && addgroup kiosk video && addgroup kiosk audio
USER 1000
The page is trusted with the seat: a page that runs in the kiosk reads the seat's keyboards and pads and sets its sound, so point it only at a server you run, and keep the seat in a namespace of its own (tv below) that no one else's workloads share. The seat and each Device of it are given to that namespace by their label (kith.dev/namespaces: tv: add it under metadata.labels of kith get seat tv-seat0 -o yaml and of each of the seat's kith get device, and apply them), as under who may claim what; until then the claim is refused and says why.
apiVersion: kith.dev/v1
kind: Volume
metadata: { name: tv, namespace: tv }
spec: { node: tv, path: /var/lib/kith/tv, size: 1Gi } # the browser's profile
---
apiVersion: kith.dev/v1
kind: DeviceClaim
metadata: { name: tv, namespace: tv }
spec: { seat: tv-seat0, access: exclusive }
---
apiVersion: kith.dev/v1
kind: Workload
metadata: { name: tv, namespace: tv }
spec:
replicas: 1
template:
deviceClaims: [tv]
initContainers:
- name: own-profile # the Volume is root's: give it to the browser's user, then end
image: registry.example/tv/kiosk@sha256:<digest>
runAsUser: 0
command: [chown, "1000:1000", /data]
volumeMounts: [{ volume: tv, path: /data }]
containers:
- name: session
image: registry.example/tv/kiosk@sha256:<digest> # pinned by digest, built as above
runAsUser: 1000
runAsNonRoot: true
userNamespaces: true # Chromium's own sandbox starts: no --no-sandbox
resources: { memory: 3Gi } # no cpu: see below
volumeMounts: [{ volume: tv, path: /data }]
env:
- { name: URL, value: "https://media.example/tv" }
- { name: CARD, value: NVidia } # the sound card's id: the audio Device's `model` label
- { name: PCM, value: "3" } # its output PCM: see Sound below
- { name: XDG_RUNTIME_DIR, value: /tmp/run }
- { name: LIBSEAT_BACKEND, value: noop }
command:
- sh
- -c
- |
mkdir -p /tmp/run && chmod 700 /tmp/run
for i in 0 1 2 3; do amixer -q -c "$CARD" sset "IEC958,$i" on; done
exec cage -- chromium --kiosk --ozone-platform=wayland --ignore-gpu-blocklist \
--autoplay-policy=no-user-gesture-required --user-data-dir=/data/profile \
--alsa-output-device="plughw:CARD=$CARD,DEV=$PCM" "$URL"
---
apiVersion: kith.dev/v1
kind: Workload
metadata: { name: encode, namespace: tv }
spec:
template:
priority: idle # only spare cycles, and a twentieth of a CPU while the TV is full screen
yieldTo: { seat: tv-seat0, when: [fullscreen] }
containers: [{ name: run, image: "registry.example/batch/encode@sha256:<digest>", resources: { memory: 2Gi } }]
The seat's sound card is a Device with its playback PCM nodes (/dev/snd/pcmC1D3p, one per output), so the claim gives the container the sound as well as the screen. userNamespaces: true costs something (see workloads): a browser's sandbox reaches kernel code a plain user never calls, which is why the seat has a namespace to itself. Not tried: this form, with a user that is not root; the first recipe on a spare PC (a GTX 1060) and on a Ryzen's GPU ran as root with --no-sandbox, and that is what these notes come from.
- Memory only. A container's
resources.cpuis a hardcpu.max, and drawing in software uses every core. The seat'sreserveis the browser's guarantee; a Workload beside it that must stay out of the way ispriority: idlewithyieldTo(the second Workload). - The screen's mode. An LG TV prefers 3840x2160 at 30 Hz and offers 4K at 60 Hz only with HDMI Ultra HD Deep Colour on for that input. Pick 1080p at 60 Hz (
wlr-randr --output NAME --mode 1920x1080@60Hzin cage) where drawing is in software. - Sound. NVIDIA's HDMI sound starts with its IEC958 switches off (
amixer sset IEC958,0 on, up to,3). The output PCM is the one whose ELD control (iface=PCM,name=ELD,device=N) is not empty, which shows once the compositor has set the mode (amixer cgetsplits the jack control's name at its comma, so ask for the ELD). A container does not see/proc/asound(masked): read/dev/snd/pcmC*D*pand askamixer. - nouveau. On Pascal it has no reclocking and no video decode: 4K and HEVC play better on a GPU with VAAPI (a Ryzen's Radeon 780M). With the firmware built in, cage needs no
WLR_RENDERER; Chromium needs--ignore-gpu-blockliston nouveau. - The image. It comes from a registry (kith reaches a plain-HTTP registry only on the same machine), or from a stock Alpine as above, with
apk addinto the Volume so the next start has the packages. status.activity. kithd sets it:fullscreenwhile the HDMI sound plays, soencodedrops to a twentieth of a CPU as a film starts and returns about ten seconds after it stops (a session may say better with a POST, as above). A seat with no sound card is judged by its inputs only.
Virtual machines #
A template's vms are virtual machines, beside or instead of its containers and exec units, in a Workload, a Job or anything with a template:
apiVersion: kith.dev/v1
kind: Workload
metadata: { name: windows }
spec:
placement: { require: { node.labels.seat: desk } }
template:
deviceClaims: [card] # a DeviceClaim for a GPU set aside for machines
vms:
- name: machine
firmware: /usr/share/edk2/x64/OVMF.4m.fd
disks: [{ path: /var/lib/machines/windows.raw }]
cpus: 8
memory: 16Gi
resources: { cpu: 8, memory: 17Gi } # what it costs the node; else its cpus and memory
- A machine starts from a
kernel(a microVM;initrd,cmdline) or from itsdisksthroughfirmware.memoryis required;cpusis 1 unless said. A disk is a raw image (readOnly: trueif it must not be written): apathis a file on the node. - A disk in a replicated Volume.
disks: [{ volume: home, file: disk.img, size: 40Gi }]names a Volume instead of apath(one of the two, not both;fileisdisk.imgunless said, one name in the Volume's directory). The machine runs where the Volume is, as a container that mounts it does, and kithd makes the image there once, sparse andsizebig, if the file is missing; it never resizes or overwrites one that exists. A node without the Volume is not given the machine: it says why in the unit's note. When the Volume is handed over to another replica, the machine follows it and starts from the same image. Keep one replica of the machine. The hypervisor opens kithd's own hard link to the image (in<state>/vm-images, which no container mounts, made at every start), so a container that shares the Volume cannot swap the image for a link to a node's file. A Volume on another file system than the state directory's, and an encrypted Volume, holds no machine's disk: the unit's note says so and the machine does not start. - kithd supervises the hypervisor; the serial console (
console=ttyS0) is the unit's log:kith logs Workload/windows --unit machine.hypervisor: qemu(default, with KVM) orcloudHypervisor; the node needsqemu-system-x86_64(-aarch64on arm64) orcloud-hypervisoron its PATH, and/dev/kvm. - Passing a device through (VFIO). A PCI device bound to
vfio-pciis aDeviceof classpci(desk-pci-0000-01-00.0; labelsdriver: vfio-pci,vendor,modelandfunction:gpu,audio,usborother). It is not in the node's seat andclass: gpunever selects it: claim it by name, or byclass: pciand itsfunction. Avmsunit gets every such Device its template claims; a container never does. The owner binds it before kithd starts (vfio-pci.ids=10de:2684,10de:22ba, IOMMU on). - Not yet: Firecracker; a network beyond QEMU's own NAT (the machine reaches out, nothing reaches it); live migration of a machine with a Volume disk; kithd binding
vfio-pci;vmson kith OS. Tested: a Job boots a kernel under KVM. Not tested: cloud-hypervisor, a real GPU passed through.
Switching one GPU #
A desktop and a machine can take turns on one GPU of a node, with no reboot. It needs an IOMMU on, vfio-pci in the node's kernel (on kith OS the vfio spec prepares the kernel with both; the rest, vms on kith OS, is not there yet) and the card bound to vfio-pci by its owner (kithd never binds or unbinds a driver). The session and the machine each name one exclusive DeviceClaim for it:
kith switch gpu windows # the machine takes the card
kith switch gpu desktop # the session takes it back
- A claim's
holder(exclusive claims only) is the workload that takes the Device ahead of others, from a holder of its own namespace; a holder of another keeps it and the named workload waits. The current holder stops, then the new one starts, and stays until another switch. A card keeps itspcilabel under either driver:selector: { pci: "0000:01:00.0" }. - What a switch loses. It takes seconds: the session stops, its windows are lost and the desktop comes back as a new session. An app that is its own workload waits for a session to hold the seat again; its Volumes are kept.
- Not built: two GPUs at once, a frame relay. Proven only with stand-ins: no real GPU, VFIO bind or driver unbind was tried.
Confidential machines #
confidential: true runs a template's machines in memory the node cannot read (SEV-SNP, TDX):
apiVersion: kith.dev/v1
kind: Workload
metadata: { name: sealed }
spec:
placement: { require: { node.labels.cpu: epyc } }
template:
confidential: true
vms:
- name: machine
firmware: /usr/share/edk2/x64/OVMF.amdsev.fd # one built for SEV-SNP (or TDX)
disks: [{ path: /var/lib/machines/sealed.raw }]
memory: 8Gi
- A node runs it only if its KVM has SEV-SNP or TDX (
kvm_amd/parameters/sev_snporkvm_intel/parameters/tdxin/sys/modulereadsY). A node with neither runs none of it and says why in the status'notes; nothing falls back to memory in the clear. Onlyvmsunits with afirmware, under QEMU: any other unit here is refused at apply. - Not yet: the scheduler knows nothing of which nodes have such a processor (use
placement); no attestation; containers inside such a machine; cloud-hypervisor. Not tested: a guest on SEV-SNP or TDX hardware, only QEMU's options and the refusal elsewhere.
Tried on a real PC #
kith OS 1.0.0 on an AMD mini PC (a Ryzen with a Radeon 780M), booted over HTTP from the firmware, claimed with --claim, and a desktop Linux PC beside it on the same LAN:
- Ran: images pulled from Docker Hub; two replicas of a web server, ready by an HTTP probe, one port with
publish: truereached from the other PC; pod to pod over IPv4 and IPv6. - A desktop on the real screen: a Workload in
kith-systemclaiming the seat (NODE-seat0: the card and two inputs) runs Alpine's weston (DRM backend, pixman renderer) at 2560x1440 with a terminal. seatd in a container cannot make the seat active (there is no VT), so the session runs withLIBSEAT_BACKEND=noop, as root in its container. - The other PC as a worker: its kithd (not root, a user's process) joined with a worker token; Jobs placed on it with
placement: { require: { kith.dev/trust: worker } }ran anexecunit and a plain container, their logs read through the first node;kith delete node/NAMEthen took it out. Apod: truetemplate does not start on a kithd that is not root ("failed to prepare rootfs"). - Not working yet: the GPU has only the firmware's framebuffer (no
amdgpuin the plain image; thegpu-amd-phoenixspec builds it in, not yet run here). (A Service used to have no status and its name reached nothing on a node started without--mesh, which kith OS's default is: now its address is on the node's loopback there, and a pod on that node reaches it, T-0723.)