312

Moss: a Rust Linux-compatible kernel in 26,000 lines of code

The choice of MIT for a kernel feels like setting up the project to be cannibalized rather than contributed to.

We've seen this movie before with the BSDs. Hardware vendors love permissive licenses because they can fork, add their proprietary HAL/drivers, and ship a closed binary blob without ever upstreaming a single fix.

Linux won specifically because the GPL forced the "greedy" actors to collaborate. In the embedded space, an MIT kernel is just free R&D for a vendor who will lock the bootloader anyway.

2 hours agoleo_e

Not sure why am getting in the middle of this but in need to point out that you are not even correct for Linux.

Linux rather famously has avoided the GPL3 and is distributed under a modified GPL2. This license allows binary blob modules. We are all very familiar with this.

As a result, the kernel that matches your description above that ships in the highest volume is Linux by a massive margin. Can you run a fully open source Linux kernel on your Android phone? Probably not. You do not have the drivers. You may not pass the security checks.

Most companies that use FreeBSD do actually contribute a lot of code. This includes Netflix most famously but even Sony gives back.

The vast majority of vendors that use Linux embedded never contribute a single line of code (like 80% or more at least - maybe 98%). Very few of them even make the kernel code they use available. I worked in video surveillance where every video recorder and camera in the entire industry is Linux based at this point. Almost none of them distribute source code.

This comment is pure ideological mythology.

10 minutes agoLeFantome

Not meaning to single you out specifically, but this entire discussion — all of this license gatekeeping is ridiculous. This is a very cool project, but if the license ruins it for you, there are zillions of open source GPL3 kernels.

I mean, this is not different from bitching about someone writing their custom kernel in C++ instead of Rust, or Zig. It’s not your project! Let people do their own thing! MIT is a perfectly fine license; maybe the lack of zealotry associated with it would even be a positive thing for whatever community might be built around this eventually, if the author is even interested in having other contributions.

an hour agoKerrAvon

Why is a proven effect "ridiculous" to discuss? It's a valid concern and the discussion could make the authors rethink their choice.

an hour agodejung

That’s the truth

an hour agoleo_e

Hello!

For the past 8 months, or so, I've been working on a project to create a Linux-compatible kernel in nothing but Rust and assembly. I finally feel as though I have enough written that I'd like to share it with the community!

I'm currently targeting the ARM64 arch, as that's what I know best. It runs on qemu as well as various dev boards that I've got lying around (pi4, jetson nano, AMD Kria, imx8, etc). It has enough implemented to run most BusyBox commands on the console.

Major things that are missing at the moment: decent FS driver (only fat32 RO at the moment), and no networking support.

More info is on the github readme.

https://github.com/hexagonal-sun/moss

Comments & contributions welcome!

6 days agohexagonal-sun

Love the MIT license. If this were further along we could use this as the foundation of our business without having to "give back" device drivers and other things.

4 hours agophkahler

This should be the sort of red flag to take note of. There’s an LLVM fork for every esoteric architecture now and this sort of thinking will lead to never being able to run your own software on your own hardware again. A reversion to the dark ages of computing.

4 hours agobfrog

Great, an MIT license to accelerate planned obsolescence and hardware junk. Truly a brilliant move

3 hours ago533474

Linux magically solves this problem how? GPL isn't magic. It doesn't compel contributing upstream. And half of modern driver stacks live in userspace anyways.

3 hours agosurajrmal

> And half of modern driver stacks live in userspace anyways ??? I haven't touched hardware whose driver lives in userspace since 2017 and it was a DMX512 controller of a shitty brand

2 hours agomikelpr

They seem to be primarily targeting arm. A lot of drivers live in userspace for arm socs, especially on the higher end.

2 hours agosurajrmal

Seriously.

To the author: kudos for the interesting project, but please strongly consider a copyleft license moving forward.

4 hours agoimiric

Do you think soup kitchens and food banks should only serve food to those who volunteer? MIT is a perfectly fine FOSS license.

3 hours agosurajrmal

No, but if someone takes the free food and builds a business by selling it to others, without giving anything back to the original places, it harms everyone other than the person doing that.

F/LOSS is not a charity or a gift, so your analogy is not appropriate. It is a social movement and philosophy with the goal of sharing knowledge and building software for the benefit of everyone. It invites collaboration, and fosters a community of like-minded people. Trust is an implicit requirement for this to succeed, and individuals and corporations who abuse it by taking the work of others and not giving anything back are harmful to these goals. Copyleft licenses exist precisely to prevent this from happening.

