KernelScript 0.1.0

Introduced KernelScript — an experimental programming language for developing eBPF programs, custom loaders, and Linux kernel extensions from a single codebase. The project is developing Multikernel Technologies, a company promoting the split-kernel/multikernel architecture for Linux. Cong Wang, the founder of the company, presented KernelScript at the Linux Foundation Open Source Summit; the project's code is published on GitHub under the license Apache 2.0.


eBPF (Extended Berkeley Packet Filter) is a technology that allows small programs to run directly in the Linux kernel without modifying its code or risking system stability. eBPF helps address various tasks, from performance monitoring to security and network optimization. For instance, eBPF can track system calls, network traffic, and other events in real time. This enables identifying performance bottlenecks and optimizing the system (Habr).

The idea behind KernelScript is to make eBPF development less painful than using the C + libbpf combination, without limiting itself to tracing, like bpftrace. Developers describe the language as a type-safe DSL that integrates eBPF, userspace and kernelspace development: from a single source file, the compiler should generate code for eBPF programs, userspace parts, and integration with kernel modules via kfunc.

The claimed capabilities of KernelScript:

  • Compilation for different targets from a single file — functions with attributes like @xdp, @tc, @helper, and @kfunc are automatically assigned to the appropriate part: XDP/TC program, helper function, kernel function, or standard userspace code.

  • Automation of tail calls — instead of manually setting up the program array and calling bpf_tail_call(), developers are encouraged to write a regular function call, leaving the generation of low-level eBPF code to the compiler.

  • Simplified work with dynptr and eBPF maps — the language hides some of the manual work with bpf_ringbuf_reserve_dynptr, bpf_dynptr_write, and similar APIs. eBPF maps can be used as global variables accessible from different programs.

  • Lifecycle management of programs — eBPF programs are presented as typed values, which, according to the authors' intent, help prevent errors like trying to call attach() before a successful load at the compilation stage.

  • Support for kfunc KernelScript allows declaring functions with the @kfunc attribute, which execute in kernel space and can be called from eBPF programs; automatic generation of kernel module and BTF registrations is promised for them.

  • Support for the main types of eBPF programs README shows examples for XDP, TC, probe programs, and perf_event, including working with hardware performance counters.

The authors emphasize that KernelScript is not a replacement for the Linux kernel or a new eBPF runtime. It is more of a compiler and high-level language that is intended to generate familiar low-level components: eBPF code, userspace loaders, Makefile, and, if necessary, kernel module.

Currently, the project should be regarded as an early experiment. The repository explicitly states that KernelScript is in a stage beta, its syntax and API may change without backward compatibility, and using it in production is not recommended yet.

Source: linux.org.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster