linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 2/8] perf: Sanitize get_callchain_buffer()
Date: Thu, 1 Aug 2013 15:28:34 +0200	[thread overview]
Message-ID: <20130801132833.GA431@somewhere> (raw)
In-Reply-To: <20130801130146.GE1032@krava.brq.redhat.com>

On Thu, Aug 01, 2013 at 03:01:46PM +0200, Jiri Olsa wrote:
> On Tue, Jul 23, 2013 at 02:31:00AM +0200, Frederic Weisbecker wrote:
> > In case of allocation failure, get_callchain_buffer() keeps the
> > refcount incremented for the current event.
> > 
> > As a result, when get_callchain_buffers() returns an error,
> > we must cleanup what it did by cancelling its last refcount
> > with a call to put_callchain_buffers().
> > 
> > This is a hack in order to be able to call free_event()
> > after that failure.
> > 
> > The original purpose of that was to simplify the failure
> > path. But this error handling is actually counter intuitive,
> > ugly and not very easy to follow because one expect to
> > see the resources used to perform a service to be cleaned
> > by the callee if case of failure, not by the caller.
> > 
> > So lets clean this up by cancelling the refcount from
> > get_callchain_buffer() in case of failure. And correctly free
> > the event accordingly in perf_event_alloc().
> > 
> > Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> > Cc: Jiri Olsa <jolsa@redhat.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Cc: Ingo Molnar <mingo@kernel.org>
> > Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> > Cc: Stephane Eranian <eranian@google.com>
> > ---
> >  kernel/events/callchain.c |    2 ++
> >  kernel/events/core.c      |   41 +++++++++++++++++++++--------------------
> >  2 files changed, 23 insertions(+), 20 deletions(-)
> > 
> > diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
> > index c772061..76a8bc5 100644
> > --- a/kernel/events/callchain.c
> > +++ b/kernel/events/callchain.c
> > @@ -117,6 +117,8 @@ int get_callchain_buffers(void)
> >  	err = alloc_callchain_buffers();
> >  exit:
> >  	mutex_unlock(&callchain_mutex);
> > +	if (err)
> > +		atomic_dec(&nr_callchain_events);
> 
> shouldn't we touch this under above lock?

Right, we should move that under the lock, or another user of the callchains may see that we failed
the allocation and simply give up instead of retrying.

> 
> also that above hunk decrements nr_callchain_events
> also for following case:
> 
>         count = atomic_inc_return(&nr_callchain_events);
>         if (WARN_ON_ONCE(count < 1)) {
>                 err = -EINVAL;
>                 goto exit;
>         }
> 
> seems like it screws the count

I'm not sure what you mean here. You mean that it could be negative when the dec is done
outside the lock?

> 
> jirka


  reply	other threads:[~2013-08-01 13:28 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-23  0:30 [PATCH 0/8] perf: Finer grained full dynticks handling Frederic Weisbecker
2013-07-23  0:30 ` [PATCH 1/8] perf: Fix branch stack refcount leak on callchain init failure Frederic Weisbecker
2013-07-31  8:55   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
2013-07-23  0:31 ` [PATCH 2/8] perf: Sanitize get_callchain_buffer() Frederic Weisbecker
2013-07-31  8:56   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
2013-08-01 13:01   ` [PATCH 2/8] " Jiri Olsa
2013-08-01 13:28     ` Frederic Weisbecker [this message]
2013-08-01 13:32       ` Jiri Olsa
2013-08-01 13:49         ` Frederic Weisbecker
2013-08-01 13:54           ` Jiri Olsa
2013-08-01 13:57             ` Frederic Weisbecker
2013-08-01 13:29   ` Jiri Olsa
2013-08-01 13:42     ` Frederic Weisbecker
2013-08-01 13:51       ` Jiri Olsa
2013-08-01 14:30         ` Frederic Weisbecker
2013-07-23  0:31 ` [PATCH 3/8] perf: Gather event accounting code Frederic Weisbecker
2013-07-31  8:56   ` [tip:perf/core] perf: Factor out event accounting code to account_event()/__free_event() tip-bot for Frederic Weisbecker
2013-08-01 13:13   ` [PATCH 3/8] perf: Gather event accounting code Jiri Olsa
2013-08-01 13:30     ` Frederic Weisbecker
2013-07-23  0:31 ` [PATCH 4/8] perf: Split per cpu " Frederic Weisbecker
2013-07-31  8:56   ` [tip:perf/core] perf: Split the per-cpu accounting part of the " tip-bot for Frederic Weisbecker
2013-07-23  0:31 ` [PATCH 5/8] perf: Migrate per cpu event accounting Frederic Weisbecker
2013-07-31  8:56   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
2013-07-23  0:31 ` [PATCH 6/8] perf: Account freq events per cpu Frederic Weisbecker
2013-07-31  8:56   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
2013-08-01 12:46   ` [PATCH 6/8] " Jiri Olsa
2013-08-01 12:48     ` Jiri Olsa
2013-08-01 13:31     ` Peter Zijlstra
2013-08-01 13:35       ` Peter Zijlstra
2013-08-01 13:39       ` Jiri Olsa
2013-08-01 13:56         ` Peter Zijlstra
2013-08-01 13:55       ` Frederic Weisbecker
2013-08-01 14:03         ` Peter Zijlstra
2013-08-01 14:06           ` Peter Zijlstra
2013-08-01 14:21             ` Frederic Weisbecker
2013-08-01 14:40               ` Peter Zijlstra
2013-08-02 16:25                 ` Frederic Weisbecker
2013-08-01 14:19           ` Frederic Weisbecker
2013-07-23  0:31 ` [PATCH 7/8] perf: Finer grained full dynticks kick Frederic Weisbecker
2013-07-31  8:56   ` [tip:perf/core] perf: Implement finer " tip-bot for Frederic Weisbecker
2013-07-23  0:31 ` [PATCH 8/8] watchdog: Remove hack to make full dynticks working Frederic Weisbecker
2013-07-23 12:33   ` Don Zickus
2013-07-23 12:44     ` Frederic Weisbecker
2013-07-23 12:45     ` Peter Zijlstra
2013-07-31  8:57   ` [tip:perf/core] watchdog: Make it work under full dynticks tip-bot for Frederic Weisbecker
2013-07-25  9:59 ` [PATCH 0/8] perf: Finer grained full dynticks handling Peter Zijlstra
2013-07-25 14:02   ` Frederic Weisbecker
2013-07-25 16:29     ` Peter Zijlstra
2013-07-25 20:07       ` Frederic Weisbecker

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=20130801132833.GA431@somewhere \
    --to=fweisbec@gmail.com \
    --cc=acme@redhat.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).