All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Adrian Hunter <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org,
	eranian@google.com, paulus@samba.org, mingo@redhat.com,
	hpa@zytor.com, mingo@kernel.org, a.p.zijlstra@chello.nl,
	efault@gmx.de, namhyung@gmail.com, jolsa@redhat.com,
	fweisbec@gmail.com, adrian.hunter@intel.com, dsahern@gmail.com,
	tglx@linutronix.de
Subject: [tip:perf/urgent] perf symbols: Prevent the use of kcore if the kernel has moved
Date: Sun, 2 Feb 2014 00:56:05 -0800	[thread overview]
Message-ID: <tip-a00d28cb72d3629c6481fe21ba6c6b4f96caed49@git.kernel.org> (raw)
In-Reply-To: <1391004884-10334-7-git-send-email-adrian.hunter@intel.com>

Commit-ID:  a00d28cb72d3629c6481fe21ba6c6b4f96caed49
Gitweb:     http://git.kernel.org/tip/a00d28cb72d3629c6481fe21ba6c6b4f96caed49
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Wed, 29 Jan 2014 16:14:41 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 31 Jan 2014 17:21:51 -0300

perf symbols: Prevent the use of kcore if the kernel has moved

Use of kcore is predicated upon it matching the recorded data.  If the
kernel has been relocated at boot time (i.e. since the data was
recorded) then do not use kcore.

Note that it is possible to make a copy of kcore at the time the data is
recorded using 'perf buildid-cache'.  Then the perf tools will use the
copy because it does match the data.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1391004884-10334-7-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/symbol.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 39ce9ad..4ac1f87 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -976,6 +976,23 @@ static int validate_kcore_modules(const char *kallsyms_filename,
 	return 0;
 }
 
+static int validate_kcore_addresses(const char *kallsyms_filename,
+				    struct map *map)
+{
+	struct kmap *kmap = map__kmap(map);
+
+	if (kmap->ref_reloc_sym && kmap->ref_reloc_sym->name) {
+		u64 start;
+
+		start = kallsyms__get_function_start(kallsyms_filename,
+						     kmap->ref_reloc_sym->name);
+		if (start != kmap->ref_reloc_sym->addr)
+			return -EINVAL;
+	}
+
+	return validate_kcore_modules(kallsyms_filename, map);
+}
+
 struct kcore_mapfn_data {
 	struct dso *dso;
 	enum map_type type;
@@ -1019,8 +1036,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 					     kallsyms_filename))
 		return -EINVAL;
 
-	/* All modules must be present at their original addresses */
-	if (validate_kcore_modules(kallsyms_filename, map))
+	/* Modules and kernel must be present at their original addresses */
+	if (validate_kcore_addresses(kallsyms_filename, map))
 		return -EINVAL;
 
 	md.dso = dso;
@@ -1424,7 +1441,7 @@ static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
 			continue;
 		scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
 			  "%s/%s/kallsyms", dir, dent->d_name);
-		if (!validate_kcore_modules(kallsyms_filename, map)) {
+		if (!validate_kcore_addresses(kallsyms_filename, map)) {
 			strlcpy(dir, kallsyms_filename, dir_sz);
 			ret = 0;
 			break;
@@ -1479,7 +1496,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
 		if (fd != -1) {
 			close(fd);
 			/* If module maps match go with /proc/kallsyms */
-			if (!validate_kcore_modules("/proc/kallsyms", map))
+			if (!validate_kcore_addresses("/proc/kallsyms", map))
 				goto proc_kallsyms;
 		}
 

  reply	other threads:[~2014-02-02  8:56 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-29 14:14 [PATCH V2 0/9] perf tools: kaslr fixes Adrian Hunter
2014-01-29 14:14 ` [PATCH V2 1/9] perf tools: Fix symbol annotation for relocated kernel Adrian Hunter
2014-01-29 18:57   ` Arnaldo Carvalho de Melo
2014-01-30  7:20     ` Adrian Hunter
2014-01-30  8:59       ` Ingo Molnar
2014-01-30  9:21         ` Adrian Hunter
2014-01-30  9:20           ` Ingo Molnar
2014-01-30 18:08             ` Arnaldo Carvalho de Melo
2014-01-30 18:12               ` Arnaldo Carvalho de Melo
2014-01-30 18:15                 ` Arnaldo Carvalho de Melo
2014-01-30 20:10                   ` Arnaldo Carvalho de Melo
2014-02-02  8:55   ` [tip:perf/urgent] perf symbols: " tip-bot for Adrian Hunter
2014-01-29 14:14 ` [PATCH V2 2/9] perf tools: Add kallsyms__get_function_start() Adrian Hunter
2014-02-02  8:55   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2014-01-29 14:14 ` [PATCH V2 3/9] perf tools: Add machine__get_kallsyms_filename() Adrian Hunter
2014-02-02  8:55   ` [tip:perf/urgent] perf machine: " tip-bot for Adrian Hunter
2014-01-29 14:14 ` [PATCH V2 4/9] perf tools: Set up ref_reloc_sym in machine__create_kernel_maps() Adrian Hunter
2014-02-02  8:55   ` [tip:perf/urgent] perf machine: " tip-bot for Adrian Hunter
2014-01-29 14:14 ` [PATCH V2 5/9] perf record: Get ref_reloc_sym from kernel map Adrian Hunter
2014-02-02  8:55   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2014-01-29 14:14 ` [PATCH V2 6/9] perf tools: Prevent the use of kcore if the kernel has moved Adrian Hunter
2014-02-02  8:56   ` tip-bot for Adrian Hunter [this message]
2014-01-29 14:14 ` [PATCH V2 7/9] perf tools: Test does not need to set up ref_reloc_sym Adrian Hunter
2014-02-02  8:56   ` [tip:perf/urgent] perf tests: No " tip-bot for Adrian Hunter
2014-01-29 14:14 ` [PATCH V2 8/9] perf tools: Adjust kallsyms for relocated kernel Adrian Hunter
2014-01-29 19:08   ` Arnaldo Carvalho de Melo
2014-01-30  8:10     ` Adrian Hunter
2014-01-31 18:21       ` Arnaldo Carvalho de Melo
2014-02-02  8:56   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2014-01-29 14:14 ` [PATCH V2 9/9] perf buildid-cache: Check relocation when checking for existing kcore Adrian Hunter
2014-01-29 19:14   ` Arnaldo Carvalho de Melo
2014-01-30  9:34     ` Adrian Hunter
2014-01-30 14:18       ` Arnaldo Carvalho de Melo
2014-01-30 16:35         ` Adrian Hunter
2014-02-02  8:56   ` [tip:perf/urgent] " tip-bot for Adrian Hunter

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=tip-a00d28cb72d3629c6481fe21ba6c6b4f96caed49@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=efault@gmx.de \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    /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.