-
Describe the bug To Reproduce
This BPF program consists of main_prog calling a tail program. The tail program writes 0 to a ring buffer.
This Go program loads the programs and map and reads from the ring buffer:
Compile the C program using Pass traffic on the interface. The tail program is removed after a random amount of time. If I don't read from the ring buffer in userspace, the tail program is not removed. If I remove the call to Expected behavior |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 18 replies
-
I'll see if I can reproduce it here. Is the "random amount of time" related to how many packets are sent? I have a setup with
have you tried with a perf buffer? |
Beta Was this translation helpful? Give feedback.
-
Hi @yasir-ss. Sorry, but what you're describing wrt. removing the call to BPF objects' lifecycles are tied to the process that created them, except when they are attached to another kernel object (like you're doing here with XDP) or pinned to bpffs. The thing that's biting you here is that PROG_ARRAYs get cleared (not removed) when their last userspace reference disappears, or when its last bpffs pin is removed. Since XDP references Edit: @yasir-ss, as Lorenz suggested below, you need the following: func (o *bpfObjects) Close() {
o.MainProg.Close()
o.TailProg.Close()
o.JumpTable.Close()
o.FlowRingBuf.Close()
} Then, after See bpf2go in If you want a tail call setup to persist throughout userspace program restarts, you can use e.g. On that note, see the following snippet to automatically populate your tail call map: Lines 11 to 22 in 42f2a98 2 more things:
|
Beta Was this translation helpful? Give feedback.
-
I played around a bit with the example. First creating a dump with strace, which ends like this:
So it looks like we are indeed removing all references which causes the entry to become empty. As far as I can tell, this is because Adding |
Beta Was this translation helpful? Give feedback.
Hi @yasir-ss. Sorry, but what you're describing wrt. removing the call to
bpf_ringbuf_output()
doesn't make much sense. As long as you keep your program running,tail_prog
will remain loaded in the kernel, and will remain injump_table
at slot 0.BPF objects' lifecycles are tied to the process that created them, except when they are attached to another kernel object (like you're doing here with XDP) or pinned to bpffs. The thing that's biting you here is that PROG_ARRAYs get cleared (not removed) when their last userspace reference disappears, or when its last bpffs pin is removed. Since XDP references
main_prog
, which referencesjump_table
, the tail call map is not deallocated, so you ca…