The Rust Programming Language Is Now One Step Closer To Entering The Mainline Linux Kernel

From LinuxReviews
Jump to navigationJump to search
Tux-000e.svg

The Linux kernel community has been discussing the possibility of using the Rust programming language to write new kernel device drivers since last summer. Initial Rust support has now landed in the Linux-Next tree. This does not guarantee that Rust will be supported or even allowed in the mainline kernel, but it does mean that there is now a fair chance that Rust will eventually be required to successfully compile a Linux kernel.

written by 권유리 (Kwon Yu-ri)  2021-03-20 - last edited 2021-03-20. © CC BY

Make-menuconfig-5.11.6.jpg
make menuconfig on Linux kernel 5.11.6.

Googles Nick Desaulniers started pushing for "in tree" Rust support in the Linux mainline kernel with a message titled "Linux kernel in-tree Rust support" in July 2020. The discussion of the wisdom of allowing Rust to be used for Linux driver development has been on-going since then. The discussions and the behind-the-scenes work has now yielded tangible results.

Kernel developer Miguel Ojeda announced that Rust support for the Linux kernel is now in linux-next!" in a message to the "Rust-for-linux" mailing list on March 18th, 2021. He noted that:

"Thanks to Stephen Rothwell, we are now in linux-next!

This does not mean we will make it into mainline, of course, but it is a nice step to make things as smooth as possible."

We are now in linux-next!
posted by Miguel Ojeda on Rust-for-linux on March 18th, 2021

The actual commit to linux-next, hailed by kernel developer and security researcher Alex Gaynor as "an exciting milestone", contains 3451 lines of code in 29 new files in a rust/ folder. It has a rather short commit message:

"This is a draft for linux-next. This message is intentionally bare-bones for the moment. It is not representative of the final contents and will be rebased."

Building a Linux-next kernel will Rust support requires the Rust compiler (rustc) and a fairly recent nightly snapshot of the Rust toolchain. That limits the currently supported platforms to x86-64 and arm64.

The Linux-Next Rust merge did not include any actual kernel drivers or other code using Rust to provide useful functionality. It does make it possible to write Linux kernel drivers in Rust. Doing so would be a gamble that Linus Torvalds approves the code for inclusion into the mainline Linux kernel. Torvalds has indicated that he is open to the idea as long as it is disabled automatically if Rust isn't present at compile-time:

"No, please make it a "is rust available" automatic config option. The exact same way we already do the compiler versions and check for various availability of compiler flags at config time."

A lot of code goes from Linux-Next to the mainline kernel almost as a matter of routine, and it would be natural to assume that the code would make it into the next major kernel version when Linux 5.12 is released and the merge window opens if it was a smaller change. Rust support is a rather big change. The amount of code isn't huge, but the implications are. There are some good reasons why Linus Torvalds may want to leave the Rust support in Linux-Next for a release-cycle or three before he merges the changes into the mainline Linux kernel. He could, for example, question why the commit contains 103 instances of the word "unsafe".

It is impossible to know what will happen during the Linux 5.13 merge window when it opens, we can only wait and see if Rust makes it into the next mainline kernel or not.

4.43
(7 votes)


avatar

Chaekyung

7 months ago
Score 1++
Please mind your language, this is a family-friendly website.
Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.