Let's Embed a Go Program into the Linux Kernel (2023)
132 points
15 days ago
| 9 comments
| sigma-star.at
| HN
st_goliath
14 days ago
[-]
I'm a bit surprised the bulk of the comments here seem to fixate onto Go specifically, seemingly missing the actual point of the article:

The article demonstrates the Usermode Driver API, showing how a Linux driver can offload work into userspace (with or without access to a working filesystem).

I mentioned this yesterday in the context of the in-kernel codec discussion[1], where the questions "can't this be done in userspace" or "why not sandboxing" were dismissed pretty quickly.

[1] https://news.ycombinator.com/item?id=40174516#40184307

reply
chrsig
14 days ago
[-]
It's a sophisticated bike shed. Much more of the population has a working knowledge of go than about the linux kernel's Usermode Driver API

...So what color is their gopher?

reply
deepsun
14 days ago
[-]
So why not Java? It has way more software written in it. :)
reply
hu3
14 days ago
[-]
Their rationale for Go is explained in the article.

> Strictly speaking, any program will do, but we need to ensure that the program in question has no dependencies on the file system. Linking it statically provides benefits. Go programs are statically linked by default, and to illustrate that the following approach works with any kind of program, we have chosen to embed a Go program into the kernel.

Please refrain from inciting language flamewars.

reply
pjmlp
14 days ago
[-]
More to the point, Sun did actually play with the idea of having Java in Solaris.

Android Things had drivers in Java, and Android has a few, although only as userspace.

reply
jerf
14 days ago
[-]
There were also some Java CPUs, which directly executed bytecode, in which case a "Java driver" would just be the lowest, system-level language available: https://en.m.wikipedia.org/wiki/Java_processor
reply
fullspectrumdev
14 days ago
[-]
I recall stumbling across this years ago while working on a Solaris project - the possibility of writing drivers in Java.

It seemed so patently absurd at the time!

reply
unnouinceput
14 days ago
[-]
Exactly!. It can be written in any language, Cobol if you want, it does not matter. Once compiled the "gas" does the actual magic, not Go.
reply
panzi
15 days ago
[-]
You can also use objcopy to generate a object file from a resource file.
reply
dwattttt
15 days ago
[-]
I was really hoping it would be executing Go in kernel.
reply
remram
14 days ago
[-]
How does this relate to the initrd? As I understand it, its purpose is also to load programs and modules before the filesystem becomes available, by embedding them in an image loaded with the kernel...
reply
NekkoDroid
14 days ago
[-]
What you as specifically talking about is a Unified Kernel Image, aka UKI (kernel + initrd/initramfs + stub + ...). It can be used as an actual "usable" system, where instead of `switch-root`ing into a mounted filesystem it just stays in the initrd. This is then refered to as a Unified System Image, aka USI.

The easiest way to execute a program in a UKI/USI is just putting it at /init which gets executed first if nothing is specified in the cmdline. So that is a way you can have it execute something. But initrd's are mostly read-only and would need to be extracted and repackaged if you want to add a file and also stops existing (for the most part) once `switch-root`ed, so I honestly am not sure if that could cover the possible intent behind such a mechanism described in the article (tho I also mostly just skimmed the article, so I very well might be wrong on that though).

reply
remram
14 days ago
[-]
> stops existing (for the most part) once `switch-root`ed

I guess that's the difference, yeah. Although "for the most part" might hide another answer?

reply
NekkoDroid
13 days ago
[-]
What I meant with it is: there is probably a way to re-create it by extracting it from the UKI and using some form of overlayfs. It's not like the initrd in the UKI gets deleted lol.
reply
nikolayasdf123
14 days ago
[-]
reminds me of go unikernel: https://github.com/icexin/eggos
reply
_pdp_
14 days ago
[-]
As soon as I read the article I thought a security person must write this and what do you know? It is!
reply
az09mugen
13 days ago
[-]
Please don't put Go with telemetry inside linux kernel.
reply
drycabinet
15 days ago
[-]
Might sound surprising until you remember there used to be Lisp Machines.
reply
slowhadoken
15 days ago
[-]
Is it a good idea to embed a proprietary language into a open source os?
reply
pjmlp
14 days ago
[-]
The C language requires paying a 216 CHF by anyone that actually wants to understand how the language works, and not how their compiler deals with the source.

