Rust in the Linux Kernel: 3 Years Later

rust linux dev

In 2022, Rust became an official Linux kernel language alongside C. Three years later, let’s assess: Was it worth it? What’s been built? What’s the future?

The Journey

Timeline

DateMilestone
Dec 2021Initial RFC
Sep 2022Rust in Linux 6.1 (tooling)
Dec 2022First Rust driver merged
2023GPU driver work intensifies
2024Apple M1 GPU driver (Asahi)
2025Multiple production drivers

Initial Skepticism

Linus Torvalds in 2022:

“I’m interested in the project but not convinced it’s practical.”

Linus Torvalds in 2025:

“The Asahi GPU driver is impressive work.”

The proof is in the drivers.

What’s Been Built

Asahi Linux GPU Driver

The flagship Rust kernel project:

// Conceptual Asahi driver structure
impl gpu::Driver for AsahiDriver {
    fn probe(&self, dev: &mut Device) -> Result {
        let firmware = self.load_firmware(dev)?;
        let hw = GpuHardware::init(dev, firmware)?;
        self.register_drm(hw)?;
        Ok(())
    }
}

Android Binder

Google rewrote the Binder IPC driver in Rust:

Additional Drivers

The Technical Reality

Safe Abstractions

Rust wraps unsafe kernel C:

// Safe Rust wrapper around kernel mutex
pub struct Mutex<T> {
    inner: bindings::mutex,
    data: UnsafeCell<T>,
}

impl<T> Mutex<T> {
    pub fn lock(&self) -> Guard<'_, T> {
        // Safe wrapper around unsafe C function
        unsafe { bindings::mutex_lock(&self.inner as *const _ as *mut _) };
        Guard { mutex: self }
    }
}

impl<T> Drop for Guard<'_, T> {
    fn drop(&mut self) {
        unsafe { bindings::mutex_unlock(&self.mutex.inner as *const _ as *mut _) };
    }
}

Memory Safety Benefits

Traditional kernel bugs prevented by Rust:

Real-World Impact

Bug ClassC Kernel FrequencyRust Prevention
Use-after-freeCommonCompile error
Buffer overflowCommonRuntime or compile
Double freeOccasionalCompile error
Data raceHard to detectCompile error

Challenges Encountered

Toolchain Maintenance

Keeping Rust toolchain synchronized:

# Kernel Makefile Rust integration
RUSTC = rustc
RUST_FLAGS = --edition 2021 -C opt-level=2

C Interop Friction

Calling between languages has overhead:

// Every C function call requires unsafe
unsafe fn raw_c_call() {
    bindings::some_c_function();
}

// Safe wrappers add some overhead
fn safe_wrapper() -> Result<()> {
    // Validation
    // Call unsafe
    // Error conversion
}

Cultural Resistance

Some kernel maintainers remain skeptical:

Most criticism has softened as working code lands.

Limited Unsafe Audit Tooling

// Auditing unsafe blocks still manual
unsafe {
    // Is this actually safe?
    // Tooling still maturing
    ptr::write(dest, value);
}

Adoption Status

Subsystems with Rust

SubsystemStatus
GPU (Asahi)Production
GPU (Nova)Development
BinderIn review
FilesystemExperiments
NetworkingExperiments
NVMePrototype

Lines of Rust Code

2022: ~1,000 LOC (infrastructure)
2023: ~10,000 LOC 
2024: ~30,000 LOC
2025: ~50,000 LOC (and growing)

Still tiny compared to ~30 million lines of C.

Developer Experience

Getting Started

# Build kernel with Rust support
make LLVM=1 rustavailable
make LLVM=1 -j$(nproc)

Writing a Module

//! Simple Rust kernel module

use kernel::prelude::*;

module! {
    type: HelloWorld,
    name: "hello_rust",
    license: "GPL",
}

struct HelloWorld;

impl kernel::Module for HelloWorld {
    fn init(_name: &'static CStr, _module: &'static ThisModule) -> Result<Self> {
        pr_info!("Hello from Rust!\n");
        Ok(HelloWorld)
    }
}

impl Drop for HelloWorld {
    fn drop(&mut self) {
        pr_info!("Goodbye from Rust!\n");
    }
}

Documentation

# Generate Rust kernel docs
make LLVM=1 rustdoc

Documentation is required for public APIs—a cultural improvement from C.

What This Means

For System Developers

Learn Rust. Kernel contributions are increasingly Rust-friendly:

For Security

Fewer CVEs from memory bugs:

For the Industry

Rust is legitimized for systems programming:

Future Outlook

Near Term (2025-2026)

Medium Term (2027+)

Long Term

Will C eventually be replaced? Probably not entirely:

Final Thoughts

Rust in the Linux kernel is working. The Asahi GPU driver alone justifies the experiment—complex hardware support with better safety guarantees.

The skeptics still exist, but the code speaks louder. Three years in, Rust is here to stay.


Memory safety isn’t just for userspace anymore.

All posts