Hacker News new | past | comments | ask | show | jobs | submit

Asterinas: OS kernel written in Rust and providing Linux-compatible ABI

https://github.com/asterinas/asterinas
Decades ago Linus Torvalds was asked in an interview if he feared Linux to be replaced by something new. His answer was that some day someone young and hungry would come along, but unless they liked writing device drivers Linux would be safe.

This is all paraphrased from my memory, so take it with a grain of salt. I think the gist of it is still valid: Projects like Asterinas are interesting and have a place, but they will not replace Linux as we have it today.

(Asterinas, from what I understood, doesn't claim to replace Linux, but it a common expectation.)

More recently, in a similar vein:

> Torvalds seemed optimistic that "some clueless young person will decide 'how hard can it be?'" and start their own operating system in Rust or some other language. If they keep at it "for many, many decades", they may get somewhere; "I am looking forward to seeing that". Hohndel clarified that by "clueless", Torvalds was referring to his younger self; "Oh, absolutely, yeah, you have to be all kinds of stupid to say 'I can do this'", he said to more laughter. He could not have done it without the "literally tens of thousands of other people"; the "only reason I ever started was that I didn't know how hard it would be, but that's what makes it fun".

https://lwn.net/Articles/990534/

> Hohndel clarified that by "clueless", Torvalds was referring to his younger self

As the saying goes "We do this not because it is easy, but because we thought it would be easy."

Occasionally these are starts of great things.

loading story #41855060
loading story #41855771
I feel like there's a potentially large audience for a kernel that targets running in a VM. For a lot of workloads, a simple VM kernel could be a win.
loading story #41855296
Also this mysterious new Fuchsia OS from Google is also shooting for full Linux compatibility and is about to show up in Android, I think this is a much more realistic path of the next generation of operating systems that have a real chance to replace Linux but who knows what their actual plans are here at the moment but I don’t believe for a moment that that project is dead in any way.
loading story #41856213
loading story #41856581
I personally dislike rust, but I love kernels, and so I'll always check these projects out.

This is one of the nicer ones.

It looks pretty conservative in it's use of Rust's advanced features. The code looks pretty easy to read and follow. There's actually a decent amount of comments (for rust code).

Not bad!

Otherwise is a decent language but what makes it difficult is the borrow semantics and lifetimes. Lifetimes are more complicated to get your head around.

But then there's this Arc, Ref, Pinning and what not - how deep is that rabbit hole?

loading story #41856306
loading story #41856204
loading story #41855987
loading story #41855995
Rust code is usually well commented in my experience.
loading story #41854248
loading story #41853577
I'm interested in these kind of kernels to run very high performance network/IO specific services on bare metal, with minimal system complexity/overheads and hopefully better (potential) stability and security.

The big concern I have however is hardware support, specifically networking hardware.

I think a very interesting approach would be to boot the machine with a FreeBSD or Linux kernel, just for the purposes of hardware as well as network support, and use a sort of Rust OS/abstraction layer for the rest, bypassing or simply not using the originally booted kernel for all user land specific stuff.

Couldn't you just boot the Linux kernel directly and launch a generic app as pid 1 instead of a full blown init system with a bunch of daemons?

That's basically what you're getting with Docker containers and a shared kernel. AWS Lambda is doing something similar with dedicated kernels with Firecracker VMs

Yes, but I wanted to bypass having the complexity of the Linux kernel completely, too.

Basically single app directly to network (the world) and as little as possible else in between.

Yes, you can. You can even have a different Pid 1 configure whatever and then replace it's core image with the new Pid 1.
If you want truly high-performance networking, you can bypass the kernel altogether with DPDK. So you don't have to worry about alternative kernels for other tasks at all. On the downside, DPDK takes over the NIC entirely, removing the kernel from the equation, so if you need the kernel to see network traffic for some reason, it won't work for you.

You can check out hardware support here: https://core.dpdk.org/supported/nics/

This was true a decade ago, with modern io_uring dpdk is probably an anti-pattern.
Interesting, it's been awhile since I looked at this stuff so I did a little searching and found this: https://www.diva-portal.org/smash/get/diva2:1789103/FULLTEXT...

Their conclusion is io_uring is still slower but not by much, and future improvements may make the difference negligible. So you're right, at least in part. Given the tradeoffs, DPDK may not be worth it anymore.

Not by much?? You're exaggerating..
loading story #41854008
loading story #41854804
Why don’t you just use a SmartNIC and P4? It won’t get faster than running on the NIC itself
i might be wrong but if it's ABI compatible the same drivers will work?

p.s.: i was wrong

>While we prioritize compatibility, it is important to note that Asterinas does not, nor will it in the future, support the loading of Linux kernel modules.

https://asterinas.github.io/book/kernel/linux-compatibility....

Linux doesn't even maintain ABI compatibility with itself, nobody else is going to manage it. The possibility that might work is there's a couple projects that maintain just enough API compatibility to reuse driver code from Linux (IIRC FreeBSD does this for some graphics drivers). But even then you're gambling with whether Linux decides to change implementation details one day, since internal APIs explicitly aren't stable.
loading story #41853663
They mention this in https://github.com/asterinas/asterinas/blob/2af9916de92f8ca1...

> While we prioritize compatibility, it is important to note that Asterinas does not, nor will it in the future, support the loading of Linux kernel modules.

loading story #41853210
No, it means you can run Linux userland/apps on this kernel, to the level/depth which they currently support of course.

They might not yet implement everything that's needed to boot a standard Linux userland but you could say boot straight into a web server built for Linux, instead of booting into init for example.

I think this looks incredible. Like how does one create a compatible abi _for all of linux_??? Wow!

> utilize the more productive Rust programming language

Nitpick: it’s 2024 and these ‘more productive’ comparisons are silly, completely unscientific, And a bit of a red flag for your project: The most productive language for a developer is the one they understand what is happening one layer below the level of abstraction they are working with. Unless you’re comparing something rating Ruby vs RiscV assembly, it’s just hocus-pocus.

> I think this looks incredible. Like how does one create a compatible abi _for all of linux_??? Wow!

FWIW that’s what the Linux compatibility layer in the BSDs does and also what WSL 1 did (https://jmmv.dev/2020/11/wsl-lost-potential.html).

It’s hard to get _everything_ perfectly right but not that difficult to get most of it working.

loading story #41856068
> Like how does one create a compatible abi _for all of linux_???

You look at Linux's syscall table[0], read through the documentation to figure out the arguments, data types, flags, return values, etc., and then implement that in your kernel. The Linux ABI is just its "library" interface to userspace.

It's probably not that difficult; writing the rest of the kernel itself is more challenging, and, frankly, more interesting. Certainly matching behavior and semantics can be tricky sometimes, I'm sure. And I wouldn't be surprised if the initial implementation of some things (like io_uring, for example, if it's even supported yet) might be primitive and poorly optimized, or might even use other syscalls to do their work.

But it's doable. While Linux's internal ABI is unstable, the syscall interface is sacred. One of Torvalds' golden rules is you don't break userspace.

[0] https://filippo.io/linux-syscall-table/

Everyone says what they are used to is better or more productive. Even in assembly vs ruby, some stuff are much easier in assembly and maybe impossible in ruby afaik
loading story #41854559
> In the framekernel OS architecture, the entire OS resides in the same address space (like a monolithic kernel) and is required to be written in Rust. However, there's a twist---the kernel is partitioned in two halves ... the unprivileged Services must be written exclusively in safe Rust.

Unprivileged services can exploit known compiler bugs and do anything they want in safe Rust. How this affects their security model?

OT: if you're interested in Asterinas, you might also be interested in Redox (entire OS written in Rust).

https://www.redox-os.org/

Redox has a proper architecture, aka microkernel multiserver.

Thus it is a much more interesting project.

This is fascinating! Couldn't really find the kernel code but would love to know more about the applicability. I'm curious since seeing the Unikraft release that promised millisecond container boot times
loading story #41856409
https://www.youtube.com/watch?v=3AQ5lpXujGo Asterinas: A safe Rust-based OS kernel for TEE by H. Tian & C. Song (Ant Group & Intel) | OC3 2024
I’ll mention another OS written in Rust, Twizzler: https://twizzler.io/

Its more of a research OS but still cool.

And I'll mention another one that a friend of mine is working on: uxrt

https://gitlab.com/uxrt

Side question - I have always wondered how a Linux system is configured at the lowest level?

Let's take example of network. There's IP address, gateway, DNS, routes etc. Depending on distribution we might see something like netplan reading config files and then calling ABI functions?

Or Linux kernel directly also reads some config files? Probably not...

Linux kernel as much as possible tries not to parse or read external data (besides stuff like acpi tables, device trees, hardware registers). For networking, you might look at the iproute codebase to see how they do things like bring a network device up, or create a bridge device, add a route, et cetera.

Edit: looks like iproute2 uses NETLINK, but non-networking tools might use syscalls or device ioctls.

https://en.m.wikipedia.org/wiki/Netlink

There was also the similar project Kerla¹ but development stalled. Recently people argued that instead of focusing on Rust-for-Linux it would be easier to create a drop-in replacement like these two. I wonder if there are enough people interested to make this happen as a sustained project.

¹ https://github.com/nuta/kerla/

> Recently people argued that instead of focusing on Rust-for-Linux it would be easier to create a drop-in replacement like these two

I guess it depends on what they mean by "easy". Certainly it's easier in the sense that you can just write code all day long, and not have to deal with the politics about Rust inside Linux, or deal with all the existing C interfaces, finding ways to wrap them in Rust in good, useful ways that leverage Rust's strengths but don't make it harder to evolve those C interfaces without trouble on the Rust side.

But the bulk of Linux is device drivers. You can build a kernel in Rust (like Asterinas) that can run all of a regular Linux userland without recompilation, and I imagine it's maybe not even that difficult to do so. But Asterinas only runs on x86_64 VMs right now, and won't run on real hardware. Getting to the point where it could -- especially on modern hardware -- might take years. Supporting all the architectures and various bits of hardware that Linux supports could take decades. I suppose limiting themselves to three or four architectures, and only supporting hardware made more recently could cut that down. But still, it's a daunting project.

Super cool project. Looks like the short-term target use-case is running a Linux-compatible OS in an Intel TDX guest VM with a significantly safer and smaller TCB. Makes sense. This way you also postpone a lot of the HW driver development drudgery and instead only target VM devices.
> Linux-compatible ABI

There's no specification of that ABI, much less a compliance test suite. How complete is this compatibility?

While developing the lx brand on illumos/SmartOS, ltp was helpful. It may not be complete, but it is a pretty good start.

https://linux-test-project.readthedocs.io/en/latest/

Here is a list of implemented syscalls, but of course each checked one could still be slightly incompatible:

https://asterinas.github.io/book/kernel/linux-compatibility....

loading story #41853945
From the README:

> Currently, Asterinas only supports x86-64 VMs. However, our aim for 2024 is to make Asterinas production-ready on x86-64 VMs.

I'm confused.

I think it’s “Currently, Asterinas only supports x86-64 VMs. However, [rather than working on additional architectures this year,] our aim for 2024 is to make Asterinas production-ready on x86-64 VMs.”
Sounds like their goal is to improve their x86-64 support before implementing other ISAs.
It's clearer from the book roadmap:

> By 2024, we aim to achieve production-ready status for VM environments on x86-64. > In 2025 and beyond, we will expand our support for CPU architectures and hardware devices.

https://asterinas.github.io/book/kernel/roadmap.html

Distinction here is between "supports" and "production-ready on", not "x86-64" and "x86-64"
Yeah, I had to read that a few times... I think they just mean it isn't production ready yet, but that's what they are aiming for.
it would be nice to know how much userspace it supports. supporting the dynamic loader, reasonable futexes, epoll, signals, uring are all big milestones
loading story #41854264
I like what they're working towards with V in Vinix as well. Exciting times to see such things with ABI compat with Linux opening new paradigms.
What’s the intended use case for this? Backend containers?
Makes a lot of sense for virtual machine containers. Inside a container inside a VM, you need far less operating system.
Lol. I am Malaysian Chinese but I honestly don't think anyone will put into production a Chinese made kernel. The risk is too high, same as no one will use a Linux distro coming out of Russian, Iran or NK. It's just cultural bias in the west.
Supposing it caught on... which do you think is riskier? Running an OS written in mostly memory safe code that somewhat might have tried to slip a backdoor in, or running an OS written in mostly memory unsafe code that has a long history of vulnerabilities and the Chinese almost certainly know about a vulnerability in.

If this catches on and has generally been subject to significant third party code review with positive results, I'm not sure any backdoor is lower cost to use than an equivalent linux vulnerability. To be fair, I'm not sure it isn't either.

You're wrong. A lot of Chinese code and hardware is in production in the west. Huawei networking hardware is widespread, for example.
loading story #41854769
{"deleted":true,"id":41852159,"parent":41847640,"time":1729020189,"type":"comment"}
{"deleted":true,"id":41854430,"parent":41847640,"time":1729037966,"type":"comment"}
The building process happens in a container?

> If everything goes well, Asterinas is now up and running inside a VM.

Seems like the developers are very confident about it too

{"deleted":true,"id":41853352,"parent":41853293,"time":1729028062,"type":"comment"}
I looked into the architecture. It turns out to be monolithic with marketing[0].

Sure is a lot of text to say: We try to use unsafe as little as possible.

Which is the minimum you'd expect anyways ¯\_(ツ)_/¯

0. https://asterinas.github.io/book/kernel/the-framekernel-arch...

The license choice is explained with the following:

> [...] we accommodate the business need for proprietary kernel modules. Unlike GPL, the MPL permits the linking of MPL-covered files with proprietary code.

Glancing at the readme, it also looks like they are treating it as a big feature:

> Asterinas surpasses Linux in terms of developer friendliness. It empowers kernel developers to [...] choose between releasing their kernel modules as open source or keeping them proprietary, thanks to the flexibility offered by MPL.

Can't wait to glue some proprietary blobs to this new, secure rust kernel /s

I'm curious about the practical aspect: Are they going to freeze a stable driver ABI, or are they going to break proprietary drivers from time to time?
loading story #41854175