Skip to contentSkip to conversation

perf data convert: Fix segfault when converting to json on arm64

PATCH Superseded Ilkka Koskinen 2 participants 4 messages Jan 17, 2024 – Feb 23, 2024 perf events

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 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.
v3:
- The architecture is checked from the actual data file to allow one to do conversion on another system. (thanks to James for the feedback)
---
tools/perf/util/data-convert-json.c | 8 +++++++-

 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-json.c +7 -1
index 5bb3c2ba95ca..405c38371870 100644
@@ -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);
 
-	output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+	/*
+	 * Arm64 doesn't have Model section in /proc/cpuinfo and, thus, cpu-desc
+	 * is not set.
+	 */
+	if (strncmp(header->env.arch, "aarch64", 7))
+		output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+
 	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
#1 lore raw

cc: Evgeny Pistun since he submitted a patch pretty similar to my first version
(https://lore.kernel.org/all/[email protected]/)

Namhyung and James,

What's your thought on this? Is one of the patches (Evgeny's or mine) good enough or should we try some other approach?

Cheers, Ilkka

Quoted 45 lines · Ilkka Koskinen

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.
v3:
- The architecture is checked from the actual data file to allow one to do conversion on another system. (thanks to James for the feedback)
---
tools/perf/util/data-convert-json.c | 8 +++++++-

1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-json.c +7 -1
index 5bb3c2ba95ca..405c38371870 100644
@@ -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);
 
-	output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+	/*
+	 * Arm64 doesn't have Model section in /proc/cpuinfo and, thus, cpu-desc
+	 * is not set.
+	 */
+	if (strncmp(header->env.arch, "aarch64", 7))
+		output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+
 	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
maintainer
#2 lore raw

Hello,

Quoted 8 lines · Ilkka Koskinen

cc: Evgeny Pistun since he submitted a patch pretty similar to my first version
(https://lore.kernel.org/all/[email protected]/)

Quoted 4 lines

Namhyung and James,

What's your thought on this? Is one of the patches (Evgeny's or mine) good enough or should we try some other approach?

Sorry for the long delay. Please see my comments below.

Quoted 33 lines · Ilkka Koskinen
Quoted 30 lines

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.
v3:
- The architecture is checked from the actual data file to allow one to do conversion on another system. (thanks to James for the feedback)
---
tools/perf/util/data-convert-json.c | 8 +++++++-

1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-json.c +0 -0
index 5bb3c2ba95ca..405c38371870 100644
@@ -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 7 lines

tools/perf/util/data-convert-json.c static void output_headers(struct perf_session *session, struct convert_json *c) · line 292

Quoted 7 lines
tools/perf/util/data-convert-json.c +6 -1
-     output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+     /*
+      * Arm64 doesn't have Model section in /proc/cpuinfo and, thus, cpu-desc
+      * is not set.
+      */
+     if (strncmp(header->env.arch, "aarch64", 7))
+             output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);

I prefer checking cpu_desc (if it's NULL) not the arch string. Maybe other arch has the same problem or can introduce one later..

Thanks,
Namhyung

Quoted 8 lines
Quoted 8 lines
tools/perf/util/data-convert-json.c +1 -1
+
      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);
--

2.43.0

#3 lore raw
Quoted 52 lines · Namhyung Kim

Hello,

Quoted 8 lines · Ilkka Koskinen

cc: Evgeny Pistun since he submitted a patch pretty similar to my first version
(https://lore.kernel.org/all/[email protected]/)

Quoted 4 lines

Namhyung and James,

What's your thought on this? Is one of the patches (Evgeny's or mine) good enough or should we try some other approach?

Sorry for the long delay. Please see my comments below.

Quoted 33 lines · Ilkka Koskinen
Quoted 30 lines

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.
v3:
- The architecture is checked from the actual data file to allow one to do conversion on another system. (thanks to James for the feedback)
---
tools/perf/util/data-convert-json.c | 8 +++++++-

1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-json.c +0 -0
index 5bb3c2ba95ca..405c38371870 100644
@@ -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 10 lines
Quoted 7 lines

tools/perf/util/data-convert-json.c static void output_headers(struct perf_session *session, struct convert_json *c) · line 292

Quoted 7 lines
tools/perf/util/data-convert-json.c +6 -1
-     output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+     /*
+      * Arm64 doesn't have Model section in /proc/cpuinfo and, thus, cpu-desc
+      * is not set.
+      */
+     if (strncmp(header->env.arch, "aarch64", 7))
+             output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);

I prefer checking cpu_desc (if it's NULL) not the arch string. Maybe other arch has the same problem or can introduce one later..

Sounds reasonable. I'll submit a new version soon

Cheers, Ilkka

Quoted 13 lines

Thanks,
Namhyung

Quoted 8 lines
Quoted 8 lines
tools/perf/util/data-convert-json.c +1 -1
+
      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);
--

2.43.0