Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf trace: Handle failure when trace point folder is missed

On Arm64 a case is perf tools fails to find the corresponding trace
point folder for system calls listed in the table 'syscalltbl_arm64',
e.g. the generated system call table contains "lookup_dcookie" but we
cannot find out the matched trace point folder for it.

We need to figure out if there have any issue for the generated system
call table, on the other hand, we need to handle the case when trace
point folder is missed under sysfs, this patch sets the flag
syscall::nonexistent as true and returns the error from
trace__read_syscall_info().

Another problem is for trace__syscall_info(), it returns two different
values if a system call doesn't exist: at the first time calling
trace__syscall_info() it returns NULL when the system call doesn't exist,
later if call trace__syscall_info() again for the same missed system
call, it returns pointer of syscall. trace__syscall_info() checks the
condition 'syscalls.table[id].name == NULL', but the name will be
assigned in the first invoking even the system call is not found.

So checking system call's name in trace__syscall_info() is not the right
thing to do, this patch simply checks flag syscall::nonexistent to make
decision if a system call exists or not, finally trace__syscall_info()
returns the consistent result (NULL) if a system call doesn't existed.

Fixes: b8b1033fcaa091d8 ("perf trace: Mark syscall ids that are not allocated to avoid unnecessary error messages")
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: bpf@vger.kernel.org
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20221121075237.127706-4-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
03e9a5d8 d4223e17

+10 -7
+10 -7
tools/perf/builtin-trace.c
··· 1814 1814 sc->tp_format = trace_event__tp_format("syscalls", tp_name); 1815 1815 } 1816 1816 1817 + /* 1818 + * Fails to read trace point format via sysfs node, so the trace point 1819 + * doesn't exist. Set the 'nonexistent' flag as true. 1820 + */ 1821 + if (IS_ERR(sc->tp_format)) { 1822 + sc->nonexistent = true; 1823 + return PTR_ERR(sc->tp_format); 1824 + } 1825 + 1817 1826 if (syscall__alloc_arg_fmts(sc, IS_ERR(sc->tp_format) ? 1818 1827 RAW_SYSCALL_ARGS_NUM : sc->tp_format->format.nr_fields)) 1819 1828 return -ENOMEM; 1820 - 1821 - if (IS_ERR(sc->tp_format)) 1822 - return PTR_ERR(sc->tp_format); 1823 1829 1824 1830 sc->args = sc->tp_format->format.fields; 1825 1831 /* ··· 2143 2137 (err = trace__read_syscall_info(trace, id)) != 0) 2144 2138 goto out_cant_read; 2145 2139 2146 - if (trace->syscalls.table[id].name == NULL) { 2147 - if (trace->syscalls.table[id].nonexistent) 2148 - return NULL; 2140 + if (trace->syscalls.table && trace->syscalls.table[id].nonexistent) 2149 2141 goto out_cant_read; 2150 - } 2151 2142 2152 2143 return &trace->syscalls.table[id]; 2153 2144