linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	kernel-team@lge.com, Masami Hiramatsu <mhiramat@kernel.org>,
	Andi Kleen <andi@firstfloor.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Wang Nan <wangnan0@huawei.com>
Subject: Re: [PATCH/RFC 5/9] perf symbols: Fixup the end address of kernel map properly
Date: Sun, 25 Jun 2017 23:34:16 +0900	[thread overview]
Message-ID: <20170625143416.GD12099@danjae.aot.lge.com> (raw)
In-Reply-To: <20170623142725.GD4622@kernel.org>

On Fri, Jun 23, 2017 at 11:27:25AM -0300, Arnaldo Carvalho de Melo wrote:
> Em Fri, Jun 23, 2017 at 02:48:23PM +0900, Namhyung Kim escreveu:
> > When /proc/kallsyms is used for kernel address, addresses in module can
> > be changed when the module is reloaded.  So if one did perf record with
> > some module and then for some reason reload the module.  Then perf
> > report might see a different address for the module and the output can
> > show incorrect symbols.
> 
> If we, as mentioned in another message, make sure that no module reload
> is performed while perf record is running, and then refuse to use
> kallsyms if the buildid for the running module is different from the one
> in the perf.data build id header, then this is solved, no?

No.  This can happen when a (same) module is reload at a different
address.  Even if we refuse the symbols of the module in
dso__split_kallsyms(), the last symbols in the kernel dso was already
fixed up with a different address and then the map end address would
be invalid.  This can make the module map overlapped to the kernel
map, so invisible when it finds maps for samples.

Thanks,
Namhyung


>  
> > For example, let a module XXX was loaded at 0xffffffff8a000000, the
> > /proc/kallsyms might show following:
> > 
> >   ...
> >   0xffffffff81234560 t last_symbol_in_vmlinux
> >   0xffffffff8a000000 t first_symbol_in_XXX
> >   ...
> > 
> > As kallsyms fixs up the symbol and map address by using next address,
> > the end address of last_symbol and kernel map would be start address of
> > XXX (0xffffffff8a000000).  And samples in 0xffffffff8a001234 can be
> > found in a map for XXX module.
> > 
> > But later, XXX was reloaded at 0xffffffff8a007000, slightly higher than
> > before.  Now reading /proc/kallsyms tells that the end address of last
> > symbol would be 0xfffffff8a007000 and so kernel map is same.  Now
> > samples in 0xffffffff8a001234 - formerly in the XXX module - would go to
> > the kernel map and show no symbols.
> > 
> > In this case, perf can know the address of map of XXX from mmap event in
> > perf.data so it can adjust kernel map address using the address of XXX
> > map.  To do that, replace map__fixup_end() by __map_groups__fixup_end().
> > This still have incorrect end address of last symbol in the kernel map
> > but it's ok since samples in that address wouldn't go to the kernel map
> > anyway.
> > 
> > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > Cc: Wang Nan <wangnan0@huawei.com>
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > ---
> >  tools/perf/util/symbol.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> > index 74078ba595b3..ce79a51f25bf 100644
> > --- a/tools/perf/util/symbol.c
> > +++ b/tools/perf/util/symbol.c
> > @@ -1832,7 +1832,7 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map)
> >  		dso->binary_type = DSO_BINARY_TYPE__KALLSYMS;
> >  		dso__set_long_name(dso, DSO__NAME_KALLSYMS, false);
> >  		map__fixup_start(map);
> > -		map__fixup_end(map);
> > +		__map_groups__fixup_end(map->groups, map->type);
> >  	}
> >  
> >  	return err;
> > @@ -1880,7 +1880,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)
> >  		machine__mmap_name(machine, path, sizeof(path));
> >  		dso__set_long_name(dso, strdup(path), true);
> >  		map__fixup_start(map);
> > -		map__fixup_end(map);
> > +		__map_groups__fixup_end(map->groups, map->type);
> >  	}
> >  
> >  	return err;
> > -- 
> > 2.13.1

  reply	other threads:[~2017-06-25 14:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23  5:48 [PATCHSET/RFC 0/9] perf tools: Support out-of-tree modules Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 1/9] perf symbols: Use absolute address to fixup map address Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 2/9] perf tools: Remove duplicate code Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 3/9] perf symbols: Discard symbols in kallsyms for loaded modules Namhyung Kim
2017-06-23 13:51   ` Arnaldo Carvalho de Melo
2017-06-25 13:47     ` Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 4/9] perf symbols: Load kernel module symbols ASAP Namhyung Kim
2017-06-23 14:26   ` Arnaldo Carvalho de Melo
2017-06-25 14:17     ` Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 5/9] perf symbols: Fixup the end address of kernel map properly Namhyung Kim
2017-06-23 14:27   ` Arnaldo Carvalho de Melo
2017-06-25 14:34     ` Namhyung Kim [this message]
2017-06-23  5:48 ` [PATCH/RFC 6/9] perf symbols: Use already loaded module dso when loading kcore Namhyung Kim
2017-06-23 13:55   ` Arnaldo Carvalho de Melo
2017-06-25 13:54     ` Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 7/9] perf tools: Add symbol_conf.use_kcore Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 8/9] perf record: Not use kcore by default Namhyung Kim
2017-06-23  5:48 ` [PATCH/RFC 9/9] perf record: Add --module-dir option Namhyung Kim
2017-06-23 14:45   ` Arnaldo Carvalho de Melo
2017-06-25 14:43     ` Namhyung Kim

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=20170625143416.GD12099@danjae.aot.lge.com \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=andi@firstfloor.org \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=wangnan0@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).