r/golang • • 7d ago

Linux kernel modules in Go

https://jespino.github.io/gokm/
288 Upvotes

12 comments sorted by

85

u/jerf 7d ago

Mod note: Normally this would fit well within my "small project" criteria, however I'm going to use a rare executive call here to let this go to the front page, because I think there's also an entire interesting conversation to be had on the utility of this approach, whether it has any use cases, costs/benefits, etc., that is, a general discussion of the utility of Go in a kernel rather than necessarily this project specifically.

15

u/mashmorgan 7d ago

Glad u did.. Am developing some lab.equpment.. and am looking for go without the "runtime" for want of word...

5

u/cookiengineer 7d ago edited 7d ago

Go checkout cilium, that's the standard eBPF framework everyone is using for Linux kernel development.

3

u/gamewiz365 6d ago

This. 

WARN: There's no such thing as a perfectly sandboxed environment (gestures broadly to this past week year). caveat emptor.

With that out of the way, eBPF gives you access to the kernel space without having to write an entire kernel module while providing additional tooling to help the developer help themself like extra verification that your program will remain within its sandboxed environment, helper functions, an entire library of data types for working with storage: bpf maps, and more.

As u/cookieengineer suggested, Cilium's go-ebpf is the icing on the cake, allowing these programs to be written in Go and compiled down to C and subsequently loaded.

7

u/jackielii 7d ago

Worth it.

3

u/Wild_Percentage5148 7d ago

Appreciate the exception, it's definitely a pretty weird and interesting design space to talk about

17

u/m33-m33 7d ago

As en experiment, or homelab IOT it could be fun.

21

u/Existing-Outside1795 7d ago

Nah, straight to prod baby.

2

u/saydostaygo 7d ago

If it works in dev, it will for sure work in prod!

6

u/hidegitsu 6d ago

Prod has more ram, why wouldn't I just do it there?

2

u/BraveNewCurrency 5d ago

Prod has more users. How else are you going to find bugs?

2

u/ianchen0119 5d ago

This is awesome. Now do eBPF in Go