# Four years of Rust in Linux, measured release by release: where the code lives, how much unsafe it needs and which drivers use it

- **Published on:** 2026-11-24
- **Category:** News
- **Original page:** https://free-linux.com/articles/rust-linux-kernel-inside-unsafe-drivers

We counted the kernel's Rust code across fourteen tags, from Linux 6.1 to 7.4-rc4: 64,078 lines of its own, another 68,146 from vendored crates, ten drivers and about 2,200 unsafe blocks. Here is why the kernel copies syn and zerocopy into its tree, why almost all the unsafe code sits in the abstractions rather than the drivers, and what you need to build it.

---

Rust landed in the kernel with **Linux 6.1** in December 2022, and almost four years later it is still a small part of the tree: under 0.5% of the lines, next to roughly 37 million lines of C once headers are counted. We measured that split a week ago in [Rust versus Linux's C](/articles/linux-7-4-rust-c-ai-fixes). This time we look inside the Rust code itself: how much it has grown in each release, how much of it the kernel community writes and how much is copied in from outside, which drivers it is in, and how much `unsafe` code it needs to talk to the C around it.

Every figure comes from a clone of Linus Torvalds' tree at tag **v7.4-rc4**, released on Sunday 22 November, plus thirteen earlier tags. We counted with `cloc` (lines of code, no comments or blank lines) and with our own script for `unsafe`; the end of the article explains how to repeat it.

## How much it has grown, release by release

<figure>
  <img src="/articles/rust-kernel-por-dentro/rust-kernel-por-version.webp" alt="Terminal in a Linux v7.4-rc4 clone running rust-por-version.sh, showing a table with tag, date, own Rust lines, vendored crate lines and lines in drivers: from 740 own and 4115 vendored in v6.1 to 64078 own, 68146 vendored and 26440 in drivers in v7.4-rc4" loading="lazy" decoding="async">
  <figcaption>Rust lines of code per tag, separating the kernel's own code from vendored crates · Own screenshot</figcaption>
</figure>


v7.4-rc4 has **568 `.rs` files**. Separating what kernel developers write from the external crates copied into the tree (*vendoring*, in the jargon), we get **64,078 lines of the kernel's own Rust** and **68,146 lines of third-party code**. 132,224 in total.

| Release | Released | Own Rust | Vendored crates | In `drivers/` |
|---|---|---:|---:|---:|
| 6.1 | Dec 2022 | 740 | 4,115 | 0 |
| 6.8 | Mar 2024 | 5,149 | 4,288 | 95 |
| 6.12 | Nov 2024 | 8,884 | 0 | 997 |
| 6.15 | May 2025 | 14,133 | 0 | 1,250 |
| 6.17 | Sep 2025 | 23,163 | 0 | 4,242 |
| 6.18 | Nov 2025 | 36,077 | 0 | 12,505 |
| 6.19 | Feb 2026 | 42,328 | 46,958 | 15,990 |
| 7.0 | Apr 2026 | 43,649 | 46,958 | 16,397 |
| 7.1 | Jun 2026 | 46,287 | 46,958 | 16,988 |
| 7.2 | Aug 2026 | 50,664 | 63,817 | 19,726 |
| 7.3 | Oct 2026 | 56,202 | 63,817 | 22,237 |
| 7.4-rc4 | Nov 2026 | 64,078 | 68,146 | 26,440 |

Three things stand out.

**The start was almost symbolic.** Linux 6.1 shipped 740 lines of its own Rust: just enough to build a sample module that prints a message. It came with a copy of the Rust standard library's `alloc` crate, adapted for the kernel and five times larger. That fork went away in **Linux 6.10**: the kernel switched to the `alloc` shipped with the compiler and, from 6.13, to its own memory types (`KBox`, `KVec`). That is why the vendored column is zero from 6.12 to 6.18. Since 6.1, the kernel's own Rust has grown **86-fold**.

**The big jump is Linux 6.18.** Almost 13,000 lines arrived in two months, nearly all of them under `drivers/`: that release brought Android's **Binder** rewritten in Rust and **Tyr**, the DRM driver for Arm Mali GPUs.

**Since 6.19, half of the Rust in the tree was not written by the kernel.** It is the `syn`, `quote` and `proc-macro2` crates, which arrived in 6.19, and `zerocopy` and `zerocopy-derive`, in 7.2. The next section explains what they are for.

## Why the kernel copies crates into its tree

The kernel does not use **Cargo**, Rust's package manager and build tool. It cannot download dependencies from crates.io during a build: everything it needs has to be in the tree and built with **Kbuild**, the same system that builds the C code. Dependencies between crates are declared by hand in `rust/Makefile`. When the kernel wants an external library, the only option is to copy it in.

The first big one was **`syn`**, a Rust code parser used by almost every procedural macro in the ecosystem. The kernel has macros of its own (the ones that generate a module's boilerplate, for instance), and up to 6.18 they parsed code by hand with a minimal parser. Miguel Ojeda, who leads Rust in the kernel, imported `syn` 2.0.106 along with `quote` and `proc-macro2` to do it properly. That is 46,958 lines at once, and it accounts for almost all of the 6.19 jump. These three crates only run on the build machine: they generate code and do not end up in the kernel image.

The second was Google's **`zerocopy`**, in Linux 7.2. It turns bytes into structures and back without copies and without `unsafe`, checking at compile time that the conversion is valid. For a kernel that constantly reads structures coming from hardware or user space, that is exactly what is needed, and this one is built into the kernel (`obj-$(CONFIG_RUST) += zerocopy.o`). In 7.4 it is at version 0.8.50.

The import method is worth a look for anyone worried about the supply chain. Each crate arrives in a commit that copies the files **without changing a single line**, "not even adding the SPDX identifiers", and includes a one-line script with `curl` and `diff` so anyone can check they match the published release. The kernel-specific changes go into separate commits, so reviewers can see exactly what was modified.

## Where the kernel's own Rust lives

<figure>
  <img src="/articles/rust-kernel-por-dentro/rust-kernel-donde-vive.webp" alt="Horizontal bar chart of the own Rust code in Linux v7.4-rc4, 64078 lines: in abstractions, rust/kernel 29139, rust/pin-init 4734, rust/macros 1483 and others 214; in drivers, nova-core 13168, android/binder 7743, drm/tyr 3585, drm_panic QR code 787, block/rnull 313, pwm_th1520 275, drm/nova 243, cpufreq-dt 163 and two network PHYs 163; samples 1551 and lib, mm and scripts 544. Below, 56 unsafe blocks per thousand lines in rust/, 7.6 in drivers/ and 95.9% with a SAFETY comment" loading="lazy" decoding="async">
  <figcaption>The kernel's own Rust in Linux 7.4-rc4 by directory, and unsafe block density · Own diagram</figcaption>
</figure>


The kernel's Rust code has two very different halves.

The first is the **abstractions**, under `rust/`: 35,570 lines. Most of it is the `kernel` crate (29,139 lines, 91 modules), which wraps the kernel's C APIs in safe types: devices, PCI, DMA, interrupts, locks, timers, memory, files. Next to it sit `pin-init`, a library for initialising structures that must not move in memory (very common in the kernel, where a linked list points into its own nodes), and the kernel's own macros.

The second is the **drivers**, and today there are ten:

| Driver | What it does | Since | Lines in 7.4-rc4 |
|---|---|---|---:|
| ASIX AX88796B PHY | Ethernet chip | 6.8 | 93 |
| rnull | Null block device for testing | 6.11 | 313 |
| `drm_panic` QR code | Draws a QR code with the error when the kernel crashes | 6.12 | 787 |
| Marvell QT2025 PHY | 10 Gb/s network chip | 6.12 | 70 |
| nova-core | Foundation of the new driver for NVIDIA GPUs with GSP | 6.15 | 13,168 |
| nova (DRM) | Graphics side of the NVIDIA driver | 6.16 | 243 |
| cpufreq-dt | CPU frequency scaling described in device tree | 6.16 | 163 |
| Binder | Android inter-process communication | 6.18 | 7,743 |
| Tyr | Arm Mali GPUs | 6.18 | 3,585 |
| TH1520 PWM | Pulse-width modulation on T-Head's RISC-V SoC | 6.19 | 275 |

Three of them hold almost everything: **nova-core**, **Binder** and **Tyr** account for 24,496 of the 26,440 lines in `drivers/`. The rest are small, and several began as proofs of concept to show the abstractions worked. `rnull`, for example, is the Rust version of `null_blk`, the block device that stores nothing and is used to benchmark the block layer without real hardware getting in the way.

The GPU driver for Apple Silicon Macs used by Asahi Linux, probably the most widely run kernel Rust code outside Android, is **not in mainline yet**. It is maintained separately and lands piece by piece as the abstractions it needs reach the tree.

## Unsafe: how much there is and where

<figure>
  <img src="/articles/rust-kernel-por-dentro/rust-kernel-unsafe-safety.webp" alt="Terminal in Linux v7.4-rc4 running unsafe-stats.py: rust has 1999 unsafe blocks with 1927 SAFETY comments, 96.4%; drivers 201 with 183, 91.0%; samples 5 of 5; others 3 of 3; total 2208 and 2118, 95.9%; plus 560 unsafe fn and 494 unsafe impl, 617 bindings calls to 544 distinct C functions, the most called being get_device, put_device, _printk, rb_first, get_file and fput" loading="lazy" decoding="async">
  <figcaption>Unsafe blocks and SAFETY comments in the kernel's own Rust in Linux 7.4-rc4 · Own screenshot</figcaption>
</figure>


In Rust, the compiler checks that there are no use-after-free bugs, null pointers or data races. Some operations it cannot verify, such as calling a C function or dereferencing a pointer that came from the other side, and those must go inside an **`unsafe { }`** block. With that keyword, the programmer takes responsibility for the operation being correct.

The kernel adds one more rule: each `unsafe` block must carry a **`// SAFETY:`** comment right above it explaining why it is sound. This is more than a habit: the 7.4-rc4 `Makefile` enables the `clippy::undocumented_unsafe_blocks` warning, which flags blocks without that comment, and turns into an error (`-Dunsafe_op_in_unsafe_fn`) any unsafe operation inside an `unsafe` function that is not wrapped in its own block.

Counting the kernel's own Rust in 7.4-rc4 we get **2,208 `unsafe` blocks**, and **95.9%** have a `SAFETY` comment in the lines just above. On top of that there are 560 functions declared `unsafe fn` and 494 `unsafe impl`, which promise the compiler that a type can be shared between threads.

The telling part is **where** that `unsafe` code is:

- The `rust/` abstractions have 1,999 blocks in 35,570 lines: **56 per thousand lines**.
- The drivers under `drivers/` have 201 blocks in 26,440 lines: **7.6 per thousand**.

That is exactly what the design was after. The dangerous code, the part that talks directly to the kernel's C, is written once in the abstraction, reviewed carefully and wrapped in a safe interface. The driver uses that interface and barely needs `unsafe`. A memory bug in a Rust driver will almost always have to come from one of those shared abstractions or from the driver's own few `unsafe` blocks, which narrows the search a lot. That is why Greg Kroah-Hartman keeps saying the point is not to rewrite what already exists, but to write **new** drivers on top of those abstractions.

The bridge to C is the bindings `bindgen` generates from the headers. The kernel's own Rust makes 617 direct calls of the form `bindings::function()` to **544 distinct C functions**, almost all of them once or twice. The most repeated are reference counting for devices and files (`get_device`, `put_device`, `get_file`, `fput`), `printk` for log messages and red-black trees (`rb_first`). Over 500 distinct C functions gives an idea of the surface that has to stay in sync: if one of them changes its signature in C, someone has to update the Rust side.

A note on method: we counted blocks with a regular expression over the code with comments stripped, not with a full parser. It may overcount an `unsafe {` inside a macro or a test, and the six-line window used to look for `SAFETY` is generous. The order of magnitude and the gap between abstractions and drivers do not depend on that detail.

## What Linux 7.4 brings

Between v7.3 and v7.4-rc4, 236 Rust files changed, with 24,001 lines added and 5,156 removed. The busiest areas are the `kernel` crate, `nova-core` and Binder, plus the `zerocopy` update. New modules arrive in the abstractions:

- **`mem`** and **`ratelimit`**, memory helpers and a way to throttle log messages.
- **`dma_buf`** and **`dma_fence`**, to share buffers between devices (the GPU and the display, for instance) and synchronise them. Graphics drivers need these.
- **`pci::cap`**, to read a PCI device's capabilities.
- **`sync::lockdep`**, which hooks Rust locks into *lockdep*, the kernel's deadlock detector.

What does not change in 7.4 is the driver list: the ten in the table were already in 7.3. What grows is the existing ones, above all `nova-core`, which keeps laying the groundwork for the NVIDIA driver to one day drive a whole GPU.

## What you need to build it

According to `scripts/min-tool-version.sh`, building a 7.4 kernel with Rust enabled needs at least **`rustc` 1.85.0**, except on s390 (1.96.0) and PowerPC (1.95.0), plus **`bindgen` 0.71.1**. Long-term support distributions tend to lag behind on Rust, which is why some package a compiler version just for the kernel.

Not every architecture can. `HAVE_RUST` is enabled on x86 (64-bit only), arm64, arm (little-endian ARMv7), riscv (64-bit and LLVM only), loongarch, s390, um and powerpc. The table in `Documentation/rust/arch-support.rst` does not list PowerPC yet. The others are missing because of the compiler: `rustc` generates code through LLVM, and LLVM does not cover every architecture GCC does. Until **gccrs** or **rustc_codegen_gcc** can build the kernel, no essential component can be written in Rust alone.

## What it means if you run Linux

If your distribution builds the kernel with `CONFIG_RUST`, you already carry some of this code, although only what your hardware needs gets loaded. You can check with `grep CONFIG_RUST= /boot/config-$(uname -r)`. In practice, the Rust you will run depends on your machine:

- On a recent **Android** device, Binder in Rust.
- With an **NVIDIA GPU**, not yet: nova-core prepares the future open driver, but today it replaces neither nouveau nor NVIDIA's driver.
- On **Arm boards with Mali GPUs** and on the **TH1520** RISC-V SoC, Tyr and the PWM driver, depending on each distribution's configuration.
- On any machine with `CONFIG_DRM_PANIC_SCREEN_QR_CODE`, the QR code that appears when the kernel crashes.

The trend in the table is clear. Rust grows by 4,000 to 8,000 lines of its own per release, almost half of it in drivers, and the pace is not slowing. At that rate, the kernel's own Rust will not reach 1% of the kernel this decade. That is not the goal either. The aim is for new drivers, which is where most bugs show up, to have an alternative with far less `unsafe` than the same code would have in C. The [Linux kernel page](/linux-kernel) lists the releases and their support dates.

## How we tested this

A clone of Torvalds' tree without downloading every file's contents, with a sparse checkout of only the `.rs` files and the `rust/` directory (a few minutes and little disk space), `cloc` 2.x to count lines and Python 3 for `unsafe`:

```bash
git clone --filter=blob:none --no-checkout https://github.com/torvalds/linux.git
cd linux
git sparse-checkout set --no-cone '*.rs' '/rust/'
git checkout v7.4-rc4

# Own Rust versus vendored crates
cloc --include-lang=Rust --fullpath \
  --not-match-d='(^|/)rust/(alloc|syn|quote|proc-macro2|zerocopy|zerocopy-derive)(/|$)' .
cloc --include-lang=Rust .

# unsafe blocks and SAFETY comments (approximate)
git ls-files '*.rs' | grep -vE '^rust/(syn|quote|proc-macro2|zerocopy)' \
  | xargs grep -c 'unsafe {' | awk -F: '{s+=$2} END {print s}'
```

For the per-release table, the same count in a loop with `git checkout` of each tag. Git downloads each release's `.rs` files only the first time it needs them. The last `grep` gives a slightly different number from ours because it neither strips comments nor handles blocks that open on one line and continue on the next; the script in the screenshot does both.

**Sources:** [Linus Torvalds' tree](https://github.com/torvalds/linux), tags v6.1 to [v7.4-rc4](https://github.com/torvalds/linux/tree/v7.4-rc4) (our own count, 24 Nov 2026); Miguel Ojeda's [commit "rust: syn: import crate"](https://github.com/torvalds/linux/commit/808c999fc9e7) and [commit "rust: zerocopy: import crate"](https://github.com/torvalds/linux/commit/c37398010a05); the [Makefile](https://github.com/torvalds/linux/blob/v7.4-rc4/Makefile), [rust/Makefile](https://github.com/torvalds/linux/blob/v7.4-rc4/rust/Makefile) and [scripts/min-tool-version.sh](https://github.com/torvalds/linux/blob/v7.4-rc4/scripts/min-tool-version.sh) in v7.4-rc4; the kernel's [Rust documentation](https://docs.kernel.org/rust/index.html) and [architecture support](https://docs.kernel.org/rust/arch-support.html); [Rust for Linux](https://rust-for-linux.com/); [syn](https://github.com/dtolnay/syn), [zerocopy](https://github.com/google/zerocopy) and [cloc](https://github.com/AlDanial/cloc).
