linux-stable/tools/bpf/bpftool
Alexander Lobakin 9cdf9b27b7 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:48:00 +02:00
..
bash-completion bpftool: Clean up _bpftool_once_attr() calls in bash completion 2023-04-05 21:27:27 -07:00
Documentation bpftool: Update doc to explain struct_ops register subcommand. 2023-04-21 11:10:10 -07:00
skeleton bpftool: Use a local bpf_perf_event_value to fix accessing its fields 2023-09-13 09:48:00 +02:00
.gitignore bpftool: Fix SPDX tag for Makefiles and .gitignore 2021-11-10 09:00:52 -08:00
btf.c bpftool: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-02-16 15:32:45 -08:00
btf_dumper.c bpftool: Replace "__fallthrough" by a comment to address merge conflict 2023-04-20 16:38:10 -07:00
cfg.c bpftool: Support printing opcodes and source file references in CFG 2023-04-05 21:27:27 -07:00
cfg.h bpftool: Support printing opcodes and source file references in CFG 2023-04-05 21:27:27 -07:00
cgroup.c bpftool: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-02-16 15:32:45 -08:00
common.c bpftool: Register struct_ops with a link. 2023-04-21 11:10:10 -07:00
feature.c bpftool: JIT limited misreported as negative value on aarch64 2023-07-19 16:35:23 +02:00
gen.c bpftool: clean-up usage of libbpf_get_error() 2022-11-20 16:17:46 -08:00
iter.c bpftool: clean-up usage of libbpf_get_error() 2022-11-20 16:17:46 -08:00
jit_disasm.c bpftool: Fix spelling mistake "disasembler" -> "disassembler" 2022-10-26 18:20:22 -07:00
json_writer.c tools: bpftool: json: Fix backslash escape typo in jsonw_puts 2023-03-29 09:48:45 -07:00
json_writer.h tools: bpftool: json: Fix backslash escape typo in jsonw_puts 2023-03-29 09:48:45 -07:00
link.c tools: bpftool: print netfilter link info 2023-04-21 11:34:49 -07:00
main.c bpftool: clean-up usage of libbpf_get_error() 2022-11-20 16:17:46 -08:00
main.h tools: bpftool: print netfilter link info 2023-04-21 11:34:49 -07:00
Makefile bpftool: Always disable stack protection for BPF objects 2023-01-13 16:44:21 +01:00
map.c bpftool: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-02-16 15:32:45 -08:00
map_perf_ring.c bpftool: Fix error message of strerror 2022-09-30 15:40:46 -07:00
net.c tools: bpftool: print netfilter link info 2023-04-21 11:34:49 -07:00
netlink_dumper.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
netlink_dumper.h
perf.c bpftool: Define _GNU_SOURCE only once 2022-10-25 10:11:56 -07:00
pids.c libbpf: Hashmap interface update to allow both long and void* keys/values 2022-11-09 20:45:14 -08:00
prog.c bpftool: Register struct_ops with a link. 2023-04-21 11:10:10 -07:00
struct_ops.c bpftool: Register struct_ops with a link. 2023-04-21 11:10:10 -07:00
tracelog.c bpftool, musl compat: Replace sys/fcntl.h by fcntl.h 2022-04-25 23:24:28 +02:00
xlated_dumper.c bpftool: Support printing opcodes and source file references in CFG 2023-04-05 21:27:27 -07:00
xlated_dumper.h bpftool: Support printing opcodes and source file references in CFG 2023-04-05 21:27:27 -07:00