* [PATCH 1/4] perf evlist: Return first evsel for non-sample event on old kernel
2012-03-01 17:25 [GIT PULL 0/4] perf/urgent fixes Arnaldo Carvalho de Melo
@ 2012-03-01 17:25 ` Arnaldo Carvalho de Melo
2012-03-01 17:25 ` [PATCH 2/4] perf probe: Ensure offset provided is not greater than function length Arnaldo Carvalho de Melo
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-03-01 17:25 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Paul Mackerras, Peter Zijlstra,
Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
On old kernels that don't support sample_id_all feature,
perf_evlist__id2evsel() returns NULL for non-sampling events.
This breaks perf top when multiple events are given on command line. Fix
it by using first evsel in the evlist. This will also prevent getting
the same (potential) problem in such new tool/ old kernel combo.
Suggested-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1329702447-25045-1-git-send-email-namhyung.kim@lge.com
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/evlist.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 3f16e08..ea32a06 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -349,6 +349,10 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
hlist_for_each_entry(sid, pos, head, node)
if (sid->id == id)
return sid->evsel;
+
+ if (!perf_evlist__sample_id_all(evlist))
+ return list_entry(evlist->entries.next, struct perf_evsel, node);
+
return NULL;
}
--
1.7.9.123.g65da0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] perf probe: Ensure offset provided is not greater than function length
2012-03-01 17:25 [GIT PULL 0/4] perf/urgent fixes Arnaldo Carvalho de Melo
2012-03-01 17:25 ` [PATCH 1/4] perf evlist: Return first evsel for non-sample event on old kernel Arnaldo Carvalho de Melo
@ 2012-03-01 17:25 ` Arnaldo Carvalho de Melo
2012-03-01 17:25 ` [PATCH 3/4] perf tools: Ensure comm string is properly terminated Arnaldo Carvalho de Melo
2012-03-01 17:25 ` [PATCH 4/4] perf probe: Ensure offset provided is not greater than function length without DWARF info too Arnaldo Carvalho de Melo
3 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-03-01 17:25 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Prashanth Nageshappa, Ananth N Mavinakayanahalli,
Srikar Dronamraju, Steven Rostedt, Andrew Morton, Jason Baron,
Masami Hiramatsu, Arnaldo Carvalho de Melo
From: Prashanth Nageshappa <prashanth@linux.vnet.ibm.com>
The perf probe command allows kprobe to be inserted at any offset from a
function start, which results in adding kprobes to unintended location.
Example: perf probe do_fork+10000 is allowed even though size of do_fork
is ~904.
This patch will ensure probe addition fails when the offset specified is
greater than size of the function.
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Link: http://lkml.kernel.org/r/4F473F33.4060409@linux.vnet.ibm.com
Signed-off-by: Prashanth Nageshappa <prashanth@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-finder.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 5d73262..74bd2e6 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -672,7 +672,7 @@ static int find_variable(Dwarf_Die *sc_die, struct probe_finder *pf)
static int convert_to_trace_point(Dwarf_Die *sp_die, Dwarf_Addr paddr,
bool retprobe, struct probe_trace_point *tp)
{
- Dwarf_Addr eaddr;
+ Dwarf_Addr eaddr, highaddr;
const char *name;
/* Copy the name of probe point */
@@ -683,6 +683,16 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dwarf_Addr paddr,
dwarf_diename(sp_die));
return -ENOENT;
}
+ if (dwarf_highpc(sp_die, &highaddr) != 0) {
+ pr_warning("Failed to get end address of %s\n",
+ dwarf_diename(sp_die));
+ return -ENOENT;
+ }
+ if (paddr > highaddr) {
+ pr_warning("Offset specified is greater than size of %s\n",
+ dwarf_diename(sp_die));
+ return -EINVAL;
+ }
tp->symbol = strdup(name);
if (tp->symbol == NULL)
return -ENOMEM;
--
1.7.9.123.g65da0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] perf tools: Ensure comm string is properly terminated
2012-03-01 17:25 [GIT PULL 0/4] perf/urgent fixes Arnaldo Carvalho de Melo
2012-03-01 17:25 ` [PATCH 1/4] perf evlist: Return first evsel for non-sample event on old kernel Arnaldo Carvalho de Melo
2012-03-01 17:25 ` [PATCH 2/4] perf probe: Ensure offset provided is not greater than function length Arnaldo Carvalho de Melo
@ 2012-03-01 17:25 ` Arnaldo Carvalho de Melo
2012-03-01 17:25 ` [PATCH 4/4] perf probe: Ensure offset provided is not greater than function length without DWARF info too Arnaldo Carvalho de Melo
3 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-03-01 17:25 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, David Ahern, Frederic Weisbecker, Paul Mackerras,
Peter Zijlstra, Thomas Gleixner, Arnaldo Carvalho de Melo
From: David Ahern <dsahern@gmail.com>
If threads in a multi-threaded process have names shorter than the main
thread the comm for the named threads is not properly terminated.
E.g., for the process 'namedthreads' where each thread is named noploop%d
where %d is the thread number:
Before:
perf script -f comm,tid,ip,sym,dso
noploop:4ads 21616 400a49 noploop (/tmp/namedthreads)
The 'ads' in the thread comm bleeds over from the process name.
After:
perf script -f comm,tid,ip,sym,dso
noploop:4 21616 400a49 noploop (/tmp/namedthreads)
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1330111898-68071-1-git-send-email-dsahern@gmail.com
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/event.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 2044324..2a6f33c 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -74,6 +74,7 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
if (size >= len)
size = len - 1;
memcpy(comm, name, size);
+ comm[size] = '\0';
} else if (memcmp(bf, "Tgid:", 5) == 0) {
char *tgids = bf + 5;
--
1.7.9.123.g65da0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] perf probe: Ensure offset provided is not greater than function length without DWARF info too
2012-03-01 17:25 [GIT PULL 0/4] perf/urgent fixes Arnaldo Carvalho de Melo
` (2 preceding siblings ...)
2012-03-01 17:25 ` [PATCH 3/4] perf tools: Ensure comm string is properly terminated Arnaldo Carvalho de Melo
@ 2012-03-01 17:25 ` Arnaldo Carvalho de Melo
3 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-03-01 17:25 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Prashanth Nageshappa, Ananth N Mavinakayanahalli,
Jason Baron, Masami Hiramatsu, Srikar Dronamraju, Steven Rostedt,
Andrew Morton, Arnaldo Carvalho de Melo
From: Prashanth Nageshappa <prashanth@linux.vnet.ibm.com>
The 'perf probe' command allows kprobe to be inserted at any offset from
a function start, which results in adding kprobes to unintended
location. (example: perf probe do_fork+10000 is allowed even though
size of do_fork is ~904).
My previous patch https://lkml.org/lkml/2012/2/24/42 addressed the case
where DWARF info was available for the kernel. This patch fixes the
case where perf probe is used on a kernel without debuginfo available.
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/4F4C544D.1010909@linux.vnet.ibm.com
Signed-off-by: Prashanth Nageshappa <prashanth@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 29cb654..e33554a 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1867,6 +1867,12 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
tev->point.symbol);
ret = -ENOENT;
goto error;
+ } else if (tev->point.offset > sym->end - sym->start) {
+ pr_warning("Offset specified is greater than size of %s\n",
+ tev->point.symbol);
+ ret = -ENOENT;
+ goto error;
+
}
return 1;
--
1.7.9.123.g65da0
^ permalink raw reply related [flat|nested] 5+ messages in thread