r/golang • • 2d ago

Linux kernel modules in Go

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

11 comments sorted by

77

u/jerf 2d 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.

11

u/mashmorgan 2d ago

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

4

u/cookiengineer 1d ago edited 1d ago

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

2

u/gamewiz365 1d 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 2d ago

Worth it.

3

u/Wild_Percentage5148 1d ago

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

14

u/m33-m33 2d ago

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

17

u/Existing-Outside1795 1d ago

Nah, straight to prod baby.

2

u/saydostaygo 1d ago

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

5

u/hidegitsu 1d ago

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

1

u/ianchen0119 13h ago

This is awesome. Now do eBPF in Go