From: Jiri Olsa <jolsa@redhat.com>
To: Janne Huttunen <janne.huttunen@nokia.com>
Cc: linux-kernel@vger.kernel.org,
"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
"Andi Kleen" <ak@linux.intel.com>,
"Arnaldo Carvalho de Melo" <acme@kernel.org>,
"Jaroslav Škarvada" <jskarvad@redhat.com>,
"Namhyung Kim" <namhyung@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>
Subject: Re: [PATCH] perf script python: Fix dict reference counting
Date: Mon, 9 Jul 2018 11:41:59 +0200 [thread overview]
Message-ID: <20180709094159.GA7615@krava> (raw)
In-Reply-To: <1531128333.2711.19.camel@nokia.com>
On Mon, Jul 09, 2018 at 12:25:33PM +0300, Janne Huttunen wrote:
> On Sun, 2018-07-08 at 13:17 +0200, Jiri Olsa wrote:
> > On Fri, Jul 06, 2018 at 09:53:44AM +0300, Janne Huttunen wrote:
> > >
> > > The dictionaries are attached to the parameter tuple that steals the
> > > references. The code should not decrement the reference counters
> > > explicitly. Otherwise the objects might be released while they are
> > > still in use which may cause perf crashes, assertions or just plain
> > > weird behavior like unexpected data changes in stored objects.
> > >
> > > Signed-off-by: Janne Huttunen <janne.huttunen@nokia.com>
> > > ---
> > > tools/perf/util/scripting-engines/trace-event-python.c | 8 ++------
> > > 1 file changed, 2 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> > > index 46e9e19..60fce44 100644
> > > --- a/tools/perf/util/scripting-engines/trace-event-python.c
> > > +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> > > @@ -908,14 +908,11 @@ static void python_process_tracepoint(struct perf_sample *sample,
> > > if (_PyTuple_Resize(&t, n) == -1)
> > > Py_FatalError("error resizing Python tuple");
> > >
> > > - if (!dict) {
> > > + if (!dict)
> > > call_object(handler, t, handler_name);
> > > - } else {
> > > + else
> > > call_object(handler, t, default_handler_name);
> > > - Py_DECREF(dict);
> > > - }
> > >
> > > - Py_XDECREF(all_entries_dict);
> > > Py_DECREF(t);
> > > }
> > >
> > > @@ -1235,7 +1232,6 @@ static void python_process_general_event(struct perf_sample *sample,
> > >
> > > call_object(handler, t, handler_name);
> > >
> > > - Py_DECREF(dict);
> > > Py_DECREF(t);
> >
> > so the dict is released when the tuple is released?
>
> To the best of my knowledge, yes.
>
> As far as I can see, there is only a single reference to each dict
> and according to the Python documentation PyTuple_SetItem() "steals"
> the reference passed to it. If so, afterwards the tuple owns the
> only reference to the dict(s) and should take care of releasing
> them when appropriate.
>
> I even built libpython with reference debugging enabled and when I
> run perf without the fix I get this:
>
> Fatal Python error: Objects/tupleobject.c:238 object at 0x7f10f2041b40 has negative ref count -1
> Aborted (core dumped)
>
> With the fix I get no errors.
>
ok, please include and mention that crash in the changelog
thanks,
jirka
next prev parent reply other threads:[~2018-07-09 9:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-06 6:53 [PATCH] perf script python: Fix dict reference counting Janne Huttunen
2018-07-08 11:17 ` Jiri Olsa
2018-07-09 9:25 ` Janne Huttunen
2018-07-09 9:41 ` Jiri Olsa [this message]
2018-07-09 10:59 ` [PATCH v2] " Janne Huttunen
2018-07-09 14:55 ` Jiri Olsa
2018-07-11 8:14 ` Namhyung Kim
2018-07-12 14:04 ` [tip:perf/urgent] " tip-bot for Janne Huttunen
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=20180709094159.GA7615@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=janne.huttunen@nokia.com \
--cc=jskarvad@redhat.com \
--cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.