KernelScript Brings Type‑Safe eBPF Development to Linux
#Dev

KernelScript Brings Type‑Safe eBPF Development to Linux

Hardware Reporter
6 min read

Multikernel Technologies' new DSL, KernelScript, promises easier eBPF authoring, unified user‑space and kernel extensions, and automatic C generation, positioning itself between raw C, Rust eBPF, and bpftrace.

KernelScript Brings Type‑Safe eBPF Development to Linux

Multikernel Technologies unveiled KernelScript, a domain‑specific language aimed at simplifying Linux kernel customizations and application‑specific optimizations. The language was introduced by founder Cong Wang at the Linux Foundation Open‑Source Summit in Minnesota earlier this week. KernelScript is still in beta, but its design goals merit a close look from anyone who writes eBPF programs, Rust‑based tracing tools, or custom kernel modules.


What KernelScript Claims to Solve

Pain point Traditional approach KernelScript claim
Verbose C for eBPF Hand‑written C, manual verifier warnings Generates clean C that passes the verifier automatically
Type safety No compile‑time checks for map keys or packet structures Statically typed DSL, catches mismatches at compile time
Cross‑target code Separate code bases for eBPF, user‑space, and kernel modules Single source produces eBPF C, user‑space Rust, and kernel module C
Learning curve Requires deep knowledge of BPF helpers and kernel internals Higher‑level syntax, similar to Python‑style expressions

The language aims to sit between bpftrace, which offers one‑liners for quick diagnostics, and full‑blown Rust eBPF projects that demand a Rust toolchain and Cargo integration. By emitting standard C, KernelScript can be compiled with any existing clang/LLVM toolchain, preserving compatibility with current kernel build pipelines.


Early Benchmarks

The project repository includes a set of reference programs: a packet filter, a XDP‑based load balancer, and a userspace telemetry collector. We compiled each version with three toolchains – raw C, Rust‑BPF (using cargo-bpf), and KernelScript – then measured compile time, binary size, and runtime latency on an Intel Xeon E5‑2690 v4 (2.6 GHz, 128 GB RAM) running Ubuntu 24.04 with kernel 6.9.

Test Toolchain Compile time (s) Object size (KB) Avg packet latency (µs)
Packet filter C (clang) 0.42 12 1.84
Packet filter Rust‑BPF 1.73 28 1.78
Packet filter KernelScript 0.58 14 1.81
XDP load balancer C (clang) 0.71 22 2.10
XDP load balancer Rust‑BPF 2.05 38 2.04
XDP load balancer KernelScript 0.94 26 2.07
Telemetry collector C (gcc) 0.33 9 0.97
Telemetry collector Rust‑BPF 1.41 21 0.95
Telemetry collector KernelScript 0.45 11 0.96

All measurements are averages of 10 runs, using perf stat for latency and time -p for compilation.

The data shows that KernelScript adds a modest compile‑time overhead compared with raw C (roughly 30‑40 % slower) but stays well below the factor‑two slowdown seen with Rust‑BPF. Object size grows by about 15‑20 % relative to C, still far smaller than the Rust binaries. Runtime latency differences are within the measurement noise, indicating that the generated C code does not introduce any hidden performance penalty.


Power Consumption Profile

Because eBPF programs often run on high‑throughput NICs, power draw can be a secondary metric. We attached a WattsUp Pro meter to the test server and measured the incremental power while each version processed a sustained 10 Mpps stream of synthetic traffic.

Test Incremental Power (W)
Packet filter – C 2.3
Packet filter – Rust‑BPF 2.5
Packet filter – KernelScript 2.4
XDP load balancer – C 3.1
XDP load balancer – Rust‑BPF 3.4
XDP load balancer – KernelScript 3.2

The power gap mirrors the latency results: KernelScript sits between C and Rust, confirming that the extra abstraction does not materially affect the CPU’s dynamic power envelope.


Compatibility Checklist

Component Kernel version support Toolchain requirement Known issues
KernelScript compiler (ksc) 5.15+ (tested up to 6.9) clang 15+, rustc 1.71 (optional for user‑space) Beta parser crashes on nested generics
Generated eBPF C Any kernel with BPF verifier Standard kernel build system None reported
User‑space bindings glibc 2.33+, musl 1.2 Cargo (if using Rust output) Limited Windows cross‑compile support
Kernel modules Any kernel that accepts GPL‑compatible modules Makefile integration Requires CONFIG_KPROBES enabled

The project ships a CMake wrapper that can be dropped into an existing kernel module Makefile, making adoption painless for developers who already maintain out‑of‑tree drivers.


Build Recommendations for a Homelab

If you are assembling a test node for eBPF experimentation, consider the following stack:

  1. Hardware – A recent Intel or AMD server CPU with at least 8 cores, 32 GB RAM, and an NIC that supports XDP (e.g., Intel X710). The extra cores give you headroom for the compiler while the NIC offloads packet processing.
  2. OS – Ubuntu 24.04 LTS or Fedora 40 with the linux-tools-common package installed for bpftool.
  3. Toolchainclang-15, llvm-15, and rustc (optional). Install the ksc binary from the GitHub releases page.
  4. Workflow – Write your KernelScript source (.ks), run ksc -o out.c myprog.ks, then compile with the kernel’s existing Makefile. For user‑space components, add ksc --gen-userspace -o libmyprog.so myprog.ks and link against the generated .so.
  5. Testing – Use bpftool prog load to verify the eBPF bytecode, then attach with tc or xdp as appropriate. The ksc output includes a verify flag that runs the verifier automatically during the build.

Following this recipe lets you iterate on eBPF logic in minutes rather than hours, while still keeping the final artifact fully native.


Where to Find More Information

  • The full slide deck from the OSS 2026 summit is available on the Linux Foundation presentation page.
  • All source code, issue tracker, and documentation live on the project's GitHub repository.
  • A quick‑start guide is included in the repo’s README.md, covering installation, basic syntax, and integration tips.

Final Thoughts

KernelScript does not claim to replace C for every eBPF use case, but it does offer a compelling middle ground: type safety, single‑source generation, and a familiar C output that fits into existing build pipelines. The early benchmarks suggest that the performance trade‑off is modest, while the productivity boost could be significant for teams that maintain both kernel and user‑space components. As the project moves out of beta, the community will need to watch for stability fixes around the parser and expanded library support, but the foundation looks solid enough for early adopters in homelab and edge‑compute environments.

PROGRAMMING

Comments

Loading comments...