linux-stable/tools/perf/util/bpf_skel
Thomas Richter b18be5a561 perf trace: Use the right bpf_probe_read(_str) variant for reading user data
[ Upstream commit 5069211e2f ]

Perf test case 111 Check open filename arg using perf trace + vfs_getname
fails on s390. This is caused by a failing function
bpf_probe_read() in file util/bpf_skel/augmented_raw_syscalls.bpf.c.

The root cause is the lookup by address. Function bpf_probe_read()
is used. This function works only for architectures
with ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE.

On s390 is not possible to determine from the address to which
address space the address belongs to (user or kernel space).

Replace bpf_probe_read() by bpf_probe_read_kernel()
and bpf_probe_read_str() by bpf_probe_read_user_str() to
explicity specify the address space the address refers to.

Output before:
 # ./perf trace -eopen,openat -- touch /tmp/111
 libbpf: prog 'sys_enter': BPF program load failed: Invalid argument
 libbpf: prog 'sys_enter': -- BEGIN PROG LOAD LOG --
 reg type unsupported for arg#0 function sys_enter#75
 0: R1=ctx(off=0,imm=0) R10=fp0
 ; int sys_enter(struct syscall_enter_args *args)
 0: (bf) r6 = r1           ; R1=ctx(off=0,imm=0) R6_w=ctx(off=0,imm=0)
 ; return bpf_get_current_pid_tgid();
 1: (85) call bpf_get_current_pid_tgid#14      ; R0_w=scalar()
 2: (63) *(u32 *)(r10 -8) = r0 ; R0_w=scalar() R10=fp0 fp-8=????mmmm
 3: (bf) r2 = r10              ; R2_w=fp0 R10=fp0
 ;
 .....
 lines deleted here
 .....
 23: (bf) r3 = r6              ; R3_w=ctx(off=0,imm=0) R6=ctx(off=0,imm=0)
 24: (85) call bpf_probe_read#4
 unknown func bpf_probe_read#4
 processed 23 insns (limit 1000000) max_states_per_insn 0 \
	 total_states 2 peak_states 2 mark_read 2
 -- END PROG LOAD LOG --
 libbpf: prog 'sys_enter': failed to load: -22
 libbpf: failed to load object 'augmented_raw_syscalls_bpf'
 libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -22
 ....

Output after:
 # ./perf test -Fv 111
 111: Check open filename arg using perf trace + vfs_getname          :
 --- start ---
     1.085 ( 0.011 ms): touch/320753 openat(dfd: CWD, filename: \
	"/tmp/temporary_file.SWH85", \
	flags: CREAT|NOCTTY|NONBLOCK|WRONLY, mode: IRUGO|IWUGO) = 3
 ---- end ----
 Check open filename arg using perf trace + vfs_getname: Ok
 #

Test with the sleep command shows:
Output before:
 # ./perf trace -e *sleep sleep 1.234567890
     0.000 (1234.681 ms): sleep/63114 clock_nanosleep(rqtp: \
         { .tv_sec: 0, .tv_nsec: 0 }, rmtp: 0x3ffe0979720) = 0
 #

Output after:
 # ./perf trace -e *sleep sleep 1.234567890
     0.000 (1234.686 ms): sleep/64277 clock_nanosleep(rqtp: \
         { .tv_sec: 1, .tv_nsec: 234567890 }, rmtp: 0x3fff3df9ea0) = 0
 #

Fixes: 14e4b9f428 ("perf trace: Raw augmented syscalls fix libbpf 1.0+ compatibility")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Co-developed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ian Rogers <irogers@google.com>
Cc: gor@linux.ibm.com
Cc: hca@linux.ibm.com
Cc: sumanthk@linux.ibm.com
Cc: svens@linux.ibm.com
Link: https://lore.kernel.org/r/20231019082642.3286650-1-tmricht@linux.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:28 +01:00
..
vmlinux perf tools: Do not ignore the default vmlinux.h 2023-11-20 11:59:28 +01: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: Use the right bpf_probe_read(_str) variant for reading user data 2023-11-20 11:59:28 +01:00
bench_uprobe.bpf.c perf bench uprobe trace_printk: Add entry attaching an BPF program that does a trace_printk 2023-07-20 11:33:24 -03:00
bperf_cgroup.bpf.c perf stat: Support old kernels for bperf cgroup counting 2022-10-14 10:29:05 -03:00
bperf_follower.bpf.c perf bpf_skel: Do not use typedef to avoid error on old clang 2021-12-06 21:57:53 -03: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: Introduce 'bperf' to share hardware PMCs with BPF 2021-03-23 17:46:44 -03: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 latency: Add -n/--use-nsec option 2022-03-22 17:43:46 -03:00
kwork_trace.bpf.c perf kwork: Add workqueue trace BPF support 2022-07-26 16:31:54 -03:00
lock_contention.bpf.c perf bpf: Move the declaration of struct rq 2023-06-23 21:35:46 -07:00
lock_data.h perf lock contention: Update default map size to 16384 2023-04-06 21:52:27 -03:00
off_cpu.bpf.c perf test: Fix offcpu test prev_state check 2023-02-19 07:58:23 -03:00
sample-filter.h perf bpf filter: Add logical OR operator 2023-03-15 11:08:36 -03:00
sample_filter.bpf.c perf bpf filter: Fix a broken perf sample data naming for BPF CO-RE 2023-05-26 15:21:08 -03:00