On Sun, Sep 6, 2020 at 7:55 AM Shung-Hsi Yu <yu@...> wrote:
Is it possible to load a BPF program at boot time?
It is possible. See the patch below:https://email@example.com/
I tried to load a BPF program and pin it in bpffs system. The system could
be extended to load bpf program, even attach it if other subsystem is ready.
But this needs kernel work.
What I'm trying to achieve is to trace every single call to a certain
function since the kernel starts, without missing anything.
More specifically, I'm trying to debug iommu_alloc failures by looking
at the stacktrace to find out which subsystem/driver allocated too
many IOMMU slots on a ppc64le system, which I do not have direct
I've considered writing a systemd unit file that loads a BPF program
before the sysinit target, but I'm not sure if that's early enough.
An alternative seems to be to use boot-time tracing with ftrace
instead (which I end up doing), but it requires recompiling the kernel
inorder to add tracepoints to retrieve the function call arguments,
and there isn't an easy way to stop tracing to prevent the tracing
buffer overflows (I end up writing a systemd unit file that sets a
ftrace event trigger that turns off tracing).
bpf program seems a good choice here since it can store arbitrary
data in its maps and based on the tracing state, it can stop tracing.
There are still some potential issues relating to not recompile kernel
and just change bpf programs and recompile bpf programs and
rebooting should just work, which is not available today. I guess this
probably can be improved. If you are interested, please take a look
at the above patch and may improve kernel to cover your use case.
Maybe there is a better way to do something like this?