iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.34k stars 3.86k forks source link

Move BPF instruction helper macros to uapi header? #758

Open osandov opened 7 years ago

osandov commented 7 years ago

The BPF instruction helper macros (BPF_ALU64_REG, BPF_EXIT_INSN, and the like) are duplicated in a few places in the kernel tree: include/linux/filter.h, tools/include/linux/filter.h, and samples/bpf/libbpf.h. bcc also has its own redefinitions. This seems kind of silly. Would it make sense to move these definitions into a common uapi header?

4ast commented 7 years ago

@borkmann Daniel opposed back then.

borkmann commented 7 years ago

Well, tools/include/linux/ has a number of shadow copied headers from the kernel tree, and for samples/bpf/, we're long-term better off to migrate the bpf library used there to tools/lib/bpf/, which will spare one copy of the headers but also the duplicated loader code.

The reason why initially the macros from include/linux/filter.h were not exposed is because they are not strict part of the kernel uapi. It's better if we expose as little as possible to user space as this is frozen forever and doesn't allow us to change it afterwards anymore.

For main use cases with LLVM, you have an ELF loader anyway, so it's not really needed (f.e. see tc from iproute2). And if any other application somewhere needs it, it can copy or freely define these macros by themselves. For the kernel internals, we have the guarantee to adapt macros in future whenever needed.