
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 gener…

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 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 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 Some Meaningful Performance Benefits For Clang + LTO Built Linux Kernels.