The second edition of patches for the Linux kernel with support for the Rust language

Miguel Ojeda, author of the Rust-for-Linux project, has submitted an updated version of Rust's device driver development components for consideration by Linux kernel developers. Rust support is considered experimental, but has already been agreed to be included in the linux-next branch. The new version eliminates the comments made during the discussion of the first version of the patches. Linus Torvalds has already joined the discussion and suggested changing the logic for processing some bit operations.

Recall that the proposed changes make it possible to use Rust as a second language for developing drivers and kernel modules. Rust support is presented as an option that is not enabled by default and does not result in the inclusion of Rust among the required build dependencies for the kernel. Using Rust to develop drivers will allow you to create safer and better drivers with minimal effort, free from problems such as accessing a memory area after it is freed, dereferencing null pointers, and buffer overruns.

Memory-safe handling is provided in Rust at compile time through reference checking, keeping track of object ownership and object lifetime (scope), as well as through evaluation of the correctness of memory access during code execution. Rust also provides protection against integer overflows, requires mandatory initialization of variable values ​​before use, handles errors better in the standard library, applies the concept of immutable references and variables by default, offers strong static typing to minimize logical errors.

The most noticeable changes in the new version of the patches:

  • The code for memory allocation is spared from the possible generation of the "panic" state when errors occur, such as out of memory. A variant of the alloc Rust library is included, which refactors the code to handle failures, but the ultimate goal is to bring all the features needed for the kernel into the main edition of alloc (the changes have already been prepared and transferred to the Rust standard library).
  • Instead of nightly builds, beta releases and stable releases of the rustc compiler can now be used to compile the kernel with Rust support. Rustc 1.54-beta1 is currently used as the reference compiler, but after the release of 1.54 at the end of the month, it will be supported as the reference compiler.
  • Added support for writing tests using the native Rust attribute "#[test]" and the ability to use doctests to document tests.
  • Added support for ARM32 and RISCV architectures in addition to the previously supported x86_64 and ARM64.
  • Improved implementations of GCC Rust (GCC frontend for Rust) and rustc_codegen_gcc (rustc backend for GCC), which now passes all basic tests.
  • A new level of abstraction has been proposed for use in Rust programs with kernel mechanisms written in C, such as red-black trees, reference-counted objects, file descriptor creation, tasks, files, and I/O vectors.
  • Improved support for the "file_operations" module, "module!" macro, macro registration, and rudimentary drivers (probe and remove) in driver development components.
  • Binder has support for passing file descriptors and LSM hooks.
  • A more functional example of a driver in Rust is proposed - bcm2835-rng for a hardware random number generator for Raspberry Pi boards.

Additionally, the projects of some companies related to the use of Rust in the core are mentioned:

  • Microsoft has expressed interest in participating in the work to integrate Rust support into the Linux kernel and is ready to provide driver implementations for Hyper-V on Rust in the coming months.
  • ARM is working on improving Rust support for ARM-based systems. Changes have already been proposed to the Rust project that move 64-bit ARM systems to the first level of support (Tier-1) platforms.
  • Google directly supports the Rust for Linux project, develops a new implementation of the Binder interprocess communication mechanism in Rust, and is considering reworking various drivers in Rust. Through the ISRG (Internet Security Research Group), Google provided funding for the integration of Rust support into the Linux kernel.
  • IBM has implemented Rust support in the kernel for PowerPC systems.
  • The LSE (Systems Research Laboratory) has developed an SPI driver in Rust.

Source: opennet.ru

Add a comment