Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios Kernel

Subsystem testing

Single-page view · as markdown

Developing native kernel subsystems

Peios Kernel / Kernel development / Subsystem testing

The kernel repository owns the native subsystem code. Make implementation changes in security/pkm/, fs/stratafs/ and net/ntfe/, with public declarations in include/uapi/pkm/.

Shared Rust cores #

The Cargo workspace in peios/rust/ compiles the semantic sources used by Kbuild through small wrapper crates. It does not maintain a second copy of the implementation. From the kernel root:

pekit test rust_cores rust_clippy uapi

For a direct host run:

cd peios/rust
cargo test --workspace --locked --offline
bash check.sh

The host workspace's toolchain is pinned in peios/rust/rust-toolchain.toml; the kernel build has its own toolchain requirements. Host tests exercise the userspace allocation/runtime path. Do not use Cargo --all-features as a substitute for Kbuild, KUnit or VM integration tests.

Kernel integration #

Use Building Peios for the supported build entry points. Select the subsystem's KUnit configuration and inspect the resulting KTAP and kernel log when exercising kernel glue. Runtime qualification and a passing host suite are separate evidence.

StrataFS test hooks documents its gated securityfs fault-injection interface.

Maintaining the reference #

The kernel owns both the native interface reference and its generators. Regenerate the ABI and constants pages from the kernel root:

python3 tools/docs/peios-reference/generate.py
python3 tools/docs/peios-reference/generate.py --check

Edit handwritten explanations directly in docs/; do not put them in generated pages. See Maintaining native subsystem documentation for provenance, claim anchors and the retained TRM.

Detailed test workflows #

  • Shared Rust core tests
  • ABI regeneration
  • KUnit execution and logs
  • Guest qualification
  • Data generators and their checks

Maintaining native subsystem documentation

Peios Kernel / Kernel development / Subsystem testing

Native kernel documentation lives with the kernel. Internals explain the implementation; Userspace interfaces describe caller contracts; Administration covers operation; Development covers changing and testing the code. The combined learn site presents these collections alongside the rest of Peios documentation.

Authored and generated sources #

Edit ordinary articles directly. tools/docs/peios-reference/generate.py regenerates the native ABI tables and StrataFS constants from this source tree. It uses a C compiler to measure ABI layouts and values; StrataFS's private constants are extracted from the C and Rust definitions. The generator does not need a sibling pkm or learn checkout.

Run it with --check to detect drift without editing pages. It refuses changes to the expected section layout or named claims until the migration mapping is reviewed, so a new table cannot silently disappear into an old split layout. Handwritten interface notes are outside the generated output and are never overwritten by regeneration.

Provenance and claim anchors #

peios/docs-migration/trm-source-map.json records the old book paths and hashes, section destinations, named claims, and the pages assembled from each source. It is separate from the upstream Linux source map. The old TRM is retained in learn/ during review; changes here do not regenerate or remove it.

Trail's named citation syntax is currently book-scoped. In the new topic pages, the same claim identifiers are preserved as explicit cite-NAME HTML anchors. The mapping records their new article addresses. Existing test citations still resolve through the retained original book; these topic anchors do not silently replace Trail's exported book citation catalogue.

Keep anchors when editing or splitting articles. Update the TRM mapping when an article or claim moves, and update its incoming links. Numbered book references have been converted to explicit links to their target explanation. Cross-system specifications retain links to their own pages on learn.peios.org.

Validation #

python3 tools/docs/peios-reference/generate.py --check
make htmldocs
make linkcheckdocs

Keep the retained TRM unchanged until the replacement has been reviewed and its external consumers have a deliberate migration path. Generated tables establish header values and layouts; they do not prove the correctness of every prose claim or qualify kernel runtime behaviour.

Shared Rust core tests

Peios Kernel / Kernel development / Subsystem testing

The kernel repository owns these crates. Kbuild and Cargo compile the same semantic files under security/pkm; nothing is copied or rewritten at build time. Small lib.rs entry points adapt their module layout to the existing Cargo crate APIs. Change core behaviour in security/pkm, and its tests in peios/rust/.

The workspace contains kacs-core, lcs-core, pnp-core, stratafs-core, the ntfe userspace library and raw peios-uapi bindings. peios/rust/ORIGIN.json records the PKM revision used for the migration. No PKM checkout is needed.

# From the kernel root: all tests, then selected Clippy correctness checks.
pekit test rust_cores rust_clippy uapi

# Or work on one crate directly.
cd peios/rust
cargo test -p kacs-core --locked --offline
cargo test --workspace --locked --offline
bash check.sh

