News: 0001605252

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

Linux 7.0 Readying Improvement For Rust + LTO Kernel Builds

([Linux Kernel] 5 Hours Ago Rust + LTO Kernel Builds)


Alice Ryhl of Google has been working on an improvement to the Linux kernel code for inlining C helpers into Rust when making use of a Link-Time Optimized (LTO) kernel build. At least some of the patches are queued up for merging in the upcoming Linux 6.20~7.0 cycle for helping those enabling the Rust kernel support and also making use of the LLVM/Clang compiler's LTO capabilities for greater performance.

This work to inline C helpers into Rust when using LTO involves adding a "__rust_helper" annotation to every Rust helper within the kernel. This "__rust_helper" is needed since C helpers cannot be inlined into Rust when using LTO because LLVM detects slightly different options on the code generation units.

In turn when using LTO for the kernel builds, "__always_inline" will be added to the helpers except when running bindgen to avoid an issue there with ignoring functions markd as inline. There is a [1]46 patch series for applying this "__rust_helper" where needed throughout the kernel code. Those patches don't need to be merged in one-go and thus left up to the individual subsystem maintainers for taking the patches but at least some of them are set for merging with Linux 7.0.

Via the [2]vfs-7.0.rust Git branch of VFS.git, the patches there have been taken for inlining the C helpers into Rust. We'll see if the full patch series via the different branches all get accepted for this next kernel cycle or will take longer to upstream it all. A separate patch will then take to wiring up the "__rust_helper" behavior.

Separately, for those wondering about the performance benefits of using Link Time Optimizations when building the Linux kernel with LLVM/Clang, recently I ran some fresh benchmarks within [3]Some Meaningful Performance Benefits For Clang + LTO Built Linux Kernels .



[1] https://lore.kernel.org/all/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com/

[2] https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/commit/?h=vfs-7.0.rust&id=5334fc280735dcf5882511a219a99b5759e14870

[3] https://www.phoronix.com/review/linux-kernel-llvm-clang-lto



A gangster assembled an engineer, a chemist, and a physicist. He explained
that he was entering a horse in a race the following week and the three
assembled guys had the job of assuring that the gangster's horse would win.
They were to reconvene the day before the race to tell the gangster how they
each propose to ensure a win. When they reconvened the gangster started with
the engineer:

Gangster: OK, Mr. engineer, what have you got?
Engineer: Well, I've invented a way to weave metallic threads into the saddle
blanket so that they will act as the plates of a battery and provide
electrical shock to the horse.
G: That's very good! But let's hear from the chemist.
Chemist: I've synthesized a powerful stimulant that dissolves
into simple blood sugars after ten minutes and therefore
cannot be detected in post-race tests.
G: Excellent, excellent! But I want to hear from the physicist before
I decide what to do. Physicist?
Physicist: Well, first consider a spherical horse in simple harmonic motion...