public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Dmitry Safonov <dima@arista.com>, Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH] perf diff: Don't crash on freeing errno-session
Date: Tue, 2 Mar 2021 09:31:23 -0300	[thread overview]
Message-ID: <YD4wG8+/cvLTQjOF@kernel.org> (raw)
In-Reply-To: <CAM9d7cibt7MdaZq2mX73N0gYViE7EGg_TcwkU6uq3NS7rgVSkw@mail.gmail.com>

Em Tue, Mar 02, 2021 at 01:47:55PM +0900, Namhyung Kim escreveu:
> Hello,
> 
> On Tue, Mar 2, 2021 at 11:35 AM Dmitry Safonov <dima@arista.com> wrote:
> >
> > __cmd_diff() sets result of perf_session__new() to d->session.
> > In case of failure, it's errno and perf-diff may crash with:
> > failed to open perf.data: Permission denied
> > Failed to open perf.data
> > Segmentation fault (core dumped)
> >
> > From the coredump:
> > 0  0x00005569a62b5955 in auxtrace__free (session=0xffffffffffffffff)
> >     at util/auxtrace.c:2681
> > 1  0x00005569a626b37d in perf_session__delete (session=0xffffffffffffffff)
> >     at util/session.c:295
> > 2  perf_session__delete (session=0xffffffffffffffff) at util/session.c:291
> > 3  0x00005569a618008a in __cmd_diff () at builtin-diff.c:1239
> > 4  cmd_diff (argc=<optimized out>, argv=<optimized out>) at builtin-diff.c:2011
> > [..]
> >
> > Funny enough, it won't always crash. For me it crashes only if failed
> > file is second in cmd-line: the reason is that cmd_diff() check files for
> > branch-stacks [in check_file_brstack()] and if the first file doesn't
> > have brstacks, it doesn't proceed to try open other files from cmd-line.
> >
> > Check d->session before calling perf_session__delete().
> >
> > Another solution would be assigning to temporary variable, checking it,
> > but I find it easier to follow with IS_ERR() check in the same function.
> > After some time it's still obvious why the check is needed, and with
> > temp variable it's possible to make the same mistake.
> >
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Jiri Olsa <jolsa@redhat.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Signed-off-by: Dmitry Safonov <dima@arista.com>
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks, tested, added a complete set of steps for a problem to be
reproduced and applied.

- Arnaldo

    Committer testing:
    
      $ perf record sleep 1
      [ perf record: Woken up 1 times to write data ]
      [ perf record: Captured and wrote 0.001 MB perf.data (8 samples) ]
      $ perf diff
      failed to open perf.data.old: No such file or directory
      Failed to open perf.data.old
      $ perf record sleep 1
      [ perf record: Woken up 1 times to write data ]
      [ perf record: Captured and wrote 0.001 MB perf.data (8 samples) ]
      $ perf diff
      # Event 'cycles:u'
      #
      # Baseline  Delta Abs  Shared Object     Symbol
      # ........  .........  ................  ..........................
      #
           0.92%    +87.66%  [unknown]         [k] 0xffffffff8825de16
          11.39%     +0.04%  ld-2.32.so        [.] __GI___tunables_init
          87.70%             ld-2.32.so        [.] _dl_check_map_versions
      $ sudo chown root:root perf.data
      [sudo] password for acme:
      $ perf diff
      failed to open perf.data: Permission denied
      Failed to open perf.data
      Segmentation fault (core dumped)
      $
    
    After the patch:
    
      $ perf diff
      failed to open perf.data: Permission denied
      Failed to open perf.data
      $
    
    Signed-off-by: Dmitry Safonov <dima@arista.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>

      reply	other threads:[~2021-03-02 15:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02  2:35 [PATCH] perf diff: Don't crash on freeing errno-session Dmitry Safonov
2021-03-02  4:47 ` Namhyung Kim
2021-03-02 12:31   ` Arnaldo Carvalho de Melo [this message]

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=YD4wG8+/cvLTQjOF@kernel.org \
    --to=acme@kernel.org \
    --cc=0x7f454c46@gmail.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dima@arista.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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