Live data from Hacker News

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

github.com

181–190 of 196 posts

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

#181
post #177
post #169

Earlier quoted context omitted.

> Rust's memory model largely makes those isolated address spaces unnecessary, I think you're confusing several concepts. Rust's "memory model" is the C++11 memory model. Maybe you meant the borrow checker and the distinction between shared and exclusive references? Yes, those make it much harder to accidentally screw up other parts of your address space, but it's downright trivial to do it on purpose – you just need…

I meant the ownership model. I'm also imagining a usage model where all the various components of the microkernel come from the same place and have passed various minimum standards like "doesn't have any unsafe blocks". If some program really needs an unsafe block to do something, then that goes into a (hopefully small) library of heavily-scrutinized functions that do dangerous things but expose safe interfaces. If w…

> If some program really needs an unsafe block to do something, then that goes into a (hopefully small) library of heavily-scrutinized functions that do dangerous things but expose safe interfaces.

Device drivers make up the largest part of the Linux kernel, and they would by necessity contain lots of unsafe blocks – the compiler can't reason about the interaction with some device. This is typically different from device to device, and there's no way this could be separated into a small library or module.

Look, I agree that a kernel written in Rust could be much safer than one written in C, and even those instances of 'unsafe' blocks would be easier to audit than C's "everything is unsafe". But it still couldn't replace all the advantages you get from micro-kernels with separate address spaces.

For example, it's impossible in Rust to safely unload a dynamically loaded library. The reason for this is, that such a library could contain static data, like string literals, which are of type &'static str. Passing a 'static reference from the library to the program doesn't require 'unsafe', but will leave a dangling reference when you unload the library. Of course, the unloading operation is itself 'unsafe', but that doesn't help you prevent, locate, or track the transfer of a 'static reference.

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

#182
post #45

Earlier quoted context omitted.

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…

Thank you :)

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

#183

Earlier quoted context omitted.

> panicking = crashing the computer That isn't very accurate. In Rust when programming in no_std, you can (must?) define your own panic handler: https://doc.rust-lang.org/nomicon/panic-handler.html Which you would define in the kernel. While I'm not going to speculate on exactly what the implementation would look like, you definitely do not need to "crash" the computer. I haven't done any kernel programming, but I'm…

Mm no, it's pretty accurate. For a start, notice that the Linux community has been very clear that panicking is unacceptable. The reason is that they cannot realistically do anything to recover. > panic handler [...] Which you would define in the kernel. While I'm not going to speculate on exactly what the implementation would look like, you definitely do not need to "crash" the computer. The panic handler loses so m…

I disagree that PanicInfo loses so much context. PanicInfo caries an arbitrary payload of &(dyn Any + Send).

Now there is a lot that the allocator could do. If you wanted something to be retriable, it could be interesting if the thing that failed was an async task. If so, that panic info could carry enough information to say, the failure was an OOM, here’s the task that failed, and it is marked as retriable. Yes, this would require a store of tasks somewhere in the kernel. Then based on it being an OOM, see if any memory can be reallocated before retrying, or wait to retry until it is.

This is where theoretically a new async based Rust kernel, especially a micro-kernel, could be interesting. Is stack unwinding in the kernel a bad idea? Maybe. Can it be done in Linux? Maybe not, maybe it’s too much work to track all this information, but I disagree with the conviction with which you right it off.

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

#184

What are some ways I can increase my knowledge in this domain that the OP is very skilled at, meaning low level OS development? I've taken an intro to OS class and am currently going through Linux From Scratch [1], which is interesting and is teaching me a lot, but it's more about how to setup a Linux distro using existing packages and not really about reading/writing the code involved. Any recommendations? [1] https…

Linux from scratch won't really help you. I'd say start by looking into writing drivers for Linux and looking at tiny OS examples for microcontrollers that can be run in emulators or cheap boards. Bare-metal projects are available for pi and beaglebone. You will absolutely have to do something like that at a minimum, so it's good to apply what you learned in your OS class to that stuff.

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

#185
post #181
post #177

Earlier quoted context omitted.

I meant the ownership model. I'm also imagining a usage model where all the various components of the microkernel come from the same place and have passed various minimum standards like "doesn't have any unsafe blocks". If some program really needs an unsafe block to do something, then that goes into a (hopefully small) library of heavily-scrutinized functions that do dangerous things but expose safe interfaces. If w…

