VOOZH about

URL: https://www.phoronix.com/news/Linux-7.2-Rust

⇱ Linux 7.2 Introducing The Rust Zerocopy Library To Eliminate More "Unsafe" Code - Phoronix


👁 Phoronix

Linux 7.2 Introducing The Rust Zerocopy Library To Eliminate More "Unsafe" Code

Written by Michael Larabel in Linux Kernel on 15 June 2026 at 07:03 AM EDT. 34 Comments
Miguel Ojeda already mailed in the many Rust code changes for the in-development Linux 7.2 kernel. This is quite a big Rust code with more than forty thousand new lines of Rust code in the kernel.

The Rust changes are so big this cycle since they are pulling in the "zerocopy" library to allow eliminating some additional "unsafe" Rust code elements within the kernel. The Rust pull request explains of integrating the Zerocopy code:
"Introduce support for the 'zerocopy' library:

Fast, safe, compile error. Pick two.

Zerocopy makes zero-cost memory manipulation effortless. We write `unsafe` so you don't have to.

It essentially provides derivable traits (e.g. 'FromBytes') and macros (e.g. 'transmute!') for safely converting between byte sequences and other types. Having such support allows us to remove some 'unsafe' code.

It is among the most downloaded Rust crates and it is also used by the Rust compiler itself.

It is licensed under "BSD-2-Clause OR Apache-2.0 OR MIT".

The crates are imported essentially as-is (only +2/-3 lines needed to be adapted), plus SPDX identifiers. Upstream has since added the SPDX identifiers as well as one of the tweaks at my request, thus reducing our future diffs on updates -- I keep the details in one of our usual live lists.

In total, it is about ~39k lines added, ~32k without counting 'benches/' which are just for documentation purposes.

The series includes a few Kbuild and rust-analyzer improvements and an example patch using it in Nova, removing one 'unsafe impl'.

I checked that the codegen of an isolated example function (similar to the Nova patch on top) is essentially identical. It also turns out that (for that particular case) the 'zerocopy' version, even with 'debug-assertions' enabled, has no remaining panics, unlike a few in the current code (since the compiler can prove the remaining 'ub_checks' statically).

So their "fast, safe" does indeed check out -- at least in that case."

Beyond pulling in Zerocopy to improve dealing with "unsafe" code around conversions, the Rust code for Linux 7.2 also adds support for AutoFDO. The Rust kernel code can now benefit from Automatic Feedback Directed Optimizations by the compiler to yield better performance. With the Rust Binder code was around a 13% performance difference.

There is also Rust support for software tag-based Kernel Address Sanitizer (KASAN), support for the upcoming Rust 1.98 release, and other improvements.

The full set of Rust feature changes submitted for the Linux 7.2 merge window can be found via this pull request.

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.