linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] perf data convert: Fix segfault when converting to json when cpu_desc isn't set
@ 2024-02-23 22:04 Ilkka Koskinen
  2024-02-24 15:49 ` Arnaldo Carvalho de Melo
  2024-02-27 17:25 ` Namhyung Kim
  0 siblings, 2 replies; 3+ messages in thread
From: Ilkka Koskinen @ 2024-02-23 22:04 UTC (permalink / raw)
  To: Namhyung Kim, James Clark, Ian Rogers
  Cc: Evgeny Pistun, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, linux-perf-users, linux-kernel,
	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.

Signed-off-by: Ilkka Koskinen <ilkka@os.amperecomputing.com>
---

v1:
    - https://lore.kernel.org/all/20240111232923.8138-1-ilkka@os.amperecomputing.com/
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)
    - https://lore.kernel.org/all/20240117215101.77713-1-ilkka@os.amperecomputing.com/
v4:
    - Made the fix more generic in case there are other architectures where cpu_desc
      isn't assigned as asked by Namhyung
    - Rephrased the subject line
---

tools/perf/util/data-convert-json.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
index 5bb3c2ba95ca..09d57efd2d9d 100644
--- a/tools/perf/util/data-convert-json.c
+++ b/tools/perf/util/data-convert-json.c
@@ -284,7 +284,9 @@ 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);
+	if (header->env.cpu_desc)
+		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);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] perf data convert: Fix segfault when converting to json when cpu_desc isn't set
  2024-02-23 22:04 [PATCH v4] perf data convert: Fix segfault when converting to json when cpu_desc isn't set Ilkka Koskinen
@ 2024-02-24 15:49 ` Arnaldo Carvalho de Melo
  2024-02-27 17:25 ` Namhyung Kim
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-02-24 15:49 UTC (permalink / raw)
  To: Ilkka Koskinen
  Cc: Namhyung Kim, James Clark, Ian Rogers, Evgeny Pistun,
	Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, linux-perf-users, linux-kernel

On Fri, Feb 23, 2024 at 02:04:58PM -0800, Ilkka Koskinen wrote:
> 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.
> 
> Signed-off-by: Ilkka Koskinen <ilkka@os.amperecomputing.com>

Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>

- Arnaldo

> ---
> 
> v1:
>     - https://lore.kernel.org/all/20240111232923.8138-1-ilkka@os.amperecomputing.com/
> 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)
>     - https://lore.kernel.org/all/20240117215101.77713-1-ilkka@os.amperecomputing.com/
> v4:
>     - Made the fix more generic in case there are other architectures where cpu_desc
>       isn't assigned as asked by Namhyung
>     - Rephrased the subject line
> ---
> 
> tools/perf/util/data-convert-json.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
> index 5bb3c2ba95ca..09d57efd2d9d 100644
> --- a/tools/perf/util/data-convert-json.c
> +++ b/tools/perf/util/data-convert-json.c
> @@ -284,7 +284,9 @@ 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);
> +	if (header->env.cpu_desc)
> +		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);
> -- 
> 2.43.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] perf data convert: Fix segfault when converting to json when cpu_desc isn't set
  2024-02-23 22:04 [PATCH v4] perf data convert: Fix segfault when converting to json when cpu_desc isn't set Ilkka Koskinen
  2024-02-24 15:49 ` Arnaldo Carvalho de Melo
@ 2024-02-27 17:25 ` Namhyung Kim
  1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-02-27 17:25 UTC (permalink / raw)
  To: Ilkka Koskinen, Ian Rogers, James Clark
  Cc: Evgeny Pistun, linux-kernel, Mark Rutland, linux-perf-users,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
	Alexander Shishkin, Peter Zijlstra, Ingo Molnar

On Fri, 23 Feb 2024 14:04:58 -0800, Ilkka Koskinen wrote:
> 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.
> 
> [...]

Applied to perf-tools-next, thanks!

Best regards,
-- 
Namhyung Kim <namhyung@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-27 17:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-23 22:04 [PATCH v4] perf data convert: Fix segfault when converting to json when cpu_desc isn't set Ilkka Koskinen
2024-02-24 15:49 ` Arnaldo Carvalho de Melo
2024-02-27 17:25 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).