From: Song Liu <songliubraving@fb.com>
To: LKML <linux-kernel@vger.kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Kernel Team <Kernel-team@fb.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, stable <stable@vger.kernel.org>
Subject: Re: [PATCH] perf-script: check session->header.env.arch before using it
Date: Sat, 16 Oct 2021 00:59:17 +0000 [thread overview]
Message-ID: <18D8F9F1-BF41-4C60-899B-53F6ED76FB2B@fb.com> (raw)
In-Reply-To: <20211004053238.514936-1-songliubraving@fb.com>
Hi Arnaldo,
Could you please share your comments on this one?
Thanks,
Song
> On Oct 3, 2021, at 10:32 PM, Song Liu <songliubraving@fb.com> wrote:
>
> When perf.data is not written cleanly, we would like to process existing
> data as much as possible (please see f_header.data.size == 0 condition
> in perf_session__read_header). However, perf.data with partial data may
> crash perf. Specifically, we see crash in perf-script for NULL
> session->header.env.arch.
>
> Fix this by checking session->header.env.arch before using it to determine
> native_arch. Also split the if condition so it is easier to read.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Song Liu <songliubraving@fb.com>
> ---
> tools/perf/builtin-script.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 6211d0b84b7a6..7821f6740ac1d 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -4039,12 +4039,17 @@ int cmd_script(int argc, const char **argv)
> goto out_delete;
>
> uname(&uts);
> - if (data.is_pipe || /* assume pipe_mode indicates native_arch */
> - !strcmp(uts.machine, session->header.env.arch) ||
> - (!strcmp(uts.machine, "x86_64") &&
> - !strcmp(session->header.env.arch, "i386")))
> + if (data.is_pipe) /* assume pipe_mode indicates native_arch */
> native_arch = true;
>
> + if (session->header.env.arch) {
> + if (!strcmp(uts.machine, session->header.env.arch))
> + native_arch = true;
> + else if (!strcmp(uts.machine, "x86_64") &&
> + !strcmp(session->header.env.arch, "i386"))
> + native_arch = true;
> + }
> +
> script.session = session;
> script__setup_sample_type(&script);
>
> --
> 2.30.2
>
next prev parent reply other threads:[~2021-10-16 0:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-04 5:32 [PATCH] perf-script: check session->header.env.arch before using it Song Liu
2021-10-16 0:59 ` Song Liu [this message]
2021-10-27 12:39 ` Arnaldo Carvalho de Melo
2021-10-27 16:41 ` Song Liu
2021-10-27 16:43 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18D8F9F1-BF41-4C60-899B-53F6ED76FB2B@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).