Commit a00d28cb authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

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: default avatarAdrian Hunter <adrian.hunter@intel.com>
Tested-by: default avatarJiri 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0ae617be
...@@ -976,6 +976,23 @@ static int validate_kcore_modules(const char *kallsyms_filename, ...@@ -976,6 +976,23 @@ static int validate_kcore_modules(const char *kallsyms_filename,
return 0; 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 kcore_mapfn_data {
struct dso *dso; struct dso *dso;
enum map_type type; enum map_type type;
...@@ -1019,8 +1036,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map, ...@@ -1019,8 +1036,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
kallsyms_filename)) kallsyms_filename))
return -EINVAL; return -EINVAL;
/* All modules must be present at their original addresses */ /* Modules and kernel must be present at their original addresses */
if (validate_kcore_modules(kallsyms_filename, map)) if (validate_kcore_addresses(kallsyms_filename, map))
return -EINVAL; return -EINVAL;
md.dso = dso; md.dso = dso;
...@@ -1424,7 +1441,7 @@ static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz) ...@@ -1424,7 +1441,7 @@ static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
continue; continue;
scnprintf(kallsyms_filename, sizeof(kallsyms_filename), scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
"%s/%s/kallsyms", dir, dent->d_name); "%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); strlcpy(dir, kallsyms_filename, dir_sz);
ret = 0; ret = 0;
break; break;
...@@ -1479,7 +1496,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map) ...@@ -1479,7 +1496,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
if (fd != -1) { if (fd != -1) {
close(fd); close(fd);
/* If module maps match go with /proc/kallsyms */ /* 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; goto proc_kallsyms;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment