Rust for Linux Explained: Why the Kernel Accepted a Second Language
What Rust for Linux is, what the 6.18 kernel actually contains, why the project adopted it as an experiment, and how abstractions keep unsafe code in one place.

For three decades, the Linux kernel was written in C and a little assembly. Since Linux 6.1 it has had a second language, Rust, and the question every C programmer asks is why a project this large and this conservative would take on a second toolchain. The answer is narrower than the headlines make it sound, and it is spelled out in the kernel's own documentation. This post explains what Rust for Linux is, what is actually in the Linux 6.18 tree, the problem it targets, and the design that lets Rust code call into C without making the kernel a different system. If you want to see what that code looks like first, write your first Rust kernel module is the hands-on follow-up.
The facts below come from the kernel's Rust documentation, in particular its pages on general information and coding guidelines, and from the source under rust/ and samples/rust/.
What it is
Rust for Linux is the support in the kernel tree for writing parts of the kernel in Rust. It has three layers. The build system can compile Rust code with rustc and link it into the kernel or into a module. A library of Rust code in rust/kernel/, called the kernel crate, wraps kernel C APIs in Rust types. And on top of that sit drivers and modules written in Rust, a few of them in tree, plus samples under samples/rust/.
The documentation says the Rust support was merged into mainline in v6.1 in order to help in determining whether Rust as a language was suitable for the kernel, that is, whether it was worth the trade-offs. Its status text for version 6.18 still describes the support as in development and experimental, and says that the support is primarily intended for kernel developers and maintainers interested in the Rust support, so that they can start working on abstractions and drivers. It says plainly that end users should not expect in-tree drivers suitable for production use. That is the honest position: it is an adopted experiment with a growing body of code, not a rewrite.
What it is not
Rust did not replace C. The kernel's core, the scheduler, the memory manager, most drivers and every filesystem are C, and the build still needs a C toolchain. A Rust module is optional: CONFIG_RUST is a configuration option that is only offered when a suitable toolchain is found. Rust is also not available everywhere. The architecture support page lists the architectures where it works, among them arm, arm64, loongarch, riscv, um and x86, with notes such as little-endian only on arm64 and x86_64 only on x86, and RISC-V needing LLVM.
The minimum versions are documented too. The build requirements for 6.18 list Rust 1.78.0 and bindgen 0.65.1 as optional tools, needed only if you enable Rust support.
The problem it targets
The kernel is written by thousands of people, and a large share of its serious bugs are the same few kinds: use after free, double free, a missing error-path cleanup, a lock not released on one branch, a data race. C leaves each of those to the programmer's discipline and the reviewer's attention. Rust makes some of them impossible to write in its safe subset, and turns others into compile errors.
A concrete example is a lock. In C, every early return between mutex_lock and mutex_unlock must unlock first, and forgetting one is a classic bug. In Rust the lock owns the data it protects, and the lock is released when the guard goes out of scope, on every path:
use kernel::sync::{new_mutex, Mutex};
struct Inner {
a: u32,
b: u32,
}
fn bump(m: &Mutex<Inner>) {
let mut guard = m.lock();
guard.a += 10;
guard.b += 20;
}This is adapted from the documentation of the kernel's Mutex type. The data in Inner can only be reached through guard, so you cannot touch it without holding the lock, and when guard is dropped at the end of bump, the mutex is unlocked, however the function leaves. The C version of the same function has to unlock explicitly, and every return in a longer function is a place to forget.
None of this removes the need to think about locking order or design. It removes one class of mistake, mechanically, and the compiler checks it for every build.
How Rust code can call C safely: abstractions and bindings
The kernel has millions of lines of C and cannot be re-expressed in Rust. The design in the documentation is layered. The bindgen tool reads kernel C headers and generates Rust declarations for the C functions and types, called bindings. Those bindings are unsafe to call directly. On top of them, the kernel crate provides abstractions: Rust types that wrap a kernel facility in a safe interface, so that using them correctly cannot cause undefined behavior.
The documentation draws the rule clearly. Drivers, which it calls "leaf" modules, should not use the C bindings directly; instead subsystems should provide as-safe-as-possible abstractions. In its diagram, the path from a driver to the C side goes through the abstractions, and a direct line from a driver to the bindings is marked forbidden. The idea is to put all the unsafe code, which is the code that has to respect conditions the compiler cannot check, into carefully reviewed abstractions, so that the driver written on top of them cannot introduce undefined behavior as long as the abstractions are correct.
That is the central trade. The amount of unsafe code does not go to zero, but it is concentrated in a small, reviewed layer, and each unsafe block carries a comment explaining why it is sound. The coding guidelines require a // SAFETY: comment before every unsafe block. A reviewer who wants to audit a Rust driver reads the abstractions once, and then the driver is checked by the compiler.
What the tree contains today
You can look at it. The samples/rust/ directory in Linux 6.18 holds a minimal module, a misc device, a PCI driver sample, a platform driver sample, a printing macros sample and others, each behind its own Kconfig option under Kernel hacking, Sample kernel code, Rust samples. The kernel crate has abstractions for allocation, locks and reference counting, errors, devices and drivers, PCI and platform buses, file operations through misc devices, and network PHY drivers. Elsewhere in the tree, a few in-tree drivers are written in Rust, such as the Asix PHY driver drivers/net/phy/ax88796b_rust.rs, which sits beside its C counterpart.
The coverage is far from complete. If a kernel C API you need has no Rust abstraction yet, the guideline in the kernel crate's documentation is explicit: write the abstraction first, rather than bypassing the crate.
Costs and objections, honestly
A second language has real costs. The build gets heavier, because it needs a compatible rustc, bindgen and libclang, and the Rust version needed moves as the kernel's code starts to use newer language features. Maintainers of C subsystems must now consider that their API has a Rust user and may need an abstraction, which is extra work. The set of people who can review Rust and C together is smaller than those who can review either. And some features the kernel relies on are still unstable in Rust, so the kernel crate enables a list of unstable features in its source and tracks their stabilization.
These are the trade-offs the experiment was meant to measure. The current answer, in the documentation, is that the experiment continues and that abstractions and drivers are the work in progress.
Where this explanation stops
This post describes the project as documented for Linux 6.18. The project moves quickly: abstractions that exist in one release are missing in the one before it, and the guidance on production use may change. Read the documentation that ships with your kernel version, not a summary, before you decide what to build on.


