2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00
linux/tools/perf/util/bpf_skel
Howard Chu 013eb043f3 perf trace: Fix BPF loading failure (-E2BIG)
As reported by Namhyung Kim and acknowledged by Qiao Zhao (link:
https://lore.kernel.org/linux-perf-users/20241206001436.1947528-1-namhyung@kernel.org/),
on certain machines, perf trace failed to load the BPF program into the
kernel. The verifier runs perf trace's BPF program for up to 1 million
instructions, returning an E2BIG error, whereas the perf trace BPF
program should be much less complex than that. This patch aims to fix
the issue described above.

The E2BIG problem from clang-15 to clang-16 is cause by this line:
 } else if (size < 0 && size >= -6) { /* buffer */

Specifically this check: size < 0. seems like clang generates a cool
optimization to this sign check that breaks things.

Making 'size' s64, and use
 } else if ((int)size < 0 && size >= -6) { /* buffer */

Solves the problem. This is some Hogwarts magic.

And the unbounded access of clang-12 and clang-14 (clang-13 works this
time) is fixed by making variable 'aug_size' s64.

As for this:
-if (aug_size > TRACE_AUG_MAX_BUF)
-	aug_size = TRACE_AUG_MAX_BUF;
+aug_size = args->args[index] > TRACE_AUG_MAX_BUF ? TRACE_AUG_MAX_BUF : args->args[index];

This makes the BPF skel generated by clang-18 work. Yes, new clangs
introduce problems too.

Sorry, I only know that it works, but I don't know how it works. I'm not
an expert in the BPF verifier. I really hope this is not a kernel
version issue, as that would make the test case (kernel_nr) *
(clang_nr), a true horror story. I will test it on more kernel versions
in the future.

Fixes: 395d38419f: ("perf trace augmented_raw_syscalls: Add more check s to pass the verifier")
Reported-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Howard Chu <howardchu95@gmail.com>
Tested-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20241213023047.541218-1-howardchu95@gmail.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2025-01-23 15:55:52 -08:00
..
vmlinux perf lock contention: Run BPF slab cache iterator 2024-12-23 13:52:03 -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: Fix BPF loading failure (-E2BIG) 2025-01-23 15:55:52 -08:00
bench_uprobe.bpf.c perf bench uprobe: Add uretprobe variant of uprobe benchmarks 2024-04-12 17:54:02 -03:00
bperf_cgroup.bpf.c perf stat: Constify control data for BPF 2024-09-03 11:43:16 -03: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 perf bpf: Fix building perf with BUILD_BPF_SKEL=1 by default in more distros 2021-12-06 21:57:53 -03:00
func_latency.bpf.c perf ftrace: Display latency statistics at the end 2025-01-08 17:20:42 -03:00
kwork_top.bpf.c perf: Increase MAX_NR_CPUS to 4096 2024-12-09 17:52:41 -03:00
kwork_trace.bpf.c perf kwork: Constify control data for BPF 2024-09-03 11:50:20 -03:00
lock_contention.bpf.c perf lock contention: Handle slab objects in -L/--lock-filter option 2024-12-23 13:53:08 -03:00
lock_data.h perf lock contention: Run BPF slab cache iterator 2024-12-23 13:52:03 -03:00
off_cpu.bpf.c perf record offcpu: Constify control data for BPF 2024-09-03 11:54:47 -03:00
sample_filter.bpf.c perf bpf-filter: Support filtering on cgroups 2024-08-28 18:21:49 -03:00
sample-filter.h perf bpf-filter: Support filtering on cgroups 2024-08-28 18:21:49 -03:00