MIT is a fine license for many projects, but not for an operating system kernel.

2 hours agoimiric

This feels eerily close to having someone try to convince me to be join their religion. You don't need to force your opinions into others. Let them choose. If folks agree then the license will hold them back in terms of building a community. There are plenty of great open source kernels that don't use GPL, including freebsd. I think most embedded os kernels are not gpl (zephyr, freertos, etc). I would argue that Linux does well in spite of its license not because of it.

2 hours agosurajrmal

Just as people who strongly prefer permissive licenses deny copyleft licenses, this is the same in reverse. If you don't want to touch GPL projects, then don't.

an hour agovacuity

yes

2 hours agoknowitnone3

MIT licensed code is a gift. A gift indeed doesn't require the recipient to give back anything related to the gift.

A "gift" requiring GPL-like conditions isn't really a gift in the common sense. It's more like a contractual agreement with something provided and specific, non-negotiable obligations. They're giving while also asserting control over others' lives, hoping for a specific outcome. That's not just a gift.

People doing MIT license are often generous enough where the code is a gift to everyone. They don't try to control their lives or societal outcomes with extra obligations. They're just giving. So, I'm grateful to them for both OSS and business adaptations of their gifts.

4 hours agonickpsecurity

While the FSF's vision for the GPL is clear, the GPL itself is not so powerful that it is more than a "gift" that has some terms if you want to do certain things you are not obligated to do. It is like a grant that enforces some reasonable conditions so the money isn't just misappropriated. I wouldn't give that to a friend for their birthday, but I think it's reasonable that powerful organizations should not be free to do whatever they want. Not that the GPL is perfect for that use, but it's good.

4 hours agovacuity

MIT is throwing a free party where food and drinks are paid for, and copyleft is where food is paid for but you BYOB. Both are fine, so what's the problem?

4 hours agonaasking

> It's more like a contractual agreement with something provided and specific, non-negotiable obligations.

The obligation is not to the author of the code, it is to the public. MIT-style licenses are gifts to people and companies who produce code and software, copyleft licenses are gifts to the public.

I don't give a shit about the happiness of programmers any more than the happiness of garbage collectors, sorry. I don't care more that you have access to the library you want to use at your job writing software for phones than I care that somebody has access to the code on their own phone. You're free to care about what you want, but the pretense at moral superiority is incoherent.

It is non-negotiable. GPL is basically proprietary software. It's owned by the public, and all of the work that you do using it belongs to the public. If you steal it, you should be sued into the ground.

4 hours agopessimizer

I get what your saying but I think it’s not the best way to describe it - “GPL is property”? Hardly - it’s a societal common good that can be used by anyone interested in helping that common good.

Are parks “proprietary”? I can’t run my car dealership from one, so it’s …proprietary? No. So using the terminology of “proprietary” doesn’t do justice to what it actually is.

3 hours agopstoll

The phrasing is a little awkward but I like the sentiment: gpl software is owned by the public/humanity/the commons/etc in the same way something like the grand canyon should be.

2 hours agowredcoll

A gift where the recipient can remove the freedoms that they've been enjoying themselves is a bad deal for ensuring those freedoms are available to everyone. A permissive license is a terrible idea for a F/LOSS kernel.

This is the paradox of tolerance, essentially.

Also, seeing F/LOSS as a "gift" is an awful way of looking at it.

4 hours agoimiric

Congratulations on the progress. If I may ask, I'm curious what considerations have motivated your choice of licence (especially since pushover licences seem extremely popular with all kinds of different Rust projects, as opposed to copyleft).

5 hours agoF3nd0

I’ve pretty much only seen MIT and to a lesser extent GPL on most open source projects. Would you expect a different license?

2 hours agodymk

What is a "pushover" license?

2 hours agotingletech

> no networking support

Would something like Smoltcp be of help here? https://github.com/smoltcp-rs/smoltcp

Great project either way!

How do you decide which sys calls to work on? Is is based on what the user space binaries demand?

4 hours agoandrewl-hn

Yip, I panic whenever I encounter a syscall that I can't handle and that prompts me to implement it.

Yeah, I was thinking of integrating that at some point. They've done a really nice job of keeping it no_std-friendly.

4 hours agohexagonal-sun

Cool project, congrats. I like the idea with libkernel which makes debugging easier before going to "hardware". It's like the advantages of a microkernel achievable in a monolithic kernel, without the huge size of LKL, UML or rump kernels. Isn't Rust async/awat depending on runtime and OS features? Using it in the kernel sounds like an complex bootstrap challenge.

