r/linux • • Apr 14 '21

Kernel [RFC] Rust support in the Linux kernel

https://lkml.org/lkml/2021/4/14/1023
608 Upvotes

316 comments sorted by

View all comments

Show parent comments

5

u/BCMM Apr 15 '21

there's a reason the kernel doesn't include languages like Go or C.

Can you expand on this?

1

u/continous Apr 15 '21

We probably shouldn't implement a specific language just because we like aspects of that language. We should be focusing exclusively on the code being submitted.

5

u/BCMM Apr 15 '21
  1. Do you understand that that code has to be written in a programming language?

  2. Are you really advocating for C to not be allowed in the kernel either?

-2

u/continous Apr 15 '21

I'm saying we shouldn't be implementing a specific coding language just because we like it. There should be far more nuanced reasons to implement it.

6

u/Shikadi297 Apr 16 '21

...There are

2

u/BCMM Apr 16 '21

That doesn't really address either question.

-1

u/continous Apr 16 '21

I'm clarifying my original statement, because your leading questions demonstrated a clear misunderstanding of what I was trying to say.

2

u/Helmic Apr 17 '21

What does "because we like it" mean? People like it because of nuanced reasons - namely the memory safety of Rust could bring about quite a bit more security and prevent bugs in things like drivers, and eventually targeted rewrites of parts of the kernel itself where this would bring the most benefit.

Any possible reason for using Rust could be explained away as "liking it." So your clarification isn't really clarifying anything. What you're probably meaning is that trivial personal preferences over things like syntax shouldn't be the primary reason to allow a language into the kernel, but if that's your concern then you didn't read the link posted by OP.

By using Rust in the Linux kernel, our hope is that:

  • New code written in Rust has a reduced risk of memory safety bugs, data races and logic bugs overall, thanks to the language properties mentioned below.

  • Maintainers are more confident in refactoring and accepting patches for modules thanks to the safe subset of Rust.

  • New drivers and modules become easier to write, thanks to abstractions that are easier to reason about, based on modern language features, as well as backed by detailed documentation.

  • More people get involved overall in developing the kernel thanks to the usage of a modern language.

  • By taking advantage of Rust tooling, we keep enforcing the documentation guidelines we have established so far in the project. For instance, we require having all public APIs, safety preconditions, unsafe blocks and type invariants documented.

Why Rust?

Rust is a systems programming language that brings several key advantages over C in the context of the Linux kernel:

  • No undefined behavior in the safe subset (when unsafe code is sound), including memory safety and the absence of data races.

  • Stricter type system for further reduction of logic errors.

  • A clear distinction between safe and unsafe code.

  • Featureful language: sum types, pattern matching, generics, RAII, lifetimes, shared & exclusive references, modules & visibility, powerful hygienic and procedural macros...

  • Extensive freestanding standard library: vocabulary types such as Result and Option, iterators, formatting, pinning, checked/saturating/wrapping integer arithmetic, etc.

  • Integrated out of the box tooling: documentation generator, formatter and linter all based on the compiler itself.

Overall, Rust is a language that has successfully leveraged decades of experience from system programming languages as well as functional ones, and added lifetimes and borrow checking on top.

-1

u/continous Apr 17 '21

What does "because we like it" mean? People like it because of nuanced reasons

I'm suggesting the justification should be those nuanced reasons, not the desire you have for the actual thing.

To give a real world example;

You shouldn't buy something just because you like it. You should buy it because you like that it is safe. You should buy it because you like that it promotes safety. Not just because you like it.

I feel lots of recent Rust development has been largely about "We like this!" more so than "Well, $this is why Rust!" I'm explaining that I feel that this is an extension of that, and that we should exercise caution and do our best to reduce our susceptibility to naivety and ignorance.