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

perf script: Fix --per-event-dump for auxtrace synth evsels

When processing PERF_RECORD_AUXTRACE_INFO several perf_evsel entries
will be synthesized and inserted into session->evlist, eventually ending
in perf_script.tool.sample(), which ends up calling builtin-script.c's
process_event(), that expects evsel->priv to be a perf_evsel_script
object with a valid FILE pointer in fp.

So we need to intercept the processing of PERF_RECORD_AUXTRACE_INFO and
then setup evsel->priv for these newly created perf_evsel instances, do
it to fix the segfault in process_event() trying to use a NULL for that
FILE pointer.

Reported-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: yuzhoujian <yuzhoujian@didichuxing.com>
Fixes: a14390fde64e ("perf script: Allow creating per-event dump files")
Link: http://lkml.kernel.org/n/tip-bthnur8r8de01gxvn2qayx6e@git.kernel.org
[ Merge fix by Ravi Bangoria before pushing upstream to preserv bisectability ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+30 -1
+30 -1
tools/perf/builtin-script.c
··· 1955 1955 struct perf_evsel *evsel; 1956 1956 1957 1957 evlist__for_each_entry(script->session->evlist, evsel) { 1958 + /* 1959 + * Already setup? I.e. we may be called twice in cases like 1960 + * Intel PT, one for the intel_pt// and dummy events, then 1961 + * for the evsels syntheized from the auxtrace info. 1962 + * 1963 + * Ses perf_script__process_auxtrace_info. 1964 + */ 1965 + if (evsel->priv != NULL) 1966 + continue; 1967 + 1958 1968 evsel->priv = perf_evsel_script__new(evsel, script->session->data); 1959 1969 if (evsel->priv == NULL) 1960 1970 goto out_err_fclose; ··· 2848 2838 return set_maps(script); 2849 2839 } 2850 2840 2841 + #ifdef HAVE_AUXTRACE_SUPPORT 2842 + static int perf_script__process_auxtrace_info(struct perf_tool *tool, 2843 + union perf_event *event, 2844 + struct perf_session *session) 2845 + { 2846 + int ret = perf_event__process_auxtrace_info(tool, event, session); 2847 + 2848 + if (ret == 0) { 2849 + struct perf_script *script = container_of(tool, struct perf_script, tool); 2850 + 2851 + ret = perf_script__setup_per_event_dump(script); 2852 + } 2853 + 2854 + return ret; 2855 + } 2856 + #else 2857 + #define perf_script__process_auxtrace_info 0 2858 + #endif 2859 + 2851 2860 int cmd_script(int argc, const char **argv) 2852 2861 { 2853 2862 bool show_full_info = false; ··· 2895 2866 .feature = perf_event__process_feature, 2896 2867 .build_id = perf_event__process_build_id, 2897 2868 .id_index = perf_event__process_id_index, 2898 - .auxtrace_info = perf_event__process_auxtrace_info, 2869 + .auxtrace_info = perf_script__process_auxtrace_info, 2899 2870 .auxtrace = perf_event__process_auxtrace, 2900 2871 .auxtrace_error = perf_event__process_auxtrace_error, 2901 2872 .stat = perf_event__process_stat_event,