linux/tools/bpf/bpftool
Alexander Lobakin fc7ed36a31 bpftool: Use a local bpf_perf_event_value to fix accessing its fields
[ Upstream commit 658ac06801 ]

Fix the following error when building bpftool:

  CLANG   profiler.bpf.o
  CLANG   pid_iter.bpf.o
skeleton/profiler.bpf.c:18:21: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_perf_event_value'
        __uint(value_size, sizeof(struct bpf_perf_event_value));
                           ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:13:39: note: expanded from macro '__uint'
tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helper_defs.h:7:8: note: forward declaration of 'struct bpf_perf_event_value'
struct bpf_perf_event_value;
       ^

struct bpf_perf_event_value is being used in the kernel only when
CONFIG_BPF_EVENTS is enabled, so it misses a BTF entry then.
Define struct bpf_perf_event_value___local with the
`preserve_access_index` attribute inside the pid_iter BPF prog to
allow compiling on any configs. It is a full mirror of a UAPI
structure, so is compatible both with and w/o CO-RE.
bpf_perf_event_read_value() requires a pointer of the original type,
so a cast is needed.

Fixes: 47c09d6a9f ("bpftool: Introduce "prog profile" command")
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230707095425.168126-5-quentin@isovalent.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-09-13 09:42:30 +02:00
..
bash-completion
Documentation bpf: Define new BPF_MAP_TYPE_USER_RINGBUF map type 2022-09-21 16:24:17 -07:00
skeleton bpftool: Use a local bpf_perf_event_value to fix accessing its fields 2023-09-13 09:42:30 +02:00
.gitignore
btf_dumper.c bpftool: Fix a wrong type cast in btf_dumper_int 2022-08-25 11:43:08 -07:00
btf.c bpftool: Fix error message of strerror 2022-09-30 15:40:46 -07:00
cfg.c
cfg.h
cgroup.c bpftool: Fix wrong cgroup attach flags being assigned to effective progs 2022-09-21 10:57:12 -07:00
common.c bpftool: Fix memory leak in do_build_table_cb 2022-12-31 13:32:23 +01:00
feature.c bpftool: JIT limited misreported as negative value on aarch64 2023-07-19 16:21:05 +02:00
gen.c bpftool: Fix error message of strerror 2022-09-30 15:40:46 -07:00
iter.c
jit_disasm.c
json_writer.c tools: bpftool: Remove invalid \' json escape 2023-05-11 23:03:17 +09:00
json_writer.h
link.c bpftool: Show parameters of BPF task iterators. 2022-09-28 16:30:08 -07:00
main.c bpftool: Clear errno after libcap's checks 2022-08-15 20:37:33 +02:00
main.h
Makefile bpftool: Always disable stack protection for BPF objects 2023-03-10 09:33:49 +01:00
map_perf_ring.c bpftool: Fix error message of strerror 2022-09-30 15:40:46 -07:00
map.c bpf: Define new BPF_MAP_TYPE_USER_RINGBUF map type 2022-09-21 16:24:17 -07:00
net.c
netlink_dumper.c
netlink_dumper.h
perf.c
pids.c
prog.c bpftool: profile online CPUs instead of possible 2023-03-10 09:32:58 +01:00
struct_ops.c
tracelog.c
xlated_dumper.c bpftool: Fix bug for long instructions in program CFG dumps 2023-05-11 23:03:21 +09:00
xlated_dumper.h