The host test toolchain is pinned to Rust 1.98.1 in peios/rust/rust-toolchain.toml. Install it with rustfmt and Clippy first. This does not change the kernel's Rust 1.83.0 build toolchain. The workspace has only local path dependencies; Cargo tests are offline after toolchain installation. pekit builds the crates in its sandbox, with its own pinned Rust 1.98.1, each crate given security/pkm where its #[path] reaches. Direct Cargo uses the ignored peios/rust/target/ directory.

The Cargo workspace tests the userspace allocation implementation. The kernel configuration is supplied by Kbuild, which has the kernel allocation/runtime dependencies. Do not use Cargo --all-features to simulate a kernel build. Run the normal kernel build and KUnit commands to exercise that integration.

For header changes, follow ABI regeneration. For kernel execution, use KUnit and guest qualification.

ABI regeneration

Peios Kernel / Kernel development / Subsystem testing

The source ABI headers live in include/uapi/pkm. The generated constants at security/pkm/kacs/peios_uapi.rs are shared directly by Cargo and Kbuild. Generated types and their layout tests live at peios/rust/peios-uapi/ztypes.rs.

bash peios/rust/peios-uapi/check-codegen-safe.sh
bash peios/rust/peios-uapi/check-userspace-clean.sh
LIBCLANG_PATH=/path/to/libclang BINDGEN=/path/to/bindgen-0.65.1 \
    bash peios/rust/peios-uapi/gen.sh --check

Run these from the kernel root. Omit --check to regenerate. The generator requires bindgen 0.65.1 (also supplied by the kernel build image), libclang, a C compiler with userspace Linux headers, and rustfmt 1.98.1. It targets Rust 1.64 syntax for generated layouts, preserving the existing runtime layout tests. The initial migration's drift check was verified with libclang 21 on x86_64. Generator/sysroot provisioning is not part of the hosted style workflow yet; CI does run the committed Rust layout tests and C header/ABI checks.

Core logic, public names, ABI layout and package manifests must remain stable during style-only work. The migrated Cargo suite retained all 1,864 tests with no ignored or failed tests at integration. Kernel and VM qualification are separate from this host test result.

The ABI generator updates compiled bindings and tests. It is separate from tools/docs/peios-reference/generate.py, which updates the documentation's ABI tables. When changing an interface, review the caller contract and both generated representations; see Maintaining native subsystem documentation.

Running KUnit

Peios Kernel / Kernel development / Subsystem testing

From the kernel repository root:

pekit run kunit

pekit run kunit builds the KUnit configuration's kernel with the pinned toolchain, then boots it with the existing PKM runner and the host's QEMU, qemu-system-x86_64. It's a script you run by hand, not a test, because it needs QEMU and wants KVM. It uses KVM when /dev/kvm is available, otherwise TCG. The run requires complete KTAP accounting, passing PKM suites, clean power-down and no kernel warning/oops/lockdep failure signatures. The serial log is kunit-qemu.log beside the image, as the direct runner writes it, or where PKM_KUNIT_LOG says. Native integration and hardware qualification remain additional checks.

The migrated configs, verifier, key generator and KUnit runner come from PKM commit ac4c6eb57ff94821f1eaea2b3bde460777d48f5b. No dependency on the old PKM checkout is needed to run these commands.

Run an existing kernel directly #

The direct runner accepts either a bzImage or a Kbuild output tree containing arch/x86/boot/bzImage. It uses host QEMU and timeout, as pekit run kunit does.

bash peios/test-kunit.sh /path/to/bzImage

The direct runner supports these environment variables:

VariableMeaningDefault
QEMU_BINQEMU executableqemu-system-x86_64
PKM_KUNIT_TIMEOUTBoot timeout in seconds420
PKM_KUNIT_LOGSerial log pathkunit-qemu.log beside the image, or in the supplied tree
PKM_KUNIT_INITRDOptional initramfsNone
PKM_KUNIT_FILTERKUnit filter globFull configured run

Set overrides in the environment of either command.

What a pass means #

The runner requires successful QEMU exit, the clean power-down marker, a top-level KTAP plan, exactly the planned number of results and the final successful result. It rejects failure, warning, oops and lockdep signatures. An unfiltered run additionally requires the PKM smoke marker and a passing PKM suite summary. A filtered run instead requires actual selected case results.

A selected passing suite is evidence for that selection, not a full suite run. Retain the serial log with the kernel revision and configuration used.

The host-side parser and runner regression tests can be run without booting:

pekit test kunit_runner

