perf ftrace: Fix access to pid in array when setting a pid filter

Command 'perf ftrace -v -- ls' fails in s390 (at least 5.12.0rc6).

The root cause is a missing pointer dereference which causes an
array element address to be used as PID.

Fix this by extracting the PID.

Output before:
# ./perf ftrace -v -- ls
function_graph tracer is used
write '-263732416' to tracing/set_ftrace_pid failed: Invalid argument
failed to set ftrace pid
#

Output after:
./perf ftrace -v -- ls
function_graph tracer is used
# tracer: function_graph
#
# CPU DURATION FUNCTION CALLS
# | | | | | | |
4) | rcu_read_lock_sched_held() {
4) 0.552 us | rcu_lockdep_current_cpu_online();
4) 6.124 us | }

Reported-by: Alexander Schmidt <alexschm@de.ibm.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Link: http://lore.kernel.org/lkml/20210421120400.2126433-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by Thomas Richter and committed by Arnaldo Carvalho de Melo 671b60cb b14585d9

Changed files
+1 -1
tools
+1 -1
tools/perf/builtin-ftrace.c
··· 289 289 290 290 for (i = 0; i < perf_thread_map__nr(ftrace->evlist->core.threads); i++) { 291 291 scnprintf(buf, sizeof(buf), "%d", 292 - ftrace->evlist->core.threads->map[i]); 292 + perf_thread_map__pid(ftrace->evlist->core.threads, i)); 293 293 if (append_tracing_file("set_ftrace_pid", buf) < 0) 294 294 return -1; 295 295 }