The linux-next branch, on which the release of Linux kernel 5.13 will be based, includes an initial set of components for developing device drivers in Rust. Documentation for using Rust in the Linux kernel has been published separately, along with a kernel module example featuring a character device driver written in Rust. The code was contributed by Stephen Rothwell, the maintainer of the linux-next branch. Typically, the linux-next branch includes code ready to be accepted in the next kernel change acceptance cycle, but it is still unclear whether Linus Torvalds will accept Rust support into Linux 5.13, as the code has not yet undergone wide developer review.
Support for developing Linux kernel drivers in Rust was actively discussed last year, including with Linus Torvalds, who did not rule out such a possibility. The idea was also supported by Greg Kroah-Hartman, who is responsible for maintaining the stable branch of the Linux 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.
To enable Rust support in the linux-next branch, an option CONFIG_RUST ('Rust support' in the 'General setup' menu) has been added to KConfig. When activated, it checks for the presence of the rustc compiler in the system, and if found, allows the inclusion of other components related to Rust (for example, a 'Rust hacking' section appears in the 'Kernel hacking' menu). The use of Rust is considered an option that is not enabled by default, thus not making Rust mandatory among the kernel's build dependencies.
Building kernel components in Rust is possible using both GCC and Clang. To use Rust in the kernel, the latest nightly builds of the rustc compiler must be installed, not older than the nightly branch of 2021-02-20 (support for stable Rust branches is promised, but currently, it is tied to some experimental features). The standard Rust libraries provided in the rust-src package and the bindgen binding generator must also be present in the system. Support is currently limited to x86_64 and ARM64 platforms.
Source: opennet.ru
