public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/3] x86: record relocation offset
@ 2009-12-30 23:26 H. Peter Anvin
  2009-12-30 23:41 ` James Bottomley
  0 siblings, 1 reply; 17+ messages in thread
From: H. Peter Anvin @ 2009-12-30 23:26 UTC (permalink / raw)
  To: James Bottomley, Arnaldo Carvalho de Melo
  Cc: Xiao Guangrong, Ingo Molnar, Thomas Gleixner, Peter Zijlstra,
	Frederic Weisbecker, Paul Mackerras, Frank Ch. Eigler,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2647 bytes --]

Modules are a completely separate thing - they are linked (not even just relocated) at insertion time, so they need to be tracked separately.

The statement that a _text-based relocation is insufficient is false.  The entire x86-32 monolithic kernel is relocated as a unit.  The x86-64 kernel, too, is relocated as a unit, but using the page tables, which means it always runs at the compile-time-selected virtual address.

    -hpa

"James Bottomley" <James.Bottomley@suse.de> wrote:

>On Wed, 2009-12-30 at 19:58 -0200, Arnaldo Carvalho de Melo wrote:
>> Em Wed, Dec 30, 2009 at 06:39:36PM -0200, Arnaldo Carvalho de Melo escreveu:
>> > Em Wed, Dec 30, 2009 at 11:45:30AM -0800, H. Peter Anvin escreveu:
>> > > The kernel already knows where it is loaded -- obviously, by sheer
>> > > necessity -- and knows how it was itself configured, and as such we
>> > > can do this calculation in C code without modifying boot_params or
>> > > the early bootstrap.
>> > 
>> > Problem is that at 'perf record' time we may not have access to the
>> > vmlinux file, and thus not be able to figure out the relocation applied
>> > in that boot.
>> > 
>> > Then, at a later time, and possibly on another machine, on another arch,
>> > we try to map back IPs to symbols, the /proc/kallsyms is completely
>> > unrelated and we now have a vmlinux unrelocated...
>> > 
>> > So we need a way to get the relocation applied at 'perf record' time and
>> > encode it in the perf.data header. Ideas about how to do that?
>> 
>> Well, I guess we could do the _stext trick again, storing its value,
>> taken from /proc/kallsyms, into the perf.data header, then figuring out
>> the relocation by looking at its value in the vmlinux symtab.
>
>So reading the thread, I think the problem only exists for x86 compiled
>as a relocateable kernel.
>
>> There were concerns in the past about relying on _stext, IIRC, James?
>
>Well, the original concerns were that _text relative relocation
>resolution only works for the core kernel, not for modules.
>Additionally, the kernel is in several sections, most notably init and
>runtime ... these may get loaded at different locations so _text
>relative symbol resolution won't work in init sections.
>
>Right at the moment, only x86 and ppc do a relocatable kernel, and, as I
>understand the process, the whole kernel image gets a relative offset
>applied, so all sections get the same offset.  Thus, for this case it
>looks like computing the offset from any known symbol would work
>(including _text).
>
>James
>
>
>
>

--
Sent from my mobile phone. Please excuse any lack of formatting.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: [PATCH 1/3] x86: record relocation offset
@ 2009-12-30 22:09 H. Peter Anvin
  0 siblings, 0 replies; 17+ messages in thread
From: H. Peter Anvin @ 2009-12-30 22:09 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Xiao Guangrong, Ingo Molnar, Thomas Gleixner, Peter Zijlstra,
	Frederic Weisbecker, Paul Mackerras, Frank Ch. Eigler,
	linux-kernel, James Bottomley

[-- Attachment #1: Type: text/plain, Size: 1911 bytes --]

Are we concerned about virtual or physical addresses, here?  I'm assuming virtual; in that case do note that we only actually relocate the kernel on 32 bits - on 64 bits the relocation is done at the page table level since we need the high map anyway.

On 32 bits one can compare any one symbol before and after relocation - it obviously doesn't matter which symbol as long as it is the same.  The kernel start will be given by _text or startup_32; if that feels too "fuzzy" we could of course add a specific kernel start symbol explicitly for that purpose.

"Arnaldo Carvalho de Melo" <acme@infradead.org> wrote:

>Em Wed, Dec 30, 2009 at 06:39:36PM -0200, Arnaldo Carvalho de Melo escreveu:
>> Em Wed, Dec 30, 2009 at 11:45:30AM -0800, H. Peter Anvin escreveu:
>> > The kernel already knows where it is loaded -- obviously, by sheer
>> > necessity -- and knows how it was itself configured, and as such we
>> > can do this calculation in C code without modifying boot_params or
>> > the early bootstrap.
>> 
>> Problem is that at 'perf record' time we may not have access to the
>> vmlinux file, and thus not be able to figure out the relocation applied
>> in that boot.
>> 
>> Then, at a later time, and possibly on another machine, on another arch,
>> we try to map back IPs to symbols, the /proc/kallsyms is completely
>> unrelated and we now have a vmlinux unrelocated...
>> 
>> So we need a way to get the relocation applied at 'perf record' time and
>> encode it in the perf.data header. Ideas about how to do that?
>
>Well, I guess we could do the _stext trick again, storing its value,
>taken from /proc/kallsyms, into the perf.data header, then figuring out
>the relocation by looking at its value in the vmlinux symtab.
>
>There were concerns in the past about relying on _stext, IIRC, James?
>
>- Arnaldo

--
Sent from my mobile phone. Please excuse any lack of formatting.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* [PATCH 0/3] perf_event: fix getting symbol error if kernel is relocatable
@ 2009-12-30  3:15 Xiao Guangrong
  2009-12-30  3:16 ` [PATCH 1/3] x86: record relocation offset Xiao Guangrong
  0 siblings, 1 reply; 17+ messages in thread
