The sixth version of patches for the Linux kernel with support for the Rust language

The sixth version of patches for the Linux kernel with support for the Rust language

Miguel Ojeda, author of the Rust-for-Linux, proposed the release of v6 components for Rust device driver development for Linux kernel developers to consider. This is the seventh edition of the patches, taking into account the first version, published without a version number. Rust support is considered experimental, but is already included in the linux-next branch and mature enough to start working on creating abstraction layers over kernel subsystems, as well as writing drivers and modules. The development is funded by Google and the ISRG (Internet Security Research Group), which is the founder of the Let’s Encrypt project and promotes HTTPS and the development of technologies to increase the security of the Internet.

In the new version:

  • The toolkit and a variant of the alloc library, which got rid of possible “panic” state generation on errors, has been updated to the Rust 1.60 , which stabilizes support for the ” maybe_uninit_extra ” mode used in kernel patches.
  • Added the ability to run tests from the documentation (tests that are simultaneously used as examples in the documentation), by converting at compile time tests tied to the kernel API into KUnit tests that run at kernel boot time.
  • Required that tests should not produce a Clippy linter warning, just like Rust core code.
  • An initial implementation of the “net” module with network functions is proposed. Rust code provides access to kernel network structures such as “Namespace” (based on the “struct net” kernel structure), SkBuff (struct sk_buff), TcpListener, TcpStream (struct socket), Ipv4Addr (struct in_addr), SocketAddrV4 ( struct sockaddr_in) and their IPv6 equivalents.
  • Implemented initial support for asynchronous programming methods (async), implemented in the form of the kasync module. For example, you can write asynchronous code to manipulate TCP sockets: async fn echo_server(stream: TcpStream) -> Result { let mut buf = [0u8; 1024]; loop { let n = stream.read(&mut buf).await?; if n == 0 { return Ok(()); } stream.write_all(&buf[..n]).await?; } }
  • Added net::filter module to manipulate network packet filters. Added example rust_netfilter.rs with filter implementation in Rust language.
  • Added implementation of a simple mutex smutex::Mutex that does not require pinning.
  • Added a NoWaitLock lock that never waits for a release, and if occupied by another thread, throws an error when trying to acquire the lock instead of stopping the caller.
  • Added a RawSpinLock lock, identified with raw_spinlock_t in the kernel, applied to sections that cannot be idle.
  • Added the ARef type for object references to which the reference counting mechanism is applied (always-refcounted).
  • The rustc_codegen_gcc backend, which allows you to use the libgccjit library from the GCC project as a code generator in rustc to provide rustc support for architectures and optimizations available in GCC, has implemented the ability to . bootstrap the rustc compiler Compiler spin-up refers to the ability of rustc to use a GCC-based code generator to build the rustc compiler itself. In addition, the recent release of GCC 12.1 includes fixes to libgccjit required for rustc_codegen_gcc to work correctly. Preparations are underway to provide the ability to install rustc_codegen_gcc using the rustup utility.
  • Progress is noted in the development of the GCC frontend gccrs with the implementation of the Rust language compiler based on GCC. There are currently two full-time developers working on gccrs.

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 safety 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 variables to be initialized before use, handles errors better in the standard library, applies the concept of immutable references and variables by default, and offers strong static typing to minimize logical errors.

Be the first to comment

Leave a Reply

Your email address will not be published.


*