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

4

u/throwaway6560192 Apr 15 '21

Things can and do go wrong. And the kernel needs to be as free of that as possible.

What kind of "things" are you expecting to go wrong here?

1

u/continous Apr 15 '21

"What do you mean we have memory unsafe code? Rust is supposed to catch all of that!"

4

u/throwaway6560192 Apr 15 '21

Rust catches everything not in an unsafe block. You only need to check the unsafe blocks, a vast improvement over C.

The kernel devs understand this, far better than you do. Nobody's going to be surprised like that.

1

u/continous Apr 15 '21

This makes an assumption Rust is without it's errors or shortcomings regarding memory.

It isn't.

https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=rust

7

u/throwaway6560192 Apr 15 '21

still vastly better than C

1

u/continous Apr 15 '21

C has been around a longer time to have more bugs found.

4

u/Shikadi297 Apr 16 '21

and many bugs were found, and many are found every day. Rust was written to help prevent the bugs that C has generated over its long time of being around

0

u/guesschess Apr 16 '21

Not really. With C, everything is explicit, so if there's something wrong, it's a bug in the compiler or with what I wrote.

With Rust, you can't actually say that.

5

u/throwaway6560192 Apr 16 '21 edited Apr 16 '21

Examples? What isn't explicit in Rust but is in C? The main difference I can think of is that outside unsafe blocks, you don't call malloc/free but instead use smart pointers like C++. If you want to use malloc/free just wrap it in an unsafe block.

Do you think the kernel devs are stupid and ignorant and haven't considered all this?

0

u/guesschess Apr 16 '21

Yeah, so if you do everything in unsafe blocks, you're effectively just writing c++ code.

4

u/throwaway6560192 Apr 16 '21

If.

You almost never need raw malloc/free. Usage of unsafe blocks is very low. Remember, with Rust you only need to manually check the unsafe blocks. In C you need to check the whole thing no exceptions.

2

u/guesschess Apr 16 '21

I actually use mmap quite a bit as well as various libnuma allocators.

In rust, something has to check, and that's the compiler.

→ More replies (0)

1

u/UARTman May 07 '21

Unsafe Rust is safer than C/C++ due to type system enforcing certain invariants.

Also, the whole fucking point of rust is to write safe abstractions over the unsafe code. If you write only unsafe, you're doing something very wrong.

0

u/guesschess May 07 '21

Why?. Look at adios from oak ridge national labs. That is entirely unsafe, and by sacrificing type safety you gain a lot in terms of IO performance and abstraction.