8 hours agoRochus

Rust's async-await is executor-agnostic and runs entirely in userspace. It is just syntax-sugar for Futures as state machines, where "await points" are your states.

An executor (I think this is what you meant by runtime) is nothing special and doesn't need to be tied to OS features at all. You can poll and run futures in a single thread. It's just something that holds and runs futures to completion.

Not very different from an OS scheduler, except it is cooperative instead of preemptive. It's a drop in the ocean of kernel complexities.

7 hours agokaoD

Yeah, for example embassy-rs is an RTOS that uses rust async on tiny microcontrollers. You can hook task execution up to a main loop and interrupts pretty easily. (And RTIC is another, more radically simple version which also uses async but just runs everything in interrupt handlers and uses the interrupt priority and nesting capability of most micros to do the scheduling)

7 hours agorcxdude

Interesting references, thanks. Moss seems to be doing the same thing as Embassy.

7 hours agoRochus

Sorry for nit but embassy is not a RTOS (or any OS), its a framework

2 hours agoboguscoder

Ok, I see. I spent a lot of time with .Net VMs, where you cannot simply separate await from the heavy machinery that runs it. I now understand that in a kernel context, you don't need a complex runtime like Tokio. But you still need a way to wake the executor up when hardware does something (like a disk interrupt); but this indeed is not a runtime dependency.

EDIT: just found this source which explains in detail how it works: https://os.phil-opp.com/async-await/

7 hours agoRochus

There’s got to be some complexity within the executor implementation though I imagine as I believe you have to suspend and resume execution of the calling thread which can be non-trivial.

7 hours agovlovich123

You can implement an executor with threading to achieve parallelism, but it's not a fundamental characteristic of Future executors.

To reiterate: an executor is just something that runs Futures to completion, and Futures are just things that you can poll for a value.

See sibling comments for additional details.

7 hours agokaoD

I’m aware; you’re not adding new information. I think you’re handwaving the difficulty of implementing work stealing in the kernel (interrupts and whatnot) + the mechanics of suspending/resuming the calling thread which isn’t as simple within the kernel as it is in userspace. eg you have to save all the register state at a minimum but it has to be integrated into the scheduler because the suspension has to pick a next task to execute and resume the register state for. On top of that you’ve got the added difficulty of doing this with work stealing (if you want good performance) and coordinating other CPUs/migrating threads between CPUs. Now you can use non interruptible sections but you really want to minimize those if you care about performance if I recall correctly.

Anyway - as I said. Implementing even a basic executor within the kernel (at least for something more involved than a single CPU machine) is more involved, especially if you care about getting good performance (and threading 100% comes up here as an OS concept so claiming it doesn’t belies a certain amount of unawareness of how kernels work internally and how they handle syscalls).

6 hours agovlovich123

No. I am adding new information but I think you are stuck on your initial idea.

There's no work stealing. Async-await is cooperative multitasking. There is no suspending or resuming a calling thread. There is no saving register state. There is not even a thread.

I will re-reiterate: async-await is just a state machine and Futures are just async values you can poll.

I'm sure moss has an actual preemptive scheduler for processes, but it's completely unrelated to its internal usage of async-await.

See embassy in sibling comments.

6 hours agokaoD

This has been a real help! The ability to easily verify the behavior of certain pieces of code (especially mem management code) must have saved me hours of debugging.

Regarding the async code, sibling posts have addressed this. However, if you want to get a taste of how this is implemented in Moss look at src/sched/waker.rs, src/sched/mod.rs, src/sched/uspc_ret.rs. These files cover the majority of the executor implementation.

6 hours agohexagonal-sun

Impressive work! Do you have any goals, other than learning and having fun?

Also how does it's design compare with Redox and Asterinas?

7 hours agoIshKebab

Are the collaborations possible/foreseeable?

an hour agocies

shouldn't this be a ShowHN?

8 hours agobramadityaw

Very cool project! I do have to admit - looking far, far into the future - I am a bit scared of a Linux ABI-compatible kernel with an MIT license.

7 hours agomarty-oehme

I agree, I know a lot of people aren't huge fans of it but in the long run Linux being GPL2 was a huge factor in its success.

6 hours agojuliangmp

Too late? https://docs.freebsd.org/en/books/handbook/linuxemu/

6 hours agoviraptor

Somewhere there is a dark timeline where the BSDs won, there are 50 commercial and open source variants all with their own kernel and userland. The only promise of interoperability is in extremely ossified layers like POSIX. There is, however, something terrible gathering its strength. A colossus. The great Shade that will eat the net. In boardroom meetings across the land, CTOs whisper its name and tremble... "OS/2."

