Search code examples
ebpfbpf

Loading large BPF program fails with "Argument list too long" and "processed 0 insns"


I am attempting to load a large BPF program using libbpf, but it fails with the following log messages:

libbpf: load bpf program failed: Argument list too long
libbpf: -- BEGIN DUMP LOG ---
libbpf: 
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0

libbpf: -- END LOG --
libbpf: failed to load program 'tc_ingress_func'
libbpf: failed to load object 'work/switch/switch.o'

When searching for the Argument list too long (E2BIG) error, I found that the verifier rejects programs exceeding 1 million instructions, but in that case the instruction counter in the log dump (processed N insns) doesn't stay at 0, therefore my case is different. I have also found various other scenarios that yield the E2BIG error, but they all result in the log dump containing some extra messages, which does not happen in my case.

Deleting some parts of the BPF program source code results in successful loading, therefore I believe the issue is related to the program size.

My question is: why is my program rejected if it doesn't exceed the limit of 1 million instructions?

I am using Kernel version 5.15


Solution

  • Because the MAX_USED_MAPS or the MAX_USED_BTFS limits have been exceeded (they are both set to 64 in kernel 5.15).

    When a BPF program contains more than 64 maps (or BTFs), the verifier rejects the program without providing any extra log messages in the 5.15 version of the Linux kernel. In newer versions, a log message has been added when MAX_USED_MAPS is exceeded, but MAX_USED_BTFS is yet to receive such an enhancement.