[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6fe63fa3-6c63-4b75-ac09-884d26f6fb95@kernel.org>
Date: Fri, 30 Aug 2024 12:24:29 +0200
From: Jiri Slaby <jirislaby@...nel.org>
To: Howard Chu <howardchu95@...il.com>, acme@...nel.org
Cc: adrian.hunter@...el.com, irogers@...gle.com, jolsa@...nel.org,
kan.liang@...ux.intel.com, namhyung@...nel.org,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
Arnaldo Carvalho de Melo <acme@...hat.com>
Subject: Re: [PATCH v5 1/8] perf trace: Fix iteration of syscall ids in
syscalltbl->entries
On 05. 07. 24, 15:20, Howard Chu wrote:
> This is a bug found when implementing pretty-printing for the
> landlock_add_rule system call, I decided to send this patch separately
> because this is a serious bug that should be fixed fast.
...
> I simplified the code to not expose the 'struct syscall' outside of
> tools/perf/util/syscalltbl.c, instead providing a function to go from
> the index to the syscall id:
>
> int syscalltbl__id_at_idx(struct syscalltbl *tbl, int idx);
...
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -3354,8 +3354,6 @@ static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id)
> static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, struct syscall *sc)
> {
> struct tep_format_field *field, *candidate_field;
> - int id;
> -
> /*
> * We're only interested in syscalls that have a pointer:
> */
> @@ -3367,7 +3365,8 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
> return NULL;
>
> try_to_find_pair:
> - for (id = 0; id < trace->sctbl->syscalls.nr_entries; ++id) {
> + for (int i = 0; i < trace->sctbl->syscalls.nr_entries; ++i) {
> + int id = syscalltbl__id_at_idx(trace->sctbl, i);
> struct syscall *pair = trace__syscall_info(trace, NULL, id);
> struct bpf_program *pair_prog;
> bool is_candidate = false;
> @@ -3456,10 +3455,10 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
> {
> int map_enter_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_enter);
> int map_exit_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_exit);
> - int err = 0, key;
> + int err = 0;
>
> - for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
> - int prog_fd;
> + for (int i = 0; i < trace->sctbl->syscalls.nr_entries; ++i) {
> + int prog_fd, key = syscalltbl__id_at_idx(trace->sctbl, i);
>
> if (!trace__syscall_enabled(trace, key))
> continue;
> @@ -3505,7 +3504,8 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
> * first and second arg (this one on the raw_syscalls:sys_exit prog
> * array tail call, then that one will be used.
> */
> - for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
> + for (int i = 0; i < trace->sctbl->syscalls.nr_entries; ++i) {
> + int key = syscalltbl__id_at_idx(trace->sctbl, i);
> struct syscall *sc = trace__syscall_info(trace, NULL, key);
> struct bpf_program *pair_prog;
> int prog_fd;
> diff --git a/tools/perf/util/syscalltbl.c b/tools/perf/util/syscalltbl.c
> index 63be7b58761d..0dd26b991b3f 100644
> --- a/tools/perf/util/syscalltbl.c
> +++ b/tools/perf/util/syscalltbl.c
> @@ -123,6 +123,13 @@ int syscalltbl__id(struct syscalltbl *tbl, const char *name)
> return sc ? sc->id : -1;
> }
>
> +int syscalltbl__id_at_idx(struct syscalltbl *tbl, int idx)
> +{
> + struct syscall *syscalls = tbl->syscalls.entries;
> +
> + return idx < tbl->syscalls.nr_entries ? syscalls[idx].id : -1;
> +}
> +
This broke NO_SYSCALL_TABLE builds. i586 in particular
(HAVE_SYSCALL_TABLE_SUPPORT is undefined there):
> gcc -fomit-frame-pointer -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -Wno-type-limits -Wstrict-aliasing=3 -Wshadow -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET -DNDEBUG=1 -O6 -fno-omit-frame-pointer -Wall -Wextra -std=gnu11 -fstack-protector-all -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/home/abuild/rpmbuild/BUILD/tools/perf/util/include -I/home/abuild/rpmbuild/BUILD/tools/perf/arch/x86/include -I/home/abuild/rpmbuild/BUILD/tools/include/ -I/home/abuild/rpmbuild/BUILD/tools/arch/x86/include/uapi -I/home/abuild/rpmbuild/BUILD/tools/include/uapi -I/home/abuild/rpmbuild/BUILD/tools/arch/x86/include/ -I/home/abuild/rpmbuild/BUILD/tools/arch/x86/ -I/home/abuild/rpmbuild/BUILD/tools/perf/util -I/home/abuild/rpmbuild/BUILD/tools/perf -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP -DHAVE_PTHREAD_BARRIER -DHAVE_EVENTFD_SUPPORT -DHAVE_GET_CURRENT_DIR_NAME -DHAVE_GETTID -DHAVE_FILE_HANDLE -DHAVE_DWARF_GETLOCATIONS_SUPPORT -DHAVE_DWARF_CFI_SUPPORT -DHAVE_AIO_SUPPORT -DHAVE_SCANDIRAT_SUPPORT -DHAVE_SCHED_GETCPU_SUPPORT -DHAVE_SETNS_SUPPORT -DHAVE_CSTRACE_SUPPORT -DHAVE_ZLIB_SUPPORT -DHAVE_LIBELF_SUPPORT -DHAVE_ELF_GETPHDRNUM_SUPPORT -DHAVE_GELF_GETNOTE_SUPPORT -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT -DHAVE_DWARF_SUPPORT -DHAVE_LIBBPF_SUPPORT -DHAVE_JITDUMP -DHAVE_LIBUNWIND_X86_SUPPORT -DHAVE_BPF_SKEL -DHAVE_DWARF_UNWIND_SUPPORT -DNO_LIBUNWIND_DEBUG_FRAME -DHAVE_LIBUNWIND_SUPPORT -DHAVE_LIBAUDIT_SUPPORT -DHAVE_LIBCRYPTO_SUPPORT -DHAVE_SLANG_SUPPORT -DHAVE_GTK2_SUPPORT -DHAVE_LIBPERL_SUPPORT -DHAVE_TIMERFD_SUPPORT -DHAVE_LIBPYTHON_SUPPORT -fPIC -DHAVE_CXA_DEMANGLE_SUPPORT -DHAVE_LZMA_SUPPORT -DHAVE_ZSTD_SUPPORT -DHAVE_LIBCAP_SUPPORT -DHAVE_BACKTRACE_SUPPORT -DHAVE_KVM_STAT_SUPPORT -DDISASM_INIT_STYLED -DHAVE_LIBBABELTRACE_SUPPORT -DHAVE_AUXTRACE_SUPPORT -DHAVE_LIBTRACEEVENT -DLIBTRACEEVENT_VERSION=67067 -I/home/abuild/rpmbuild/BUILD/tools/perf/libapi/include -I/home/abuild/rpmbuild/BUILD/tools/perf/libbpf/include -I/home/abuild/rpmbuild/BUILD/tools/perf/libsubcmd/include -I/home/abuild/rpmbuild/BUILD/tools/perf/libsymbol/include -I/home/abuild/rpmbuild/BUILD/tools/perf/libperf/include -Wl,-z,noexecstack -lunwind-x86 -lunwind-x86 -llzma -lunwind -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.40.0/i586-linux-thread-multi-64int/CORE -fstack-protector-strong -L/usr/lib/perl5/5.40.0/i586-linux-thread-multi-64int/CORE -L/usr/lib \
> perf-in.o -Wl,--whole-archive /home/abuild/rpmbuild/BUILD/tools/perf/libapi/libapi.a /home/abuild/rpmbuild/BUILD/tools/perf/libperf/libperf.a /home/abuild/rpmbuild/BUILD/tools/perf/libsubcmd/libsubcmd.a /home/abuild/rpmbuild/BUILD/tools/perf/libsymbol/libsymbol.a /home/abuild/rpmbuild/BUILD/tools/perf/libbpf/libbpf.a libperf-bench.a libperf-test.a libperf-ui.a libperf-util.a libpmu-events.a -Wl,--no-whole-archive -Wl,--start-group -lpthread -lrt -lm -ldl -lopencsd_c_api -lopencsd -lz -lelf -ldw -lunwind-x86 -llzma -lunwind -lunwind-x86 -laudit -lcrypto -lslang -ldl -lperl -lpthread -ldl -lm -lcrypt -lutil -lc -lpython3.11 -ldl -lm -lutil -lstdc++ -llzma -lzstd -lcap -lbabeltrace-ctf -ltraceevent -Wl,--end-group -o perf
> /usr/lib/gcc/i586-suse-linux/14/../../../../i586-suse-linux/bin/ld: perf-in.o: in function `cmd_trace':
> (.text+0x81411): undefined reference to `syscalltbl__id_at_idx'
> /usr/lib/gcc/i586-suse-linux/14/../../../../i586-suse-linux/bin/ld: (.text+0x814b2): undefined reference to `syscalltbl__id_at_idx'
> /usr/lib/gcc/i586-suse-linux/14/../../../../i586-suse-linux/bin/ld: (.text+0x8154c): undefined reference to `syscalltbl__id_at_idx'
Should there be something like a function returning identity mapping for
!HAVE_SYSCALL_TABLE_SUPPORT?
thanks,
--
js
suse labs
Powered by blists - more mailing lists