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

Miguel Ojeda, the author of the Rust-for-Linux project, proposed to the Linux kernel developers the release of version 6 of the components for developing device drivers in Rust. This is the seventh edition of the patches, considering the first version published without a version number. Rust support is considered experimental but has already been included in the linux-next branch and is sufficiently developed to begin work on creating abstraction layers over kernel subsystems as well as writing drivers and modules. The development is funded by Google and ISRG (Internet Security Research Group), which is the founder of the Let's Encrypt project and promotes HTTPS and the development of technologies to enhance internet security.

In the new version:

  • The toolchain and the alloc library variant, free of potential 'panic' state generations when errors occur, have been updated to Rust 1.60, which stabilizes support for the 'maybe_uninit_extra' mode used in kernel patches.
  • The ability to run tests from the documentation (tests that also serve as examples in the documentation) has been added by transforming during compilation tests tied to the kernel API into KUnit tests that run during kernel boot.
  • Requirements have been adopted stipulating that tests must not trigger warnings from the Clippy linter, as well as the Rust code for the kernel.
  • An initial implementation of the 'net' module with networking functions has been proposed. Access has been provided in Rust code to kernel networking structures such as 'Namespace' (based on the kernel structure 'struct net'), SkBuff (struct sk_buff), TcpListener, TcpStream (struct socket), Ipv4Addr (struct in_addr), SocketAddrV4 (struct sockaddr_in), and their IPv6 equivalents.
  • Initial support for asynchronous programming (async) methods has been implemented in the form of the kasync module. For example, you can create 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?; } }
  • A net::filter module has been added for manipulating network packet filters. An example rust_netfilter.rs has been added demonstrating a filter implemented in Rust.
  • A simple mutex implementation, smutex::Mutex, has been added that does not require pinning.
  • A NoWaitLock has been introduced, which never causes waiting for release and instead produces an error when attempting to acquire the lock if it is held by another thread, rather than blocking the caller.
  • A RawSpinLock has been added, corresponding to raw_spinlock_t in the kernel, applied to sections that cannot be in a waiting state.
  • An ARef type has been introduced for references to an object that uses a reference counting mechanism (always-refcounted).
  • In the rustc_codegen_gcc backend, which allows using the libgccjit library from the GCC project as a code generator in rustc to support GCC architectures and optimizations in rustc, the ability to bootstrap the rustc compiler has been implemented. Bootstrapping the compiler refers to the ability to use a GCC-based code generator in rustc to build the rustc compiler itself. Additionally, recent GCC 12.1 releases included fixes in libgccjit necessary for the correct operation of rustc_codegen_gcc. Preparations are underway to enable the installation of rustc_codegen_gcc via the rustup utility.
  • Progress is noted in the development of the GCC frontend gccrs with the implementation of a Rust language compiler based on GCC. Currently, two developers are actively working on gccrs.

As a reminder, the proposed changes allow Rust to be used as a secondary language for developing drivers and kernel modules. Rust support is presented as an option, not enabled by default, and does not lead to Rust being included among the mandatory build dependencies for the kernel. Using Rust for driver development will enable creating secure and higher-quality drivers with minimal effort, free from issues such as dereferencing freed memory, null pointer dereferencing, 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