6 hours agojorvi

Waaaarp

2 hours agomaybewhenthesun

Also, AFAIK SmartOS / Ilumos has had a combat layer for it, too.

4 hours agoandrewl-hn

Why?

7 hours agostingraycharles

because otherwise big tech companies will take it and modify and release hardware with it without releasing patches etc? Basically being selfish and greedy?

6 hours agop0w3n3d

Does this happen to freebsd? I know plenty of closed source Linux drivers.

3 hours agosurajrmal

Isn't that basically every router out there?

an hour agobmicraft

It is neither selfish nor greedy to accept and use a gift freely given to you.

Receiving a gift does not confer obligations on the recipient.

5 hours agosneak

True, but you would probably still be pissed if somebody took your gift and hit you over the head with it.

5 hours agoHendrikto

It does. There is an implied expectation that the recipient will will not be selfish. They can pay it back, pay it forward, possibly later when they can afford it, etc., but they are expected not to be selfish and also give someone something eventually.

3 hours agomordae

Because unlike most other functionality, you generally need hw specs or cooperation to write drivers (see Nvidia GSP).

Anyone can write Photoshop (provided reasonable resources). The problem is going to be proprietary file format and compatibility with the ecosystem. It's same with hardware, except several orders of magnitude worse.

5 hours agomnau

It will be compatible for ~5 minutes:

https://www.kernel.org/doc/html/v4.10/process/stable-api-non...

3 hours agodevnullbrain

> [Moss has] binary compatibility with Linux userspace applications (currently capable of running most BusyBox commands).

Per your link

> Note: Please realize that this article describes the in kernel interfaces, not the kernel to userspace interfaces.

2 hours agoathrowaway3z

Just a hobby, won’t be big and professional like Linux?

6 hours agonikanj

I see what you did there, fair human.

2 hours agonoumenon1111

;-)

6 hours agohexagonal-sun

I don't know much about Linux internals - how difficult would it be to reimplement KVM? I'm guessing a big undertaking.

4 hours agocedws

> MIT license

What have you done?!

an hour agotheoldgreybeard

Really neat. Do you have any specific long term goals for it? Eg, provide an OS distro (using Linux drivers?) to provide memory safety for security-critical contexts?

Also, are there any opportunities to make this kernel significantly faster than Linux’s?

7 hours agomeisel

Eventually, It'd be amazing to use Moss as my daily driver OS. That means targeting the specific hardware that I have, but in doing so, I hope to build up enough of the abstractions to allow easier porting of hardware.

A more concrete mid-term goal is for it to be 'self-hosting'. By that I mean you could edit the code, download dependencies and compile the kernel from within Moss.

6 hours agohexagonal-sun

Are you interested in beating Linux performance-wise? Eg:

- Moving away from the too-small 4kb default page size (while having a good strategy for dealing with fragmentation)?

- Make it easy to minimize/track interrupts on a core, for low-latency contexts

2 hours agomeisel

In what extent is this compatible with Linux?

Could I swap Ubuntu's or Android's kernel with this, while keeping those OSes bootable?

7 hours agomaxloh

While it's very legitimate question, the answer is between the lines in the README, and it mostly means that there is a user space binary compatibility for everything that is implemented.

It might seem obscure, but syscalls to get access to kernel requires a tight integration on compilation and linking. So this is their approach and this is where the compatibility really means something : since you can cross compile on another machine, they don't need the full toolchain right away. Just compile your code on a linux machine, and run it there. You're at the mercy of all missing kernel API implementations, but it looks like a very good strategy if you aim is to code a kernel, as you only have to focus on actual syscalls implementation without getting distracted by toolchain.

7 hours agotuyiown

At this stage you'd need to contribute to it, not treat it as a finished product.

4 hours agoHackerThemAll

This plus using Fil-C for the BusyBox commands is a nice combination (once Fil-C supports ARM64).

3 hours agoerichocean

Or... rewrite BusyBox in Rust. (And most certainly such a project already exists.)

an hour agoforgotpwd16

Yay another rewrite of 60s/70s tech.

an hour agorandyfox

I understand that you've only been on HN for 7 days, but please don't do this. It's gross.

37 minutes agoCharlesW

Just shows how little we have achieved since then. In both hardware architecture and software based on that hardware.

37 minutes agoTowaway69

Wait until they get to the networking layer; you're going to hate what Vint Cerf did in the 70s :)

15 minutes agoeterps

[dead]