Guest qualification

Peios Kernel / Kernel development / Subsystem testing

The harnesses in peios/qualification/ build small initramfs guests and boot a supplied kernel. They do not build that kernel or qualify an entire OS release. Use an x86_64 Linux host with gcc, static libc development files, cpio, timeout and qemu-system-x86_64; firmware fixture preparation also needs zstd. QEMU uses KVM when available, with TCG fallback. The harnesses run on the host, outside pekit's sandbox, with the host's tools.

Run the pekit commands below from the kernel repository. Their underlying scripts locate the guest C sources relative to themselves and can also be called directly from another working directory with absolute input paths.

Compile the guest programs #

pekit test qualification_build

This compiles all guest C programs with static linking and warnings as errors. It does not boot a VM or require signing keys. A passing compilation is separate from a passing guest run.

Mount namespaces and StrataFS #

pekit run qualify_mntns /path/to/bzImage
pekit run qualify_stratafs /path/to/bzImage
pekit run qualify_stratafs_fuse /path/to/bzImage
pekit run qualify_stratafs_dir_bench /path/to/bzImage

Each accepts a direct image, including the bzImage that pekit build kernel gives, or a Kbuild output tree containing arch/x86/boot/bzImage. Supply a kernel with the relevant Peios subsystem and the guest's required filesystem support enabled. A script finding the image does not establish that the configuration meets its needs.

The mount-namespace harness exercises KACS objects through syscalls and checks both child and parent results. The StrataFS smoke harness exercises a mounted filesystem. The directory benchmark validates its expected result rows and completion marker; retain those rows when comparing performance. These harnesses reject their failure markers, kernel warnings, and fatal diagnostics, and require successful QEMU exit.

The FUSE passthrough harness also needs CONFIG_FUSE_FS=y and CONFIG_FUSE_PASSTHROUGH=y. It checks lazy opens, shared mappings, read-only and private controls, copy publication, and mapping lifetime. It requires a clean guest poweroff. Its direct entry point is peios/qualification/test-stratafs-fuse.sh, with the same image or output-tree argument.

Module signatures #

pekit run qualify_modsig /path/to/kbuild-output /path/to/modules-root

The first directory must contain arch/x86/boot/bzImage. The second must contain one matching release under lib/modules/, with modules.dep and signed, zstd-compressed modules trusted by the kernel. The harness selects a dependency-free module, boots with a copy of it and a corrupted copy, and requires the valid module to load and the corrupted one to be rejected.

The flat directory pekit build kernel gives is not the required Kbuild layout, and its modules.tar contains unsigned modules. Prepare the output layout and separately signed module tree before invoking this harness. Confirm signature enforcement in the supplied kernel configuration; a load alone is not evidence of enforcement when testing a differently configured kernel.

Firmware signatures #

The kernel needs its firmware verification policy and CONFIG_TEST_FIRMWARE=m. The matching module tree must contain a trusted, signed test_firmware.ko.zst. Prepare fixtures in a new, existing output directory:

mkdir /path/to/fixtures
bash peios/qualification/prepare-fwsig.sh \
    /path/to/kbuild-output /path/to/modules-root /path/to/fixtures

Preparation compiles root/init, copies the firmware test module, and creates good, unsigned, tampered and compressed firmware payloads under root/lib/firmware/. It does not sign anything. Have the signing coordinator provide detached Peios signatures trusted by this kernel at:

  • root/lib/firmware/fwsig-good.bin.peios.sig
  • root/lib/firmware/fwsig-goodz.bin.zst.peios.sig

Preserve the prepared directory as a whole, including its signed test module. The guest reuses the good signature when testing tampered bytes. No private signing key is passed to the harness. Once the fixtures are signed:

pekit run qualify_fwsig \
    /path/to/kbuild-output /path/to/modules-root /path/to/fixtures

The harness boots once with kacs_fwsig=enforce and once with kacs_fwsig=log. It requires four guest checks per mode, the appropriate refusal or log verdict, no listed fatal diagnostics, and successful QEMU exit. The expected policy warnings are part of the test, so this harness does not reject every warning.

Logs and timeouts #

Set QEMU_BIN to choose another QEMU executable. The retained PKM_* names are the current script interfaces. Timeout values are in seconds.

