LKML Archive on lore.kernel.org
 help / color / Atom feed
From: David Miller <davem@davemloft.net>
To: acme@ghostprotocols.net
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/5] perf: Catch and handle out-of-date hist entry maps.
Date: Tue, 27 Mar 2012 03:14:18 -0400 (EDT)
Message-ID: <20120327.031418.1220315351537060808.davem@davemloft.net> (raw)
In-Reply-To: <20120325.162818.1509258059090497224.davem@davemloft.net>

From: David Miller <davem@davemloft.net>
Date: Sun, 25 Mar 2012 16:28:18 -0400 (EDT)

> @@ -253,6 +253,15 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
>  		if (!cmp) {
>  			he->period += period;
>  			++he->nr_events;
> +
> +			/* If the map of an existing hist_entry has
> +			 * become out-of-date due to an exec() or
> +			 * similar, update it.  Otherwise we will
> +			 * mis-adjust symbol addresses when computing
> +			 * the history counter to increment.
> +			 */
> +			if (he->ms.map != entry->ms.map)
> +				he->ms.map = entry->ms.map;
>  			goto out;

This unfortunately has a bug, when we hook up a map to a hist_entry we
must mark it referenced.  Otherwise it can get freed up prematurely.

Here's a new version of this patch:

--------------------
perf: Catch and handle out-of-date hist entry maps.

When a process exec()'s, all the maps are retired, but we keep the
hist entries around which hold references to those outdated maps.

If the same library gets mapped in for which we have hist entries, a
new map will be created.  But when we take a perf entry hit within
that map, we'll find the existing hist entry with the older map.

This causes symbol translations to be done incorrectly.  For example,
the perf entry processing will lookup the correct uptodate map entry
and use that to calculate the symbol and DSO relative address.  But
later when we update the histogram we'll translate the address using
the outdated map file instead leading to conditions such as
out-of-range offsets in symbol__inc_addr_samples() which now has an
assertion for this situation.

Therefore, update the map of the hist_entry dynamically at
lookup/creation time.

Signed-off-by: David S. Miller <davem@davemloft.net>
---
 tools/perf/util/hist.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 3dc99a9..bf0f259 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -253,6 +253,18 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
 		if (!cmp) {
 			he->period += period;
 			++he->nr_events;
+
+			/* If the map of an existing hist_entry has
+			 * become out-of-date due to an exec() or
+			 * similar, update it.  Otherwise we will
+			 * mis-adjust symbol addresses when computing
+			 * the history counter to increment.
+			 */
+			if (he->ms.map != entry->ms.map) {
+				he->ms.map = entry->ms.map;
+				if (he->ms.map)
+					he->ms.map->referenced = true;
+			}
 			goto out;
 		}
 
-- 
1.7.9.1


  reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-25 20:28 David Miller
2012-03-27  7:14 ` David Miller [this message]
2012-04-13 18:03   ` [tip:perf/core] perf hists: " tip-bot for David Miller

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=20120327.031418.1220315351537060808.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git