From: Xiao Guangrong @ 2009-12-30  3:15 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, H. Peter Anvin, Peter Zijlstra,
	Frederic Weisbecker, Paul Mackerras, LKML

Hi,

If the kernel is relocatable, perf tools can't get symbol
name correctly, See: http://lkml.org/lkml/2009/12/20/218

The purpose of this patchset is to fix this bug, and it base
on my previously patchset: http://lkml.org/lkml/2009/12/29/4
since it used 'inject' event

 arch/x86/boot/compressed/head_32.S |    2 ++
 arch/x86/boot/compressed/head_64.S |    3 +++
 arch/x86/include/asm/bootparam.h   |    3 ++-
 arch/x86/kernel/asm-offsets_32.c   |    1 +
 arch/x86/kernel/asm-offsets_64.c   |    1 +
 arch/x86/kernel/cpu/perf_event.c   |   10 ++++++++++
 include/linux/perf_event.h         |    1 +
 kernel/perf_event.c                |   23 +++++++++++++++++++++--
 tools/perf/builtin-record.c        |    3 +++
 tools/perf/util/session.c          |    6 ++++++
 tools/perf/util/symbol.c           |   13 +++++++++++++
 tools/perf/util/symbol.h           |    3 ++-
 12 files changed, 65 insertions(+), 4 deletions(-)


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2010-01-01  9:28 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-30 23:26 [PATCH 1/3] x86: record relocation offset H. Peter Anvin
2009-12-30 23:41 ` James Bottomley
2009-12-30 23:46   ` H. Peter Anvin
2009-12-31  0:30     ` Arnaldo Carvalho de Melo
2009-12-31  3:00       ` Xiao Guangrong
2009-12-31 10:36         ` Arnaldo Carvalho de Melo
2009-12-31 10:50           ` Xiao Guangrong
2010-01-01  9:27           ` Ingo Molnar
2009-12-31  2:58     ` Xiao Guangrong
2009-12-31  0:53   ` Frank Ch. Eigler
  -- strict thread matches above, loose matches on Subject: below --
2009-12-30 22:09 H. Peter Anvin
2009-12-30  3:15 [PATCH 0/3] perf_event: fix getting symbol error if kernel is relocatable Xiao Guangrong
2009-12-30  3:16 ` [PATCH 1/3] x86: record relocation offset Xiao Guangrong
2009-12-30 13:15   ` Arnaldo Carvalho de Melo
2009-12-30 19:45     ` H. Peter Anvin
2009-12-30 20:39       ` Arnaldo Carvalho de Melo
2009-12-30 21:58         ` Arnaldo Carvalho de Melo
2009-12-30 22:22           ` James Bottomley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox