Eighth version of the Linux kernel patches with Rust language support

Miguel Ojeda, the author of the Rust-for-Linux project, proposed for consideration by the Linux kernel developers the release of v8 components for device driver development in Rust. This is the fifth revision of the patches based on the first version, which was published without a version number. Support for Rust is considered experimental but has already been included in the linux-next branch, aiming for integration in the upcoming 5.20/6.0 release and is sufficiently developed to begin work on creating abstraction layers over kernel subsystems, as well as for writing drivers and modules. The development is funded by Google and the Internet Security Research Group (ISRG), which is the sponsor of the Let’s Encrypt project and promotes HTTPS along with developing technologies to enhance internet security.

In the new version:

  • The toolchain and variant of the alloc library, free of potential panic state generations when errors occur, have been updated to the Rust 1.62 release. Compared to the previously used version, the Rust toolchain has stabilized support for the const_fn_trait_bound functionality used in kernel patches.
  • The code bindings have been separated into a standalone crate package called 'bindings', simplifying recompilation in case changes are made only to the main 'kernel' package.
  • The implementation of the 'concat_idents!' macro has been rewritten as a procedural macro, decoupled from the concat_idents functionality and allowing references to local variables.
  • The 'static_assert!' macro has been rewritten, enabling the use of 'core::assert!()' in any context instead of constants.
  • The 'build_error!' macro has been adapted to work with modules set to 'RUST_BUILD_ASSERT_{WARN,ALLOW}'.
  • A separate file with settings 'kernel/configs/rust.config' has been added.
  • Files processed in macro substitutions with the '*.i' extension have been renamed to '*.rsi'.
  • Support for building Rust components with optimization levels different from those used for C code has been discontinued.
  • A fs module has been added, providing wrappers for working with file systems. An example of a simple file system written in Rust has been proposed.
  • A workqueue module has been added for working with system queues (providing wrappers over the kernel structures work_struct and workqueue_struct).
  • The development of the kasync module has continued with the implementation of asynchronous programming methods (async). An example of a TCP server written in Rust, functioning at the kernel level, has been added.
  • The ability to handle interrupts in Rust using the [Threaded]Handler traits and [Threaded]Registration types has been added.
  • A procedural macro ‘#[vtable]’ has been introduced, simplifying work with function pointer tables such as the file_operations structure.
  • Implementation of bidirectional linked lists ‘unsafe_list::List’ has been added.
  • Initial support for RCU (Read-Copy-Update) and a Guard type for verifying read lock binding to the current thread has been added.
  • The Task::spawn() function has been added for creating and automatically launching kernel threads. The Task::wake_up() method has also been introduced.
  • The delay module has been added, allowing the use of delays (a wrapper over msleep()).

The proposed changes enable the use of Rust as a secondary language for developing drivers and kernel modules. Rust support is presented as an optional feature, not active by default, and does not result in Rust being included among the mandatory build dependencies for the kernel. Using Rust for driver development will allow for the creation of safe and higher-quality drivers with minimal effort, eliminating issues such as accessing memory after it has been freed, dereferencing null pointers, and buffer overflows.

Safe memory handling in Rust is ensured at compile time through reference checking, ownership tracking of objects, and considerations of object lifetimes (scope), as well as runtime checks for correctness in memory access. Rust also provides protections against integer overflows, requires variables to be initialized before use, manages errors more effectively in the standard library, employs immutability by default for references and variables, and offers strong static typing to minimize logical errors.

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster