At the ongoing Linux Plumbers Conference 2022, an engineer from Western Digital presented a talk about the development of an experimental driver for NVMe (NVM Express) SSDs, written in Rust and operating at the Linux kernel level. Although the project is still in its early stages, testing has shown that the performance of the NVMe driver in Rust matches that of the existing NVMe driver in the kernel, written in C.


The report states that the current NVMe driver in C fully satisfies developers, but the NVMe subsystem is a good platform to explore the feasibility of developing drivers in Rust, as it is fairly simple, widely used, has high performance requirements, has a proven reference implementation for comparison, and supports multiple interfaces (dev, pci, dma, blk-mq, gendisk, sysfs).
It is noted that the PCI NVMe driver in Rust already provides the necessary functionality for operation, but it is not yet ready for widespread use, as it requires additional modifications. Future plans include removing existing unsafe blocks from the code, supporting device removal operations and driver unloading, supporting the sysfs interface, implementing deferred initialization, creating a driver for blk-mq, and experimenting with asynchronous programming models for queue_rq.

Additionally, it is worth mentioning the experiments conducted by NCC Group on developing drivers in Rust for the FreeBSD kernel. As an example, a simple echo driver is examined in detail, which returns the data written to the file /dev/rustmodule. In the next phase of experiments, NCC Group is considering the possibility of rewriting kernel core components in Rust to enhance the security of network and file operations.
However, despite demonstrating the possibility of creating simple modules in Rust, a more integrated approach of Rust into the FreeBSD kernel will require additional work. For instance, there is a need to create a set of abstraction layers over the subsystems and structures of the kernel, similar to the enhancements prepared by the Rust for Linux project. Further experiments with the Illumos kernel are also planned to identify common Rust abstractions that could be used in Rust-written drivers for Linux, BSD, and Illumos.
According to Microsoft and Google, around 70% of vulnerabilities in their software products are due to unsafe memory handling. It's believed that using Rust will help reduce the risk of vulnerabilities caused by unsafe memory operations and eliminate errors such as dereferencing freed memory 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
