perf data convert: Fix segfault when converting to json on arm64
PATCH v2 1/1 perf data convert: Fix segfault when converting to json on arm64
Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get assigned.
Running
$ perf data convert --to-json perf.data.json
ends up calling output_json_string() with NULL pointer, which causes a segmentation fault.
---
v1:
- https://lore.kernel.org/all/[email protected]/
v2:
- Changed the patch based on James's comments.
---tools/perf/util/data-convert-json.c | 6 ++++++
1 file changed, 6 insertions(+)
tools/perf/util/data-convert-json.c +6 -0
@@ -284,7 +284,13 @@ static void output_headers(struct perf_session *session, struct convert_json *c)output_json_key_string (out, true,2 ,"os-release" , header->env.os_release);output_json_key_string (out, true,2 ,"arch" , header->env.arch); +#if !defined(__aarch64__) +/* +* arm64 doesn't have Model section in /proc/cpuinfo and, thus, cpu-desc +* is not set. +*/ output_json_key_string (out, true,2 ,"cpu-desc" , header->env.cpu_desc); +#endif output_json_key_string (out, true,2 ,"cpuid" , header->env.cpuid);output_json_key_format (out, true,2 ,"nrcpus-online" ,"%u" , header->env.nr_cpus_online);output_json_key_format (out, true,2 ,"nrcpus-avail" ,"%u" , header->env.nr_cpus_avail);
Signature · 1 line
2.43.0
Quoted 24 lines · Ilkka Koskinen
Arm64 doesn't have Model in
/proc/cpuinfoand, thus,cpu_descdoesn't get assigned.Running
$ perf data convert --to-json perf.data.jsonends up calling
output_json_string()with NULL pointer, which causes a segmentation fault.Signed-off-by Ilkka Koskinen <[email protected]>---
v1:
- https://lore.kernel.org/all/[email protected]/
v2:
- Changed the patch based on James's comments.
---tools/perf/util/data-convert-json.c| 6 ++++++1 file changed, 6 insertions(+)tools/perf/util/data-convert-json.c +0
-0
tools/perf/util/data-convert-json.c static void output_headers(struct perf_session *session, struct convert_json *c) · line 287
Quoted 4 lines
tools/perf/util/data-convert-json.c +1
-0@@ -284,7 +284,13 @@ static void output_headers(struct perf_session *session, struct convert_json *c)output_json_key_string (out, true,2 ,"os-release" , header->env.os_release);output_json_key_string (out, true,2 ,"arch" , header->env.arch); +#if !defined(__aarch64__)
I think this needs to read from header->env.arch, otherwise it won't work if you run data convert on another machine.
I'm assuming that perf data convert is one of the commands that runs on a pre-recorded file, rather than a command that creates the perf.data file to begin with?
Quoted 9 lines
tools/perf/util/data-convert-json.c +5
-0+/* +* arm64 doesn't have Model section in /proc/cpuinfo and, thus, cpu-desc +* is not set. +*/ output_json_key_string (out, true,2 ,"cpu-desc" , header->env.cpu_desc); +#endif output_json_key_string (out, true,2 ,"cpuid" , header->env.cpuid);output_json_key_format (out, true,2 ,"nrcpus-online" ,"%u" , header->env.nr_cpus_online);output_json_key_format (out, true,2 ,"nrcpus-avail" ,"%u" , header->env.nr_cpus_avail);
Quoted 30 lines · James Clark
Quoted 27 lines · Ilkka Koskinen
Arm64 doesn't have Model in
/proc/cpuinfoand, thus,cpu_descdoesn't get assigned.Running
$ perf data convert --to-json perf.data.jsonends up calling
output_json_string()with NULL pointer, which causes a segmentation fault.Signed-off-by Ilkka Koskinen <[email protected]>---
v1:
- https://lore.kernel.org/all/[email protected]/
v2:
- Changed the patch based on James's comments.
---tools/perf/util/data-convert-json.c| 6 ++++++1 file changed, 6 insertions(+)tools/perf/util/data-convert-json.c +0
-0@@ -284,7 +284,13 @@ static void output_headers(struct perf_session *session, struct convert_json *c)output_json_key_string (out, true,2 ,"os-release" , header->env.os_release);output_json_key_string (out, true,2 ,"arch" , header->env.arch);
Quoted 8 lines
tools/perf/util/data-convert-json.c static void output_headers(struct perf_session *session, struct convert_json *c) · line 287
Quoted 1 line
tools/perf/util/data-convert-json.c +1
-0+#if !defined(__aarch64__)I think this needs to read from
header->env.arch, otherwise it won't work if you run data convert on another machine.I'm assuming that perf data convert is one of the commands that runs on a pre-recorded file, rather than a command that creates the perf.data file to begin with?
Oh, right. I'll fix it right away.
Cheers, Ilkka
Quoted 11 lines
Quoted 10 lines
tools/perf/util/data-convert-json.c +5
-0+/* +* arm64 doesn't have Model section in /proc/cpuinfo and, thus, cpu-desc +* is not set. +*/ output_json_key_string (out, true,2 ,"cpu-desc" , header->env.cpu_desc); +#endif output_json_key_string (out, true,2 ,"cpuid" , header->env.cpuid);output_json_key_format (out, true,2 ,"nrcpus-online" ,"%u" , header->env.nr_cpus_online);output_json_key_format (out, true,2 ,"nrcpus-avail" ,"%u" , header->env.nr_cpus_avail);