Skip to contentSkip to conversation

perf/urgent fixes

GIT PULL New Jiri Olsa 2 participants 4 messages Jun 4, 2014 – Jun 5, 2014 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

hi Ingo,
please consider pulling

thanks,
jirka

The following changes since commit b69cf53640da2b86439596118cfa95233154ee76:

perf: Fix a race between ring_buffer_detach() and ring_buffer_attach() (2014-05-19 21:44:56 +0900)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git tags/perf-urgent-for-mingo

for you to fetch changes up to 082f96a93eb5ba9bf771518a0dda590624568e8e:

perf probe: Fix perf probe to find correct variable DIE (2014-06-04 14:49:20 +0200)

----------------------------------------------------------------
perf/urgent fixes:

. Fix perf probe to find correct variable DIE (Masami Hiramatsu)

. Fix a segfault in perf probe if asked for variable it doesn't find (Masami Hiramatsu)

----------------------------------------------------------------
Masami Hiramatsu (2):
perf probe: Fix a segfault if asked for variable it doesn't find perf probe: Fix perf probe to find correct variable DIE

 tools/perf/util/dwarf-aux.c    | 7 +++++--
 tools/perf/util/probe-finder.c | 4 ++--
 2 files changed, 7 insertions(+), 4 deletions(-)
author reviewer
#1 lore raw

PATCH 1/2 perf probe: Fix a segfault if asked for variable it doesn't find

From: Masami Hiramatsu <[email protected]>

Fix a segfault bug by asking for variable it doesn't find. Since the convert_variable() didn't handle error code returned from convert_variable_location(), it just passed an incomplete variable field and then a segfault was occurred when formatting the field.

This fixes that bug by handling success code correctly in convert_variable(). Other callers of convert_variable_location() are correctly checking the return code.

This bug was introduced by following commit. But another hidden erroneous error handling has been there previously (-ENOMEM case).

commit 3d918a12a1b3088ac16ff37fa52760639d6e2403

---
 tools/perf/util/probe-finder.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/probe-finder.c +2 -2
index 5627621..9d8eb26 100644
@@ -511,12 +511,12 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
 
 	ret = convert_variable_location(vr_die, pf->addr, pf->fb_ops,
 					&pf->sp_die, pf->tvar);
-	if (ret == -ENOENT)
+	if (ret == -ENOENT || ret == -EINVAL)
 		pr_err("Failed to find the location of %s at this address.\n"
 		       " Perhaps, it has been optimized out.\n", pf->pvar->var);
 	else if (ret == -ENOTSUP)
 		pr_err("Sorry, we don't support this variable location yet.\n");
-	else if (pf->pvar->field) {
+	else if (ret == 0 && pf->pvar->field) {
 		ret = convert_variable_fields(vr_die, pf->pvar->var,
 					      pf->pvar->field, &pf->tvar->ref,
 					      &die_mem);
Signature · 1 line
1.8.3.1
author reviewer
#2 lore raw

PATCH 2/2 perf probe: Fix perf probe to find correct variable DIE

In reply to Jiri Olsa

From: Masami Hiramatsu <[email protected]>

Fix perf probe to find correct variable DIE which has location or external instance by tracking down the lexical blocks.

Current die_find_variable() expects that the all variable DIEs which has DW_TAG_variable have a location. However, since recent dwarf information may have declaration variable DIEs at the entry of function (subprogram), die_find_variable() returns it.

To solve this problem, it must track down the DIE tree to find a DIE which has an actual location or a reference for external instance.

e.g. finding a DIE which origin is <0xdc73>;

<1><11496>: Abbrev Number: 95 (DW_TAG_subprogram)

    <11497>   DW_AT_abstract_origin: <0xdc42>
    <1149b>   DW_AT_low_pc      : 0x1850
[...]
 <2><114cc>: Abbrev Number: 119 (DW_TAG_variable) <- this is a declaration
    <114cd>   DW_AT_abstract_origin: <0xdc73>
 <2><114d1>: Abbrev Number: 119 (DW_TAG_variable)
[...]
 <3><115a7>: Abbrev Number: 105 (DW_TAG_lexical_block)
    <115a8>   DW_AT_ranges      : 0xaa0
 <4><115ac>: Abbrev Number: 96 (DW_TAG_variable) <- this has a location
    <115ad>   DW_AT_abstract_origin: <0xdc73>
    <115b1>   DW_AT_location    : 0x486c        (location list)
---
 tools/perf/util/dwarf-aux.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/dwarf-aux.c +5 -2
index 7defd77..cc66c40 100644
@@ -747,14 +747,17 @@ struct __find_variable_param {
 static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data)
 {
 	struct __find_variable_param *fvp = data;
+	Dwarf_Attribute attr;
 	int tag;
 
 	tag = dwarf_tag(die_mem);
 	if ((tag == DW_TAG_formal_parameter ||
 	     tag == DW_TAG_variable) &&
-	    die_compare_name(die_mem, fvp->name))
+	    die_compare_name(die_mem, fvp->name) &&
+	/* Does the DIE have location information or external instance? */
+	    (dwarf_attr(die_mem, DW_AT_external, &attr) ||
+	     dwarf_attr(die_mem, DW_AT_location, &attr)))
 		return DIE_FIND_CB_END;
-
 	if (dwarf_haspc(die_mem, fvp->addr))
 		return DIE_FIND_CB_CONTINUE;
 	else
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Jiri Olsa
Quoted 28 lines · Jiri Olsa

hi Ingo,
please consider pulling

thanks,
jirka

The following changes since commit b69cf53640da2b86439596118cfa95233154ee76:

perf: Fix a race between ring_buffer_detach() and ring_buffer_attach() (2014-05-19 21:44:56 +0900)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git tags/perf-urgent-for-mingo

for you to fetch changes up to 082f96a93eb5ba9bf771518a0dda590624568e8e:

perf probe: Fix perf probe to find correct variable DIE (2014-06-04 14:49:20 +0200)

----------------------------------------------------------------
perf/urgent fixes:

. Fix perf probe to find correct variable DIE (Masami Hiramatsu)

. Fix a segfault in perf probe if asked for variable it doesn't find (Masami Hiramatsu)

Quoted 8 lines

----------------------------------------------------------------
Masami Hiramatsu (2):
perf probe: Fix a segfault if asked for variable it doesn't find perf probe: Fix perf probe to find correct variable DIE

 tools/perf/util/dwarf-aux.c    | 7 +++++--
 tools/perf/util/probe-finder.c | 4 ++--
 2 files changed, 7 insertions(+), 4 deletions(-)

Pulled, thanks a lot Jiri!

Ingo