X
Business

Programming languages: Rust in the Linux kernel takes another step forwards

The Rust for Linux project is making headway, but Linux creator still has some advice to knock it into shape.
Written by Liam Tung, Contributing Writer

The Google-backed project to make Rust a second programming language in Linux kernel development after C just took it's next big step. 

Key to the project is Spain-based developer Miguel Ojeda, who's been leading the charge to bring Mozilla-hatched systems programming language Rust to the Linux kernel. 

He penned an initial request for comment (RFC) about the Rust proposal for the Linux kernel last month, and on Sunday shared his latest RFC on the project. 

SEE: Hiring Kit: Python developer (TechRepublic Premium)

Rust and the Rust compiler are two key elements that developers have taken a liking to, despite a relatively steep learning curve for those who know how to write in C and C++. 

The idea is that new parts of the Linux kernel can be written in Rust rather than rewriting the 30 million lines of code that the kernel consists of today.     

Rust, as a language, has found financial and engineering support from Amazon Web Services, Google, Microsoft, Facebook, and others because of the language's ability to catch memory-related security issues before code reaches production. 

Linux, of course, is at the heart of much of the internet's infrastructure, running most of the world's cloud infrastructure and web servers.    

But questions remain about whether Linux creator Linus Torvalds and other key kernel developers will bite at the Rust proposal or reject it. Torvalds, for example, had some major objections to 'panics' caused by some Linux kernel hardware drivers that were written in Rust.  

The key question is whether Ojeda's RFC and pull request gets merged with the main Linux kernel project. 

Ojeda outlined some of the main Rust improvements, including the subject of panics. 

"We have removed infallible allocations. In order to do so, we have integrated a subset of the `alloc` standard library crate, with some additions on top. This allows us to customize things to our needs, while giving upstream the time they need to evaluate our changes," writes Ojeda. 

"Eventually, the goal is to have everything the kernel needs in upstream `alloc` and drop it from the kernel tree. We have already started this process and some changes have been already accepted upstream."

Additionally, `alloc` is now compiled with panicking allocation methods disabled, preventing their use within the kernel by mistake, he says. 

There are also improvements for the Rust compiler for the Linux kernel. To date, Ojeda's project has been using nightly releases of the compiler (rustc). Now the kernel can be compiled with the beta and stable versions of rustc. 

"At the moment, we are using the 1.54-beta1 version as our reference compiler. At the end of this month, `rustc` 1.54 will be released, and we will move to that version as our reference," notes Ojeda. 

The Rust compiler is an important part of the language, offering developers helpful error messages, tooling and support for code-completion support in popular code editors like Microsoft's VS Code, VIM and Intellij IDEA.  

There's still more work to do, however. Ojeda notes that the Linux kernel still requires unstable features, even if it is compiled with a stable `rustc` release. 

"Thus we cannot guarantee that future `rustc` versions will work without changes to the kernel tree," he warns. 

SEE: Virtual hiring tips for job seekers and recruiters (free PDF) (TechRepublic)

Ojeda and his collaborators have been working on GNU Compiler Collection (GCC) for Rust, a GCC front end for Rust. There are new Rust components that use Linux kernel C implementations for drivers, with updates for Binder, a component for communicating with the kernel driver, as well as work on the Rust-based random-number generator in some Raspberry Pi devices. 

On top of all this, Ojeda's project now has support from Microsoft's Linux team, chip designer Arm, Google, and IBM.

Microsoft's Linux Systems Group wants to contribute to Rust into Linux kernel. Ojeda hopes to submit select Hyper-V drivers written in Rust in the coming months. 

Arm is working with the Rust community to improve Rust for Arm-based systems. For example, Arm's RFC contribution to the Rust language made Linux on 64-bit Arm systems a Tier-1 Rust supported platform. Google supports and contributes directly to the Rust for Linux project. The Rust Android team is evaluating a new Binder implementation, where other drivers could use a Rust-rewrite. IBM is backing Rust Linux kernel support for PowerPC.  

Torvalds did raise one potential objection to Ojeda's suggestion on "endianness", a computer science memory concept, that falls into big-endian (BE) or little-endian (LE) classes regarding the location of bytes in memory addresses.

"Let's just try to kill big-endian data, it's disgusting and should just die already," Torvalds said in response to Ojeda's RFC. "BE is practically dead anyway, we shouldn't add new cases. Networking has legacy reasons from the bad old days when byte order wars were still a thing, but those days are gone. Linus." 

Via The Register, Torvalds has said Rust could be merged in the Linux 5.14 release. 

The Rust for Linux project is open source and can be viewed here on GitHub.  

Editorial standards