> If some program really needs an unsafe block to do something, then that goes into a (hopefully small) library of heavily-scrutinized functions that do dangerous things but expose safe interfaces. Device drivers make up the largest part of the Linux kernel, and they would by necessity contain lots of unsafe blocks – the compiler can't reason about the interaction with some device. This is typically different from de…

Exactly. Looking towards the language to keep you safe is essentially client side security, it's the memory model that isn't safe: dumping everything in on executable allows for all kinds of tricks to be performed. Only a micro kernel has with the present architectures the ability to isolate one driver from another in such a way that those drivers can not accidentally or purposefully attack each others address space.

Another advantage is that there is no such thing as a kernel crash, worst case you get a device driver that needs restarting. The whole loadable module model is broken by design and replicating it in Rust isn't going to solve that particular problem (and it isn't one that Rust is trying to solve).

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

#186
post #175

Earlier quoted context omitted.

But that's one of the big promises of micro-kernels: You don't have to have 100% trust in the driver for that gamepad you bought from some unknown company. What about that WiFi driver with 10,000s of lines of code? Are you absolutely sure there isn't some code in it that accidentally or purposefully leaks the rest of your kernel data structures to the outside world? With drivers in their own isolated address space, y…

That was the point behind Singularity OS[1] IIRC. Using managed code which could be verified safe by the OS using static analysis. Can't find it right now, but I recall reading they implemented a network driver with minimal overhead compared to a traditional OS. While they used message passing, a lot of overhead could be eliminated due to the assumptions of safe code. [1]: https://en.wikipedia.org/wiki/Singularity_%2…

Message passing by itself doesn't have to be slow (you can use the paging subsystem for this purpose), but you are looking at two more context switches per system call.

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

#187

Rewriting the Linux kernel in rust would be a rehash of why we ended up with Linux in the first place: rewriting an older OS from scratch. I would love to see a solid implementation of a real micro kernel based OS based on a message passing core in Rust to become a viable alternative to the now 50 year old Unix architecture. This would give us a possibility of some real progress on the security and process scheduling…

Written properly, a monolithic kernel in Rust would provide many of the benefits of a microkernel, due to the memory safety. It'd be much along the same lines as Microsoft Research's Midori, with software isolation instead of hardware isolation.

It would be wide open to specially crafted drivers, it's the equivalent of client side security (or maybe that should be 'compile time security'). Memory safety is something only process space isolation can bring.

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

#188
post #159
post #98

Earlier quoted context omitted.

nice project! curious how the rust ownership model works in a monolithic kernel context. are the lifetimes of kernel structures associated with a process "owned" by the process itself somehow?

I’m not sure this answers what you asked, objects that are referenced from multiple objects are simply wrapped with Arc .

sortof. i'm just kinda curious if any of rust's cool memory management features work particularly well or have to be bypassed in a monolithic kernel context.

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

#189

Earlier quoted context omitted.

> In fact in this instance I think it's a little disingenuous to quote Linux and say it could happen again. Seems apropos to me, given the fact that a Linux ABI compatible hobby project is under discussion - and that everyone here is familiar with the famous Usenet announcement. > The industry is totally different now. There's much more competition than there was when... I wonder how you define "competition"? Because…

> I wonder how you define "competition"? Because there were way more operating systems in use then, and the industry was far more fractured. There is way more competition now: + Linux (countless distributions) + FreeBSD + OpenBSD + NetBSD + DragonflyBSD + HardenedBSD + Darwin + Minix 3 (which wasn't free when Linux was released) + Illumos + OpenIndiana + Nexenta OS + SmartOS + ...and many others based off OpenSolaris…

Odd, you purportedly know the difference between an OS and a distro - but that doesn't stop you from generating the above nonsense list. Just look at the last 5 items... seriously - all these Illumos derivatives are distinct operating systems in competition with one another? And to a degree that is no different from Netware vs OS/2?! Be serous, that list only further proves my point about the total lack of distinguishing difference in the present offerings - relative to the pre-linux environment.

> So just because you might exist in a Linux-only...

Obnoxiously presumptuous.

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

#190
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…

How did you set-up the ssh system? Where a new vm is spawned on ssh ?
Post reply on HN