* [GIT PULL 0/2] perf/urgent fixes for 2.6.35
@ 2010-06-17 20:36 Arnaldo Carvalho de Melo
2010-06-17 20:36 ` [PATCH 1/2] perf session: Remove threads from tree on PERF_RECORD_EXIT Arnaldo Carvalho de Melo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-06-17 20:36 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David S. Miller,
Frédéric Weisbecker, Ian Munsie, Ingo Molnar,
Mike Galbraith, Paul Mackerras, Peter Zijlstra, Stephane Eranian,
Tom Zanussi
Hi Ingo,
Please pull from:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 perf/urgent
Regards,
- Arnaldo
Arnaldo Carvalho de Melo (1):
perf session: Remove threads from tree on PERF_RECORD_EXIT
Ian Munsie (1):
perf record: prevent kill(0, SIGTERM);
tools/perf/builtin-record.c | 2 +-
tools/perf/util/event.c | 4 +++-
tools/perf/util/session.c | 11 +++++++++++
tools/perf/util/session.h | 2 ++
tools/perf/util/thread.h | 5 ++++-
5 files changed, 21 insertions(+), 3 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] perf session: Remove threads from tree on PERF_RECORD_EXIT
2010-06-17 20:36 [GIT PULL 0/2] perf/urgent fixes for 2.6.35 Arnaldo Carvalho de Melo
@ 2010-06-17 20:36 ` Arnaldo Carvalho de Melo
2010-06-17 20:36 ` [PATCH 2/2] perf record: prevent kill(0, SIGTERM); Arnaldo Carvalho de Melo
2010-06-18 8:51 ` [GIT PULL 0/2] perf/urgent fixes for 2.6.35 Ingo Molnar
2 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-06-17 20:36 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David S. Miller,
Frédéric Weisbecker, Mike Galbraith, Paul Mackerras,
Peter Zijlstra, Stephane Eranian, Tom Zanussi
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Move them to a session->dead_threads list just like we do with maps that
are replaced, because we may have hist_entries pointing to them.
This fixes a bug when inserting maps for a new thread that reused the
TID, mixing maps for two different threads, causing an endless loop.
The code for insering maps should be made more robust but for .35 this
is the minimalistic patch.
Reported-by: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/event.c | 4 +++-
tools/perf/util/session.c | 11 +++++++++++
tools/perf/util/session.h | 2 ++
tools/perf/util/thread.h | 5 ++++-
4 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 1f08f00..2fbf6a4 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -538,8 +538,10 @@ int event__process_task(event_t *self, struct perf_session *session)
dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid,
self->fork.ppid, self->fork.ptid);
- if (self->header.type == PERF_RECORD_EXIT)
+ if (self->header.type == PERF_RECORD_EXIT) {
+ perf_session__remove_thread(session, thread);
return 0;
+ }
if (thread == NULL || parent == NULL ||
thread__fork(thread, parent) < 0) {
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8f83a18..c422cd6 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -90,6 +90,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
memcpy(self->filename, filename, len);
self->threads = RB_ROOT;
+ INIT_LIST_HEAD(&self->dead_threads);
self->hists_tree = RB_ROOT;
self->last_match = NULL;
self->mmap_window = 32;
@@ -131,6 +132,16 @@ void perf_session__delete(struct perf_session *self)
free(self);
}
+void perf_session__remove_thread(struct perf_session *self, struct thread *th)
+{
+ rb_erase(&th->rb_node, &self->threads);
+ /*
+ * We may have references to this thread, for instance in some hist_entry
+ * instances, so just move them to a separate list.
+ */
+ list_add_tail(&th->node, &self->dead_threads);
+}
+
static bool symbol__match_parent_regex(struct symbol *sym)
{
if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0))
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 55c6881..9fa0fc2 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -26,6 +26,7 @@ struct perf_session {
unsigned long size;
unsigned long mmap_window;
struct rb_root threads;
+ struct list_head dead_threads;
struct thread *last_match;
struct machine host_machine;
struct rb_root machines;
@@ -99,6 +100,7 @@ int perf_session__create_kernel_maps(struct perf_session *self);
int do_read(int fd, void *buf, size_t size);
void perf_session__update_sample_type(struct perf_session *self);
+void perf_session__remove_thread(struct perf_session *self, struct thread *th);
static inline
struct machine *perf_session__find_host_machine(struct perf_session *self)
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 1dfd9ff..ee6bbcf 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -6,7 +6,10 @@
#include "symbol.h"
struct thread {
- struct rb_node rb_node;
+ union {
+ struct rb_node rb_node;
+ struct list_head node;
+ };
struct map_groups mg;
pid_t pid;
char shortname[3];
--
1.6.2.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] perf record: prevent kill(0, SIGTERM);
2010-06-17 20:36 [GIT PULL 0/2] perf/urgent fixes for 2.6.35 Arnaldo Carvalho de Melo
2010-06-17 20:36 ` [PATCH 1/2] perf session: Remove threads from tree on PERF_RECORD_EXIT Arnaldo Carvalho de Melo
@ 2010-06-17 20:36 ` Arnaldo Carvalho de Melo
2010-06-18 8:51 ` [GIT PULL 0/2] perf/urgent fixes for 2.6.35 Ingo Molnar
2 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-06-17 20:36 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Ian Munsie, David S. Miller,
Frédéric Weisbecker, Ingo Molnar, Paul Mackerras,
Peter Zijlstra, Tom Zanussi, Arnaldo Carvalho de Melo
From: Ian Munsie <imunsie@au1.ibm.com>
At exit, perf record will kill the process it was profiling by sending a
SIGTERM to child_pid (if it had been initialised), but in certain situations
child_pid may be 0 and perf would mistakenly kill more processes than intended.
child_pid is set to the return of fork() to either 0 or the pid of the child.
Ordinarily this would not present an issue as the child calls execvp to spawn
the process to be profiled and would therefore never run it's sig_atexit and
never attempt to kill pid 0.
However, if a nonexistant binary had been passed in to perf record the call to
execvp would fail and child_pid would be left set to 0. The child would then
exit and it's atexit handler, finding that child_pid was initialised to 0,
would call kill(0, SIGTERM), resulting in every process within it's process
group being killed.
In the case that perf was being run directly from the shell this typically
would not be an issue as the shell isolates the process. However, if perf was
being called from another program it could kill unexpected processes, which may
even include X.
This patch changes the logic of the test for whether child_pid was initialised
to only consider positive pids as valid, thereby never attempting to kill pid
0.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <1276072680-17378-1-git-send-email-imunsie@au1.ibm.com>
Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-record.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index dc3435e..711745f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -193,7 +193,7 @@ static void sig_handler(int sig)
static void sig_atexit(void)
{
- if (child_pid != -1)
+ if (child_pid > 0)
kill(child_pid, SIGTERM);
if (signr == -1)
--
1.6.2.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [GIT PULL 0/2] perf/urgent fixes for 2.6.35
2010-06-17 20:36 [GIT PULL 0/2] perf/urgent fixes for 2.6.35 Arnaldo Carvalho de Melo
2010-06-17 20:36 ` [PATCH 1/2] perf session: Remove threads from tree on PERF_RECORD_EXIT Arnaldo Carvalho de Melo
2010-06-17 20:36 ` [PATCH 2/2] perf record: prevent kill(0, SIGTERM); Arnaldo Carvalho de Melo
@ 2010-06-18 8:51 ` Ingo Molnar
2 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2010-06-18 8:51 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: linux-kernel, David S. Miller, Fr??d??ric Weisbecker, Ian Munsie,
Mike Galbraith, Paul Mackerras, Peter Zijlstra, Stephane Eranian,
Tom Zanussi
* Arnaldo Carvalho de Melo <acme@infradead.org> wrote:
> Hi Ingo,
>
> Please pull from:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 perf/urgent
>
> Regards,
>
> - Arnaldo
>
> Arnaldo Carvalho de Melo (1):
> perf session: Remove threads from tree on PERF_RECORD_EXIT
>
> Ian Munsie (1):
> perf record: prevent kill(0, SIGTERM);
>
> tools/perf/builtin-record.c | 2 +-
> tools/perf/util/event.c | 4 +++-
> tools/perf/util/session.c | 11 +++++++++++
> tools/perf/util/session.h | 2 ++
> tools/perf/util/thread.h | 5 ++++-
> 5 files changed, 21 insertions(+), 3 deletions(-)
Pulled, thanks Arnaldo!
Ingo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-06-18 8:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-17 20:36 [GIT PULL 0/2] perf/urgent fixes for 2.6.35 Arnaldo Carvalho de Melo
2010-06-17 20:36 ` [PATCH 1/2] perf session: Remove threads from tree on PERF_RECORD_EXIT Arnaldo Carvalho de Melo
2010-06-17 20:36 ` [PATCH 2/2] perf record: prevent kill(0, SIGTERM); Arnaldo Carvalho de Melo
2010-06-18 8:51 ` [GIT PULL 0/2] perf/urgent fixes for 2.6.35 Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®