Plenty of times they aren't the same.

https://www.iso.org/standard/74528.html

reply
PhilipRoman
14 days ago
[-]
That's not really fair, the working drafts are freely available and (if you take the latest one before official standardization) are the same as the official releases. https://port70.net/~nsz/c/c23/n3220.pdf

To be honest, I've never met a single professional who actually bought any IEEE or ISO standard.

reply
jimjimjim
14 days ago
[-]
Hi. I've paid for access to ISO standards for PDF related work.
reply
nicce
14 days ago
[-]
But are you professional in their eyes? :’D
reply
pjmlp
14 days ago
[-]
They are drafts for a reason.

Plus who seats at WG14 table?

Big corporations selling compilers and OSes.

reply
eru
14 days ago
[-]
> The C language requires paying a 216 CHF by anyone that actually wants to understand how the language works, and not how their compiler deals with the source.

The binary you are actually executing is made with your compiler, not with the standard; which is just a static human readable document after all.

Though I'm not sure what your point is.

reply
pjmlp
14 days ago
[-]
How did that compiler sprung into existence, magic digital pixie dust?
reply
eru
14 days ago
[-]
You know that especially for C, compilers predate the language spec?
reply
pjmlp
14 days ago
[-]
Ever heard of a book called K&R C, and another book called The Annotated Reference of UNIX, aka Lion's Book?

Also lots of AT&T and Bell Labs money poured into employees salaries.

reply
eru
14 days ago
[-]
What about that book? K&R C is more of an introduction and perhaps a manual. It ain't a spec.

And that book was very much written to describe existing implementation(s) of C.

reply
exe34
14 days ago
[-]
No, somebody wrote it.
reply
eru
14 days ago
[-]
Yes, indeed.

What a strange question..

reply
eurleif
15 days ago
[-]
Proprietary? Go is under the BSD license.
reply
JetSetIlly
14 days ago
[-]
Yes. The Go implementation from Google is under the BSD licence.

There's also the GNU implementation in GCC that's under the GNU GPL 3 licence. Moreover, the specification itself doesn't seem to have any licencing requirements at all.

So you're absolutely right: Go is the very opposite of proprietary.

reply
neonsunset
14 days ago
[-]
In the same way .NET is proprietary under MIT license.

Welcome to the club :)

reply
slowhadoken
14 days ago
[-]
Golang is trademarked by Google. It’s a corporate faux open source project. FAANG is co-opting free labor. Even open source platforms like GitHub are a wolf in sheep’s clothing. What Microsoft or Google can’t defeat they acquire.
reply
eurleif
14 days ago
[-]
FOSSmarks (hosted by FSF, and writers include people affiliated with FSF)[0]:

>Trademarks and FOSS are not incompatible; instead, trademarks are legal tools strongly aligned with FOSS principles. A trademark is an assurance that the recipient of the goods or services is receiving a product of known source and qualities. Controlling how a FOSS project trademark is used protects the community and its software, by preventing use of the trademark in ways that are harmful to the reputation of the community or the software.

Linux is a registered trademark of Linus Torvalds[1]. GNU is a registered trademark of the FSF[2]. Your definition of "proprietary" isn't shared by virtually anyone, and would make virtually everything "faux open source", including the "open source os" project you originally worried about Go being integrated into.

[0] https://static.fsf.org/nosvn/licensing/2020/FOSSmarksv2.pdf

[1] https://tsdr.uspto.gov/#caseNumber=74560867&caseSearchType=U...

[2] https://tsdr.uspto.gov/#caseNumber=85380218&caseSearchType=U...

reply
slowhadoken
14 days ago
[-]
Meredith Whittaker and Elon Musk share similar opinions as me on the subject. I assume you’re a captain of industry?
reply
abenga
14 days ago
[-]
How is Go proprietary?
reply