HarnessDefault logLog overrideTimeout override (default)
Mount namespacesmntns-qemu.logPKM_MNTNS_LOGPKM_MNTNS_TIMEOUT (120)
StrataFS smokestratafs-qemu.logPKM_STRATAFS_LOGPKM_STRATAFS_TIMEOUT (120)
StrataFS FUSE passthroughstratafs-fuse-qemu.logPKM_STRATAFS_FUSE_LOGPKM_STRATAFS_FUSE_TIMEOUT (120)
Directory benchmarkstratafs-dir-bench-qemu.logPKM_STRATAFS_DIR_BENCH_LOGPKM_STRATAFS_DIR_BENCH_TIMEOUT (1200)
Module signaturesmodsig-qemu.logPKM_MODSIG_LOGPKM_MODSIG_TIMEOUT (120)
Firmware signaturesfwsig-enforce-qemu.log, fwsig-log-qemu.logPKM_FWSIG_LOGDIRPKM_FWSIG_TIMEOUT (120 per boot)

Logs default to the supplied tree, or beside the direct image where that input form is supported. Ensure the chosen log directory exists and is writable. Use distinct log paths for concurrent runs. Temporary initramfs trees are removed on exit; retain serial logs, kernel revision/configuration, module provenance and fixture identity as the evidence for a qualification run.

StrataFS test hooks

Peios Kernel / Kernel development / Subsystem testing

Several of this chapter's promises are about windows that no arrangement of real filesystems can hold open. A copy-up is never observable in a partial state (Copy-Up) — but a real copy-up publishes within microseconds. A failed install rolls the lower link back (Links) — but the install fails only under allocation pressure between two steps of one syscall. A dentry whose provider identity no longer matches yields ESTALE (Rename) — but every walk rebuilds the dentry moments before the operation, so the mismatch needs the provider to change inside a single syscall.

The test hooks exist so conformance tests can steer exactly those windows and nothing else. They are not conformance surface: no behaviour in this chapter depends on them, and they carry no named citations.

Gating #

The hooks are doubly gated:

  • CONFIG_STRATAFS_FS_TEST_HOOKS compiles them in. Without it every hook site is an inline constant zero.
  • stratafs.test_hooks=1 on the kernel command line registers them. Without it nothing appears in securityfs and each hook site reduces to reading one never-true flag.

Production images build the option but never pass the parameter; only the provium test profiles do. Arming a hook additionally requires reaching a mounted securityfs, which on a managed system means a caller able to establish the mount and satisfy its policy class.

Interface #

Each hook point is one securityfs file under stratafs/hooks/, alongside KACS's own security/pkm/kacs/ endpoints. securityfs rather than debugfs is forced by kernel lockdown: the Peios kernel builds LOCK_DOWN_KERNEL_FORCE_INTEGRITY, and the integrity set refuses every debugfs open that is not a read of a mode-0444 file — a debugfs hook would be visible and permanently untouchable. Lockdown does not gate securityfs. Writing a hook's file arms or disarms it; reading reports its state:

WriteEffect
holdTasks reaching the point block until the hook is cleared
fail NThe next task to reach the point fails with errno N, once
clearDisarm; every held task is released

A read returns <mode> waiting=<W> hits=<H>, where <mode> is none, hold or fail, W is the number of tasks currently blocked — poll it to know the victim has arrived — and H is the number of arrivals the hook has affected. A held task waits killably, so a fatal signal always removes it. A fail arms exactly one failure and disarms itself; hold persists until cleared.

Points #

FileMoment
copy-up-beginBefore the copy-up context is created — before any staging exists. A failure here is a source descriptor that could not be read (Descriptors on Copy-Up).
copy-up-publishAfter the staged object is complete — content, attributes, metadata — and before publication. A hold here is an in-flight copy-up, staged but unpublished (Copy-Up).
rename-providerIn rename, after the walk-time provider is captured and before the locked re-lookup that verifies it (Rename).
link-installIn link, between the lower link succeeding and the outer inode installing. A failure here exercises the rollback of Links.
supersede-publishAfter the staged source and destination are checked, immediately before the backing rename publishes a supersede replacement. Failure leaves the original provider untouched.
supersede-removeFor a supersede across distinct strata, after publication and release of the create-stratum directory lock and write hold, before reacquiring write access to the original provider and re-looking-up its name. Failure exercises cleanup of the published replacement.
staging-recoverAfter a staging marker is validated as an orphan, before acquiring backing-mount write access for its removal. A hold lets a test remount the provider read-only while rename is scanning an overwritten directory; failure leaves the orphan in place.

copy-up-begin and copy-up-publish sit on both copy-up shapes — the anonymous regular-file stage and the named directory/symlink stage — so a hold at copy-up-publish pins whichever kind is in flight.

Peios Learn — documentation for Peios software.

Built with Trail.