Live data from Hacker News

Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

github.com

41–50 of 196 posts

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#41
Author here. I'm surprised to see my hobby project on Hacker News.

I know this kind of stuff spark the ``it's meaningless to rewrite everything (especially Linux) in Rust'' debate. I agree 100% that rewriting Linux in Rust (or your favorite language) is just a waste of time and such a project won't live long.

That said, what I'd say here is that it's fun. Really fun. Implementing ABI compatibility requires you to understand under the hood of the kernel. You can learn how printf(3) works. You can learn what happens before main().

Especially, in Rust, it's inspiring to explore ways to write a kernel safely and expressively. One of my favorite part is the implementation of read system call [1].

Lastly, You can try this OS on SSH. Hope you enjoy :)

    ssh root@kerla-demo.seiya.me
[1]: https://github.com/nuta/kerla/blob/main/kernel/syscalls/read...

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#42
post #13
post #10

Earlier quoted context omitted.

Absolute codswallop. Linux will be here for many, many years to come yet.

Absolutely! But in Rust . Why do you think the Linux developers are bolting on Rust in the Linux kernel themselves? [0] It has already been admitted. [0] https://lore.kernel.org/lkml/20210704202756.29107-1-ojeda@ke...

They've been writing drivers and such for years now and they've indeed levelled up the tooling integration. Your original post said along the lines of "if linux is to survive". Even if it was a full rewrite in rust (not going to happen) then it's still be Linux, with the same leadership. Most users wouldn't be able to tell the difference.

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#43
post #21

This may be a naive question, but I cannot help but wonder: As C and Rust aim to be link-compatible, wouldn't it be easier to gradually replace parts of the Linux kernel with Rust code? The only technical problem I can think of is that Rust may not be available for all CPU architectures Linux supports, but this is just speculation on my part having done no research on the matter.

The Rust for Linux kernel project aims to enable writing Linux kernel device drivers in Rust. See: https://lwn.net/Articles/862018/ The issue of Rust's LLVM based compiler toolchain not targeting all CPU archs is intended to be solved by the gcc-rs project. See: https://lwn.net/Articles/871283/ I think the approach the Rust for Linux project is taking is wise: Not about outright re-writes but more about focusing on t…

Last I checked, one of the big problems was the Rust panics when you run out of memory, which is unacceptable in the kernel. Is there any progress on that?

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#44
post #41

Author here. I'm surprised to see my hobby project on Hacker News. I know this kind of stuff spark the ``it's meaningless to rewrite everything (especially Linux) in Rust'' debate. I agree 100% that rewriting Linux in Rust (or your favorite language) is just a waste of time and such a project won't live long. That said, what I'd say here is that it's fun. Really fun. Implementing ABI compatibility requires you to und…

> I know this kind of stuff spark the ``it's meaningless to rewrite everything (especially Linux) in Rust'' debate. I agree 100% that rewriting Linux in Rust (or your favorite language) is just a waste of time and such a project won't live long.

Considering that this is exactly how Linux was born (just a hobby project for fun), I wouldn't assume so fast that it's useless. Moreover, you don't need to justify yourself if you just want to have fun !

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#45

A minimal interactive demo running busybox is here: ssh root@kerla-demo.seiya.me

That’s very cool! Could you share some details on how to set it up for oneself with AWS Firecracker the same way that this demo was set up? Also, as owner of the instances are you able to see what commands people are running? First thing I did was to type hello, and it said hello world to me :)

Author here. I've made the demo system public [1] but it's written just for me so it should be painful to set up the same environment.

The mechanism is pretty simple: a Node.js server (running on genuine Linux) listens on tcp:22. Once you connect, it boots a dedicated Firecracker microVM instance and forwards network packets between your SSH client and VM.

Regarding the command history, others (including I) can't see what you type. If you could, it must be a vulnerability.

[1] https://github.com/nuta/kerla-demo

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#46

Earlier quoted context omitted.

The type of software makes the difference - does it process untrusted input, maybe even over the network? This here is a kernel including a memory-safe TCP/IP stack ( https://github.com/smoltcp-rs/smoltcp/ ), and not having it crash or be full of security vulnerabilities due to preventable memory corruption is a quality beyond personal language preferences.

It is possible to overstate a valid case until it becomes meaningless... are modern OS IP stacks written in C really 'crash'ing or 'full of security vulnerabilities'? No.

The fact is that it is overwhelmingly more difficult to write and guarantee that your C code is "safe" to the same extent that a naively-written Rust program which accomplishes the same thing would be, especially as your software's complexity increases.

Is it possible to write C code that has the safety properties of Rust code which provides the same functionality? Absolutely, in theory. But will you be able to accomplish this and then guarantee this safety and have the confidence that future code changes won't break those guarantees? That becomes exceedingly more difficult to do, nevermind the extra time and effort it would take. In most cases this would be prohibitively expensive, and you'd just get on with life hoping for the best and mitigating what you can.

In my view, one of the killer features of Rust is its ability to be easily ABI-compatible with C as needed, which I see as a pragmatic feature of Rust that acknowledges the messy software reality of our world and the fact that C (or any other language) isn't just going to be "replaced" by rewriting stuff everywhere, neither anytime soon nor probably ever in totality. This lets us more readily combine the great capabilities of Rust with the enormous volumes of useful code that already exist today without resorting to dogmatic approaches of always thinking we need to rewrite the latter. The "rewrite everything in Rust" idea is fun in an academic kind of way, but in the real world economics will prevent that from happening everywhere, in a similar way that economics usually prevents you from validating and providing certain safety guarantees about your C code.

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#47
post #21

This may be a naive question, but I cannot help but wonder: As C and Rust aim to be link-compatible, wouldn't it be easier to gradually replace parts of the Linux kernel with Rust code? The only technical problem I can think of is that Rust may not be available for all CPU architectures Linux supports, but this is just speculation on my part having done no research on the matter.

A practical problem is that in order to gain the benefit of linking Rust and C code, one has to give up Rust's wonderful guarantees at the interface. So until islands of Rust meet up, these interact through a C ABI, and have to expose C-like behavior.

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#48

For each piece of software, there just be a version in Rust, and that version must advertise it's rustiness

For each rust submission, there shall be a comment at top lamenting the gradual rusting of hackernews.

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#49
post #38

For each piece of software, there just be a version in Rust, and that version must advertise it's rustiness

I mean honestly who cares? its their time. I use rust over c/c++ these days for practical reasons. 1. the toolchain is better. (cargo ala) 2. maintenance of the software is better. (static linked binaries, easier deploys) 3. memory safety. 4. resource consumption (cpu/ram) when I don't need 4 I use golang (most cases) because of 1, 2, and 3. and I choose tools (all other things being equal) written in rust for the sa…

Me too, but in my case it's despite of point 2.

Re: Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility

#50

Earlier quoted context omitted.

The Rust for Linux kernel project aims to enable writing Linux kernel device drivers in Rust. See: https://lwn.net/Articles/862018/ The issue of Rust's LLVM based compiler toolchain not targeting all CPU archs is intended to be solved by the gcc-rs project. See: https://lwn.net/Articles/871283/ I think the approach the Rust for Linux project is taking is wise: Not about outright re-writes but more about focusing on t…

Last I checked, one of the big problems was the Rust panics when you run out of memory, which is unacceptable in the kernel. Is there any progress on that?

Yes a lot. https://rust-for-linux.github.io/docs/alloc/alloc/index.html
Post reply on HN