-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] Support compile libbpf-tools to Wasm(WebAssembly) and get tools running from the cloud in 1 line #4306
Comments
Would you please give me some feedback or suggestions? If you think it's worth trying, I can continue to do more implements and researches on this issue. |
What are expected changes in bcc/libbpf-tools? Just makefile options or your have something more. If just makefile options you probably don't need to modify bcc/libbpf-tools makefile as you can just compile libbpf tool with different make options. Due to long-time maintenance, I would like to see what changes are needed in bcc/libbpf-tools. If there are no changes needed, I think you have total freedom to create a webassembly-libbpf repo... |
Thanks for the suggestions!
I think I may need to change in bcc/libbpf-tools:
And I would create an The main difficulty in combining wasm and ebpf may be that the memory layout of WASM is different from that of eBPF programs, and the structure of C language cannot be directly mapped, so any transfer structures must be serialized. For example, the event submitted in the kernel: bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &data, sizeof(data)); The event cannot be directly read in user space wasm vm like this, event both the wasm code and eBPF code is compiled from C: static void handle_event(void *ctx, int cpu, void *data, __u32 data_size)
{
struct str_t *e = data;
struct tm *tm;
char ts[16];
printf("%-9s %-7d %s\n", ts, e->pid, e->str);
} I will go and prepare for more detail designs and some draft implements later. Thanks for you time! |
Hey, @yunwei37, I am the author of that draft PR (there's another one that's already merged) and a BumbleBee contributor. Let me know if there's any update on this idea, I like it! |
This is a minimal working runtime and toolchain example based on libbpf and WAMR, with only 300+ lines in runtime host implementation: https://github.com/eunomia-bpf/wasm-bpf A WebAssembly eBPF library and runtime powered by CO-RE(Compile Once – Run Everywhere) libbpf and WAMR.
|
Hi, community!
I propose that maybe we can try to compile the
libbpf-tools
C code to OCI-compatible WebAssembly module, and then use a launcher to get eBPF programs running from the cloud to the kernel in 1 line of bash?Just like what bumblebee has done, but with the help of WebAssembly:
rewrite
the existing libbpf-tools or do a lot ofcode modification
, we can use the existing C code and compile it to WasmCompile once, run everywhere
). We have tested some tools onx86
andarm
to prove it.plugin
in other systems, like what Envoy has done: WebAssembly-in-Envoyother languages
(Go, Rust, Java, TypeScript, etc.), Over 30 programming languages can be compiled to WebAssembly modules.As far as I know, Bumblebee seems cannot support running on Arm: Fail installation on ARM and document supported architecture.
We have created a
prove-of-concept
library and a demo tool to show how to compile libbpf base tools to Wasm and run it:Background
What is Wasm?
What is WASI?
The compile workflow
The workflow to compile a
libbpf-tool
toWasm
maybe like this:bpftool
WASI
supportlauncher
to load the Wasm module in user space: export some helper functions to the WebAssembly runtime, and then load the bpf object into the kernel from the wasm module with the helper functions.What needs to be done?
What maybe need to be done in libbpf-tools next if we want to support wasm target:
WASI
does not have any modules for executing eBPF programs. In other words, we need to create an abstraction layer between the WebAssembly Runtime and the libbpf library.argp
to wasm, becauseWASI
only has standard c library supported.libbpf
APIs to our ABI interfaces between libbpf and WebAssembly runtime.Some small problems may need to be fixed, but I think we may no need to do many code modifications.
some usage examples
Take the
sigsnoop
tool as an example, we can use the following command to run it from the cloud:Or you can compile the
sigsnoop
tool locally to Wasm and run it:The text was updated successfully, but these errors were encountered: