一些嵌入式开发板/设备默认没有开eBPF相关的选项,自己编译内核时,想要开启之,一般常规方法就是make menuconfig来一个个开,这样做的好处是,相关的依赖内核选项也会同时开启,内核代码仓库中有一个config工具脚本,可以让我们命令行方式免交互直接开启,但这种方法没有开启相关的依赖项。
为了方便一次性开启所有相关的内核选项,我记录并使用config命令开启并测试了所有相关选项。测试环境为5.10的ARM64开发板,理论5.15也是通用的。RISC-V现在有了debian与ubuntu的官方镜像,22.04.3的Ubuntu现在内核版本为5.19,我测试官方多数的内核选项都开启了,如果手上的RISC-V设备没有开启,可以参考下面的一把梭的命令,与ARM64一样的使用。rk3588的SOC提供的内核代码是支持交叉编译的,默认使用GCC编译,在开启eBPF与生成BTF这件事上,其实不用考虑切换到LLVM,现在的GCC提供了CTF技术支持,生成内核的vmlinux BTF文件一点问题也没有。
下面给出经过我测试后没有问题的脚本命令:
scripts/config --enable CONFIG_BPF_LSM
scripts/config --enable CONFIG_KGDB
scripts/config --enable CONFIG_FUNCTION_PROFILER
scripts/config --enable CONFIG_FTRACE_SYSCALLS
scripts/config --enable CONFIG_BPF_KPROBE_OVERRIDE
scripts/config --enable CONFIG_TRACE_EVENT_INJECT
scripts/config --enable CONFIG_HIST_TRIGGERS
scripts/config --enable CONFIG_SCHED_TRACER
scripts/config --enable CONFIG_IRQSOFF_TRACER
scripts/config --enable CONFIG_FUNCTION_TRACER
scripts/config --enable CONFIG_STACK_TRACER
scripts/config --disable CONFIG_MAGIC_SYSRQ
scripts/config --enable CONFIG_IKHEADERS
scripts/config --enable CONFIG_DEBUG_INFO_BTF
scripts/config --enable CONFIG_DEBUG_INFO
scripts/config --disable DEBUG_INFO_REDUCED
scripts/config --disable DEBUG_INFO_COMPRESSED
scripts/config --disable DEBUG_INFO_SPLIT
scripts/config --disable DEBUG_INFO_DWARF4
scripts/config --disable GDB_SCRIPTS
scripts/config --disable DEBUG_EFI
scripts/config --disable ARM64_RELOC_TEST
scripts/config --enable CONFIG_BPF_SYSCALL
scripts/config --enable CONFIG_BPF_JIT
scripts/config --enable CONFIG_HAVE_BPF_JIT
scripts/config --enable CONFIG_HAVE_EBPF_JIT
scripts/config --enable CONFIG_MODULES
scripts/config --enable CONFIG_BPF
scripts/config --enable CONFIG_BPF_EVENTS
scripts/config --enable CONFIG_PERF_EVENTS
scripts/config --enable CONFIG_HAVE_PERF_EVENTS
scripts/config --enable CONFIG_PROFILING
scripts/config --enable CONFIG_BPF_UNPRIV_DEFAULT_OFF
scripts/config --enable CONFIG_CGROUP_BPF
scripts/config --enable CONFIG_BPFILTER
scripts/config --module CONFIG_BPFILTER_UMH
scripts/config --module CONFIG_NET_CLS_BPF
scripts/config --module CONFIG_NET_ACT_BPF
scripts/config --enable CONFIG_BPF_STREAM_PARSER
scripts/config --enable CONFIG_LWTUNNEL_BPF
scripts/config --module CONFIG_NETFILTER_XT_MATCH_BPF
scripts/config --enable CONFIG_IPV6_SEG6_BPF
scripts/config --enable CONFIG_KPROBE_EVENTS
scripts/config --enable CONFIG_KPROBES
scripts/config --enable CONFIG_HAVE_KPROBES
scripts/config --enable CONFIG_HAVE_REGS_AND_STACK_ACCESS_API
scripts/config --enable CONFIG_KPROBES_ON_FTRACE
scripts/config --enable CONFIG_FPROBE
scripts/config --enable CONFIG_BPF_KPROBE_OVERRIDE
scripts/config --enable CONFIG_UPROBE_EVENTS
scripts/config --enable CONFIG_ARCH_SUPPORTS_UPROBES
scripts/config --enable CONFIG_UPROBES
scripts/config --enable CONFIG_MMU
scripts/config --enable CONFIG_TRACEPOINTS
scripts/config --enable CONFIG_HAVE_SYSCALL_TRACEPOINTS
scripts/config --enable CONFIG_BPF_LSM
scripts/config --enable CONFIG_BPF_LIRC_MODE2
scripts/config --module CONFIG_VSOCKETS
scripts/config --module CONFIG_VSOCKETS_DIAG
scripts/config --enable CONFIG_VHOST_VSOCK
scripts/config --enable CONFIG_VHOST_NET
scripts/config --enable CONFIG_VSOCKMON
scripts/config --disable SERIAL_CONEXANT_DIGICOLOR
scripts/config --disable SERIAL_SPRD
scripts/config --disable CONFIG_KPROBES_SANITY_TEST
scripts/config --enable KGDB_HONOUR_BLOCKLIST
scripts/config --enable BPF_JIT_ALWAYS_ON
scripts/config --disable CONFIG_TRACEFS_DISABLE_AUTOMOUNT
scripts/config --enable CONFIG_KALLSYMS_ALL
上面的config命令开启了eBPF相关的内核选项,也同时开启了虚拟化、调试相关以及相关依赖等选项,只需要执行一下就开启了。
如何使用?首先弄到相应设备的内核代码,将当前设备/boot/config-xxx复制到内核代码保存为.config文件,然后复制执行上面的命令,可以全部复制到终端窗口一次性粘贴后回车,整个过程只需要5秒钟就可以!接着就是编译与刷机测试效果。