[TECH TOPIC] Rust for Linux

Miguel Ojeda
2023-08-07T10:03:59Z

Hi all,

This is https://lpc.events/event/17/abstracts/1602/ (submitted
yesterday, but we just recalled the mailing list requirement). This
talk could go into either the Kernel Summit track or the Refereed
track.

Rust for Linux [1] is the project adding support for the Rust language
to the Linux kernel. Soon after LPC 2022, the initial support for Rust
was merged into the kernel for v6.1.

Since then, there has been progress in several different areas,
including the addition of safe abstractions around kernel
functionality and subsystems, as well as infrastructure and tooling
changes. The talk will give a high-level overview of some of them,
such as:

- Core: `Opaque`, `CString`, `ScopeGuard`, `concat_idents!`,
`{static,build}_assert!`: basic functionality that is widely used in
Rust code.

- Kernel primitives: `Arc`, `Lock`, `Guard`, `Mutex`, `SpinLock`,
`CondVar`, `Task`, `workqueue::Queue`: exposing existing C kernel APIs
as zero-cost and safe Rust abstractions.

- `pinned-init` API: a solution to the safe pinned initialization problem.

- KUnit integration for Rust doctests.

- `klint`: a tool to introduce extra static analysis passes,
including an analysis that validates that Rust code follows the kernel
locking rules by tracking the preemption count at compile-time.

- Rust generated documentation at https://rust.docs.kernel.org.

Now that the project is developed in-tree, we will also explain some
of the changes to our workflow too, such as our branch setup, the
policy around unsoundness issues for stable kernels and the Rust
version upgrade policy.

Finally, we will switch our focus to the future, where we will briefly
discuss what is coming up imminently and longer term, such as the
placement of Rust code within the tree and the build system changes;
and also try to discuss and seek input from the community on ways in
which we can address some of the broader challenges we have been
facing. For example, a recurring theme is how can we make adding Rust
to a given subsystem more palatable to overburdened maintainers?

[1] https://rust-for-linux.com

Cheers,
Miguel