linux/tools/perf/util/bpf_skel
Viktor Malik ea6992784d perf trace: Refactor augmented_raw_syscalls using bpf_for
The loop for processing syscall args in augment_raw_syscalls has a
history of breaking with Clang updates, see e.g. commit 013eb043f3
("perf trace: Fix BPF loading failure (-E2BIG)") from Clang 15 to 16.

Now, a similar thing happened between Clang 21 and 22. While the issue
is mitigated on the main line by a recent verifier update, it remains
broken on the 6.12 and 6.18 stable branches:

    [linux-6.18.y]# sudo perf trace true
    libbpf: prog 'sys_enter': BPF program load failed: -E2BIG
    libbpf: prog 'sys_enter': -- BEGIN PROG LOAD LOG --
    [...]
    BPF program is too large. Processed 1000001 insn
    processed 1000001 insns (limit 1000000) max_states_per_insn 40 total_states 37941 peak_states 232 mark_read 0
    -- END PROG LOAD LOG --
    libbpf: prog 'sys_enter': failed to load: -E2BIG
    libbpf: failed to load object 'augmented_raw_syscalls_bpf'
    libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -E2BIG
    Error: failed to get syscall or beauty map fd
    [...]

The reason is that the loop is quite complex and the BPF verifier often
struggles to prove that it terminates.

Fix the issue by replacing the standard for loop with the bpf_for macro,
which uses a numeric BPF iterator. This should prevent future breakages
of this kind since the verifier has a much easier job proving that the
loop terminates.

Small adjustments were necessary for the loop to make it work.  The main
problem is that the verifier sometimes has problems with bpf_for loops
that use a carry-over state, such as the `payload_offset` and `output`
vars here, since the verifier tries to track their values too precisely
and cannot prove loop convergence. To resolve the issue, we (1)
explicitly recompute `payload_offset` in every iteration and (2) use a
trick with adding a global zero to `output` to help the verifier forget
its precise state and use a range instead.

Finally, to keep backwards compatibility with older kernel versions that
don't have bpf_for (i.e. numeric iterators), fall back to standard loop.

Signed-off-by: Viktor Malik <vmalik@redhat.com>
Cc: stable@vger.kernel.org
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Fixes: a68fd6a6cd ("perf trace: Collect augmented data using BPF")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-07-16 10:57:40 -07:00
..
vmlinux perf lock contention: Symbolize zone->lock using BTF 2025-04-29 12:23:53 -03:00
.gitignore perf build: Add ability to build with a generated vmlinux.h 2023-06-23 21:35:45 -07:00
augmented_raw_syscalls.bpf.c perf trace: Refactor augmented_raw_syscalls using bpf_for 2026-07-16 10:57:40 -07:00
bperf_cgroup.bpf.c perf stat: Add/fix bperf cgroup max events workarounds 2025-10-25 16:44:21 -07:00
bperf_cgroup.h perf stat: Add/fix bperf cgroup max events workarounds 2025-10-25 16:44:21 -07:00
bperf_follower.bpf.c perf stat: Support inherit events during fork() for bperf 2024-11-01 23:31:08 -07:00
bperf_leader.bpf.c perf bpf_skel: Do not use typedef to avoid error on old clang 2021-12-06 21:57:53 -03:00
bperf_u.h perf stat: Support inherit events during fork() for bperf 2024-11-01 23:31:08 -07:00
bpf_prog_profiler.bpf.c
func_latency.bpf.c perf ftrace latency: Add -e option to measure time between two events 2025-07-14 22:51:58 -07:00
kwork_top.bpf.c perf: Completely remove possibility to override MAX_NR_CPUS 2025-09-12 10:52:22 -03:00
kwork_trace.bpf.c perf kwork: Remove unreachable judgments 2025-03-18 16:55:30 -07:00
lock_contention.bpf.c perf lock contention: Enable end-timestamp accounting for cgroup aggregation 2026-06-04 17:34:52 -03:00
lock_data.h perf lock contention: Enable end-timestamp accounting for cgroup aggregation 2026-06-04 17:34:52 -03:00
off_cpu.bpf.c perf record --off-cpu: Add --off-cpu-thresh option 2025-05-05 21:51:54 -03:00
perf_version.h perf test: add test for BPF metadata collection 2025-06-20 14:55:24 -07:00
sample_filter.bpf.c perf bpf: Use __builtin_preserve_field_info for GCC compatibility 2025-10-02 14:57:07 -03:00
sample-filter.h perf bpf-filter: Support filtering on cgroups 2024-08-28 18:21:49 -03:00
syscall_summary.bpf.c perf trace: Handle task exit in BPF syscall summary 2026-02-26 10:49:00 -08:00
syscall_summary.h perf trace: Support --summary-mode=cgroup 2025-05-13 18:20:46 -03:00